1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4     (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 Also see acknowledgements in Readme.html
9 
10 You may use this sample code for anything you like, it is not covered by the
11 same license as the rest of the engine.
12 -----------------------------------------------------------------------------
13 */
14 
15 #ifndef _ItemSelectorViewManager_H_
16 #define _ItemSelectorViewManager_H_
17 
18 #include "OgreString.h"
19 
20 #include <CEGUI/CEGUIImageset.h>
21 #include <CEGUI/CEGUISystem.h>
22 #include <CEGUI/CEGUILogger.h>
23 #include <CEGUI/CEGUISchemeManager.h>
24 #include <CEGUI/CEGUIWindowManager.h>
25 #include <CEGUI/CEGUIWindow.h>
26 #include <CEGUI/elements/CEGUICheckbox.h>
27 #include <CEGUI/elements/CEGUICombobox.h>
28 #include <CEGUI/elements/CEGUIListbox.h>
29 #include <CEGUI/elements/CEGUIListboxTextItem.h>
30 #include <CEGUI/elements/CEGUIPushButton.h>
31 #include <CEGUI/elements/CEGUIScrollbar.h>
32 #include <CEGUI/elements/CEGUIScrollablePane.h>
33 
34     /** Provides interface between a View and a Controller.
35     */
36     class ItemSelectorInterface
37     {
38     public:
~ItemSelectorInterface(void)39         virtual ~ItemSelectorInterface(void) {}
40         virtual void itemStateChanged(const size_t index, const bool state) = 0;
41     };
42 
43     /** A generic view for showing checkbox items in a vertical list.  Checkboxes
44         are in a Scrollable pane so items can be scrolled into view.
45     */
46     class ItemSelectorViewManager
47     {
48     public:
49         ItemSelectorViewManager(const Ogre::String& parentWindowName);
~ItemSelectorViewManager(void)50         ~ItemSelectorViewManager(void){}
51 
52         /** Returns number of items in the container.
53         */
getSelectorCount(void)54         size_t getSelectorCount(void) const { return mItemSelectorContainer.size(); }
55         /** iterates through compositors available through CompositorManager and update list
56         */
57         /** Add a new Item selector to the container
58         */
59         void addItemSelector(const Ogre::String& displayText);
getItemSelectorText(const size_t index)60         Ogre::String getItemSelectorText(const size_t index) const
61         {
62             return Ogre::String(mItemSelectorContainer.at(index).CheckBoxWidget->getText().c_str());
63         }
64         /** Inform Manager about who will be the controller that responds to item event messages.
65         */
66         void setItemSelectorController(ItemSelectorInterface* controller);
67 
68     protected:
69         struct ItemSelector
70         {
71             // make use of widget text member to store Compositor name
72             // widget toggle state is used for enable/disable compositor
73             // widget ID used for selector index
74             CEGUI::Checkbox* CheckBoxWidget;
75 
ItemSelectorItemSelector76             ItemSelector() : CheckBoxWidget(0) {}
77         };
78 		typedef Ogre::vector<ItemSelector>::type ItemSelectorContainer;
79         typedef ItemSelectorContainer::iterator ItemSelectorIterator;
80 
81         float mVerticalScrollPosition;
82         CEGUI::Window* mParentWindow;
83         CEGUI::ScrollablePane* mScrollablePane;
84         ItemSelectorInterface* mItemSelectorController;
85 
86         ItemSelectorContainer mItemSelectorContainer;
87 
88     private:
89         bool handleCheckStateChanged(const CEGUI::EventArgs& e);
90 
91     };
92 
93 
94 #endif
95