Difference between revisions of "Most important events"
m (Robot: Adding Category:Uncategorised) |
m (Bot: Automated text replacement (-<code>[:space:]?<cpp/>(.*?)</code> +<syntaxhighlight lang="cpp">\1</syntaxhighlight>)) |
||
Line 4: | Line 4: | ||
I'm only going to change the initialiseSample function for each widget + adding some others. | I'm only going to change the initialiseSample function for each widget + adding some others. | ||
====EventGalore.h==== | ====EventGalore.h==== | ||
− | < | + | <syntaxhighlight lang="cpp"> |
#ifndef _EventGalore_h_ | #ifndef _EventGalore_h_ | ||
#define _EventGalore_h_ | #define _EventGalore_h_ | ||
Line 50: | Line 50: | ||
}; | }; | ||
#endif // _EventGalore_h_ | #endif // _EventGalore_h_ | ||
− | </ | + | </syntaxhighlight> |
====main.cpp==== | ====main.cpp==== | ||
− | < | + | <syntaxhighlight lang="cpp"> |
#if defined( __WIN32__ ) || defined( _WIN32 ) | #if defined( __WIN32__ ) || defined( _WIN32 ) | ||
#define WIN32_LEAN_AND_MEAN | #define WIN32_LEAN_AND_MEAN | ||
Line 72: | Line 72: | ||
return app.run(); | return app.run(); | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
===Widgets=== | ===Widgets=== | ||
Line 92: | Line 92: | ||
* EventMouseLeaves - Fired when the mouse leaves the widget. Inherited from Window. | * EventMouseLeaves - Fired when the mouse leaves the widget. Inherited from Window. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
PushButton * pushButton = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Button1")); | PushButton * pushButton = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Button1")); | ||
sheet->addChildWindow(pb); | sheet->addChildWindow(pb); | ||
Line 102: | Line 102: | ||
pushButton->subscribeEvent(PushButton::EventMouseEnters, Event::Subscriber(&EventGalore::onMouseEnters, this)); | pushButton->subscribeEvent(PushButton::EventMouseEnters, Event::Subscriber(&EventGalore::onMouseEnters, this)); | ||
pushButton->subscribeEvent(PushButton::EventMouseLeaves, Event::Subscriber(&EventGalore::onMouseLeaves, this)); | pushButton->subscribeEvent(PushButton::EventMouseLeaves, Event::Subscriber(&EventGalore::onMouseLeaves, this)); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onPushButtonClicked(const CEGUI::EventArgs &e) | bool onPushButtonClicked(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 128: | Line 128: | ||
return true; | return true; | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
====Listbox==== | ====Listbox==== | ||
Line 136: | Line 136: | ||
* EventSelectionChanged - Fired when a or another item has been selected. | * EventSelectionChanged - Fired when a or another item has been selected. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
Listbox * listBox = static_cast<Listbox*>(winMgr.createWindow("TaharezLook/Listbox", "Listbox1")); | Listbox * listBox = static_cast<Listbox*>(winMgr.createWindow("TaharezLook/Listbox", "Listbox1")); | ||
sheet->addChildWindow(listBox); | sheet->addChildWindow(listBox); | ||
Line 152: | Line 152: | ||
listBox->subscribeEvent(Listbox::EventSelectionChanged, Event::Subscriber(&EventGalore::onSelectionChanged, this)); | listBox->subscribeEvent(Listbox::EventSelectionChanged, Event::Subscriber(&EventGalore::onSelectionChanged, this)); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onSelectionChanged(const CEGUI::EventArgs &e) | bool onSelectionChanged(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 164: | Line 164: | ||
return true; | return true; | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
====Checkbox==== | ====Checkbox==== | ||
Line 174: | Line 174: | ||
* EventMouseLeaves - Fired when the mouse moves out of the checkbox. Inherited from Window. | * EventMouseLeaves - Fired when the mouse moves out of the checkbox. Inherited from Window. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
Checkbox * checkBox = static_cast<Checkbox*>(winMgr.createWindow("TaharezLook/Checkbox", "Checkbox1")); | Checkbox * checkBox = static_cast<Checkbox*>(winMgr.createWindow("TaharezLook/Checkbox", "Checkbox1")); | ||
sheet->addChildWindow(checkBox); | sheet->addChildWindow(checkBox); | ||
Line 186: | Line 186: | ||
checkBox->subscribeEvent(Checkbox::EventMouseEnters, Event::Subscriber(&EventGalore::onMouseEnters, this)); | checkBox->subscribeEvent(Checkbox::EventMouseEnters, Event::Subscriber(&EventGalore::onMouseEnters, this)); | ||
checkBox->subscribeEvent(Checkbox::EventMouseLeaves, Event::Subscriber(&EventGalore::onMouseLeaves, this)); | checkBox->subscribeEvent(Checkbox::EventMouseLeaves, Event::Subscriber(&EventGalore::onMouseLeaves, this)); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onCheckStateChanged(const CEGUI::EventArgs &e) | bool onCheckStateChanged(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 226: | Line 226: | ||
} | } | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
This might confuse at first sight. Let me go through this here, in steps. | This might confuse at first sight. Let me go through this here, in steps. | ||
* First, our checkbox is created and our mouse remains still. | * First, our checkbox is created and our mouse remains still. | ||
Line 239: | Line 239: | ||
* EventSelectStateChanged - Fired when the radiobutton has been selected. | * EventSelectStateChanged - Fired when the radiobutton has been selected. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
RadioButton * radioButton = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton", "RadioButton1")); | RadioButton * radioButton = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton", "RadioButton1")); | ||
sheet->addChildWindow(radioButton); | sheet->addChildWindow(radioButton); | ||
Line 262: | Line 262: | ||
radioButton->subscribeEvent(RadioButton::EventSelectStateChanged, Event::Subscriber(&EventGalore::onButton2SelectChanged, this)); | radioButton->subscribeEvent(RadioButton::EventSelectStateChanged, Event::Subscriber(&EventGalore::onButton2SelectChanged, this)); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onButton1SelectChanged(const CEGUI::EventArgs &e) | bool onButton1SelectChanged(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 298: | Line 298: | ||
return true; | return true; | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
====Editbox==== | ====Editbox==== | ||
Line 306: | Line 306: | ||
* EventTextAccepted - Fired when someone has pressed TAB or RETURN, or when someone has clicked another window. | * EventTextAccepted - Fired when someone has pressed TAB or RETURN, or when someone has clicked another window. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
Editbox * editBox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Editbox1")); | Editbox * editBox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Editbox1")); | ||
sheet->addChildWindow(editBox); | sheet->addChildWindow(editBox); | ||
Line 315: | Line 315: | ||
editBox->subscribeEvent(Editbox::EventTextAccepted, Event::Subscriber(&EventGalore::onTextAccepted, this)); | editBox->subscribeEvent(Editbox::EventTextAccepted, Event::Subscriber(&EventGalore::onTextAccepted, this)); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onTextAccepted(const CEGUI::EventArgs &e) | bool onTextAccepted(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 336: | Line 336: | ||
return true; | return true; | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
====MultiLineEditbox==== | ====MultiLineEditbox==== | ||
Line 346: | Line 346: | ||
This widget doesn't have the event TextAccepted, so you'll need to 'apply' the input by a button for example. | This widget doesn't have the event TextAccepted, so you'll need to 'apply' the input by a button for example. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
MultiLineEditbox * multiLineEditbox = static_cast<MultiLineEditbox*>(winMgr.createWindow("TaharezLook/MultiLineEditbox", "MultiEditbox1")); | MultiLineEditbox * multiLineEditbox = static_cast<MultiLineEditbox*>(winMgr.createWindow("TaharezLook/MultiLineEditbox", "MultiEditbox1")); | ||
sheet->addChildWindow(multiLineEditbox); | sheet->addChildWindow(multiLineEditbox); | ||
Line 361: | Line 361: | ||
textWindow->setSize(UVector2(cegui_reldim(0.6f), cegui_reldim(0.1f))); | textWindow->setSize(UVector2(cegui_reldim(0.6f), cegui_reldim(0.1f))); | ||
textWindow->setText("Now edit me!"); | textWindow->setText("Now edit me!"); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onTextChanged(const CEGUI::EventArgs &e) | bool onTextChanged(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 372: | Line 372: | ||
return true; | return true; | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
Notice what happens when you enter text on another line though :) | Notice what happens when you enter text on another line though :) | ||
Line 382: | Line 382: | ||
* EventRollupToggled - Fired when the window gets rolled up, or rolled down. | * EventRollupToggled - Fired when the window gets rolled up, or rolled down. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
FrameWindow * frameWindow = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "FrameWindow1")); | FrameWindow * frameWindow = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "FrameWindow1")); | ||
sheet->addChildWindow(frameWindow) | sheet->addChildWindow(frameWindow) | ||
Line 391: | Line 391: | ||
frameWindow->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventGalore::onCloseClicked, this)); | frameWindow->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventGalore::onCloseClicked, this)); | ||
frameWindow->subscribeEvent(FrameWindow::EventRollupToggled, Event::Subscriber(&EventGalore::onRollupToggled, this)); | frameWindow->subscribeEvent(FrameWindow::EventRollupToggled, Event::Subscriber(&EventGalore::onRollupToggled, this)); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onCloseClicked(const CEGUI::EventArgs &e) | bool onCloseClicked(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 419: | Line 419: | ||
return true; | return true; | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
====ProgressBar==== | ====ProgressBar==== | ||
Line 429: | Line 429: | ||
* EventMouseClick - Fired when someone clicked on the window. Inherited from Window. | * EventMouseClick - Fired when someone clicked on the window. Inherited from Window. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
ProgressBar * progressBar = static_cast<ProgressBar*>(winMgr.createWindow("TaharezLook/ProgressBar", "ProgressBar1")); | ProgressBar * progressBar = static_cast<ProgressBar*>(winMgr.createWindow("TaharezLook/ProgressBar", "ProgressBar1")); | ||
sheet->addChildWindow(progressBar); | sheet->addChildWindow(progressBar); | ||
Line 446: | Line 446: | ||
resultWindow->setProperty("FrameEnabled", "false"); | resultWindow->setProperty("FrameEnabled", "false"); | ||
resultWindow->setProperty("BackgroundEnabled", "false"); | resultWindow->setProperty("BackgroundEnabled", "false"); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onProgressDone(const CEGUI::EventArgs &e) | bool onProgressDone(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 479: | Line 479: | ||
return true; | return true; | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
====Slider==== | ====Slider==== | ||
Line 488: | Line 488: | ||
* EventThumbTrackEnded - Fired when the user stops moving the slider's thumb. Handy when a change causes an CPU expensive operation, because now you only catch the 'final' change. | * EventThumbTrackEnded - Fired when the user stops moving the slider's thumb. Handy when a change causes an CPU expensive operation, because now you only catch the 'final' change. | ||
− | < | + | <syntaxhighlight lang="cpp"> |
Slider * slider = static_cast<Slider*>(winMgr.createWindow("TaharezLook/Slider", "Slider1")); | Slider * slider = static_cast<Slider*>(winMgr.createWindow("TaharezLook/Slider", "Slider1")); | ||
sheet->addChildWindow(slider); | sheet->addChildWindow(slider); | ||
Line 500: | Line 500: | ||
slider->subscribeEvent(Slider::EventProgressChanged, Event::Subscriber(&EventGalore::onSliderChangeEnded, this)); | slider->subscribeEvent(Slider::EventProgressChanged, Event::Subscriber(&EventGalore::onSliderChangeEnded, this)); | ||
− | </ | + | </syntaxhighlight> |
− | < | + | <syntaxhighlight lang="cpp"> |
bool onSliderValueChanged(const CEGUI::EventArgs &e) | bool onSliderValueChanged(const CEGUI::EventArgs &e) | ||
{ | { | ||
Line 530: | Line 530: | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
====Spinner==== | ====Spinner==== |
Revision as of 12:45, 27 February 2011
This article is going to show you the most important and usefull events of each widget.
Contents
Getting started
I'm only going to change the initialiseSample function for each widget + adding some others.
EventGalore.h
#ifndef _EventGalore_h_ #define _EventGalore_h_ #include "CEGuiSample.h" #include "CEGUI.h" class EventGalore : public CEGuiSample { public: bool initialiseSample() { try { using namespace CEGUI; WindowManager& winMgr = WindowManager::getSingleton(); // Load the TaharezLook scheme and set up the default mouse cursor and font SchemeManager::getSingleton().loadScheme("TaharezLook.scheme"); System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow"); if(!FontManager::getSingleton().isFontPresent("Commonwealth-10")) FontManager::getSingleton().createFont("Commonwealth-10.font"); // Set the GUI Sheet Window* sheet = winMgr.createWindow("DefaultWindow", "root_wnd"); System::getSingleton().setGUISheet(sheet); // Place here the code from the widgets, place functions below this function. } catch(CEGUI::Exception &e) { #if defined( __WIN32__ ) || defined( _WIN32 ) MessageBox(NULL, e.getMessage().c_str(), "Error initializing the demo", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else std::cerr << "Error initializing the demo:" << e.getMessage().c_str() << "\n"; #endif } return true; } void cleanupSample(void) { } }; #endif // _EventGalore_h_
main.cpp
#if defined( __WIN32__ ) || defined( _WIN32 ) #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include "windows.h" #endif #include "EventGalore.h" #if defined( __WIN32__ ) || defined( _WIN32 ) int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) #else int main(int argc, char *argv[]) #endif { EventGalore app; return app.run(); }
Widgets
Window
The Window widget is a important baseclass, all widgets inherit this class. It has lots 'n lots of events, where a few are introduced by other widgets, and where many are unimportant. If a event is taken from this Window class, it is mentioned.
- EventDragDropItemEnters - Fired when a drag and drop item floats over the window.
- EventDragDropItemLeaves - Fired when a drag and drop item floats out of the window.
- EventDragDropItemDropped - Fired when the item has been dropped on the window.
PushButton
The button is a simple, expected widget. It contains only one important event, but we are going to add a few more.
- EventClicked - Fired when the button has been clicked.
- EventMouseEnters - Fired when the mouse enters the widget. Inherited from Window.
- EventMouseLeaves - Fired when the mouse leaves the widget. Inherited from Window.
PushButton * pushButton = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Button1")); sheet->addChildWindow(pb); pushButton->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); pushButton->setSize(UVector2(cegui_reldim(0.2f), cegui_reldim(0.08f))); pushButton->setText("Hey! Come here!"); pushButton->subscribeEvent(PushButton::EventClicked, Event::Subscriber(&EventGalore::onPushButtonClicked, this)); pushButton->subscribeEvent(PushButton::EventMouseEnters, Event::Subscriber(&EventGalore::onMouseEnters, this)); pushButton->subscribeEvent(PushButton::EventMouseLeaves, Event::Subscriber(&EventGalore::onMouseLeaves, this));
bool onPushButtonClicked(const CEGUI::EventArgs &e) { // Our button has been clicked! CEGUI::PushButton * pushButton = static_cast<CEGUI::PushButton*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("Button1")); pushButton->setText("We got clicked!"); return true; } bool onMouseEnters(const CEGUI::EventArgs &e) { // Mouse has entered the button. (Hover) CEGUI::PushButton * pushButton = static_cast<CEGUI::PushButton*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("Button1")); pushButton->setText("Now click!"); return true; } bool onMouseLeaves(const CEGUI::EventArgs &e) { // Mouse has left the button. CEGUI::PushButton * pushButton = static_cast<CEGUI::PushButton*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("Button1")); // Back to its original state! pushButton->setText("Hey! Come here!"); return true; }
Listbox
The listbox is a very usefull listing widget. Only has one important event.
- EventSelectionChanged - Fired when a or another item has been selected.
Listbox * listBox = static_cast<Listbox*>(winMgr.createWindow("TaharezLook/Listbox", "Listbox1")); sheet->addChildWindow(listBox); listBox->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); listBox->setSize(UVector2(cegui_reldim(0.4f), cegui_reldim(0.4f))); ListboxTextItem * listBoxItem = new ListboxTextItem("Our very first item.", 1); listBoxItem->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush"); listBox->addItem(listBoxItem); listBoxItem = new ListboxTextItem("Our second item.", 2); listBoxItem->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush"); listBox->addItem(listBoxItem); listBox->subscribeEvent(Listbox::EventSelectionChanged, Event::Subscriber(&EventGalore::onSelectionChanged, this));
bool onSelectionChanged(const CEGUI::EventArgs &e) { // The selection has changed. CEGUI::Listbox * listBox = static_cast<CEGUI::Listbox*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("Listbox1")); // Get the item we selected CEGUI::ListboxItem * selectedItem = listBox->getFirstSelectedItem(); selectedItem->setText("Oh we got selected!"); return true; }
Checkbox
A checkable item useful for boolean(true or false) 'questions'.
- EventCheckStateChanged - Fired when the checkbox got checked or un-checked.
- EventMouseEnters - Fired when the mouse hovers over the checkbox. Inherited from Window.
- EventMouseLeaves - Fired when the mouse moves out of the checkbox. Inherited from Window.
Checkbox * checkBox = static_cast<Checkbox*>(winMgr.createWindow("TaharezLook/Checkbox", "Checkbox1")); sheet->addChildWindow(checkBox); checkBox->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); checkBox->setSize(UVector2(cegui_reldim(0.4f), cegui_reldim(0.1f))); // A question where people can only answer yes or no (true or false) checkBox->setText("Hey! Do you want to be rich?"); checkBox->subscribeEvent(Checkbox::EventCheckStateChanged, Event::Subscriber(&EventGalore::onCheckStateChanged, this)); checkBox->subscribeEvent(Checkbox::EventMouseEnters, Event::Subscriber(&EventGalore::onMouseEnters, this)); checkBox->subscribeEvent(Checkbox::EventMouseLeaves, Event::Subscriber(&EventGalore::onMouseLeaves, this));
bool onCheckStateChanged(const CEGUI::EventArgs &e) { // Our item has been checked or unchecked, update our item accordingly. updateCheckbox(); return true; } bool onMouseEnters(const CEGUI::EventArgs &e) { // The mouse has entered, update the checkbox accordingly. updateCheckbox(); return true; } bool onMouseLeaves(const CEGUI::EventArgs &e) { CEGUI::Checkbox * checkBox = static_cast<CEGUI::Checkbox*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("Checkbox1")); // Reset checkBox->setText("Hey! Do you want to be rich?"); return true; } void updateCheckbox() { CEGUI::Checkbox * checkBox = static_cast<CEGUI::Checkbox*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("Checkbox1")); if (checkBox->isSelected()) { // Our checkbox is selected, so someone has previously said 'yes'. checkBox->setText("Click to choose no!"); } else { // Our item is not selected, so someone hasn't done anything yet, or it has been previously // unchecked. checkBox->setText("Click to choose yes!"); } }
This might confuse at first sight. Let me go through this here, in steps.
- First, our checkbox is created and our mouse remains still.
- Second, the mouse enters the checkbox, updateCheckbox is called. In this case, our checkbox isn't selected by default, so the text becomes 'Click to choose yes!'.
- Third, we click. The onCheckStateChanged function is called, and that function calls updateCheckbox again to instantly change the text again. We have clicked the checkbox, while it wasn't previously checked, this means its checked now. Text becomes 'Click to choose no!'.
- Fourth, we move our mouse away from the checkbox. The onMouseLeaves function is called, where we reset the text to our question.
RadioButton
Similar to Checkbox, only it can be grouped, and once selected, it cannot be unselected (except when another button has been selected). Note, in this case, both functions are called when you click the unselected radiobutton. This is because one is unselected and one is selected.
- EventSelectStateChanged - Fired when the radiobutton has been selected.
RadioButton * radioButton = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton", "RadioButton1")); sheet->addChildWindow(radioButton); radioButton->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); radioButton->setSize(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); radioButton->setText("Yes"); radioButton->setGroupID(0); radioButton->subscribeEvent(RadioButton::EventSelectStateChanged, Event::Subscriber(&EventGalore::onButton1SelectChanged, this)); // To make sure the event is fired. radioButton->setSelected(true); radioButton = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton", "RadioButton2")); sheet->addChildWindow(radioButton); radioButton->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.2f))); radioButton->setSize(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); radioButton->setText("No"); radioButton->setGroupID(0); radioButton->subscribeEvent(RadioButton::EventSelectStateChanged, Event::Subscriber(&EventGalore::onButton2SelectChanged, this));
bool onButton1SelectChanged(const CEGUI::EventArgs &e) { CEGUI::RadioButton * radioButton1 = static_cast<CEGUI::RadioButton*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("RadioButton1")); if (radioButton1->isSelected()) { // This one just got selected. radioButton1->setText("Ok then. Yes it is."); } else { // This one got unselected. Reset it. radioButton1->setText("Yes"); } return true; } bool onButton2SelectChanged(const CEGUI::EventArgs &e) { // We have chosen no. CEGUI::RadioButton * radioButton2 = static_cast<CEGUI::RadioButton*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("RadioButton2")); if (radioButton2->isSelected()) { // This one just got selected. radioButton2->setText("Ok then. No it is."); } else { // This one got unselected. Reset it. radioButton2->setText("No"); } return true; }
Editbox
A simple editable box where text can be entered.
- EventTextAccepted - Fired when someone has pressed TAB or RETURN, or when someone has clicked another window.
Editbox * editBox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Editbox1")); sheet->addChildWindow(editBox); editBox->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); editBox->setSize(UVector2(cegui_reldim(0.4f), cegui_reldim(0.1f))); editBox->setText("Edit me!"); editBox->subscribeEvent(Editbox::EventTextAccepted, Event::Subscriber(&EventGalore::onTextAccepted, this));
bool onTextAccepted(const CEGUI::EventArgs &e) { // Our text has been accepted by either deactivating it or pressing tab or enter. CEGUI::Editbox * editBox = static_cast<CEGUI::Editbox*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("Editbox1")); // So we got the text here, do something with it. Lets just..put the text back in reverse order. CEGUI::String currentText = editBox->getText(); std::string finalString; CEGUI::String::reverse_iterator ppkNode = currentText.rbegin(); CEGUI::String::reverse_iterator ppkEnd = currentText.rend(); for (; ppkNode != ppkEnd; ++ppkNode) { finalString.push_back((*ppkNode)); } editBox->setText(finalString); return true; }
MultiLineEditbox
This widget is pretty much the same as editbox, but allows more lines.
- EventTextChanged - Fired when text has been changed. Inherited from window.
This widget doesn't have the event TextAccepted, so you'll need to 'apply' the input by a button for example.
MultiLineEditbox * multiLineEditbox = static_cast<MultiLineEditbox*>(winMgr.createWindow("TaharezLook/MultiLineEditbox", "MultiEditbox1")); sheet->addChildWindow(multiLineEditbox); multiLineEditbox->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); multiLineEditbox->setSize(UVector2(cegui_reldim(0.3f), cegui_reldim(0.3f))); multiLineEditbox->setText("Now edit me!"); multiLineEditbox->subscribeEvent(MultiLineEditbox::EventTextChanged, Event::Subscriber(&EventGalore::onTextChanged, this)); // This text is going to show the result. Window * textWindow = winMgr.createWindow("TaharezLook/StaticText", "StaticText1"); sheet->addChildWindow(textWindow); textWindow->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.5f))); textWindow->setSize(UVector2(cegui_reldim(0.6f), cegui_reldim(0.1f))); textWindow->setText("Now edit me!");
bool onTextChanged(const CEGUI::EventArgs &e) { CEGUI::WindowManager * winMgr = CEGUI::WindowManager::getSingletonPtr(); CEGUI::MultiLineEditbox * multiLineEditbox = static_cast<CEGUI::MultiLineEditbox*>(winMgr->getWindow("MultiEditbox1")); CEGUI::Window * textWindow = winMgr->getWindow("StaticText1"); textWindow->setText(multiLineEditbox->getText()); return true; }
Notice what happens when you enter text on another line though :)
FrameWindow
This is a window where you usually put your widgets on.
- EventCloseClicked - Fired when the 'X' in the upper right corner is clicked (of the Framewindow).
- EventRollupToggled - Fired when the window gets rolled up, or rolled down.
FrameWindow * frameWindow = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "FrameWindow1")); sheet->addChildWindow(frameWindow) frameWindow->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); frameWindow->setSize(UVector2(cegui_reldim(0.4f), cegui_reldim(0.4f))); frameWindow->setText("Our window"); frameWindow->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventGalore::onCloseClicked, this)); frameWindow->subscribeEvent(FrameWindow::EventRollupToggled, Event::Subscriber(&EventGalore::onRollupToggled, this));
bool onCloseClicked(const CEGUI::EventArgs &e) { // Someone has clicked the upper right 'X'. // We don't HAVE to cast to FrameWindow, as the method we are going to use to close the window // is available in Window, but for the sake of clarity... CEGUI::FrameWindow * frameWindow = static_cast<CEGUI::FrameWindow*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("FrameWindow1")); frameWindow->destroy(); // Note: Dont try to delete the pointer. return true; } bool onRollupToggled(const CEGUI::EventArgs &e) { CEGUI::FrameWindow * frameWindow = static_cast<CEGUI::FrameWindow*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("FrameWindow1")); if (frameWindow->isRolledup()) { frameWindow->setText("Rolled up"); } else { frameWindow->setText("Our window"); } return true; }
ProgressBar
A progress widget.
- EventProgressDone - Fired when the progress bar reaches 100%(1.0f).
- EventProgressChanged - Fired when the progress changes.
- EventMouseClick - Fired when someone clicked on the window. Inherited from Window.
ProgressBar * progressBar = static_cast<ProgressBar*>(winMgr.createWindow("TaharezLook/ProgressBar", "ProgressBar1")); sheet->addChildWindow(progressBar); progressBar->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); progressBar->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim(0.04f))); progressBar->subscribeEvent(ProgressBar::EventProgressDone, Event::Subscriber(&EventGalore::onProgressDone, this)); progressBar->subscribeEvent(ProgressBar::EventProgressChanged, Event::Subscriber(&EventGalore::onProgressChanged, this)); progressBar->subscribeEvent(ProgressBar::EventMouseClick, Event::Subscriber(&EventGalore::onMouseClick, this)); Window * resultWindow = winMgr.createWindow("TaharezLook/StaticText", "StaticText1"); sheet->addChildWindow(resultWindow); resultWindow->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.05f))); resultWindow->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim(0.06f))); resultWindow->setText("Lets start progressing!"); resultWindow->setProperty("FrameEnabled", "false"); resultWindow->setProperty("BackgroundEnabled", "false");
bool onProgressDone(const CEGUI::EventArgs &e) { // The progress bar is full. CEGUI::Window * resultWindow = CEGUI::WindowManager::getSingletonPtr()->getWindow("StaticText1"); resultWindow->setText("We are done!"); return true; } bool onProgressChanged(const CEGUI::EventArgs &e) { // The progress changed. CEGUI::WindowManager * winMgr = CEGUI::WindowManager::getSingletonPtr(); CEGUI::ProgressBar * progressBar = static_cast<CEGUI::ProgressBar*>(winMgr->getWindow("ProgressBar1")); CEGUI::Window * resultWindow = winMgr->getWindow("StaticText1"); float progress = progressBar->getProgress(); int finalProgress = static_cast<int>(progress*100); std::stringstream resultStr; resultStr << "Progress: " << finalProgress << "%"; resultWindow->setText(resultStr.str()); return true; } bool onMouseClick(const CEGUI::EventArgs &e) { CEGUI::ProgressBar * progressBar = static_cast<CEGUI::ProgressBar*>(CEGUI::WindowManager::getSingletonPtr()->getWindow("ProgressBar1")); progressBar->setProgress(progressBar->getProgress() + 0.05f); return true; }
Slider
A widget which accepts input though moving a 'thumb' between a range.
- EventValueChanged - Fired when the slider's thumb has moved one step left or right.
- EventThumbTrackEnded - Fired when the user stops moving the slider's thumb. Handy when a change causes an CPU expensive operation, because now you only catch the 'final' change.
Slider * slider = static_cast<Slider*>(winMgr.createWindow("TaharezLook/Slider", "Slider1")); sheet->addChildWindow(slider); slider->setPosition(UVector2(cegui_reldim(0.1f), cegui_reldim(0.1f))); slider->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim(0.04f))); slider->setMaxValue(1.0f); slider->setClickStep(0.1f); slider->setCurrentValue(0.5f); // Start half way slider->subscribeEvent(Slider::EventValueChanged, Event::Subscriber(&EventGalore::onSliderValueChanged, this)); slider->subscribeEvent(Slider::EventProgressChanged, Event::Subscriber(&EventGalore::onSliderChangeEnded, this));
bool onSliderValueChanged(const CEGUI::EventArgs &e) { // The slider moved. CEGUI::WindowManager * winMgr = CEGUI::WindowManager::getSingletonPtr(); CEGUI::Slider * slider = static_cast<CEGUI::Slider*>(winMgr->getWindow("Slider1")); CEGUI::Window * resultWindow = winMgr->getWindow("StaticText1"); std::stringstream resultStr; resultStr << "Moved to: " << slider->getCurrentValue(); resultWindow->setText(resultStr); return true; } bool onSliderChangeEnded(const CEGUI::EventArgs &e) { // The slider stopped moving (user released mouse) CEGUI::WindowManager * winMgr = CEGUI::WindowManager::getSingletonPtr(); CEGUI::Slider * slider = static_cast<CEGUI::Slider*>(winMgr->getWindow("Slider1")); CEGUI::Window * resultWindow = winMgr->getWindow("StaticText1"); std::stringstream resultStr; resultStr << "Moving stopped at: " << slider->getCurrentValue(); resultWindow->setText(resultStr); return true; }