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

Revision 12292, 2.2 kB (checked in by robert, 4 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: osgwidgetshader.cpp 28 2008-03-26 15:26:48Z cubicool $
3
4#include <osgWidget/Util>
5#include <osgWidget/WindowManager>
6#include <osgWidget/StyleManager>
7#include <osgWidget/Box>
8
9const unsigned int MASK_2D = 0xF0000000;
10
11const std::string& STYLE1 =
[9370]12    "color 0 0 0 128\n"
13    "padding 5\n"
[8588]14;
15
16const std::string& STYLE2 =
[9370]17    "color 1.0 0.5 0.0\n"
[8588]18;
19
20const std::string& STYLE3 =
[9370]21    "fill true\n"
[8588]22;
23
24const std::string& STYLE4 =
[9370]25    "pos 100.0 100.0\n"
26    "size 600 600\n"
[8588]27;
28
29class CustomStyled: public osgWidget::Widget {
30};
31
32class CustomStyle: public osgWidget::Style {
[9370]33    virtual bool applyStyle(osgWidget::Widget* w, osgWidget::Reader r) {
34        CustomStyled* cs = dynamic_cast<CustomStyled*>(w);
[8588]35
[9370]36        if(!cs) return false;
[8588]37
[9370]38        osgWidget::warn() << "Here, okay." << std::endl;
[8588]39
[9370]40        return true;
41    }
[8588]42};
43
44int main(int argc, char** argv) {
[9370]45    osgViewer::Viewer viewer;
[8588]46
[9370]47    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
48        &viewer,
49        1280.0f,
50        1024.0f,
51        MASK_2D
52    );
[8588]53
[9370]54    osgWidget::Box* box = new osgWidget::Box("box", osgWidget::Box::VERTICAL);
[8588]55
[9370]56    osgWidget::Widget* widget1 = new osgWidget::Widget("w1", 200.0f, 200.0f);
57    osgWidget::Widget* widget2 = new osgWidget::Widget("w2", 100.0f, 100.0f);
58    osgWidget::Widget* widget3 = new osgWidget::Widget("w3", 0.0f, 0.0f);
[9395]59    // CustomStyled*      cs      = new CustomStyled();
[8588]60
[9370]61    // Yep.
62    wm->getStyleManager()->addStyle(new osgWidget::Style("widget.style1", STYLE1));
63    wm->getStyleManager()->addStyle(new osgWidget::Style("widget.style2", STYLE2));
64    wm->getStyleManager()->addStyle(new osgWidget::Style("spacer", STYLE3));
65    wm->getStyleManager()->addStyle(new osgWidget::Style("window", STYLE4));
66    // wm->getStyleManager()->addStyle(new CustomStyle("widget", ""));
[8588]67
[9370]68    widget1->setStyle("widget.style1");
69    widget2->setStyle("widget.style2");
70    widget3->setStyle("spacer");
[8588]71
[9370]72    box->setStyle("window");
[8588]73
[9370]74    box->addWidget(widget1);
75    box->addWidget(widget2);
76    box->addWidget(widget3);
[8588]77
[9370]78    wm->addChild(box);
[8588]79
[9370]80    // box->resizePercent(0.0f, 100.0f);
[8588]81
[9370]82    return osgWidget::createExample(viewer, wm);
[8588]83}
Note: See TracBrowser for help on using the browser.