| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | #include <osgWidget/Util> |
|---|
| 5 | #include <osgWidget/WindowManager> |
|---|
| 6 | #include <osgWidget/StyleManager> |
|---|
| 7 | #include <osgWidget/Box> |
|---|
| 8 | |
|---|
| 9 | const unsigned int MASK_2D = 0xF0000000; |
|---|
| 10 | |
|---|
| 11 | const std::string& STYLE1 = |
|---|
| 12 | "color 0 0 0 128\n" |
|---|
| 13 | "padding 5\n" |
|---|
| 14 | ; |
|---|
| 15 | |
|---|
| 16 | const std::string& STYLE2 = |
|---|
| 17 | "color 1.0 0.5 0.0\n" |
|---|
| 18 | ; |
|---|
| 19 | |
|---|
| 20 | const std::string& STYLE3 = |
|---|
| 21 | "fill true\n" |
|---|
| 22 | ; |
|---|
| 23 | |
|---|
| 24 | const std::string& STYLE4 = |
|---|
| 25 | "pos 100.0 100.0\n" |
|---|
| 26 | "size 600 600\n" |
|---|
| 27 | ; |
|---|
| 28 | |
|---|
| 29 | class CustomStyled: public osgWidget::Widget { |
|---|
| 30 | }; |
|---|
| 31 | |
|---|
| 32 | class 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 | |
|---|
| 44 | int 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 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 81 | |
|---|
| 82 | return osgWidget::createExample(viewer, wm); |
|---|
| 83 | } |
|---|