File: osgwidgetframe.cpp

package info (click to toggle)
openscenegraph 3.2.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,820 kB
  • ctags: 34,610
  • sloc: cpp: 370,040; ansic: 9,071; java: 1,020; yacc: 548; objc: 288; makefile: 285; xml: 155; lex: 151
file content (124 lines) | stat: -rw-r--r-- 4,461 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: osgwidgetframe.cpp 40 2008-04-11 14:05:11Z cubicool $

#include <osgWidget/Util>
#include <osgWidget/WindowManager>
#include <osgWidget/Frame>
#include <osgWidget/Box>
#include <osgDB/ReadFile>

const unsigned int MASK_2D = 0xF0000000;

int main(int argc, char** argv) {
    osgViewer::Viewer viewer;

    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
        &viewer,
        1280.0f,
        1024.0f,
        MASK_2D,
        osgWidget::WindowManager::WM_PICK_DEBUG
    );
    
    osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame(
        "frame",
        32.0f,
        32.0f,
        300.0f,
        300.0f
    );

    osgWidget::Frame* frame2 = osgWidget::Frame::createSimpleFrameFromTheme(
        "frameTheme",
        osgDB::readImageFile("osgWidget/theme-1.png"),
        300.0f,
        300.0f,
        osgWidget::Frame::FRAME_ALL
        );
    frame2->setPosition(300,100,0);
    frame2->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);

    osgWidget::Frame* frame22 = osgWidget::Frame::createSimpleFrameFromTheme(
        "frameTheme",
        osgDB::readImageFile("osgWidget/theme-2.png"),
        300.0f,
        300.0f,
        osgWidget::Frame::FRAME_ALL
        );
    frame22->setPosition(300,100,0);
    frame22->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);


    osgWidget::Frame* frame3 = osgWidget::Frame::createSimpleFrameFromTheme(
        "frameTheme",
        osgDB::readImageFile("osgWidget/theme-2.png"),
        300.0f,
        300.0f,
        osgWidget::Frame::FRAME_ALL
        );
    frame3->setPosition(300,100,0);
    frame3->getBackground()->setColor(0.0f, 0.0f, 0.0f, 1.0f);
    
    osgWidget::Table* table  = new osgWidget::Table("table", 2, 2);
    osgWidget::Box*   bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL);

    table->addWidget(new osgWidget::Widget("red", 300.0f, 300.0f), 0, 0);
    table->addWidget(new osgWidget::Widget("white", 300.0f, 300.0f), 0, 1);
    table->addWidget(new osgWidget::Widget("yellow", 300.0f, 300.0f), 1, 0);
    table->addWidget(new osgWidget::Widget("purple", 300.0f, 300.0f), 1, 1);
    table->getByRowCol(0, 0)->setColor(1.0f, 0.0f, 0.0f, 1.0f);
    table->getByRowCol(0, 1)->setColor(1.0f, 1.0f, 1.0f, 1.0f);
    table->getByRowCol(1, 0)->setColor(1.0f, 1.0f, 0.0f, 1.0f);
    table->getByRowCol(1, 1)->setColor(1.0f, 0.0f, 1.0f, 1.0f);
    table->getByRowCol(0, 0)->setMinimumSize(100.0f, 100.0f);
    table->getByRowCol(0, 1)->setMinimumSize(100.0f, 100.0f);
    table->getByRowCol(1, 0)->setMinimumSize(100.0f, 100.0f);
    table->getByRowCol(1, 1)->setMinimumSize(100.0f, 100.0f);

    frame->setWindow(table);

    // Give frame some nice textures.
    // TODO: This has to be done after setWindow(); wtf?
    frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);

    osgWidget::Widget* l = frame->getBorder(osgWidget::Frame::BORDER_LEFT);
    osgWidget::Widget* r = frame->getBorder(osgWidget::Frame::BORDER_RIGHT);
    osgWidget::Widget* t = frame->getBorder(osgWidget::Frame::BORDER_TOP);
    osgWidget::Widget* b = frame->getBorder(osgWidget::Frame::BORDER_BOTTOM);

    l->setImage("osgWidget/border-left.tga", true);
    r->setImage("osgWidget/border-right.tga", true);
    t->setImage("osgWidget/border-top.tga", true);
    b->setImage("osgWidget/border-bottom.tga", true);

    l->setTexCoordWrapVertical();
    r->setTexCoordWrapVertical();
    t->setTexCoordWrapHorizontal();
    b->setTexCoordWrapHorizontal();

    // Create the bottom, XArt panel.
    osgWidget::Widget* left   = new osgWidget::Widget("left", 512.0f, 256.0f);
    osgWidget::Widget* center = new osgWidget::Widget("center", 256.0f, 256.0f);
    osgWidget::Widget* right  = new osgWidget::Widget("right", 512.0f, 256.0f);

    left->setImage("osgWidget/panel-left.tga", true);
    center->setImage("osgWidget/panel-center.tga", true);
    right->setImage("osgWidget/panel-right.tga", true);

    center->setTexCoordWrapHorizontal();

    bottom->addWidget(left);
    bottom->addWidget(center);
    bottom->addWidget(right);
    bottom->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
    bottom->setOrigin(0.0f, 1024.0f - 256.0f);

    // Add everything to the WindowManager.
    wm->addChild(frame);
    wm->addChild(frame2);
    wm->addChild(frame22);
    wm->addChild(frame3);
    wm->addChild(bottom);

    return osgWidget::createExample(viewer, wm);
}