openscenegraph
TabWidget
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUI_TABWIDGET
15#define OSGUI_TABWIDGET
16
17#include <osgUI/Popup>
18#include <osg/Switch>
19#include <osgText/Text>
20
21namespace osgUI
22{
23
24class OSGUI_EXPORT Tab : public osg::Object
25{
26public:
27
28 Tab() {}
29 Tab(const std::string& str) : _text(str) {}
30
31 Tab(const Tab& item, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(item,copyop), _text(item._text) {}
32
33 META_Object(osgUI, Tab);
34
35 void setText(const std::string& text) { _text = text; }
36 std::string& getText() { return _text; }
37 const std::string& getText() const { return _text; }
38
39 void setWidget(osgUI::Widget* widget) { _widget = widget; }
40 osgUI::Widget* getWidget() { return _widget.get(); }
41 const osgUI::Widget* getWidget() const { return _widget.get(); }
42
43protected:
44 virtual ~Tab() {}
45
46 std::string _text;
47 osg::ref_ptr<osgUI::Widget> _widget;
48};
49
50class OSGUI_EXPORT TabWidget : public osgUI::Widget
51{
52public:
53 TabWidget();
54 TabWidget(const TabWidget& combobox, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
55 META_Node(osgUI, TabWidget);
56
57 void addTab(Tab* item) { _tabs.push_back(item); dirty(); }
58
59 void setTab(unsigned int i, Tab* item) { _tabs[i] = item; dirty(); }
60 Tab* getTab(unsigned int i) { return _tabs[i].get(); }
61 const Tab* getTab(unsigned int i) const { return _tabs[i].get(); }
62
63 void clear() { _tabs.clear(); dirty(); }
64 void removeTab(unsigned int i) { _tabs.erase(_tabs.begin()+i); dirty(); }
65 unsigned int getNumTabs() { return static_cast<unsigned int>(_tabs.size()); }
66
67 typedef std::vector< osg::ref_ptr<Tab> > Tabs;
68
69 void setTabs(const Tabs& items) { _tabs = items; }
70 Tabs& getTabs() { return _tabs; }
71 const Tabs& getTabs() const { return _tabs; }
72
73 void setCurrentIndex(unsigned int i);
74 unsigned int getCurrentIndex() const { return _currentIndex; }
75
76 virtual void currrentIndexChanged(unsigned int i);
77 virtual void currentIndexChangedImplementation(unsigned int i);
78
79
80 virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
81 virtual void createGraphicsImplementation();
82 virtual void enterImplementation();
83 virtual void leaveImplementation();
84
85protected:
86 virtual ~TabWidget() {}
87
88 void _activateWidgets();
89
90 osg::Node* _createTabFrame(const osg::BoundingBox& extents, osgUI::FrameSettings* fs, const osg::Vec4& color);
91 osg::Node* _createTabHeader(const osg::BoundingBox& extents, osgUI::FrameSettings* fs, const osg::Vec4& color);
92
93 Tabs _tabs;
94 unsigned int _currentIndex;
95
96 osg::ref_ptr<osg::Switch> _inactiveHeaderSwitch;
97 osg::ref_ptr<osg::Switch> _activeHeaderSwitch;
98 osg::ref_ptr<osg::Switch> _tabWidgetSwitch;
99};
100
101}
102
103#endif