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

Revision 8602, 3.3 kB (checked in by robert, 6 years ago)

From Jeremy Moles, Updated file references to reflect new data in OpenSceneGraph-Data

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
9const unsigned int MASK_2D = 0xF0000000;
10
11int main(int argc, char** argv) {
12    osgViewer::Viewer viewer;
13
14    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
15        &viewer,
16        1280.0f,
17        1024.0f,
18        MASK_2D,
19        osgWidget::WindowManager::WM_PICK_DEBUG
20    );
21   
22    osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame(
23        "frame",
24        32.0f,
25        32.0f,
26        300.0f,
27        300.0f
28    );
29   
30    osgWidget::Table* table  = new osgWidget::Table("table", 2, 2);
31    osgWidget::Box*   bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL);
32
33    table->addWidget(new osgWidget::Widget("red", 300.0f, 300.0f), 0, 0);
34    table->addWidget(new osgWidget::Widget("white", 300.0f, 300.0f), 0, 1);
35    table->addWidget(new osgWidget::Widget("yellow", 300.0f, 300.0f), 1, 0);
36    table->addWidget(new osgWidget::Widget("purple", 300.0f, 300.0f), 1, 1);
37    table->getByRowCol(0, 0)->setColor(1.0f, 0.0f, 0.0f, 1.0f);
38    table->getByRowCol(0, 1)->setColor(1.0f, 1.0f, 1.0f, 1.0f);
39    table->getByRowCol(1, 0)->setColor(1.0f, 1.0f, 0.0f, 1.0f);
40    table->getByRowCol(1, 1)->setColor(1.0f, 0.0f, 1.0f, 1.0f);
41    table->getByRowCol(0, 0)->setMinimumSize(100.0f, 100.0f);
42    table->getByRowCol(0, 1)->setMinimumSize(100.0f, 100.0f);
43    table->getByRowCol(1, 0)->setMinimumSize(100.0f, 100.0f);
44    table->getByRowCol(1, 1)->setMinimumSize(100.0f, 100.0f);
45
46    frame->setWindow(table);
47
48    // Give frame some nice textures.
49    // TODO: This has to be done after setWindow(); wtf?
50    frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
51
52    osgWidget::Widget* l = frame->getBorder(osgWidget::Frame::BORDER_LEFT);
53    osgWidget::Widget* r = frame->getBorder(osgWidget::Frame::BORDER_RIGHT);
54    osgWidget::Widget* t = frame->getBorder(osgWidget::Frame::BORDER_TOP);
55    osgWidget::Widget* b = frame->getBorder(osgWidget::Frame::BORDER_BOTTOM);
56
57    l->setImage("osgWidget/border-left.tga", true);
58    r->setImage("osgWidget/border-right.tga", true);
59    t->setImage("osgWidget/border-top.tga", true);
60    b->setImage("osgWidget/border-bottom.tga", true);
61
62    l->setTexCoordWrapVertical();
63    r->setTexCoordWrapVertical();
64    t->setTexCoordWrapHorizontal();
65    b->setTexCoordWrapHorizontal();
66
67    // Create the bottom, XArt panel.
68    osgWidget::Widget* left   = new osgWidget::Widget("left", 512.0f, 256.0f);
69    osgWidget::Widget* center = new osgWidget::Widget("center", 256.0f, 256.0f);
70    osgWidget::Widget* right  = new osgWidget::Widget("right", 512.0f, 256.0f);
71
72    left->setImage  ("osgWidget/panel-left.tga", true);
73    center->setImage("osgWidget/panel-center.tga", true);
74    right->setImage ("osgWidget/panel-right.tga", true);
75
76    center->setTexCoordWrapHorizontal();
77
78    bottom->addWidget(left);
79    bottom->addWidget(center);
80    bottom->addWidget(right);
81    bottom->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
82    bottom->setOrigin(0.0f, 1024.0f - 256.0f);
83
84    // Add everything to the WindowManager.
85    wm->addChild(frame);
86    wm->addChild(bottom);
87
88    return osgWidget::createExample(viewer, wm);
89}
Note: See TracBrowser for help on using the browser.