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