root/OpenSceneGraph/trunk/examples/osgwidgetframe/osgwidgetframe.cpp @ 13347

Revision 12292, 4.4 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
Line 
1// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
2// $Id: osgwidgetframe.cpp 40 2008-04-11 14:05:11Z cubicool $
3
4#include <osgWidget/Util>
5#include <osgWidget/WindowManager>
6#include <osgWidget/Frame>
7#include <osgWidget/Box>
8#include <osgDB/ReadFile>
9
10const unsigned int MASK_2D = 0xF0000000;
11
12int main(int argc, char** argv) {
13    osgViewer::Viewer viewer;
14
15    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
16        &viewer,
17        1280.0f,
18        1024.0f,
19        MASK_2D,
20        osgWidget::WindowManager::WM_PICK_DEBUG
21    );
22   
23    osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame(
24        "frame",
25        32.0f,
26        32.0f,
27        300.0f,
28        300.0f
29    );
30
31    osgWidget::Frame* frame2 = osgWidget::Frame::createSimpleFrameFromTheme(
32        "frameTheme",
33        osgDB::readImageFile("osgWidget/theme-1.png"),
34        300.0f,
35        300.0f,
36        osgWidget::Frame::FRAME_ALL
37        );
38    frame2->setPosition(300,100,0);
39    frame2->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);
40
41    osgWidget::Frame* frame22 = osgWidget::Frame::createSimpleFrameFromTheme(
42        "frameTheme",
43        osgDB::readImageFile("osgWidget/theme-2.png"),
44        300.0f,
45        300.0f,
46        osgWidget::Frame::FRAME_ALL
47        );
48    frame22->setPosition(300,100,0);
49    frame22->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);
50
51
52    osgWidget::Frame* frame3 = osgWidget::Frame::createSimpleFrameFromTheme(
53        "frameTheme",
54        osgDB::readImageFile("osgWidget/theme-2.png"),
55        300.0f,
56        300.0f,
57        osgWidget::Frame::FRAME_ALL
58        );
59    frame3->setPosition(300,100,0);
60    frame3->getBackground()->setColor(0.0f, 0.0f, 0.0f, 1.0f);
61   
62    osgWidget::Table* table  = new osgWidget::Table("table", 2, 2);
63    osgWidget::Box*   bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL);
64
65    table->addWidget(new osgWidget::Widget("red", 300.0f, 300.0f), 0, 0);
66    table->addWidget(new osgWidget::Widget("white", 300.0f, 300.0f), 0, 1);
67    table->addWidget(new osgWidget::Widget("yellow", 300.0f, 300.0f), 1, 0);
68    table->addWidget(new osgWidget::Widget("purple", 300.0f, 300.0f), 1, 1);
69    table->getByRowCol(0, 0)->setColor(1.0f, 0.0f, 0.0f, 1.0f);
70    table->getByRowCol(0, 1)->setColor(1.0f, 1.0f, 1.0f, 1.0f);
71    table->getByRowCol(1, 0)->setColor(1.0f, 1.0f, 0.0f, 1.0f);
72    table->getByRowCol(1, 1)->setColor(1.0f, 0.0f, 1.0f, 1.0f);
73    table->getByRowCol(0, 0)->setMinimumSize(100.0f, 100.0f);
74    table->getByRowCol(0, 1)->setMinimumSize(100.0f, 100.0f);
75    table->getByRowCol(1, 0)->setMinimumSize(100.0f, 100.0f);
76    table->getByRowCol(1, 1)->setMinimumSize(100.0f, 100.0f);
77
78    frame->setWindow(table);
79
80    // Give frame some nice textures.
81    // TODO: This has to be done after setWindow(); wtf?
82    frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
83
84    osgWidget::Widget* l = frame->getBorder(osgWidget::Frame::BORDER_LEFT);
85    osgWidget::Widget* r = frame->getBorder(osgWidget::Frame::BORDER_RIGHT);
86    osgWidget::Widget* t = frame->getBorder(osgWidget::Frame::BORDER_TOP);
87    osgWidget::Widget* b = frame->getBorder(osgWidget::Frame::BORDER_BOTTOM);
88
89    l->setImage("osgWidget/border-left.tga", true);
90    r->setImage("osgWidget/border-right.tga", true);
91    t->setImage("osgWidget/border-top.tga", true);
92    b->setImage("osgWidget/border-bottom.tga", true);
93
94    l->setTexCoordWrapVertical();
95    r->setTexCoordWrapVertical();
96    t->setTexCoordWrapHorizontal();
97    b->setTexCoordWrapHorizontal();
98
99    // Create the bottom, XArt panel.
100    osgWidget::Widget* left   = new osgWidget::Widget("left", 512.0f, 256.0f);
101    osgWidget::Widget* center = new osgWidget::Widget("center", 256.0f, 256.0f);
102    osgWidget::Widget* right  = new osgWidget::Widget("right", 512.0f, 256.0f);
103
104    left->setImage("osgWidget/panel-left.tga", true);
105    center->setImage("osgWidget/panel-center.tga", true);
106    right->setImage("osgWidget/panel-right.tga", true);
107
108    center->setTexCoordWrapHorizontal();
109
110    bottom->addWidget(left);
111    bottom->addWidget(center);
112    bottom->addWidget(right);
113    bottom->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
114    bottom->setOrigin(0.0f, 1024.0f - 256.0f);
115
116    // Add everything to the WindowManager.
117    wm->addChild(frame);
118    wm->addChild(frame2);
119    wm->addChild(frame22);
120    wm->addChild(frame3);
121    wm->addChild(bottom);
122
123    return osgWidget::createExample(viewer, wm);
124}
Note: See TracBrowser for help on using the browser.