| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | #include <iostream> |
|---|
| 5 | #include <osgDB/ReadFile> |
|---|
| 6 | #include <osgWidget/Util> |
|---|
| 7 | #include <osgWidget/WindowManager> |
|---|
| 8 | #include <osgWidget/Box> |
|---|
| 9 | #include <osgWidget/Label> |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | const unsigned int MASK_2D = 0xF0000000; |
|---|
| 15 | const unsigned int MASK_3D = 0x0F000000; |
|---|
| 16 | |
|---|
| 17 | struct ColorLabel: public osgWidget::Label { |
|---|
| 18 | ColorLabel(const char* label): |
|---|
| 19 | osgWidget::Label("", "") { |
|---|
| 20 | setFont("fonts/Vera.ttf"); |
|---|
| 21 | setFontSize(14); |
|---|
| 22 | setFontColor(1.0f, 1.0f, 1.0f, 1.0f); |
|---|
| 23 | setColor(0.3f, 0.3f, 0.3f, 1.0f); |
|---|
| 24 | addHeight(18.0f); |
|---|
| 25 | setCanFill(true); |
|---|
| 26 | setLabel(label); |
|---|
| 27 | setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MASK_MOUSE_MOVE); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | bool mousePush(double, double, osgWidget::WindowManager*) { |
|---|
| 31 | return true; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | bool mouseEnter(double, double, osgWidget::WindowManager*) { |
|---|
| 35 | setColor(0.6f, 0.6f, 0.6f, 1.0f); |
|---|
| 36 | |
|---|
| 37 | return true; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | bool mouseLeave(double, double, osgWidget::WindowManager*) { |
|---|
| 41 | setColor(0.3f, 0.3f, 0.3f, 1.0f); |
|---|
| 42 | |
|---|
| 43 | return true; |
|---|
| 44 | } |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | class ColorLabelMenu: public ColorLabel { |
|---|
| 48 | osg::ref_ptr<osgWidget::Window> _window; |
|---|
| 49 | |
|---|
| 50 | public: |
|---|
| 51 | ColorLabelMenu(const char* label): |
|---|
| 52 | ColorLabel(label) { |
|---|
| 53 | _window = new osgWidget::Box( |
|---|
| 54 | std::string("Menu_") + label, |
|---|
| 55 | osgWidget::Box::VERTICAL, |
|---|
| 56 | true |
|---|
| 57 | ); |
|---|
| 58 | |
|---|
| 59 | _window->addWidget(new ColorLabel("Open Some Stuff")); |
|---|
| 60 | _window->addWidget(new ColorLabel("Do It Now")); |
|---|
| 61 | _window->addWidget(new ColorLabel("Hello, How Are U?")); |
|---|
| 62 | _window->addWidget(new ColorLabel("Hmmm...")); |
|---|
| 63 | _window->addWidget(new ColorLabel("Option 5")); |
|---|
| 64 | |
|---|
| 65 | _window->resize(); |
|---|
| 66 | |
|---|
| 67 | setColor(0.8f, 0.8f, 0.8f, 0.8f); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | void managed(osgWidget::WindowManager* wm) { |
|---|
| 71 | osgWidget::Label::managed(wm); |
|---|
| 72 | |
|---|
| 73 | wm->addChild(_window.get()); |
|---|
| 74 | |
|---|
| 75 | _window->hide(); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | void positioned() { |
|---|
| 79 | osgWidget::Label::positioned(); |
|---|
| 80 | |
|---|
| 81 | _window->setOrigin(getX(), getHeight()); |
|---|
| 82 | _window->resize(getWidth()); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | bool mousePush(double, double, osgWidget::WindowManager*) { |
|---|
| 86 | if(!_window->isVisible()) _window->show(); |
|---|
| 87 | |
|---|
| 88 | else _window->hide(); |
|---|
| 89 | |
|---|
| 90 | return true; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | bool mouseLeave(double, double, osgWidget::WindowManager*) { |
|---|
| 94 | if(!_window->isVisible()) setColor(0.8f, 0.8f, 0.8f, 0.8f); |
|---|
| 95 | |
|---|
| 96 | return true; |
|---|
| 97 | } |
|---|
| 98 | }; |
|---|
| 99 | |
|---|
| 100 | int main(int argc, char** argv) { |
|---|
| 101 | osgViewer::Viewer viewer; |
|---|
| 102 | |
|---|
| 103 | osgWidget::WindowManager* wm = new osgWidget::WindowManager( |
|---|
| 104 | &viewer, |
|---|
| 105 | 1280.0f, |
|---|
| 106 | 1024.0f, |
|---|
| 107 | MASK_2D, |
|---|
| 108 | osgWidget::WindowManager::WM_PICK_DEBUG | |
|---|
| 109 | osgWidget::WindowManager::WM_NO_BETA_WARN |
|---|
| 110 | ); |
|---|
| 111 | |
|---|
| 112 | osgWidget::Window* menu = new osgWidget::Box("menu", osgWidget::Box::HORIZONTAL); |
|---|
| 113 | |
|---|
| 114 | menu->addWidget(new ColorLabelMenu("Pick me!")); |
|---|
| 115 | menu->addWidget(new ColorLabelMenu("No, wait, pick me!")); |
|---|
| 116 | menu->addWidget(new ColorLabelMenu("Dont pick them...")); |
|---|
| 117 | menu->addWidget(new ColorLabelMenu("Grarar!?!")); |
|---|
| 118 | |
|---|
| 119 | wm->addChild(menu); |
|---|
| 120 | |
|---|
| 121 | menu->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f); |
|---|
| 122 | menu->resizePercent(100.0f); |
|---|
| 123 | |
|---|
| 124 | osg::Node* model = osgDB::readNodeFile("osgcool.osg"); |
|---|
| 125 | |
|---|
| 126 | model->setNodeMask(MASK_3D); |
|---|
| 127 | |
|---|
| 128 | return osgWidget::createExample(viewer, wm, model); |
|---|
| 129 | } |
|---|