OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ComboBox.h
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_COMBOBOX
15 #define OSGUI_COMBOBOX
16 
17 #include <osgUI/Popup>
18 #include <osg/Switch>
19 #include <osgText/Text>
20 
21 namespace osgUI
22 {
23 
25 {
26 public:
27 
28  Item() : _color(1.0f,1.0f,1.0f,0.0f) {}
29  Item(const std::string& str) : _text(str), _color(1.0f,1.0f,1.0f,0.0f) {}
30  Item(const std::string& str, const osg::Vec4& col) : _text(str), _color(col) {}
31  Item(const osg::Vec4& col) : _color(col) {}
32 
33  Item(const Item& item, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(item,copyop), _text(item._text), _color(item._color) {}
34 
36 
37  void setText(const std::string& text) { _text = text; }
38  std::string& getText() { return _text; }
39  const std::string& getText() const { return _text; }
40 
41  void setColor(const osg::Vec4f& color) { _color = color; }
42  osg::Vec4f& getColor() { return _color; }
43  const osg::Vec4f& getColor() const { return _color; }
44 
45 protected:
46  virtual ~Item() {}
47 
48  std::string _text;
50 };
51 
53 {
54 public:
55  ComboBox();
56  ComboBox(const ComboBox& combobox, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
58 
59  void addItem(Item* item) { _items.push_back(item); dirty(); }
60 
61  void setItem(unsigned int i, Item* item) { _items[i] = item; dirty(); }
62  Item* getItem(unsigned int i) { return _items[i].get(); }
63  const Item* getItem(unsigned int i) const { return _items[i].get(); }
64 
65  void clear() { _items.clear(); dirty(); }
66  void removeItem(unsigned int i) { _items.erase(_items.begin()+i); dirty(); }
67  unsigned int getNumItems() { return static_cast<unsigned int>(_items.size()); }
68 
69  typedef std::vector< osg::ref_ptr<Item> > Items;
70 
71  void setItems(const Items& items) { _items = items; }
72  Items& getItems() { return _items; }
73  const Items& getItems() const { return _items; }
74 
75  void setCurrentIndex(unsigned int i);
76  unsigned int getCurrentIndex() const { return _currentIndex; }
77 
78  virtual void currrentIndexChanged(unsigned int i);
79  virtual void currentIndexChangedImplementation(unsigned int i);
80 
81 
82  virtual bool handleImplementation(osgGA::EventVisitor* ev, osgGA::Event* event);
83  virtual void createGraphicsImplementation();
84  virtual void enterImplementation();
85  virtual void leaveImplementation();
86 
87 protected:
88  virtual ~ComboBox() {}
89 
90  Items _items;
91  unsigned int _currentIndex;
94 
98 };
99 
100 }
101 
102 #endif
const Item * getItem(unsigned int i) const
Definition: ComboBox.h:63
osg::Vec3d _popupItemSize
Definition: ComboBox.h:93
Item * getItem(unsigned int i)
Definition: ComboBox.h:62
osg::Vec4 _color
Definition: ComboBox.h:49
osg::Vec4f & getColor()
Definition: ComboBox.h:42
Items _items
Definition: ComboBox.h:90
void setText(const std::string &text)
Definition: ComboBox.h:37
Item(const Item &item, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: ComboBox.h:33
osg::ref_ptr< osgUI::Popup > _popup
Definition: ComboBox.h:97
#define META_Node(library, name)
Definition: Node.h:59
Items & getItems()
Definition: ComboBox.h:72
unsigned int _currentIndex
Definition: ComboBox.h:91
void removeItem(unsigned int i)
Definition: ComboBox.h:66
void setItems(const Items &items)
Definition: ComboBox.h:71
void addItem(Item *item)
Definition: ComboBox.h:59
void setItem(unsigned int i, Item *item)
Definition: ComboBox.h:61
osg::ref_ptr< osg::Switch > _backgroundSwitch
Definition: ComboBox.h:96
#define META_Object(library, name)
Definition: Object.h:42
virtual ~ComboBox()
Definition: ComboBox.h:88
void setColor(const osg::Vec4f &color)
Definition: ComboBox.h:41
const osg::Vec4f & getColor() const
Definition: ComboBox.h:43
std::string & getText()
Definition: ComboBox.h:38
std::vector< osg::ref_ptr< Item > > Items
Definition: ComboBox.h:69
Item(const std::string &str)
Definition: ComboBox.h:29
unsigned int getCurrentIndex() const
Definition: ComboBox.h:76
osg::ref_ptr< osg::Switch > _buttonSwitch
Definition: ComboBox.h:95
void clear()
Definition: ComboBox.h:65
std::string _text
Definition: ComboBox.h:48
Item(const std::string &str, const osg::Vec4 &col)
Definition: ComboBox.h:30
virtual ~Item()
Definition: ComboBox.h:46
Item(const osg::Vec4 &col)
Definition: ComboBox.h:31
Definition: AlphaFunc.h:19
const Items & getItems() const
Definition: ComboBox.h:73
unsigned int getNumItems()
Definition: ComboBox.h:67
const std::string & getText() const
Definition: ComboBox.h:39
osg::Vec3d _popupItemOrigin
Definition: ComboBox.h:92
#define OSGUI_EXPORT
Definition: Widget.h:22