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