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

Revision 9395, 2.2 kB (checked in by robert, 5 years ago)

Fixed warnings

Line 
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 =
12    "color 0 0 0 128\n"
13    "padding 5\n"
14;
15
16const std::string& STYLE2 =
17    "color 1.0 0.5 0.0\n"
18;
19
20const std::string& STYLE3 =
21    "fill true\n"
22;
23
24const std::string& STYLE4 =
25    "pos 100.0 100.0\n"
26    "size 600 600\n"
27;
28
29class CustomStyled: public osgWidget::Widget {
30};
31
32class CustomStyle: public osgWidget::Style {
33    virtual bool applyStyle(osgWidget::Widget* w, osgWidget::Reader r) {
34        CustomStyled* cs = dynamic_cast<CustomStyled*>(w);
35
36        if(!cs) return false;
37
38        osgWidget::warn() << "Here, okay." << std::endl;
39
40        return true;
41    }
42};
43
44int main(int argc, char** argv) {
45    osgViewer::Viewer viewer;
46
47    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
48        &viewer,
49        1280.0f,
50        1024.0f,
51        MASK_2D
52    );
53
54    osgWidget::Box* box = new osgWidget::Box("box", osgWidget::Box::VERTICAL);
55
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);
59    // CustomStyled*      cs      = new CustomStyled();
60
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", ""));
67
68    widget1->setStyle("widget.style1");
69    widget2->setStyle("widget.style2");
70    widget3->setStyle("spacer");
71
72    box->setStyle("window");
73
74    box->addWidget(widget1);
75    box->addWidget(widget2);
76    box->addWidget(widget3);
77
78    wm->addChild(box);
79
80    // box->resizePercent(0.0f, 100.0f);
81
82    return osgWidget::createExample(viewer, wm);
83}
Note: See TracBrowser for help on using the browser.