TabWidget 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef OSGUI_TABWIDGET
  14. #define OSGUI_TABWIDGET
  15. #include <osgUI/Popup>
  16. #include <osg/Switch>
  17. #include <osgText/Text>
  18. namespace osgUI
  19. {
  20. class OSGUI_EXPORT Tab : public osg::Object
  21. {
  22. public:
  23. Tab() {}
  24. Tab(const std::string& str) : _text(str) {}
  25. Tab(const Tab& item, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(item,copyop), _text(item._text) {}
  26. META_Object(osgUI, Tab);
  27. void setText(const std::string& text) { _text = text; }
  28. std::string& getText() { return _text; }
  29. const std::string& getText() const { return _text; }
  30. void setWidget(osgUI::Widget* widget) { _widget = widget; }
  31. osgUI::Widget* getWidget() { return _widget.get(); }
  32. const osgUI::Widget* getWidget() const { return _widget.get(); }
  33. protected:
  34. virtual ~Tab() {}
  35. std::string _text;
  36. osg::ref_ptr<osgUI::Widget> _widget;
  37. };
  38. class OSGUI_EXPORT TabWidget : public osgUI::Widget
  39. {
  40. public:
  41. TabWidget();
  42. TabWidget(const TabWidget& combobox, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  43. META_Node(osgUI, TabWidget);
  44. void addTab(Tab* item) { _tabs.push_back(item); dirty(); }
  45. void setTab(unsigned int i, Tab* item) { _tabs[i] = item; dirty(); }
  46. Tab* getTab(unsigned int i) { return _tabs[i].get(); }
  47. const Tab* getTab(unsigned int i) const { return _tabs[i].get(); }
  48. void clear() { _tabs.clear(); dirty(); }
  49. void removeTab(unsigned int i) { _tabs.erase(_tabs.begin()+i); dirty(); }
  50. unsigned int getNumTabs() { return static_cast<unsigned int>(_tabs.size()); }
  51. typedef std::vector< osg::ref_ptr<Tab> > Tabs;
  52. void setTabs(const Tabs& items) { _tabs = items; }
  53. Tabs& getTabs() { return _tabs; }
  54. const Tabs& getTabs() const { return _tabs; }
  55. void setCurrentIndex(unsigned int i);
  56. unsigned int getCurrentIndex() const { return _currentIndex; }
  57. virtual void currrentIndexChanged(unsigned int i);
  58. virtual void currentIndexChangedImplementation(unsigned int i);
  59. virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
  60. virtual void createGraphicsImplementation();
  61. virtual void enterImplementation();
  62. virtual void leaveImplementation();
  63. protected:
  64. virtual ~TabWidget() {}
  65. void _activateWidgets();
  66. osg::Node* _createTabFrame(const osg::BoundingBox& extents, osgUI::FrameSettings* fs, const osg::Vec4& color);
  67. osg::Node* _createTabHeader(const osg::BoundingBox& extents, osgUI::FrameSettings* fs, const osg::Vec4& color);
  68. Tabs _tabs;
  69. unsigned int _currentIndex;
  70. osg::ref_ptr<osg::Switch> _inactiveHeaderSwitch;
  71. osg::ref_ptr<osg::Switch> _activeHeaderSwitch;
  72. osg::ref_ptr<osg::Switch> _tabWidgetSwitch;
  73. };
  74. }
  75. #endif