Difference between revisions of "Dialog System"
(→WindowSystem.h) |
|||
Line 2: | Line 2: | ||
==== Explanation ==== | ==== Explanation ==== | ||
− | The DemoSample class is the "main" application. It initializes CEGUI and loads a simple layout. It then initialises instances of the SimpleWindow and the SimpleDialog classes. These contain the specific code to handle the behavior of the Simple Window and the Simple Dialog. In turn they rely on the behaviors define within the | + | The DemoSample class is the "main" application. It initializes CEGUI and loads a simple layout. It then initialises instances of the SimpleWindow and the SimpleDialog classes. These contain the specific code to handle the behavior of the Simple Window and the Simple Dialog. In turn they rely on the behaviors define within the DialogSystem class to activate higher level features. |
− | The | + | The DialogSystem class implements the behavior of the 'Ok', 'Cancel', and 'Apply' buttons that we've become accustomed to in the world of Windows. The DialogSystem::DialogSystemEvents enumaration defines the high level events supported by the DialogSystem class: |
open: display the window and its data | open: display the window and its data | ||
ok: save the data and close the window | ok: save the data and close the window | ||
Line 18: | Line 18: | ||
doClose(): hide the window | doClose(): hide the window | ||
− | The SimpleWindow class will manage everything that has to do with the Simple Window. The initWindow() function initialises the | + | The SimpleWindow class will manage everything that has to do with the Simple Window. The initWindow() function initialises the DialogSystem by specifying the handle of the window/dialog (the name specified within the layout file) and whether it should initially be visible or not. Then it instructs the DialogSystem to handle four events as well as which action to initiate in response to these events: |
1) Pressing the "Toolbar_btnSimpleWindow" button opens the SimpleWindow. | 1) Pressing the "Toolbar_btnSimpleWindow" button opens the SimpleWindow. | ||
2) Pressing the "SimpleWindow_btnClose" button performs an 'Ok', saving the data and closing the window. | 2) Pressing the "SimpleWindow_btnClose" button performs an 'Ok', saving the data and closing the window. | ||
Line 26: | Line 26: | ||
The SimpleWindow class then overrides the doLoad() virtual function to place the contents of a variable (dataString) into its associated Editbox. It also overrides the doSave() virtual function to place the contents of the Editbox back into the variable. | The SimpleWindow class then overrides the doLoad() virtual function to place the contents of a variable (dataString) into its associated Editbox. It also overrides the doSave() virtual function to place the contents of the Editbox back into the variable. | ||
− | The SimpleDialog class replicates many of what the SimpleWindow performed. The first difference is that it specifies the handle of a parent window. This signals the | + | The SimpleDialog class replicates many of what the SimpleWindow performed. The first difference is that it specifies the handle of a parent window. This signals the DialogSystem class that when the Simple Dialog is opened it should disable its parent, making the Simple Dialog modal; inputs to the parent are blocked while this dialog is opened. |
− | The second difference is the addition of an apply button. This apply button requires that two events be specified. The event of clicking on the apply button "SimpleDialog_btnApply" is bound to the high level event of | + | The second difference is the addition of an apply button. This apply button requires that two events be specified. The event of clicking on the apply button "SimpleDialog_btnApply" is bound to the high level event of DialogSystem::apply, which will call upon doSave() to move the widget data into the variables. Text changes within the edit box "SimpleDialog_edtValue" are also bound to the high level event of DialogSystem::modified, which will enable the apply button whenever the contents of the edit box are modified. If there were additional widgets within the window then their 'modified' events would also need to be specified. |
CEGUI has more widgets than an Editbox. These can easily be incorporated within the logic presented here. | CEGUI has more widgets than an Editbox. These can easily be incorporated within the logic presented here. | ||
Line 42: | Line 42: | ||
#include "CEGUI.h" | #include "CEGUI.h" | ||
#include "DemoUtils.h" | #include "DemoUtils.h" | ||
− | #include " | + | #include "DialogSystem.h" |
− | class SimpleWindow : public | + | class SimpleWindow : public DialogSystem |
{ | { | ||
public: | public: | ||
Line 53: | Line 53: | ||
// Initialise the windowing system | // Initialise the windowing system | ||
− | + | DialogSystem::initialise("winSimpleWindow", // The handle of this window | |
false); // Initially invisible | false); // Initially invisible | ||
// A modeless window does not have a parent | // A modeless window does not have a parent | ||
Line 59: | Line 59: | ||
// Subscribe to widget events | // Subscribe to widget events | ||
// Note that the "close" button is set to behave as an "ok" button | // Note that the "close" button is set to behave as an "ok" button | ||
− | + | DialogSystem::bindEvent( "Toolbar_btnSimpleWindow", PushButton::EventClicked, DialogSystem::open); | |
− | + | DialogSystem::bindEvent( "SimpleWindow_btnClose", PushButton::EventClicked, DialogSystem::ok); | |
// Subscribe to window events | // Subscribe to window events | ||
− | + | DialogSystem::bindEvent("winSimpleWindow", FrameWindow::EventCloseClicked, DialogSystem::cancel); // The 'X' button was clicked | |
− | + | DialogSystem::bindEvent("winSimpleWindow", FrameWindow::EventKeyDown, DialogSystem::escape); // The 'escape' key was pressed | |
} | } | ||
protected: | protected: | ||
Line 71: | Line 71: | ||
// Handle the load action by placing data into widgets | // Handle the load action by placing data into widgets | ||
CEGUI::WindowManager::getSingleton().getWindow("SimpleWindow_edtValue")->setText(dataString); | CEGUI::WindowManager::getSingleton().getWindow("SimpleWindow_edtValue")->setText(dataString); | ||
− | return | + | return DialogSystem::doLoad(); |
} | } | ||
bool doSave() | bool doSave() | ||
Line 77: | Line 77: | ||
// Handle the save action by moving widget data into variables | // Handle the save action by moving widget data into variables | ||
dataString = CEGUI::WindowManager::getSingleton().getWindow("SimpleWindow_edtValue")->getText(); | dataString = CEGUI::WindowManager::getSingleton().getWindow("SimpleWindow_edtValue")->getText(); | ||
− | return | + | return DialogSystem::doSave(); |
} | } | ||
private: | private: | ||
Line 85: | Line 85: | ||
////////////////////////////////////////////// | ////////////////////////////////////////////// | ||
− | class SimpleDialog : public | + | class SimpleDialog : public DialogSystem |
{ | { | ||
public: | public: | ||
Line 95: | Line 95: | ||
// Initialise the windowing system | // Initialise the windowing system | ||
− | + | DialogSystem::initialise("dlgSimpleDialog", // The handle of this window | |
false, // Initially invisible | false, // Initially invisible | ||
"winToolbar"); // The handle of its parent, making it a modal dialog | "winToolbar"); // The handle of its parent, making it a modal dialog | ||
// Subscribe to widget events | // Subscribe to widget events | ||
− | + | DialogSystem::bindEvent( "Toolbar_btnSimpleDialog", PushButton::EventClicked, DialogSystem::open); | |
− | + | DialogSystem::bindEvent( "SimpleDialog_btnOk", PushButton::EventClicked, DialogSystem::ok); | |
− | + | DialogSystem::bindEvent( "SimpleDialog_btnCancel", PushButton::EventClicked, DialogSystem::cancel); | |
− | + | DialogSystem::bindEvent( "SimpleDialog_btnApply", PushButton::EventClicked, DialogSystem::apply); | |
// These events trigger a 'modified' event, activating the 'apply' button | // These events trigger a 'modified' event, activating the 'apply' button | ||
− | + | DialogSystem::bindEvent( "SimpleDialog_edtValue", Editbox::EventTextChanged, DialogSystem::modified); | |
// Subscribe to window events | // Subscribe to window events | ||
// Pressing the 'X' button will behave as a cancel | // Pressing the 'X' button will behave as a cancel | ||
− | + | DialogSystem::bindEvent( "dlgSimpleDialog", FrameWindow::EventCloseClicked, DialogSystem::cancel); // The 'X' button was clicked | |
− | + | DialogSystem::bindEvent( "dlgSimpleDialog", FrameWindow::EventKeyDown, DialogSystem::escape); // The 'escape' key was pressed | |
} | } | ||
protected: | protected: | ||
Line 118: | Line 118: | ||
// Handle the load action by placing data into widgets | // Handle the load action by placing data into widgets | ||
CEGUI::WindowManager::getSingleton().getWindow("SimpleDialog_edtValue")->setText(dataString); | CEGUI::WindowManager::getSingleton().getWindow("SimpleDialog_edtValue")->setText(dataString); | ||
− | return | + | return DialogSystem::doLoad(); |
} | } | ||
bool doSave() | bool doSave() | ||
Line 124: | Line 124: | ||
// Handle the save action by moving widget data into variables | // Handle the save action by moving widget data into variables | ||
dataString = CEGUI::WindowManager::getSingleton().getWindow("SimpleDialog_edtValue")->getText(); | dataString = CEGUI::WindowManager::getSingleton().getWindow("SimpleDialog_edtValue")->getText(); | ||
− | return | + | return DialogSystem::doSave(); |
} | } | ||
private: | private: | ||
Line 166: | Line 166: | ||
− | ==== | + | ==== DialogSystem.h ==== |
<pre> | <pre> | ||
− | #ifndef | + | #ifndef _DialogSystem_h_ |
− | #define | + | #define _DialogSystem_h_ |
#include "CEGUI.h" | #include "CEGUI.h" | ||
#include "vector" | #include "vector" | ||
− | class | + | class DialogSystem |
{ | { | ||
public: | public: | ||
− | + | DialogSystem(); | |
− | enum | + | enum DialogSystemEvents { open, ok, cancel, escape, apply, modified }; |
bool isModified(); // Return whether data within the window is modified | bool isModified(); // Return whether data within the window is modified | ||
Line 187: | Line 187: | ||
virtual bool doClose(); // Close the window | virtual bool doClose(); // Close the window | ||
void initialise(const CEGUI::String& window, bool visible, const CEGUI::String& parent = ""); // Initialise the window system | void initialise(const CEGUI::String& window, bool visible, const CEGUI::String& parent = ""); // Initialise the window system | ||
− | void bindEvent(const CEGUI::String& widget, const CEGUI::String& event, | + | void bindEvent(const CEGUI::String& widget, const CEGUI::String& event, DialogSystem::DialogSystemEvents action); // Subscribe to window events |
private: | private: | ||
// Events | // Events | ||
Line 203: | Line 203: | ||
}; | }; | ||
− | #endif // | + | #endif // _DialogSystem_h_ |
</pre> | </pre> | ||
− | ==== | + | ==== DialogSystem.cpp ==== |
<pre> | <pre> | ||
− | #include " | + | #include "DialogSystem.h" |
#include "assert.h" | #include "assert.h" | ||
− | + | DialogSystem::DialogSystem() | |
{ | { | ||
m_modal = false; | m_modal = false; | ||
} | } | ||
− | bool | + | bool DialogSystem::isModified() |
{ | { | ||
// Return whether data within the window is modified | // Return whether data within the window is modified | ||
Line 223: | Line 223: | ||
} | } | ||
− | bool | + | bool DialogSystem::doOpen() |
{ | { | ||
// Open the window | // Open the window | ||
Line 241: | Line 241: | ||
} | } | ||
− | bool | + | bool DialogSystem::doLoad() |
{ | { | ||
// Populate the window widgets with data | // Populate the window widgets with data | ||
Line 253: | Line 253: | ||
} | } | ||
− | bool | + | bool DialogSystem::doSave() |
{ | { | ||
// Update the data with the inputs from the widgets | // Update the data with the inputs from the widgets | ||
Line 264: | Line 264: | ||
} | } | ||
− | bool | + | bool DialogSystem::doClose() |
{ | { | ||
// Close the window | // Close the window | ||
Line 280: | Line 280: | ||
} | } | ||
− | void | + | void DialogSystem::initialise(const CEGUI::String& window, bool visible, const CEGUI::String& parent) |
{ | { | ||
// Initialise the window system | // Initialise the window system | ||
Line 291: | Line 291: | ||
− | void | + | void DialogSystem::bindEvent(const CEGUI::String& widget, const CEGUI::String& widgetEvent, DialogSystemEvents action) |
{ | { | ||
// Subscribe to events | // Subscribe to events | ||
Line 298: | Line 298: | ||
{ | { | ||
case open: | case open: | ||
− | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(& | + | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onOpen, this)); |
break; | break; | ||
case ok: | case ok: | ||
− | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(& | + | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onOk, this)); |
break; | break; | ||
case cancel: | case cancel: | ||
− | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(& | + | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onCancel, this)); |
break; | break; | ||
case escape: | case escape: | ||
− | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(& | + | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onEscape, this)); |
break; | break; | ||
case apply: | case apply: | ||
− | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(& | + | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onApply, this)); |
m_apply = widget; | m_apply = widget; | ||
break; | break; | ||
case modified: | case modified: | ||
if(!m_apply.empty()) | if(!m_apply.empty()) | ||
− | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(& | + | widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onModified, this)); |
break; | break; | ||
} | } | ||
} | } | ||
− | bool | + | bool DialogSystem::onOpen(const CEGUI::EventArgs& e) |
{ | { | ||
// Open the window | // Open the window | ||
Line 326: | Line 326: | ||
} | } | ||
− | bool | + | bool DialogSystem::onOk(const CEGUI::EventArgs& e) |
{ | { | ||
// The 'ok' button was pressed | // The 'ok' button was pressed | ||
Line 333: | Line 333: | ||
} | } | ||
− | bool | + | bool DialogSystem::onCancel(const CEGUI::EventArgs& e) |
{ | { | ||
// The 'cancel' button was pressed | // The 'cancel' button was pressed | ||
Line 340: | Line 340: | ||
} | } | ||
− | bool | + | bool DialogSystem::onEscape(const CEGUI::EventArgs& e) |
{ | { | ||
// The 'escape' key was pressed | // The 'escape' key was pressed | ||
Line 355: | Line 355: | ||
} | } | ||
− | bool | + | bool DialogSystem::onApply(const CEGUI::EventArgs& e) |
{ | { | ||
// The 'apply' button was pressed | // The 'apply' button was pressed | ||
Line 362: | Line 362: | ||
} | } | ||
− | bool | + | bool DialogSystem::onModified(const CEGUI::EventArgs& e) |
{ | { | ||
// A widget within the window was modified | // A widget within the window was modified |
Revision as of 08:22, 1 May 2006
The default CEGUI implementation stores the currently specified values of the widgets such that closing and then reopening a window will redisplay those values. Presented here is a different approach, to allow values to be saved or cancelled.
Contents
Explanation
The DemoSample class is the "main" application. It initializes CEGUI and loads a simple layout. It then initialises instances of the SimpleWindow and the SimpleDialog classes. These contain the specific code to handle the behavior of the Simple Window and the Simple Dialog. In turn they rely on the behaviors define within the DialogSystem class to activate higher level features.
The DialogSystem class implements the behavior of the 'Ok', 'Cancel', and 'Apply' buttons that we've become accustomed to in the world of Windows. The DialogSystem::DialogSystemEvents enumaration defines the high level events supported by the DialogSystem class:
open: display the window and its data ok: save the data and close the window cancel: close the window without saving the data escape: close the window without saving the data apply: save the data without closing the window modified: enable the 'apply' button
These high level events accomplish their jobs through the use of four basic actions:
doOpen(): display the window doLoad(): copy the value of variables into their associated widgets doSave(): copy the value of the widgets into their associated variables doClose(): hide the window
The SimpleWindow class will manage everything that has to do with the Simple Window. The initWindow() function initialises the DialogSystem by specifying the handle of the window/dialog (the name specified within the layout file) and whether it should initially be visible or not. Then it instructs the DialogSystem to handle four events as well as which action to initiate in response to these events: 1) Pressing the "Toolbar_btnSimpleWindow" button opens the SimpleWindow. 2) Pressing the "SimpleWindow_btnClose" button performs an 'Ok', saving the data and closing the window. 3) Clicking on the 'X' button closes the dialog without saving any modifications (cancel). 4) Pressing the 'escape' key closes the dialog without saving any modifications (cancel).
The SimpleWindow class then overrides the doLoad() virtual function to place the contents of a variable (dataString) into its associated Editbox. It also overrides the doSave() virtual function to place the contents of the Editbox back into the variable.
The SimpleDialog class replicates many of what the SimpleWindow performed. The first difference is that it specifies the handle of a parent window. This signals the DialogSystem class that when the Simple Dialog is opened it should disable its parent, making the Simple Dialog modal; inputs to the parent are blocked while this dialog is opened.
The second difference is the addition of an apply button. This apply button requires that two events be specified. The event of clicking on the apply button "SimpleDialog_btnApply" is bound to the high level event of DialogSystem::apply, which will call upon doSave() to move the widget data into the variables. Text changes within the edit box "SimpleDialog_edtValue" are also bound to the high level event of DialogSystem::modified, which will enable the apply button whenever the contents of the edit box are modified. If there were additional widgets within the window then their 'modified' events would also need to be specified.
CEGUI has more widgets than an Editbox. These can easily be incorporated within the logic presented here.
Please post comments or questions on the message board thread for the Windowing System
WindowingSystemDemo.h
#ifndef _WindowingSystemDemo_h_ #define _WindowingSystemDemo_h_ #include "CEGuiSample.h" #include "CEGUI.h" #include "DemoUtils.h" #include "DialogSystem.h" class SimpleWindow : public DialogSystem { public: void initWindow() { // Initialise the window using namespace CEGUI; // Initialise the windowing system DialogSystem::initialise("winSimpleWindow", // The handle of this window false); // Initially invisible // A modeless window does not have a parent // Subscribe to widget events // Note that the "close" button is set to behave as an "ok" button DialogSystem::bindEvent( "Toolbar_btnSimpleWindow", PushButton::EventClicked, DialogSystem::open); DialogSystem::bindEvent( "SimpleWindow_btnClose", PushButton::EventClicked, DialogSystem::ok); // Subscribe to window events DialogSystem::bindEvent("winSimpleWindow", FrameWindow::EventCloseClicked, DialogSystem::cancel); // The 'X' button was clicked DialogSystem::bindEvent("winSimpleWindow", FrameWindow::EventKeyDown, DialogSystem::escape); // The 'escape' key was pressed } protected: bool doLoad() { // Handle the load action by placing data into widgets CEGUI::WindowManager::getSingleton().getWindow("SimpleWindow_edtValue")->setText(dataString); return DialogSystem::doLoad(); } bool doSave() { // Handle the save action by moving widget data into variables dataString = CEGUI::WindowManager::getSingleton().getWindow("SimpleWindow_edtValue")->getText(); return DialogSystem::doSave(); } private: CEGUI::String dataString; // Variable associated with the Editbox }; ////////////////////////////////////////////// class SimpleDialog : public DialogSystem { public: void initWindow() { // Initialise the dialog using namespace CEGUI; WindowManager& winMgr = WindowManager::getSingleton(); // Initialise the windowing system DialogSystem::initialise("dlgSimpleDialog", // The handle of this window false, // Initially invisible "winToolbar"); // The handle of its parent, making it a modal dialog // Subscribe to widget events DialogSystem::bindEvent( "Toolbar_btnSimpleDialog", PushButton::EventClicked, DialogSystem::open); DialogSystem::bindEvent( "SimpleDialog_btnOk", PushButton::EventClicked, DialogSystem::ok); DialogSystem::bindEvent( "SimpleDialog_btnCancel", PushButton::EventClicked, DialogSystem::cancel); DialogSystem::bindEvent( "SimpleDialog_btnApply", PushButton::EventClicked, DialogSystem::apply); // These events trigger a 'modified' event, activating the 'apply' button DialogSystem::bindEvent( "SimpleDialog_edtValue", Editbox::EventTextChanged, DialogSystem::modified); // Subscribe to window events // Pressing the 'X' button will behave as a cancel DialogSystem::bindEvent( "dlgSimpleDialog", FrameWindow::EventCloseClicked, DialogSystem::cancel); // The 'X' button was clicked DialogSystem::bindEvent( "dlgSimpleDialog", FrameWindow::EventKeyDown, DialogSystem::escape); // The 'escape' key was pressed } protected: bool doLoad() { // Handle the load action by placing data into widgets CEGUI::WindowManager::getSingleton().getWindow("SimpleDialog_edtValue")->setText(dataString); return DialogSystem::doLoad(); } bool doSave() { // Handle the save action by moving widget data into variables dataString = CEGUI::WindowManager::getSingleton().getWindow("SimpleDialog_edtValue")->getText(); return DialogSystem::doSave(); } private: CEGUI::String dataString; }; ////////////////////////////////////////// class DemoSample : public CEGuiSample { public: bool initialiseSample() { using namespace CEGUI; try { initDemo("../datafiles/layouts/WindowingSystem.layout"); // Initialise the Simple Window and the Simple Dialog simpleWindow.initWindow(); simpleDialog.initWindow(); } catch(Exception &e) { ErrorMessage(e.getMessage().c_str(), "Error initializing the demo"); } return true; } void cleanupSample(void) { } private: SimpleWindow simpleWindow; SimpleDialog simpleDialog; }; #endif // _WindowingSystemDemo_h_
DialogSystem.h
#ifndef _DialogSystem_h_ #define _DialogSystem_h_ #include "CEGUI.h" #include "vector" class DialogSystem { public: DialogSystem(); enum DialogSystemEvents { open, ok, cancel, escape, apply, modified }; bool isModified(); // Return whether data within the window is modified // Actions virtual bool doOpen(); // Open the window virtual bool doLoad(); // Assign the data into the widgets virtual bool doSave(); // Assign the widgets into the data virtual bool doClose(); // Close the window void initialise(const CEGUI::String& window, bool visible, const CEGUI::String& parent = ""); // Initialise the window system void bindEvent(const CEGUI::String& widget, const CEGUI::String& event, DialogSystem::DialogSystemEvents action); // Subscribe to window events private: // Events bool onOpen(const CEGUI::EventArgs& e); // Open the window bool onOk(const CEGUI::EventArgs& e); // Save the data and close the window bool onCancel(const CEGUI::EventArgs& e); // Close the window bool onEscape(const CEGUI::EventArgs& e); // Close the window bool onApply(const CEGUI::EventArgs& e); // Save the data bool onModified(const CEGUI::EventArgs& e); // A widget in the window has been modified CEGUI::String m_parent; // Handle to the parent CEGUI::String m_window; // Handle to the window CEGUI::String m_apply; // Handle of the apply button bool m_modal; // Whether the window is modal }; #endif // _DialogSystem_h_
DialogSystem.cpp
#include "DialogSystem.h" #include "assert.h" DialogSystem::DialogSystem() { m_modal = false; } bool DialogSystem::isModified() { // Return whether data within the window is modified assert(!m_apply.empty() && "The isModified() function requires that you specify an \"Apply\" button"); return !CEGUI::WindowManager::getSingleton().getWindow(m_apply)->isDisabled(); } bool DialogSystem::doOpen() { // Open the window assert(!m_window.empty() && "You have forgotten to call initialise()"); if(m_modal) { // Displaying a modal window disables its parent assert(!m_parent.empty() && "The value of m_modal or m_parent has become corrupted"); CEGUI::WindowManager::getSingleton().getWindow(m_parent)->setEnabled(false); } // Display the window CEGUI::WindowManager::getSingleton().getWindow(m_window)->setVisible(true); // Load the data into the widgets return doLoad(); } bool DialogSystem::doLoad() { // Populate the window widgets with data // Note that this can also be used to simulate an undo for every widget // present in the window // Disable the apply button since there are no modifications if(!m_apply.empty()) CEGUI::WindowManager::getSingleton().getWindow(m_apply)->setEnabled(false); return true; } bool DialogSystem::doSave() { // Update the data with the inputs from the widgets // Disable the apply button since there are no modifications if(!m_apply.empty()) CEGUI::WindowManager::getSingleton().getWindow(m_apply)->setEnabled(false); return true; } bool DialogSystem::doClose() { // Close the window assert(!m_window.empty() && "You have forgotten to call initialise()"); if(m_modal) { // Closing a modal window enables its parent assert(!m_parent.empty() && "The value of m_modal or m_parent has become corrupted"); CEGUI::WindowManager::getSingleton().getWindow(m_parent)->setEnabled(true); } CEGUI::WindowManager::getSingleton().getWindow(m_window)->setVisible(false); return true; } void DialogSystem::initialise(const CEGUI::String& window, bool visible, const CEGUI::String& parent) { // Initialise the window system // Specifying a parent makes this window modal m_window = window; CEGUI::WindowManager::getSingleton().getWindow(m_window)->setVisible(visible); m_parent = parent; m_modal = !m_parent.empty(); } void DialogSystem::bindEvent(const CEGUI::String& widget, const CEGUI::String& widgetEvent, DialogSystemEvents action) { // Subscribe to events CEGUI::Window* widgetHandle = CEGUI::WindowManager::getSingleton().getWindow(widget); switch(action) { case open: widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onOpen, this)); break; case ok: widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onOk, this)); break; case cancel: widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onCancel, this)); break; case escape: widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onEscape, this)); break; case apply: widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onApply, this)); m_apply = widget; break; case modified: if(!m_apply.empty()) widgetHandle->subscribeEvent(widgetEvent, CEGUI::Event::Subscriber(&DialogSystem::onModified, this)); break; } } bool DialogSystem::onOpen(const CEGUI::EventArgs& e) { // Open the window return doOpen(); } bool DialogSystem::onOk(const CEGUI::EventArgs& e) { // The 'ok' button was pressed // Respond by saving the data and closing the window return doSave() && doClose(); } bool DialogSystem::onCancel(const CEGUI::EventArgs& e) { // The 'cancel' button was pressed // Respond by closing the window without saving the data return doClose(); } bool DialogSystem::onEscape(const CEGUI::EventArgs& e) { // The 'escape' key was pressed // Respond by closing the dialog without saving the data // Note that Win32AppHelper::doDirectInputEvents() intercepts this key // This means that the escape key will NOT reach here const CEGUI::KeyEventArgs& keyArgs = static_cast<const CEGUI::KeyEventArgs&>(e); if(keyArgs.scancode == CEGUI::Key::Escape) { return doClose(); } else return false; } bool DialogSystem::onApply(const CEGUI::EventArgs& e) { // The 'apply' button was pressed // Respond by saving the data without closing the window return doSave(); } bool DialogSystem::onModified(const CEGUI::EventArgs& e) { // A widget within the window was modified // Respond by enabling the 'apply' button CEGUI::WindowManager::getSingleton().getWindow(m_apply)->setEnabled(true); return true; }
WindowingSystem.layout
<?xml version="1.0" encoding="UTF-8"?> <GUILayout> <Window Type="DefaultWindow" Name="Root" > <Property Name="UnifiedAreaRect" Value="{{0.000000,0.000000},{0.000000,0.000000},{1.000000,0.000000},{1.000000,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> <Window Type="TaharezLook/FrameWindow" Name="winToolbar" > <Property Name="AlwaysOnTop" Value="True" /> <Property Name="CaptionColour" Value="00FFFFFF" /> <Property Name="CloseButtonEnabled" Value="False" /> <Property Name="EWSizingCursorImage" Value="set:TaharezLook image:MouseEsWeCursor" /> <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseTarget" /> <Property Name="NESWSizingCursorImage" Value="set:TaharezLook image:MouseNeSwCursor" /> <Property Name="NSSizingCursorImage" Value="set:TaharezLook image:MouseNoSoCursor" /> <Property Name="NWSESizingCursorImage" Value="set:TaharezLook image:MouseNwSeCursor" /> <Property Name="Text" Value="Toolbar" /> <Property Name="TitlebarEnabled" Value="False" /> <Property Name="TitlebarFont" Value="Commonwealth-10" /> <Property Name="UnifiedAreaRect" Value="{{0.248750,0.000000},{0.010001,0.000000},{0.568749,0.000000},{0.081667,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> <Window Type="TaharezLook/Button" Name="Toolbar_btnSimpleWindow" > <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseArrow" /> <Property Name="Text" Value="Simple Window" /> <Property Name="UnifiedAreaRect" Value="{{0.065103,0.000000},{0.227595,0.000000},{0.475554,0.000000},{0.686899,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> <Window Type="TaharezLook/Button" Name="Toolbar_btnSimpleDialog" > <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseArrow" /> <Property Name="Text" Value="Simple Dialog" /> <Property Name="UnifiedAreaRect" Value="{{0.538253,0.000000},{0.227595,0.000000},{0.948703,0.000000},{0.686899,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> </Window> <Window Type="TaharezLook/FrameWindow" Name="winSimpleWindow" > <Property Name="CaptionColour" Value="00FFFFFF" /> <Property Name="EWSizingCursorImage" Value="set:TaharezLook image:MouseEsWeCursor" /> <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseTarget" /> <Property Name="NESWSizingCursorImage" Value="set:TaharezLook image:MouseNeSwCursor" /> <Property Name="NSSizingCursorImage" Value="set:TaharezLook image:MouseNoSoCursor" /> <Property Name="NWSESizingCursorImage" Value="set:TaharezLook image:MouseNwSeCursor" /> <Property Name="Text" Value="Simple Window" /> <Property Name="TitlebarEnabled" Value="True" /> <Property Name="TitlebarFont" Value="Commonwealth-10" /> <Property Name="UnifiedAreaRect" Value="{{0.005000,0.000000},{0.168333,0.000000},{0.420000,0.000000},{0.511666,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> <Window Type="TaharezLook/Button" Name="SimpleWindow_btnClose" > <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseArrow" /> <Property Name="Text" Value="Close" /> <Property Name="UnifiedAreaRect" Value="{{0.688554,0.000000},{0.804855,0.000000},{0.938554,0.000000},{0.943204,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> <Window Type="TaharezLook/StaticText" Name="SimpleWindow_lblValue" > <Property Name="BackgroundImage" Value="set:TaharezLook image:StaticBackdrop" /> <Property Name="BottomFrameImage" Value="set:TaharezLook image:StaticBottom" /> <Property Name="BottomLeftFrameImage" Value="set:TaharezLook image:StaticBottomLeft" /> <Property Name="BottomRightFrameImage" Value="set:TaharezLook image:StaticBottomRight" /> <Property Name="Font" Value="Commonwealth-10" /> <Property Name="LeftFrameImage" Value="set:TaharezLook image:StaticLeft" /> <Property Name="RightFrameImage" Value="set:TaharezLook image:StaticRight" /> <Property Name="Text" Value="Value:" /> <Property Name="TopFrameImage" Value="set:TaharezLook image:StaticTop" /> <Property Name="TopLeftFrameImage" Value="set:TaharezLook image:StaticTopLeft" /> <Property Name="TopRightFrameImage" Value="set:TaharezLook image:StaticTopRight" /> <Property Name="UnifiedAreaRect" Value="{{0.455591,0.000000},{0.430746,0.000000},{0.606068,0.000000},{0.569095,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> <Window Type="TaharezLook/Editbox" Name="SimpleWindow_edtValue" > <Property Name="Font" Value="Commonwealth-10" /> <Property Name="MaxTextLength" Value="1073741823" /> <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseTextBar" /> <Property Name="UnifiedAreaRect" Value="{{0.618241,0.000000},{0.430746,0.000000},{0.970525,0.000000},{0.569095,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> </Window> <Window Type="TaharezLook/FrameWindow" Name="dlgSimpleDialog" > <Property Name="CaptionColour" Value="00FFFFFF" /> <Property Name="EWSizingCursorImage" Value="set:TaharezLook image:MouseEsWeCursor" /> <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseTarget" /> <Property Name="NESWSizingCursorImage" Value="set:TaharezLook image:MouseNeSwCursor" /> <Property Name="NSSizingCursorImage" Value="set:TaharezLook image:MouseNoSoCursor" /> <Property Name="NWSESizingCursorImage" Value="set:TaharezLook image:MouseNwSeCursor" /> <Property Name="Text" Value="Simple Dialog" /> <Property Name="TitlebarEnabled" Value="True" /> <Property Name="TitlebarFont" Value="Commonwealth-10" /> <Property Name="UnifiedAreaRect" Value="{{0.436250,0.000000},{0.165000,0.000000},{0.916249,0.000000},{0.508333,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> <Window Type="TaharezLook/Button" Name="SimpleDialog_btnOk" > <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseArrow" /> <Property Name="Text" Value="Ok" /> <Property Name="UnifiedAreaRect" Value="{{0.173754,0.000000},{0.804855,0.000000},{0.423754,0.000000},{0.943204,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> <Window Type="TaharezLook/Button" Name="SimpleDialog_btnCancel" > <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseArrow" /> <Property Name="Text" Value="Cancel" /> <Property Name="UnifiedAreaRect" Value="{{0.451828,0.000000},{0.804855,0.000000},{0.701828,0.000000},{0.943204,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> <Window Type="TaharezLook/Button" Name="SimpleDialog_btnApply" > <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseArrow" /> <Property Name="Text" Value="Apply" /> <Property Name="UnifiedAreaRect" Value="{{0.731230,0.000000},{0.804855,0.000000},{0.981230,0.000000},{0.943204,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> <Window Type="TaharezLook/Editbox" Name="SimpleDialog_edtValue" > <Property Name="Font" Value="Commonwealth-10" /> <Property Name="MaxTextLength" Value="1073741823" /> <Property Name="MouseCursorImage" Value="set:TaharezLook image:MouseTextBar" /> <Property Name="UnifiedAreaRect" Value="{{0.626093,0.000000},{0.418446,0.000000},{0.971449,0.000000},{0.556795,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> <Window Type="TaharezLook/StaticText" Name="SimpleDialog_lblValue" > <Property Name="BackgroundImage" Value="set:TaharezLook image:StaticBackdrop" /> <Property Name="BottomFrameImage" Value="set:TaharezLook image:StaticBottom" /> <Property Name="BottomLeftFrameImage" Value="set:TaharezLook image:StaticBottomLeft" /> <Property Name="BottomRightFrameImage" Value="set:TaharezLook image:StaticBottomRight" /> <Property Name="LeftFrameImage" Value="set:TaharezLook image:StaticLeft" /> <Property Name="RightFrameImage" Value="set:TaharezLook image:StaticRight" /> <Property Name="Text" Value="Value:" /> <Property Name="TopFrameImage" Value="set:TaharezLook image:StaticTop" /> <Property Name="TopLeftFrameImage" Value="set:TaharezLook image:StaticTopLeft" /> <Property Name="TopRightFrameImage" Value="set:TaharezLook image:StaticTopRight" /> <Property Name="UnifiedAreaRect" Value="{{0.482291,0.000000},{0.418446,0.000000},{0.617709,0.000000},{0.556795,0.000000}}" /> <Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" /> </Window> </Window> </Window> </GUILayout>
main.cpp
#if defined( __WIN32__ ) || defined( _WIN32 ) #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include "windows.h" #endif #include "WindowingSystemDemo.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 { DemoSample app; return app.run(); }