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

Revision 12292, 3.9 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
RevLine 
[8588]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 =
[8600]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..."
[8588]17;
18
19const char* LABEL2 =
[8600]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"
[8588]23;
24
25osgWidget::Label* createLabel(const std::string& l, unsigned int size=13) {
[8600]26    osgWidget::Label* label = new osgWidget::Label("", "");
[8588]27
[8602]28    label->setFont("fonts/Vera.ttf");
[8600]29    label->setFontSize(size);
30    label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
31    label->setLabel(l);
[8588]32
[8600]33    /*
34    text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);
35    text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER);
36    text->setBackdropOffset(0.2f);
37    */
[8588]38
[8600]39    return label;
[8588]40}
41
42int main(int argc, char** argv) {
[8600]43    osgViewer::Viewer viewer;
[8588]44
[8600]45    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
46        &viewer,
47        1280.0f,
48        1024.0f,
49        MASK_2D,
[9289]50        // osgWidget::WindowManager::WM_USE_RENDERBINS |
51        osgWidget::WindowManager::WM_PICK_DEBUG
[8600]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);
[8588]58
[8600]59    // Setup the labels for horizontal box.
60    label1->setPadding(10.0f);
61    label2->setPadding(10.0f);
[8588]62
[8600]63    label1->addSize(21.0f, 22.0f);
64    label2->addSize(21.0f, 22.0f);
[8588]65
[8600]66    label1->setColor(1.0f, 0.5f, 0.0f, 0.0f);
[9289]67    label2->setColor(1.0f, 0.5f, 0.0f, 0.5f);
[8588]68
[9289]69    label2->setImage("Images/Brick-Norman-Brown.TGA", true);
70
[8600]71    box->addWidget(label1);
72    box->addWidget(label2);
73    box->attachMoveCallback();
74    box->attachScaleCallback();
75    box->attachRotateCallback();
[8588]76
[8600]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);
[8588]81
[8600]82    label3->setPadding(3.0f);
83    label4->setPadding(3.0f);
84    label5->setPadding(3.0f);
[8588]85
[8600]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   
[9289]90    //label5->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
91    //label5->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
[8588]92
[8600]93    // Test our label copy construction...
[9289]94    osgWidget::Label* label6 = osg::clone(label5, "label6", osg::CopyOp::DEEP_COPY_ALL);
[8588]95
[8600]96    label6->setLabel("abcdefghijklmnopqrs");
[8588]97
[8600]98    vbox->addWidget(label3);
99    vbox->addWidget(label4);
100    vbox->addWidget(label5);
101    vbox->addWidget(label6);
102    vbox->attachMoveCallback();
103    vbox->attachScaleCallback();
[8588]104
[8600]105    vbox->resize();
[8588]106
[8600]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);
[8588]111
[8600]112    // Test our label-in-window copy construction...
[9289]113    osgWidget::Box* clonedBox = osg::clone(box, "HBOX-new", osg::CopyOp::DEEP_COPY_ALL);
[8600]114   
115    clonedBox->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.5f);
[8588]116
[8600]117    wm->addChild(box);
118    wm->addChild(vbox);
119    wm->addChild(clonedBox);
[8588]120
[8600]121    return osgWidget::createExample(viewer, wm);
[8588]122}
Note: See TracBrowser for help on using the browser.