- Timestamp:
- 07/16/08 00:03:59 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgwidgetnotebook/osgwidgetnotebook.cpp
r8588 r8600 13 13 14 14 class Notebook: public osgWidget::Box { 15 osg::ref_ptr<osgWidget::Box> _tabs;16 osg::ref_ptr<osgWidget::Canvas> _windows;15 osg::ref_ptr<osgWidget::Box> _tabs; 16 osg::ref_ptr<osgWidget::Canvas> _windows; 17 17 18 18 public: 19 // NOTE: This whole thing is just a hack to demonstrate a concept. The real20 // implementation would need to be much cleaner.21 bool callbackTabPressed(osgWidget::Event& ev) {22 osgWidget::Canvas::Vector& objs = _windows->getObjects();19 // NOTE: This whole thing is just a hack to demonstrate a concept. The real 20 // implementation would need to be much cleaner. 21 bool callbackTabPressed(osgWidget::Event& ev) { 22 osgWidget::Canvas::Vector& objs = _windows->getObjects(); 23 23 24 for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer(25 osgWidget::Widget::LAYER_MIDDLE,26 i27 );24 for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer( 25 osgWidget::Widget::LAYER_MIDDLE, 26 i 27 ); 28 28 29 _windows->getByName(ev.getWidget()->getName())->setLayer(30 osgWidget::Widget::LAYER_MIDDLE,31 objs.size()32 );29 _windows->getByName(ev.getWidget()->getName())->setLayer( 30 osgWidget::Widget::LAYER_MIDDLE, 31 objs.size() 32 ); 33 33 34 _windows->resize();34 _windows->resize(); 35 35 36 return true;37 }36 return true; 37 } 38 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");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 43 44 for(unsigned int i = 0; i < 4; i++) {45 std::stringstream ss;44 for(unsigned int i = 0; i < 4; i++) { 45 std::stringstream ss; 46 46 47 // Setup everything for our Tab...48 ss << "Tab_" << i;47 // Setup everything for our Tab... 48 ss << "Tab_" << i; 49 49 50 osgWidget::Label* label1 = new osgWidget::Label(ss.str());50 osgWidget::Label* label1 = new osgWidget::Label(ss.str()); 51 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);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 60 61 _tabs->addWidget(label1);61 _tabs->addWidget(label1); 62 62 63 // Setup everything for the Window corresponding to the Tab64 // in the Canvas down below.65 std::stringstream descr;63 // Setup everything for the Window corresponding to the Tab 64 // in the Canvas down below. 65 std::stringstream descr; 66 66 67 descr68 << "This is some text" << std::endl69 << "for the Tab_" << i << " tab." << std::endl70 << "Press the button up top" << std::endl71 << "And this should go to the next Window!" << std::endl72 ;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 73 74 osgWidget::Label* label2 = new osgWidget::Label(ss.str());74 osgWidget::Label* label2 = new osgWidget::Label(ss.str()); 75 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);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 83 84 _windows->addWidget(label2, 0.0f, 0.0f);84 _windows->addWidget(label2, 0.0f, 0.0f); 85 85 86 label1->setEventMask(osgWidget::EVENT_MOUSE_PUSH);87 label1->addCallback(osgWidget::Callback(88 &Notebook::callbackTabPressed,89 this,90 osgWidget::EVENT_MOUSE_PUSH91 ));92 }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 93 94 osgWidget::Label* label = new osgWidget::Label("label");94 osgWidget::Label* label = new osgWidget::Label("label"); 95 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);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 103 104 addWidget(label);105 addWidget(_tabs->embed());106 addWidget(_windows->embed());107 }104 addWidget(label); 105 addWidget(_tabs->embed()); 106 addWidget(_windows->embed()); 107 } 108 108 }; 109 109 110 110 int main(int argc, char** argv) { 111 osgViewer::Viewer viewer;111 osgViewer::Viewer viewer; 112 112 113 osgWidget::WindowManager* wm = new osgWidget::WindowManager(114 &viewer,115 1280.0f,116 720.0f,117 MASK_2D,118 osgWidget::WindowManager::WM_PICK_DEBUG119 );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 120 121 Notebook* notebook = new Notebook("notebook");121 Notebook* notebook = new Notebook("notebook"); 122 122 123 osgWidget::warn()124 << "Sizes are..." << std::endl125 << "Cur: " << notebook->getSize() << std::endl126 << "Min: " << notebook->getMinSize() << std::endl127 ;123 osgWidget::warn() 124 << "Sizes are..." << std::endl 125 << "Cur: " << notebook->getSize() << std::endl 126 << "Min: " << notebook->getMinSize() << std::endl 127 ; 128 128 129 notebook->attachMoveCallback();129 notebook->attachMoveCallback(); 130 130 131 wm->addChild(notebook);131 wm->addChild(notebook); 132 132 133 return osgWidget::createExample(viewer, wm);133 return osgWidget::createExample(viewer, wm); 134 134 }
