1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
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.
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.
14#ifndef OSGUI_TABWIDGET
15#define OSGUI_TABWIDGET
19#include <osgText/Text>
24class OSGUI_EXPORT Tab : public osg::Object
29 Tab(const std::string& str) : _text(str) {}
31 Tab(const Tab& item, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(item,copyop), _text(item._text) {}
33 META_Object(osgUI, Tab);
35 void setText(const std::string& text) { _text = text; }
36 std::string& getText() { return _text; }
37 const std::string& getText() const { return _text; }
39 void setWidget(osgUI::Widget* widget) { _widget = widget; }
40 osgUI::Widget* getWidget() { return _widget.get(); }
41 const osgUI::Widget* getWidget() const { return _widget.get(); }
47 osg::ref_ptr<osgUI::Widget> _widget;
50class OSGUI_EXPORT TabWidget : public osgUI::Widget
54 TabWidget(const TabWidget& combobox, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
55 META_Node(osgUI, TabWidget);
57 void addTab(Tab* item) { _tabs.push_back(item); dirty(); }
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(); }
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()); }
67 typedef std::vector< osg::ref_ptr<Tab> > Tabs;
69 void setTabs(const Tabs& items) { _tabs = items; }
70 Tabs& getTabs() { return _tabs; }
71 const Tabs& getTabs() const { return _tabs; }
73 void setCurrentIndex(unsigned int i);
74 unsigned int getCurrentIndex() const { return _currentIndex; }
76 virtual void currrentIndexChanged(unsigned int i);
77 virtual void currentIndexChangedImplementation(unsigned int i);
80 virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
81 virtual void createGraphicsImplementation();
82 virtual void enterImplementation();
83 virtual void leaveImplementation();
86 virtual ~TabWidget() {}
88 void _activateWidgets();
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);
94 unsigned int _currentIndex;
96 osg::ref_ptr<osg::Switch> _inactiveHeaderSwitch;
97 osg::ref_ptr<osg::Switch> _activeHeaderSwitch;
98 osg::ref_ptr<osg::Switch> _tabWidgetSwitch;