Saturday, April 07, 2007

User Interfaces are GO!

So, yesterday I started working on the user interface code. I thought it over a bit, and came to the conclusion I would go with the "Everything is a window" approach. The reason for this was so that I could make the WindowManager class a Task, shove it into my engine, and forget about it.

However, it made me think later on: What if you're playing an FPS, and everything is a window? Then there might be a chance that you have your comm. window open while laying an ambush. You suddenly see an enemy walk around the corner. He hasn't seen you yet, so you jump up, aim at his head and hit left mouse. But instead of shooting him the head, you'll order a pizza from the comm. window, and end up dead yourself. Oops, comm. window stole the cursor focus.

So, before I managed to mess everything up, I changed it all to be "not-everything-is-a-window", and non-task. Basically, I have to keep track of the WindowManager now, and during each update cycle check if the mouse is over a window, and then ignore the input in the regular game handler. When it's not over a window, I do my normal mouse logic. In the case of the FPS, it would mean I have to press a special button before I'm able to interact with the UI.

Right now, basics are in, that is: I have the WindowManager, basic flat-style windows and response from the windows from the mouse. As seen in this exciting image(I merged to images together, because having 2 huge black images with 4 colored squares is boring).


Basically, I clicked on the blue window, and it came Top-Most. Exciting huh? Indeed, it's not...

Before I started to work on the gooey system, I also updated my mouse input code a bit. It no longer uses DirectInput but regular Mouse Events. This has the added advantage of that I have the mouse acceleration that Windows provides for me(Before, the Windows mouse would move faster than the in-game mouse. That's now fixed.). Also, the Windows mouse cursor is now hidden. I have no idea what kept me from doing Cursor.Hide() in the first place...

Tomorrow and monday it is easter(Yes, we have 2 easter days), so I doubt I'll manage to do any work on the gooey system. But, I'm currently writing the mouse-event cascading system. Meaning: When the mouse is over a certain window, this window will check for any updates(movement, etc.) and trigger the events, and then see if any of it's children need to know about the mouse update. I started out with this code to be in the WindowManager, but that ended up being a horrible mess. So I now leave this to the base Control class.

1 comment:

Anonymous said...

thats a pretty nice stuff will this be an open-source?