| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | #include <osg/io_utils> |
|---|
| 5 | #include <osgWidget/Util> |
|---|
| 6 | #include <osgWidget/WindowManager> |
|---|
| 7 | #include <osgWidget/Box> |
|---|
| 8 | #include <osgWidget/Label> |
|---|
| 9 | |
|---|
| 10 | const unsigned int MASK_2D = 0xF0000000; |
|---|
| 11 | |
|---|
| 12 | const 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 | |
|---|
| 19 | const 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 | |
|---|
| 25 | osgWidget::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 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | return label; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | int 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 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 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 | } |
|---|