Gui system
Posted: Sat Oct 30, 2010 12:32 pm
I've been working on a gui system for Moosader's "Picking Open Sticks" game, and although it's not too polished and it's kinda lame, I think it's awesome!:D ... so I thought I'll share what I got done so far... maybe get some constructive criticism from other people who made gui systems(or similar stuff) on how they made theirs :D.
Here's basically how it looks like:
I implemented so far a basic widget(which is the base widget - doesn't do much), a label widget(-displays text), a line_edit widget(-you can enter text in it), and a button widget.
Widgets have focusing levels, and when you click on a widget it gets focus, meaning that it is drawn before the other widgets and it receives the keyboard input events!
Also you can move widgets using drag&drop :D.
It works "kinda" like qt does(notice the "" ...) though way lamer. For example if you want to get user input for his name you can make a class UserNameWidget : public Widget, and you add a line_edit widget and a button widget to it. And when the button is clicked you save the text from the line_edit to a string in the UserNameWidget(where it will be accesible), clear the line_edit text and maybe change the game's state to notify the change(or you can have a flag in the class to notify that the user has entered the name )
I didn't implement a slots/signals pattern, I found it rather difficult to do.. so I made a set of virtual functions(which you can reimplement in derived classes) that get called when a event of sorts happens.
here's a code example of how to use it :D
L.E. : The Picking Open Sticks project is available at google code
Here's basically how it looks like:
I implemented so far a basic widget(which is the base widget - doesn't do much), a label widget(-displays text), a line_edit widget(-you can enter text in it), and a button widget.
Widgets have focusing levels, and when you click on a widget it gets focus, meaning that it is drawn before the other widgets and it receives the keyboard input events!
Also you can move widgets using drag&drop :D.
It works "kinda" like qt does(notice the "" ...) though way lamer. For example if you want to get user input for his name you can make a class UserNameWidget : public Widget, and you add a line_edit widget and a button widget to it. And when the button is clicked you save the text from the line_edit to a string in the UserNameWidget(where it will be accesible), clear the line_edit text and maybe change the game's state to notify the change(or you can have a flag in the class to notify that the user has entered the name )
I didn't implement a slots/signals pattern, I found it rather difficult to do.. so I made a set of virtual functions(which you can reimplement in derived classes) that get called when a event of sorts happens.
here's a code example of how to use it :D
Code: Select all
//create a widget
gui::Label label;
//initialize with default image .. or you can use your own image
label.SetDefaultImage();
//set the position of the widget. default = 0,0
label.SetPos(550,0);
//set the alignment of the text --label specific function
label.SetAlignment(gui::Center);
//add the label to the guimanager(*making it a main widget), or to another widget(*making it a child widget)
gui::GuiManager::GetSingleton().AddWidget("label",&label);