| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | #include <osgDB/WriteFile> |
|---|
| 5 | |
|---|
| 6 | #include <osgWidget/Util> |
|---|
| 7 | #include <osgWidget/WindowManager> |
|---|
| 8 | #include <osgWidget/Box> |
|---|
| 9 | #include <osgWidget/Table> |
|---|
| 10 | #include <osgWidget/Frame> |
|---|
| 11 | #include <osgWidget/Label> |
|---|
| 12 | #include <osgWidget/Input> |
|---|
| 13 | |
|---|
| 14 | const unsigned int MASK_2D = 0xF0000000; |
|---|
| 15 | |
|---|
| 16 | const char* INFO = |
|---|
| 17 | "Use the Input Wigets below to enter the X, Y, and Z position of a\n" |
|---|
| 18 | "sphere to be inserted into the scene. Once you've done this, use\n" |
|---|
| 19 | "the button below to add it!" |
|---|
| 20 | ; |
|---|
| 21 | |
|---|
| 22 | void setupLabel(osgWidget::Label* label) { |
|---|
| 23 | label->setFontSize(16); |
|---|
| 24 | label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); |
|---|
| 25 | label->setFont("fonts/Vera.ttf"); |
|---|
| 26 | label->setPadding(2.0f); |
|---|
| 27 | label->setHeight(18.0f); |
|---|
| 28 | label->setCanFill(true); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | osgWidget::Input* createTableRow( |
|---|
| 32 | osgWidget::Table* table, |
|---|
| 33 | unsigned int rowNum, |
|---|
| 34 | const std::string& valName |
|---|
| 35 | ) { |
|---|
| 36 | std::stringstream ssLabel; |
|---|
| 37 | std::stringstream ssInput; |
|---|
| 38 | |
|---|
| 39 | ssLabel << "Label_Row" << rowNum; |
|---|
| 40 | ssInput << "Input_Row" << rowNum; |
|---|
| 41 | |
|---|
| 42 | osgWidget::Label* label = new osgWidget::Label(ssLabel.str(), valName); |
|---|
| 43 | osgWidget::Input* input = new osgWidget::Input(ssInput.str(), "", 20); |
|---|
| 44 | |
|---|
| 45 | setupLabel(label); |
|---|
| 46 | setupLabel(input); |
|---|
| 47 | |
|---|
| 48 | label->setWidth(50.0f); |
|---|
| 49 | label->setColor(0.1f, 0.1f, 0.1f, 1.0f); |
|---|
| 50 | |
|---|
| 51 | input->setWidth(150.0f); |
|---|
| 52 | input->setColor(0.4f, 0.4f, 0.4f, 1.0f); |
|---|
| 53 | |
|---|
| 54 | table->addWidget(label, rowNum, 0); |
|---|
| 55 | table->addWidget(input, rowNum, 1); |
|---|
| 56 | |
|---|
| 57 | return input; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | osgWidget::Label* createLabel(const std::string& text) { |
|---|
| 61 | osgWidget::Label* label = new osgWidget::Label("", text); |
|---|
| 62 | |
|---|
| 63 | setupLabel(label); |
|---|
| 64 | |
|---|
| 65 | return label; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | class Button: public osgWidget::Label { |
|---|
| 69 | public: |
|---|
| 70 | typedef std::vector<osgWidget::Input*> Inputs; |
|---|
| 71 | |
|---|
| 72 | private: |
|---|
| 73 | Inputs _xyz; |
|---|
| 74 | |
|---|
| 75 | public: |
|---|
| 76 | Button(const std::string& text, const Inputs& inputs): |
|---|
| 77 | osgWidget::Label("", text), |
|---|
| 78 | _xyz(inputs) { |
|---|
| 79 | setupLabel(this); |
|---|
| 80 | |
|---|
| 81 | setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK); |
|---|
| 82 | setShadow(0.1f); |
|---|
| 83 | addHeight(4.0f); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | bool mousePush(double, double, osgWidget::WindowManager*) { |
|---|
| 87 | osgWidget::warn() |
|---|
| 88 | << "x: " << _xyz[0]->getLabel() << std::endl |
|---|
| 89 | << "y: " << _xyz[1]->getLabel() << std::endl |
|---|
| 90 | << "z: " << _xyz[2]->getLabel() << std::endl |
|---|
| 91 | ; |
|---|
| 92 | |
|---|
| 93 | return false; |
|---|
| 94 | } |
|---|
| 95 | }; |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | bool info(osgWidget::Event& ev) { |
|---|
| 99 | osgWidget::warn() << "MousePush @ Window: " << ev.getWindow()->getName() << std::endl; |
|---|
| 100 | |
|---|
| 101 | return true; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | int main(int argc, char** argv) { |
|---|
| 105 | osgViewer::Viewer viewer; |
|---|
| 106 | |
|---|
| 107 | osgWidget::WindowManager* wm = new osgWidget::WindowManager( |
|---|
| 108 | &viewer, |
|---|
| 109 | 1280.0f, |
|---|
| 110 | 1024.0f, |
|---|
| 111 | MASK_2D, |
|---|
| 112 | osgWidget::WindowManager::WM_PICK_DEBUG |
|---|
| 113 | ); |
|---|
| 114 | |
|---|
| 115 | osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL); |
|---|
| 116 | osgWidget::Table* table = new osgWidget::Table("table", 3, 2); |
|---|
| 117 | osgWidget::Box* lbox1 = new osgWidget::Box("lbox1", osgWidget::Box::HORIZONTAL); |
|---|
| 118 | osgWidget::Box* lbox2 = new osgWidget::Box("lbox2", osgWidget::Box::HORIZONTAL); |
|---|
| 119 | osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture( |
|---|
| 120 | "frame", |
|---|
| 121 | "osgWidget/theme.png", |
|---|
| 122 | 64.0f, |
|---|
| 123 | 64.0f, |
|---|
| 124 | 16.0f, |
|---|
| 125 | 16.0f, |
|---|
| 126 | 100.0f, |
|---|
| 127 | 100.0f |
|---|
| 128 | ); |
|---|
| 129 | |
|---|
| 130 | osgWidget::Input* x = createTableRow(table, 0, "X Position"); |
|---|
| 131 | osgWidget::Input* y = createTableRow(table, 1, "Y Position"); |
|---|
| 132 | osgWidget::Input* z = createTableRow(table, 2, "Z Position"); |
|---|
| 133 | |
|---|
| 134 | Button::Inputs inputs; |
|---|
| 135 | |
|---|
| 136 | inputs.push_back(x); |
|---|
| 137 | inputs.push_back(y); |
|---|
| 138 | inputs.push_back(z); |
|---|
| 139 | |
|---|
| 140 | table->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH)); |
|---|
| 141 | |
|---|
| 142 | lbox1->addWidget(createLabel(INFO)); |
|---|
| 143 | lbox2->addWidget(new Button("Add To Scene...", inputs)); |
|---|
| 144 | |
|---|
| 145 | box->addWidget(lbox1->embed()); |
|---|
| 146 | box->addWidget(table->embed()); |
|---|
| 147 | box->addWidget(lbox2->embed()); |
|---|
| 148 | box->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH)); |
|---|
| 149 | |
|---|
| 150 | frame->setWindow(box); |
|---|
| 151 | frame->getEmbeddedWindow()->setSize(box->getWidth(), box->getHeight()); |
|---|
| 152 | frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); |
|---|
| 153 | frame->attachTabFocusCallback(); |
|---|
| 154 | |
|---|
| 155 | for(osgWidget::Frame::Iterator i = frame->begin(); i != frame->end(); i++) { |
|---|
| 156 | if(i->valid()) i->get()->setColor(0.5f, 0.7f, 1.0f, 1.0f); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | wm->addChild(frame); |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | lbox1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT); |
|---|
| 173 | lbox1->getBackground()->setColor(0.0f, 1.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT); |
|---|
| 174 | lbox1->getBackground()->setColor(0.0f, 0.0f, 1.0f, 1.0f, osgWidget::Widget::LOWER_RIGHT); |
|---|
| 175 | lbox1->getBackground()->setColor(1.0f, 1.0f, 1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT); |
|---|
| 176 | lbox1->setVisibilityMode(osgWidget::Window::VM_ENTIRE); |
|---|
| 177 | lbox1->update(); |
|---|
| 178 | |
|---|
| 179 | int r = osgWidget::createExample(viewer, wm); |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | return r; |
|---|
| 185 | } |
|---|