Trick: Working with Gosu
I recently played a bunch of refactorings on my project(Bakery), because i had to introduce a flow.
Gosu actually enforces one window per process, so if you have 2 windows, the other one freezes…. There is no hack around that…
So here is what i did to accomplish the wizard like flow.
I pulled a BaseWindow(which is a subclass of Gosu::Window) out of my implementation, and i started going with something called BakeryWindow, which is a pure ruby class, having an accessor to set the window into it(Why did i not receive it in the constructor???, thats because i have other problems…. the whole object graph has to be serialized and persisted, i will talk about it in another post after this one).
Now the simple thing i do is allow my Windows to dictate any size they want to be, and have a REL method, (Relative) which does the calculation of the relative coordinates absolute being the Gosu::Window (0, 0) top left corner(NOTE that a Gosu::Window does not let you change the dimensions). And the content that i want rendered @ (20, 30) in my BakeryWindow instance, which of the size 200×300, rendering over an actual window which is 1024×768, will actually render @ (20, 30) relative to the origin of my window, rather than the Gosu::Window and my window will be rendered at the center of the Gosu::Window. Which saves me the trouble of closing and opening the windows, worrying about resource sharing, windows freezing and every other problem AND it doesn’t look all that bad(even within a big window).
Check out bakery_wizard.rb from Bakery. Feel free to reuse the code if you are facing the same problem… :-)