| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | #include <osg/io_utils> |
|---|
| 10 | #include <osgDB/ReadFile> |
|---|
| 11 | #include <osgWidget/Util> |
|---|
| 12 | #include <osgWidget/WindowManager> |
|---|
| 13 | #include <osgWidget/Box> |
|---|
| 14 | |
|---|
| 15 | const unsigned int MASK_2D = 0xF0000000; |
|---|
| 16 | const unsigned int MASK_3D = 0x0F000000; |
|---|
| 17 | |
|---|
| 18 | struct ColorWidget: public osgWidget::Widget { |
|---|
| 19 | ColorWidget(): |
|---|
| 20 | osgWidget::Widget("", 256.0f, 256.0f) { |
|---|
| 21 | setEventMask(osgWidget::EVENT_ALL); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | bool mouseEnter(double, double, const osgWidget::WindowManager*) { |
|---|
| 25 | addColor(-osgWidget::Color(0.4f, 0.4f, 0.4f, 0.0f)); |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | return true; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | bool mouseLeave(double, double, const osgWidget::WindowManager*) { |
|---|
| 33 | addColor(osgWidget::Color(0.4f, 0.4f, 0.4f, 0.0f)); |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | return true; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | bool mouseOver(double x, double y, const osgWidget::WindowManager*) { |
|---|
| 41 | |
|---|
| 42 | osgWidget::Color c = getImageColorAtPointerXY(x, y); |
|---|
| 43 | |
|---|
| 44 | if(c.a() < 0.001f) { |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | return false; |
|---|
| 48 | } |
|---|
| 49 | return true; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | bool keyUp(int key, int keyMask, osgWidget::WindowManager*) { |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | return true; |
|---|
| 56 | } |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | osgWidget::Box* createBox(const std::string& name, osgWidget::Box::BoxType bt) { |
|---|
| 60 | osgWidget::Box* box = new osgWidget::Box(name, bt, true); |
|---|
| 61 | osgWidget::Widget* widget1 = new osgWidget::Widget(name + "_widget1", 100.0f, 100.0f); |
|---|
| 62 | osgWidget::Widget* widget2 = new osgWidget::Widget(name + "_widget2", 100.0f, 100.0f); |
|---|
| 63 | osgWidget::Widget* widget3 = new ColorWidget(); |
|---|
| 64 | |
|---|
| 65 | widget1->setColor(0.3f, 0.3f, 0.3f, 1.0f); |
|---|
| 66 | widget2->setColor(0.6f, 0.6f, 0.6f, 1.0f); |
|---|
| 67 | |
|---|
| 68 | widget3->setImage("osgWidget/natascha.png"); |
|---|
| 69 | widget3->setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT); |
|---|
| 70 | widget3->setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT); |
|---|
| 71 | widget3->setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT); |
|---|
| 72 | widget3->setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT); |
|---|
| 73 | |
|---|
| 74 | box->addWidget(widget1); |
|---|
| 75 | box->addWidget(widget2); |
|---|
| 76 | box->addWidget(widget3); |
|---|
| 77 | |
|---|
| 78 | return box; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | int main(int argc, char** argv) { |
|---|
| 82 | osgViewer::Viewer viewer; |
|---|
| 83 | |
|---|
| 84 | osgWidget::WindowManager* wm = new osgWidget::WindowManager( |
|---|
| 85 | &viewer, |
|---|
| 86 | 1280.0f, |
|---|
| 87 | 1024.0f, |
|---|
| 88 | MASK_2D, |
|---|
| 89 | osgWidget::WindowManager::WM_PICK_DEBUG |
|---|
| 90 | ); |
|---|
| 91 | |
|---|
| 92 | wm->setPointerFocusMode(osgWidget::WindowManager::PFM_SLOPPY); |
|---|
| 93 | |
|---|
| 94 | osgWidget::Window* box1 = createBox("HBOX", osgWidget::Box::HORIZONTAL); |
|---|
| 95 | osgWidget::Window* box2 = createBox("VBOX", osgWidget::Box::VERTICAL); |
|---|
| 96 | osgWidget::Window* box3 = createBox("HBOX2", osgWidget::Box::HORIZONTAL); |
|---|
| 97 | osgWidget::Window* box4 = createBox("VBOX2", osgWidget::Box::VERTICAL); |
|---|
| 98 | |
|---|
| 99 | box1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 0.8f); |
|---|
| 100 | box1->attachMoveCallback(); |
|---|
| 101 | |
|---|
| 102 | box2->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.8f); |
|---|
| 103 | box2->attachMoveCallback(); |
|---|
| 104 | |
|---|
| 105 | box3->getBackground()->setColor(0.0f, 0.0f, 1.0f, 0.8f); |
|---|
| 106 | box3->attachMoveCallback(); |
|---|
| 107 | |
|---|
| 108 | wm->addChild(box1); |
|---|
| 109 | wm->addChild(box2); |
|---|
| 110 | wm->addChild(box3); |
|---|
| 111 | wm->addChild(box4); |
|---|
| 112 | |
|---|
| 113 | box4->hide(); |
|---|
| 114 | |
|---|
| 115 | osg::Node* model = osgDB::readNodeFile("spaceship.osgt"); |
|---|
| 116 | |
|---|
| 117 | model->setNodeMask(MASK_3D); |
|---|
| 118 | |
|---|
| 119 | return osgWidget::createExample(viewer, wm, model); |
|---|
| 120 | } |
|---|