Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Samples/Compositor/src/ItemSelectorViewManager.cpp @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 4.5 KB
RevLine 
[1]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL like the rest of the engine.
12-----------------------------------------------------------------------------
13*/
14
15#include <CEGUI/CEGUIPropertyHelper.h>
16
17#include "OgreStringConverter.h"
18#include "ItemSelectorViewManager.h"
19
20//-----------------------------------------------------------------------------------
21// ItemSelectorViewManager Methods
22//-----------------------------------------------------------------------------------
23#define WIDGET_XPOS 0.0
24#define WIDGET_YSTART 0.1f
25#define WIDGET_YOFFSET 0.13f
26#define ITEM_YSIZE 15
27#define ITEM_YSPACING 2
28
29    ItemSelectorViewManager::ItemSelectorViewManager(const Ogre::String& parentWindowName)
30        : mItemSelectorController(0)
31    {
32        mParentWindow = CEGUI::WindowManager::getSingleton().getWindow(parentWindowName);
33        // add a scrollable pane as a child to the parent
34        mScrollablePane = (CEGUI::ScrollablePane*)CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/ScrollablePane",
35                                    ("MainScrollPane"));
36        mScrollablePane->setHorizontalAlignment(CEGUI::HA_CENTRE);
37        mScrollablePane->setSize(CEGUI::UVector2(CEGUI::UDim(0.9, 0), CEGUI::UDim(0.75, 0)));
38        mParentWindow->addChildWindow(mScrollablePane);
39        mScrollablePane->setPosition(CEGUI::UVector2(CEGUI::UDim(WIDGET_XPOS, 0), CEGUI::UDim(WIDGET_YSTART, 0)));
40        // setup scrollable pane to resize to inside of parent window when parent resizes
41        // scrollbars should only become visible when required
42        // automatically handled by scrollable pane
43    }
44//-----------------------------------------------------------------------------------
45    void ItemSelectorViewManager::addItemSelector(const Ogre::String& displayText)
46    {
47        // add a new item selector
48        // determine new index for item
49        assert(mScrollablePane);
50        const size_t idx = mItemSelectorContainer.size();
51        mItemSelectorContainer.push_back(ItemSelector());
52        ItemSelector& item = mItemSelectorContainer.back();
53        // create new checkbox
54        CEGUI::Checkbox* checkbox = item.CheckBoxWidget = (CEGUI::Checkbox*)CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Checkbox",
55                                    ( ("ItemCheckbox" + Ogre::StringConverter::toString(idx)).c_str() ));
56        // set checkbox ID to selector ID
57        checkbox->setID(idx);
58        checkbox->setSize(CEGUI::UVector2(CEGUI::UDim(0, 140), CEGUI::UDim(0, ITEM_YSIZE)));
59        checkbox->setText(displayText.c_str());
60        checkbox->setProperty("HoverTextColour", CEGUI::PropertyHelper::colourToString(CEGUI::colour(1.0, 1.0, 0.0)));
61        // add event handler for when checkbox state changes
62        checkbox->subscribeEvent(CEGUI::Checkbox::EventCheckStateChanged, CEGUI::Event::Subscriber(&ItemSelectorViewManager::handleCheckStateChanged, this ));
63        checkbox->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0), CEGUI::UDim(0, 12 + (ITEM_YSIZE + ITEM_YSPACING)* static_cast<float>(idx))));
64        // add checkbox to the scroll pane
65        mScrollablePane->addChildWindow(checkbox);
66    }
67//-----------------------------------------------------------------------------------
68    void ItemSelectorViewManager::setItemSelectorController(ItemSelectorInterface* controller)
69    {
70        mItemSelectorController = controller;
71    }
72//-----------------------------------------------------------------------------------
73    bool ItemSelectorViewManager::handleCheckStateChanged(const CEGUI::EventArgs& e)
74    {
75        // activate controller if set
76        if (mItemSelectorController)
77        {
78            CEGUI::Checkbox* checkbox = static_cast<CEGUI::Checkbox*>(
79                static_cast<const CEGUI::WindowEventArgs&>(e).window);
80            mItemSelectorController->itemStateChanged(checkbox->getID(), checkbox->isSelected());
81            float selectColour = checkbox->isSelected() ? 0.0f : 1.0f;
82            checkbox->setProperty("NormalTextColour",
83                CEGUI::PropertyHelper::colourToString(CEGUI::colour(selectColour, 1.0f, selectColour)));
84        }
85        return true;
86    }
Note: See TracBrowser for help on using the repository browser.