| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | #include <osg/io_utils> |
|---|
| 5 | #include <osgGA/TrackballManipulator> |
|---|
| 6 | #include <osgGA/StateSetManipulator> |
|---|
| 7 | #include <osgViewer/ViewerEventHandlers> |
|---|
| 8 | #include <osgWidget/Util> |
|---|
| 9 | #include <osgWidget/WindowManager> |
|---|
| 10 | #include <osgWidget/Box> |
|---|
| 11 | #include <osgWidget/Canvas> |
|---|
| 12 | #include <osgWidget/Label> |
|---|
| 13 | #include <osgWidget/Label> |
|---|
| 14 | #include <osgWidget/ViewerEventHandlers> |
|---|
| 15 | |
|---|
| 16 | const unsigned int MASK_2D = 0xF0000000; |
|---|
| 17 | const unsigned int MASK_3D = 0x0F000000; |
|---|
| 18 | |
|---|
| 19 | class Notebook: public osgWidget::Box { |
|---|
| 20 | osg::ref_ptr<osgWidget::Box> _tabs; |
|---|
| 21 | osg::ref_ptr<osgWidget::Canvas> _windows; |
|---|
| 22 | |
|---|
| 23 | public: |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | bool callbackTabPressed(osgWidget::Event& ev) { |
|---|
| 27 | osgWidget::Canvas::Vector& objs = _windows->getObjects(); |
|---|
| 28 | |
|---|
| 29 | for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer( |
|---|
| 30 | osgWidget::Widget::LAYER_MIDDLE, |
|---|
| 31 | i * 2 |
|---|
| 32 | ); |
|---|
| 33 | |
|---|
| 34 | _windows->getByName(ev.getWidget()->getName())->setLayer( |
|---|
| 35 | osgWidget::Widget::LAYER_MIDDLE, |
|---|
| 36 | objs.size() * 2 |
|---|
| 37 | ); |
|---|
| 38 | |
|---|
| 39 | _windows->resize(); |
|---|
| 40 | |
|---|
| 41 | return true; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | Notebook(const std::string& name): |
|---|
| 45 | osgWidget::Box(name, osgWidget::Box::VERTICAL) { |
|---|
| 46 | _tabs = new osgWidget::Box("tabs", osgWidget::Box::HORIZONTAL); |
|---|
| 47 | _windows = new osgWidget::Canvas("canvas"); |
|---|
| 48 | |
|---|
| 49 | for(unsigned int i = 0; i < 4; i++) { |
|---|
| 50 | std::stringstream ss; |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | ss << "Tab_" << i; |
|---|
| 54 | |
|---|
| 55 | osgWidget::Label* label1 = new osgWidget::Label(ss.str()); |
|---|
| 56 | |
|---|
| 57 | label1->setFont("fonts/VeraMono.ttf"); |
|---|
| 58 | label1->setFontSize(20); |
|---|
| 59 | label1->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); |
|---|
| 60 | label1->setColor(0.0f, i / 4.0f, 0.3f, 1.0f); |
|---|
| 61 | label1->setLabel(ss.str()); |
|---|
| 62 | label1->addSize(20.0f, 20.0f); |
|---|
| 63 | label1->setShadow(0.1f); |
|---|
| 64 | label1->setCanFill(true); |
|---|
| 65 | |
|---|
| 66 | _tabs->addWidget(label1); |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | std::stringstream descr; |
|---|
| 71 | |
|---|
| 72 | descr |
|---|
| 73 | << "This is some text" << std::endl |
|---|
| 74 | << "for the Tab_" << i << " tab." << std::endl |
|---|
| 75 | << "Press the button up top" << std::endl |
|---|
| 76 | << "And this should go to the next Window!" << std::endl |
|---|
| 77 | ; |
|---|
| 78 | |
|---|
| 79 | osgWidget::Label* label2 = new osgWidget::Label(ss.str()); |
|---|
| 80 | |
|---|
| 81 | label2->setFont("fonts/Vera.ttf"); |
|---|
| 82 | label2->setFontSize(15); |
|---|
| 83 | label2->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); |
|---|
| 84 | label2->setColor(0.0f, i / 4.0f, 0.3f, 1.0f); |
|---|
| 85 | label2->setLabel(descr.str()); |
|---|
| 86 | label2->setLayer(osgWidget::Widget::LAYER_MIDDLE, i * 2); |
|---|
| 87 | label2->addSize(50.0f, 50.0f); |
|---|
| 88 | |
|---|
| 89 | _windows->addWidget(label2, 0.0f, 0.0f); |
|---|
| 90 | |
|---|
| 91 | label1->setEventMask(osgWidget::EVENT_MOUSE_PUSH); |
|---|
| 92 | label1->addCallback(new osgWidget::Callback( |
|---|
| 93 | &Notebook::callbackTabPressed, |
|---|
| 94 | this, |
|---|
| 95 | osgWidget::EVENT_MOUSE_PUSH |
|---|
| 96 | )); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | osgWidget::Label* label = new osgWidget::Label("label"); |
|---|
| 100 | |
|---|
| 101 | label->setFont("fonts/arial.ttf"); |
|---|
| 102 | label->setFontSize(15); |
|---|
| 103 | label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); |
|---|
| 104 | label->setLabel("Drag the window here..."); |
|---|
| 105 | label->addSize(20.0f, 20.0f); |
|---|
| 106 | label->setShadow(0.08f); |
|---|
| 107 | label->setCanFill(true); |
|---|
| 108 | |
|---|
| 109 | addWidget(label); |
|---|
| 110 | addWidget(_tabs->embed()); |
|---|
| 111 | addWidget(_windows->embed()); |
|---|
| 112 | } |
|---|
| 113 | }; |
|---|
| 114 | |
|---|
| 115 | void bound(osg::Node* node) { |
|---|
| 116 | osg::BoundingSphere bs = node->getBound(); |
|---|
| 117 | |
|---|
| 118 | osgWidget::warn() << "center: " << bs.center() << " radius: " << bs.radius() << std::endl; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | int main(int argc, char** argv) { |
|---|
| 122 | osgViewer::Viewer viewer; |
|---|
| 123 | |
|---|
| 124 | osgWidget::WindowManager* wm = new osgWidget::WindowManager( |
|---|
| 125 | &viewer, |
|---|
| 126 | 1280.0f, |
|---|
| 127 | 720.0f, |
|---|
| 128 | MASK_2D |
|---|
| 129 | |
|---|
| 130 | ); |
|---|
| 131 | |
|---|
| 132 | Notebook* notebook1 = new Notebook("notebook1"); |
|---|
| 133 | Notebook* notebook2 = new Notebook("notebook2"); |
|---|
| 134 | |
|---|
| 135 | notebook2->setOrigin(100.0f, 100.0f); |
|---|
| 136 | |
|---|
| 137 | notebook1->attachMoveCallback(); |
|---|
| 138 | notebook2->attachMoveCallback(); |
|---|
| 139 | |
|---|
| 140 | wm->addChild(notebook1); |
|---|
| 141 | wm->addChild(notebook2); |
|---|
| 142 | |
|---|
| 143 | return osgWidget::createExample(viewer, wm); |
|---|
| 144 | } |
|---|