2008-07-16 01:21:25 +08:00
|
|
|
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
|
|
|
// $Id: osgwidgetshader.cpp 28 2008-03-26 15:26:48Z cubicool $
|
|
|
|
|
|
|
|
#include <osgWidget/Util>
|
|
|
|
#include <osgWidget/WindowManager>
|
|
|
|
#include <osgWidget/StyleManager>
|
|
|
|
#include <osgWidget/Box>
|
|
|
|
|
|
|
|
const unsigned int MASK_2D = 0xF0000000;
|
|
|
|
|
|
|
|
const std::string& STYLE1 =
|
2008-12-17 04:29:00 +08:00
|
|
|
"color 0 0 0 128\n"
|
|
|
|
"padding 5\n"
|
2008-07-16 01:21:25 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
const std::string& STYLE2 =
|
2008-12-17 04:29:00 +08:00
|
|
|
"color 1.0 0.5 0.0\n"
|
2008-07-16 01:21:25 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
const std::string& STYLE3 =
|
2008-12-17 04:29:00 +08:00
|
|
|
"fill true\n"
|
2008-07-16 01:21:25 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
const std::string& STYLE4 =
|
2008-12-17 04:29:00 +08:00
|
|
|
"pos 100.0 100.0\n"
|
|
|
|
"size 600 600\n"
|
2008-07-16 01:21:25 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
class CustomStyled: public osgWidget::Widget {
|
|
|
|
};
|
|
|
|
|
|
|
|
class CustomStyle: public osgWidget::Style {
|
2008-12-17 04:29:00 +08:00
|
|
|
virtual bool applyStyle(osgWidget::Widget* w, osgWidget::Reader r) {
|
|
|
|
CustomStyled* cs = dynamic_cast<CustomStyled*>(w);
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
if(!cs) return false;
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
osgWidget::warn() << "Here, okay." << std::endl;
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
return true;
|
|
|
|
}
|
2008-07-16 01:21:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2008-12-17 04:29:00 +08:00
|
|
|
osgViewer::Viewer viewer;
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
|
|
|
&viewer,
|
|
|
|
1280.0f,
|
|
|
|
1024.0f,
|
|
|
|
MASK_2D
|
|
|
|
);
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
osgWidget::Box* box = new osgWidget::Box("box", osgWidget::Box::VERTICAL);
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
osgWidget::Widget* widget1 = new osgWidget::Widget("w1", 200.0f, 200.0f);
|
|
|
|
osgWidget::Widget* widget2 = new osgWidget::Widget("w2", 100.0f, 100.0f);
|
|
|
|
osgWidget::Widget* widget3 = new osgWidget::Widget("w3", 0.0f, 0.0f);
|
|
|
|
CustomStyled* cs = new CustomStyled();
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
// Yep.
|
|
|
|
wm->getStyleManager()->addStyle(new osgWidget::Style("widget.style1", STYLE1));
|
|
|
|
wm->getStyleManager()->addStyle(new osgWidget::Style("widget.style2", STYLE2));
|
|
|
|
wm->getStyleManager()->addStyle(new osgWidget::Style("spacer", STYLE3));
|
|
|
|
wm->getStyleManager()->addStyle(new osgWidget::Style("window", STYLE4));
|
|
|
|
// wm->getStyleManager()->addStyle(new CustomStyle("widget", ""));
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
widget1->setStyle("widget.style1");
|
|
|
|
widget2->setStyle("widget.style2");
|
|
|
|
widget3->setStyle("spacer");
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
box->setStyle("window");
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
box->addWidget(widget1);
|
|
|
|
box->addWidget(widget2);
|
|
|
|
box->addWidget(widget3);
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
wm->addChild(box);
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
// box->resizePercent(0.0f, 100.0f);
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-12-17 04:29:00 +08:00
|
|
|
return osgWidget::createExample(viewer, wm);
|
2008-07-16 01:21:25 +08:00
|
|
|
}
|