root/OpenSceneGraph/trunk/examples/osgwidgetnotebook/osgwidgetnotebook.cpp @ 12292

Revision 12292, 4.5 kB (checked in by robert, 3 years ago)

Ran svn propset -R svn:eol-style native . on the OpenSceneGraph

  • Property svn:eol-style set to native
RevLine 
[8588]1// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
2// $Id: osgwidgetnotebook.cpp 45 2008-04-23 16:46:11Z cubicool $
3
4#include <osg/io_utils>
[9289]5#include <osgGA/TrackballManipulator>
6#include <osgGA/StateSetManipulator>
7#include <osgViewer/ViewerEventHandlers>
[8588]8#include <osgWidget/Util>
9#include <osgWidget/WindowManager>
10#include <osgWidget/Box>
11#include <osgWidget/Canvas>
12#include <osgWidget/Label>
[9289]13#include <osgWidget/Label>
14#include <osgWidget/ViewerEventHandlers>
[8588]15
16const unsigned int MASK_2D = 0xF0000000;
17const unsigned int MASK_3D = 0x0F000000;
18
19class Notebook: public osgWidget::Box {
[8600]20    osg::ref_ptr<osgWidget::Box>    _tabs;
21    osg::ref_ptr<osgWidget::Canvas> _windows;
[8588]22
23public:
[8600]24    // NOTE: This whole thing is just a hack to demonstrate a concept. The real
25    // implementation would need to be much cleaner.
26    bool callbackTabPressed(osgWidget::Event& ev) {
27        osgWidget::Canvas::Vector& objs = _windows->getObjects();
[8588]28
[8600]29        for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer(
30            osgWidget::Widget::LAYER_MIDDLE,
[9289]31            i * 2
[8600]32        );
[8588]33
[8600]34        _windows->getByName(ev.getWidget()->getName())->setLayer(
35            osgWidget::Widget::LAYER_MIDDLE,
[9289]36            objs.size() * 2
[8600]37        );
[8588]38
[8600]39        _windows->resize();
[8588]40
[8600]41        return true;
42    }
[8588]43
[8600]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");
[8588]48
[8600]49        for(unsigned int i = 0; i < 4; i++) {
50            std::stringstream ss;
[8588]51
[8600]52            // Setup everything for our Tab...
53            ss << "Tab_" << i;
[8588]54
[8600]55            osgWidget::Label* label1 = new osgWidget::Label(ss.str());
[8588]56
[8602]57            label1->setFont("fonts/VeraMono.ttf");
[8600]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);
[8588]65
[8600]66            _tabs->addWidget(label1);
[8588]67
[8600]68            // Setup everything for the Window corresponding to the Tab
69            // in the Canvas down below.
70            std::stringstream descr;
[8588]71
[8600]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            ;
[8588]78
[8600]79            osgWidget::Label* label2 = new osgWidget::Label(ss.str());
[8588]80
[8602]81            label2->setFont("fonts/Vera.ttf");
[8600]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());
[9289]86            label2->setLayer(osgWidget::Widget::LAYER_MIDDLE, i * 2);
[8600]87            label2->addSize(50.0f, 50.0f);
[8588]88
[8600]89            _windows->addWidget(label2, 0.0f, 0.0f);
[8588]90
[8600]91            label1->setEventMask(osgWidget::EVENT_MOUSE_PUSH);
[9289]92            label1->addCallback(new osgWidget::Callback(
[8600]93                &Notebook::callbackTabPressed,
94                this,
95                osgWidget::EVENT_MOUSE_PUSH
96            ));
97        }
[8588]98
[8600]99        osgWidget::Label* label = new osgWidget::Label("label");
[8588]100
[8602]101        label->setFont("fonts/arial.ttf");
[8600]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);
[9289]108   
[8600]109        addWidget(label);
110        addWidget(_tabs->embed());
111        addWidget(_windows->embed());
112    }
[8588]113};
114
[9289]115void bound(osg::Node* node) {
116    osg::BoundingSphere bs = node->getBound();
117
118    osgWidget::warn() << "center: " << bs.center() << " radius: " << bs.radius() << std::endl;
119}
120
[8588]121int main(int argc, char** argv) {
[8600]122    osgViewer::Viewer viewer;
[8588]123
[8600]124    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
125        &viewer,
126        1280.0f,
127        720.0f,
[9289]128        MASK_2D //,
129        //osgWidget::WindowManager::WM_USE_RENDERBINS
[8600]130    );
[8588]131
[9289]132    Notebook* notebook1 = new Notebook("notebook1");
133    Notebook* notebook2 = new Notebook("notebook2");
[8588]134
[9289]135    notebook2->setOrigin(100.0f, 100.0f);
[8588]136
[9289]137    notebook1->attachMoveCallback();
138    notebook2->attachMoveCallback();
[8588]139
[9289]140    wm->addChild(notebook1);
141    wm->addChild(notebook2);
[8588]142
[8600]143    return osgWidget::createExample(viewer, wm);
[8588]144}
Note: See TracBrowser for help on using the browser.