root/OpenSceneGraph/trunk/examples/osgwidgetlabel/osgwidgetlabel.cpp @ 8588

Revision 8588, 3.5 kB (checked in by robert, 6 years ago)

From Jeremy Moles, import of the osgWidget NodeKit?, sourced from the original http://osgwidget.googlecode.com/svn/trunk

Notes from Robert Osfield, I've merged osgWidget trunk, and added/changed CMakeLists.txt file to make it suitable for inclusion in the core OSG, and moved imagery/scripts/shaders out into OpenSceneGraph-Data

Line 
1// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
2// $Id: osgwidgetlabel.cpp 66 2008-07-14 21:54:09Z cubicool $
3
4#include <osg/io_utils>
5#include <osgWidget/Util>
6#include <osgWidget/WindowManager>
7#include <osgWidget/Box>
8#include <osgWidget/Label>
9
10const unsigned int MASK_2D = 0xF0000000;
11
12const char* LABEL1 =
13        "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\n"
14        "do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"
15        "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n"
16        "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in..."
17;
18
19const char* LABEL2 =
20        "...reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n"
21        "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in \n"
22        "culpa qui officia deserunt mollit anim id est laborum. BBBBB"
23;
24
25osgWidget::Label* createLabel(const std::string& l, unsigned int size=13) {
26        osgWidget::Label* label = new osgWidget::Label("", "");
27
28        label->setFont("fonts/arial.ttf");
29        label->setFontSize(size);
30        label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
31        label->setLabel(l);
32
33        /*
34        text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);
35        text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER);
36        text->setBackdropOffset(0.2f);
37        */
38
39        return label;
40}
41
42int main(int argc, char** argv) {
43        osgViewer::Viewer viewer;
44
45        osgWidget::WindowManager* wm = new osgWidget::WindowManager(
46                &viewer,
47                1280.0f,
48                1024.0f,
49                MASK_2D,
50                osgWidget::WindowManager::WM_PICK_DEBUG |
51                osgWidget::WindowManager::WM_NO_INVERT_Y
52        );
53       
54        osgWidget::Box*   box    = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL);
55        osgWidget::Box*   vbox   = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
56        osgWidget::Label* label1 = createLabel(LABEL1);
57        osgWidget::Label* label2 = createLabel(LABEL2);
58
59        // Setup the labels for horizontal box.
60        label1->setPadding(10.0f);
61        label2->setPadding(10.0f);
62
63        label1->addSize(21.0f, 22.0f);
64        label2->addSize(21.0f, 22.0f);
65
66        label1->setColor(1.0f, 0.5f, 0.0f, 0.0f);
67        label2->setColor(1.0f, 0.5f, 0.0f, 0.0f);
68
69        box->addWidget(label1);
70        box->addWidget(label2);
71        box->attachMoveCallback();
72        box->attachScaleCallback();
73        box->attachRotateCallback();
74
75        // Setup the labels for the vertical box.
76        osgWidget::Label* label3 = createLabel("Label 3", 80);
77        osgWidget::Label* label4 = createLabel("Label 4", 60);
78        osgWidget::Label* label5 = createLabel("ABCDEFGHIJK", 93);
79
80        label3->setPadding(3.0f);
81        label4->setPadding(3.0f);
82        label5->setPadding(3.0f);
83
84        label3->setColor(0.0f, 0.0f, 0.5f, 0.5f);
85        label4->setColor(0.0f, 0.0f, 0.5f, 0.5f);
86        label5->setColor(0.0f, 0.0f, 0.5f, 0.5f);
87       
88        label5->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
89        label5->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
90
91        // Test our label copy construction...
92        osgWidget::Label* label6 = label5->cloneAs("label6");
93
94        label6->setLabel("abcdefghijklmnopqrs");
95
96        vbox->addWidget(label3);
97        vbox->addWidget(label4);
98        vbox->addWidget(label5);
99        vbox->addWidget(label6);
100        vbox->attachMoveCallback();
101        vbox->attachScaleCallback();
102
103        vbox->resize();
104
105        // vbox->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
106        // vbox->setVisibleArea(50, 50, 500, 200);
107        // vbox->setAnchorVertical(osgWidget::Window::VA_TOP);
108        // vbox->setAnchorHorizontal(osgWidget::Window::HA_RIGHT);
109
110        // Test our label-in-window copy construction...
111        osgWidget::Box* clonedBox = box->cloneAs("HBOX-new");
112       
113        clonedBox->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.5f);
114
115        wm->addChild(box);
116        wm->addChild(vbox);
117        wm->addChild(clonedBox);
118
119        return osgWidget::createExample(viewer, wm);
120}
Note: See TracBrowser for help on using the browser.