1 /***********************************************************************
2 created:    12/7/2012
3 author:     Lukas E Meindl
4 *************************************************************************/
5 /***************************************************************************
6 *   Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
7 *
8 *   Permission is hereby granted, free of charge, to any person obtaining
9 *   a copy of this software and associated documentation files (the
10 *   "Software"), to deal in the Software without restriction, including
11 *   without limitation the rights to use, copy, modify, merge, publish,
12 *   distribute, sublicense, and/or sell copies of the Software, and to
13 *   permit persons to whom the Software is furnished to do so, subject to
14 *   the following conditions:
15 *
16 *   The above copyright notice and this permission notice shall be
17 *   included in all copies or substantial portions of the Software.
18 *
19 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 *   OTHER DEALINGS IN THE SOFTWARE.
26 ***************************************************************************/
27 #ifndef _Widget_Demo_
28 #define _Widget_Demo_
29 
30 #include "SampleBase.h"
31 
32 #include <vector>
33 #include <map>
34 
35 
36 #include "CEGUI/ForwardRefs.h"
37 
38 class EventHandlerObject;
39 class MyListItem;
40 struct WidgetPropertiesObject;
41 
42 typedef std::vector<MyListItem*> WidgetListType;
43 
44 // Sample class
45 class WidgetDemo : public Sample
46 {
47 public:
48     // method to initialse the samples windows and events.
49     virtual bool initialise(CEGUI::GUIContext* guiContext);
50 
51     void handleWidgetEventFired(const CEGUI::String& eventName, CEGUI::String logMessage);
52 
53     // method to perform any required cleanup operations.
54     virtual void deinitialise();
55 protected:
56     // initialisation helpers
57     void initialiseAvailableWidgetsMap();
58 
59     void addItemToWidgetList(const CEGUI::String& widgetName, WidgetListType &widgetList);
60     void createLayout();
61 
62     void initialiseWidgetInspector(CEGUI::Window* container);
63 
64     void initialiseWidgetPropertiesDisplayWindow(CEGUI::Window* widgetPropertiesInspectionContainer);
65     void initialiseWidgetSelector(CEGUI::Window* container);
66     void initialiseWidgetDisplayWindow();
67     void initialiseEventLights(CEGUI::Window* container);
68     void initialiseWidgetSelectorContainer(CEGUI::Window* widgetSelectorContainer);
69     void initialiseWidgetSelectorListbox();
70     void initialiseBackgroundWindow(CEGUI::Window* background);
71     void initialiseSkinCombobox(CEGUI::Window* container);
72     void initialiseWidgetsEventsLog();
73 
74     void initialiseEventHandlerObjects();
75 
76     void createListContent(CEGUI::Window* root);
77 
78     bool handleSkinSelectionAccepted(const CEGUI::EventArgs& args);
79     bool handleWidgetSelectionChanged(const CEGUI::EventArgs& args);
80 
81     void fillWidgetPropertiesDisplayWindow( CEGUI::Window* widgetWindowRoot );
82     void handleSpecialWindowCases( CEGUI::Window* widgetWindowRoot, CEGUI::String widgetTypeString );
83     CEGUI::Window* retrieveOrCreateWidgetWindow(const CEGUI::String& widgetTypeString, const CEGUI::String& widgetName);
84     bool getWidgetType(CEGUI::String &widgetName, CEGUI::String &widgetTypeString);
85     CEGUI::Window* createWidget(const CEGUI::String &widgetMapping, const CEGUI::String &widgetType);
86 
87     CEGUI::Window* initialiseSpecialWidgets(CEGUI::Window* widgetWindow, const CEGUI::String &widgetType);
88 
89     void initMenubar(CEGUI::Menubar* menuBar);
90     void initRadioButtons(CEGUI::RadioButton* radioButton, CEGUI::Window*& widgetWindow);
91     void initListbox(CEGUI::Listbox* listbox);
92     void initItemListbox(CEGUI::ItemListbox* itemListbox);
93     void initCombobox(CEGUI::Combobox* combobox);
94     void initMultiColumnList(CEGUI::MultiColumnList* multilineColumnList);
95     void subscribeToAllEvents(CEGUI::Window* widgetWindow);
96     void addEventHandlerObjectToMap(CEGUI::String eventName);
97 
98 
99     void logFiredEvent(const CEGUI::String& logMessage);
100 
101     void destroyWidgetWindows();
102     void deinitWidgetListItems();
103 
104     bool handleRenderingEnded(const CEGUI::EventArgs& args);
105     bool handleRootWindowUpdate(const CEGUI::EventArgs& args);
106 
107     void saveWidgetPropertiesToMap(const CEGUI::Window* widgetRoot, const CEGUI::Window* widgetWindow);
108 
109     static const CEGUI::String s_widgetDemoWindowPrefix;
110 
111     CEGUI::GUIContext* d_guiContext;
112 
113     CEGUI::Listbox* d_widgetSelectorListbox;
114     CEGUI::Combobox* d_skinSelectionCombobox;
115     CEGUI::Window* d_widgetDisplayWindow;
116     CEGUI::Window* d_widgetDisplayWindowInnerWindow;
117     CEGUI::Window* d_widgetsEventsLog;
118 
119     CEGUI::Window* d_currentlyDisplayedWidgetRoot;
120 
121     CEGUI::Window* d_windowLightMouseMoveEvent;
122     CEGUI::Window* d_windowLightUpdatedEvent;
123 
124     CEGUI::MultiColumnList* d_widgetPropertiesDisplayWindow;
125 
126     std::map<CEGUI::String, WidgetListType> d_skinListItemsMap;
127     std::map<CEGUI::String, CEGUI::Window*> d_widgetsMap;
128     std::map<CEGUI::String, EventHandlerObject*> d_eventHandlerObjectsMap;
129     std::map<const CEGUI::Window*, WidgetPropertiesObject> d_widgetPropertiesMap;
130 };
131 
132 #endif
133