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

Revision 12292, 3.9 kB (checked in by robert, 3 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: 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/Vera.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_USE_RENDERBINS |
51        osgWidget::WindowManager::WM_PICK_DEBUG
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.5f);
68
69    label2->setImage("Images/Brick-Norman-Brown.TGA", true);
70
71    box->addWidget(label1);
72    box->addWidget(label2);
73    box->attachMoveCallback();
74    box->attachScaleCallback();
75    box->attachRotateCallback();
76
77    // Setup the labels for the vertical box.
78    osgWidget::Label* label3 = createLabel("Label 3", 80);
79    osgWidget::Label* label4 = createLabel("Label 4", 60);
80    osgWidget::Label* label5 = createLabel("ABCDEFGHIJK", 93);
81
82    label3->setPadding(3.0f);
83    label4->setPadding(3.0f);
84    label5->setPadding(3.0f);
85
86    label3->setColor(0.0f, 0.0f, 0.5f, 0.5f);
87    label4->setColor(0.0f, 0.0f, 0.5f, 0.5f);
88    label5->setColor(0.0f, 0.0f, 0.5f, 0.5f);
89   
90    //label5->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
91    //label5->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
92
93    // Test our label copy construction...
94    osgWidget::Label* label6 = osg::clone(label5, "label6", osg::CopyOp::DEEP_COPY_ALL);
95
96    label6->setLabel("abcdefghijklmnopqrs");
97
98    vbox->addWidget(label3);
99    vbox->addWidget(label4);
100    vbox->addWidget(label5);
101    vbox->addWidget(label6);
102    vbox->attachMoveCallback();
103    vbox->attachScaleCallback();
104
105    vbox->resize();
106
107    // vbox->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
108    // vbox->setVisibleArea(50, 50, 500, 200);
109    // vbox->setAnchorVertical(osgWidget::Window::VA_TOP);
110    // vbox->setAnchorHorizontal(osgWidget::Window::HA_RIGHT);
111
112    // Test our label-in-window copy construction...
113    osgWidget::Box* clonedBox = osg::clone(box, "HBOX-new", osg::CopyOp::DEEP_COPY_ALL);
114   
115    clonedBox->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.5f);
116
117    wm->addChild(box);
118    wm->addChild(vbox);
119    wm->addChild(clonedBox);
120
121    return osgWidget::createExample(viewer, wm);
122}
Note: See TracBrowser for help on using the browser.