Sunday, April 2, 2017

Window Sizing on Windows

Sometimes when you write a piece of code that you think should just work, or return an error, it does neither. As it so happens, sizing a window for an application on Windows is one of those situations.

All three of us at Oakmound use Windows computers, so Oak, while hypothetically compatible with other operating systems, has only ever been tested on Windows as of now. One issue that we've had since the beginning of working on this project relates to this line of code:

 // s is of type shiny/screen.Screen  
 s.NewWindow(&screen.NewWindowOptions{640,480, "Window Title"})  


This code uses Go's built in UI library, shiny, to open up a new window that we can then draw to. It looks like it should open a window that's 640 pixels wide and 480 pixels tall. Until very recently, that was only sort-of true. The window size of the created window was, on some versions of Windows, 640x480, but we were expecting that the client size would be 640x480. The client size of a window is the workable space of the window, without borders given by operating system:

What this meant was if we made our 640x480 window and then tried to draw the player's healthbar at 320x450, it would never show up.

After some experimentation, I discovered that Windows would always reduce the width we were given by 16, and the height by 39, with a minimum size of 120x0. For a quick fix, we increased the dimensions of anything we wanted to create by 16x39, but given we already had reason to distrust Windows we went a little deeper into the issue and raised a issue with golang to resolve the problem.

It turns out, if you really want your client size to be a particular value on Windows, you need to create your window and then immediately resize it, which thankfully shiny now does.

To make sure this doesn't cause issues on other operating systems, we also now scale our internal 640x480 buffer for Agent Blue, which stores all of our active graphics, to whatever size the OS gives us.

No comments:

Post a Comment