Changeset 8600
- Timestamp:
- 07/16/08 00:03:59
- Files:
-
- OpenSceneGraph/trunk/examples/osgwidgetaddremove/osgwidgetaddremove.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/examples/osgwidgetframe/osgwidgetframe.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/examples/osgwidgetinput/osgwidgetinput.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/examples/osgwidgetlabel/osgwidgetlabel.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/examples/osgwidgetmenu/osgwidgetmenu.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/examples/osgwidgetnotebook/osgwidgetnotebook.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/examples/osgwidgetscrolled/osgwidgetscrolled.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/examples/osgwidgetshader/osgwidgetshader.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph/trunk/examples/osgwidgetaddremove/osgwidgetaddremove.cpp
r8588 r8600 12 12 class ABCWidget: public osgWidget::Label { 13 13 public: 14 ABCWidget(const std::string& label):15 osgWidget::Label("", label) {16 setFont("fonts/Calibri1.ttf");17 setFontSize(20);18 setCanFill(true);19 setShadow(0.08f);20 addSize(10.0f, 10.0f);21 }14 ABCWidget(const std::string& label): 15 osgWidget::Label("", label) { 16 setFont("fonts/Calibri1.ttf"); 17 setFontSize(20); 18 setCanFill(true); 19 setShadow(0.08f); 20 addSize(10.0f, 10.0f); 21 } 22 22 }; 23 23 24 24 class Button: public osgWidget::Label { 25 25 public: 26 Button(const std::string& label):27 osgWidget::Label("", label) {28 setFont("fonts/Calibri1.ttf");29 setFontSize(30);30 setColor(0.8f, 0.2f, 0.2f, 0.8f);31 setCanFill(true);32 setShadow(0.1f);33 setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK);34 addSize(20.0f, 20.0f);35 }26 Button(const std::string& label): 27 osgWidget::Label("", label) { 28 setFont("fonts/Calibri1.ttf"); 29 setFontSize(30); 30 setColor(0.8f, 0.2f, 0.2f, 0.8f); 31 setCanFill(true); 32 setShadow(0.1f); 33 setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK); 34 addSize(20.0f, 20.0f); 35 } 36 36 37 // NOTE! I need to make it clearer than Push/Release can happen so fast that38 // the changes you make aren't visible with your refresh rate. Throttling state39 // changes and what-have-you on mousePush/mouseRelease/etc. is going to be40 // annoying...37 // NOTE! I need to make it clearer than Push/Release can happen so fast that 38 // the changes you make aren't visible with your refresh rate. Throttling state 39 // changes and what-have-you on mousePush/mouseRelease/etc. is going to be 40 // annoying... 41 41 42 virtual bool mousePush(double, double, osgWidget::WindowManager*) {43 addColor(0.2f, 0.2f, 0.2f, 0.0f);44 45 return true;46 }42 virtual bool mousePush(double, double, osgWidget::WindowManager*) { 43 addColor(0.2f, 0.2f, 0.2f, 0.0f); 44 45 return true; 46 } 47 47 48 virtual bool mouseRelease(double, double, osgWidget::WindowManager*) {49 addColor(-0.2f, -0.2f, -0.2f, 0.0f);50 51 return true;52 }48 virtual bool mouseRelease(double, double, osgWidget::WindowManager*) { 49 addColor(-0.2f, -0.2f, -0.2f, 0.0f); 50 51 return true; 52 } 53 53 }; 54 54 55 55 class AddRemove: public osgWidget::Box { 56 osg::ref_ptr<osgWidget::Window> _win1;56 osg::ref_ptr<osgWidget::Window> _win1; 57 57 58 58 public: 59 AddRemove():60 osgWidget::Box ("buttons", osgWidget::Box::VERTICAL),61 _win1 (new osgWidget::Box("win1", osgWidget::Box::VERTICAL)) {62 addWidget(new Button("Add Widget"));63 addWidget(new Button("Remove Widget"));59 AddRemove(): 60 osgWidget::Box ("buttons", osgWidget::Box::VERTICAL), 61 _win1 (new osgWidget::Box("win1", osgWidget::Box::VERTICAL)) { 62 addWidget(new Button("Add Widget")); 63 addWidget(new Button("Remove Widget")); 64 64 65 // Take special note here! Not only do the Button objects have their66 // own overridden methods for changing the color, but they have attached67 // callbacks for doing the work with local data.68 getByName("Widget_1")->addCallback(osgWidget::Callback(69 &AddRemove::handlePressAdd,70 this,71 osgWidget::EVENT_MOUSE_PUSH72 ));65 // Take special note here! Not only do the Button objects have their 66 // own overridden methods for changing the color, but they have attached 67 // callbacks for doing the work with local data. 68 getByName("Widget_1")->addCallback(osgWidget::Callback( 69 &AddRemove::handlePressAdd, 70 this, 71 osgWidget::EVENT_MOUSE_PUSH 72 )); 73 73 74 getByName("Widget_2")->addCallback(osgWidget::Callback(75 &AddRemove::handlePressRemove,76 this,77 osgWidget::EVENT_MOUSE_PUSH78 ));79 }74 getByName("Widget_2")->addCallback(osgWidget::Callback( 75 &AddRemove::handlePressRemove, 76 this, 77 osgWidget::EVENT_MOUSE_PUSH 78 )); 79 } 80 80 81 virtual void managed(osgWidget::WindowManager* wm) {82 osgWidget::Box::managed(wm);81 virtual void managed(osgWidget::WindowManager* wm) { 82 osgWidget::Box::managed(wm); 83 83 84 _win1->setOrigin(250.0f, 0.0f);84 _win1->setOrigin(250.0f, 0.0f); 85 85 86 wm->addChild(_win1.get());87 }86 wm->addChild(_win1.get()); 87 } 88 88 89 bool handlePressAdd(osgWidget::Event& ev) {90 static unsigned int num = 0;89 bool handlePressAdd(osgWidget::Event& ev) { 90 static unsigned int num = 0; 91 91 92 std::stringstream ss;92 std::stringstream ss; 93 93 94 ss << "a random widget " << num;94 ss << "a random widget " << num; 95 95 96 _win1->addWidget(new ABCWidget(ss.str()));97 _win1->resize();96 _win1->addWidget(new ABCWidget(ss.str())); 97 _win1->resize(); 98 98 99 num++;99 num++; 100 100 101 return true;102 }101 return true; 102 } 103 103 104 bool handlePressRemove(osgWidget::Event& ev) {105 // TODO: Temporary hack!106 const osgWidget::Box::Vector& v = _win1->getObjects();107 108 if(!v.size()) return false;104 bool handlePressRemove(osgWidget::Event& ev) { 105 // TODO: Temporary hack! 106 const osgWidget::Box::Vector& v = _win1->getObjects(); 107 108 if(!v.size()) return false; 109 109 110 osgWidget::Widget* w = _win1->getObjects()[v.size() - 1].get();110 osgWidget::Widget* w = _win1->getObjects()[v.size() - 1].get(); 111 111 112 _win1->removeWidget(w);113 _win1->resize();112 _win1->removeWidget(w); 113 _win1->resize(); 114 114 115 return true;116 }115 return true; 116 } 117 117 }; 118 118 119 119 int main(int argc, char** argv) { 120 osgViewer::Viewer viewer;120 osgViewer::Viewer viewer; 121 121 122 osgWidget::WindowManager* wm = new osgWidget::WindowManager(123 &viewer,124 1280.0f,125 1024.0f,126 MASK_2D127 );128 129 osgWidget::Box* buttons = new AddRemove();122 osgWidget::WindowManager* wm = new osgWidget::WindowManager( 123 &viewer, 124 1280.0f, 125 1024.0f, 126 MASK_2D 127 ); 128 129 osgWidget::Box* buttons = new AddRemove(); 130 130 131 wm->addChild(buttons);131 wm->addChild(buttons); 132 132 133 return createExample(viewer, wm);133 return createExample(viewer, wm); 134 134 } OpenSceneGraph/trunk/examples/osgwidgetframe/osgwidgetframe.cpp
r8588 r8600 10 10 11 11 int main(int argc, char** argv) { 12 osgViewer::Viewer viewer;12 osgViewer::Viewer viewer; 13 13 14 osgWidget::WindowManager* wm = new osgWidget::WindowManager(15 &viewer,16 1280.0f,17 1024.0f,18 MASK_2D,19 osgWidget::WindowManager::WM_PICK_DEBUG20 );21 22 osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame(23 "frame",24 32.0f,25 32.0f,26 300.0f,27 300.0f28 );29 30 osgWidget::Table* table = new osgWidget::Table("table", 2, 2);31 osgWidget::Box* bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL);14 osgWidget::WindowManager* wm = new osgWidget::WindowManager( 15 &viewer, 16 1280.0f, 17 1024.0f, 18 MASK_2D, 19 osgWidget::WindowManager::WM_PICK_DEBUG 20 ); 21 22 osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame( 23 "frame", 24 32.0f, 25 32.0f, 26 300.0f, 27 300.0f 28 ); 29 30 osgWidget::Table* table = new osgWidget::Table("table", 2, 2); 31 osgWidget::Box* bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL); 32 32 33 table->addWidget(new osgWidget::Widget("red", 300.0f, 300.0f), 0, 0);34 table->addWidget(new osgWidget::Widget("white", 300.0f, 300.0f), 0, 1);35 table->addWidget(new osgWidget::Widget("yellow", 300.0f, 300.0f), 1, 0);36 table->addWidget(new osgWidget::Widget("purple", 300.0f, 300.0f), 1, 1);37 table->getByRowCol(0, 0)->setColor(1.0f, 0.0f, 0.0f, 1.0f);38 table->getByRowCol(0, 1)->setColor(1.0f, 1.0f, 1.0f, 1.0f);39 table->getByRowCol(1, 0)->setColor(1.0f, 1.0f, 0.0f, 1.0f);40 table->getByRowCol(1, 1)->setColor(1.0f, 0.0f, 1.0f, 1.0f);41 table->getByRowCol(0, 0)->setMinimumSize(100.0f, 100.0f);42 table->getByRowCol(0, 1)->setMinimumSize(100.0f, 100.0f);43 table->getByRowCol(1, 0)->setMinimumSize(100.0f, 100.0f);44 table->getByRowCol(1, 1)->setMinimumSize(100.0f, 100.0f);33 table->addWidget(new osgWidget::Widget("red", 300.0f, 300.0f), 0, 0); 34 table->addWidget(new osgWidget::Widget("white", 300.0f, 300.0f), 0, 1); 35 table->addWidget(new osgWidget::Widget("yellow", 300.0f, 300.0f), 1, 0); 36 table->addWidget(new osgWidget::Widget("purple", 300.0f, 300.0f), 1, 1); 37 table->getByRowCol(0, 0)->setColor(1.0f, 0.0f, 0.0f, 1.0f); 38 table->getByRowCol(0, 1)->setColor(1.0f, 1.0f, 1.0f, 1.0f); 39 table->getByRowCol(1, 0)->setColor(1.0f, 1.0f, 0.0f, 1.0f); 40 table->getByRowCol(1, 1)->setColor(1.0f, 0.0f, 1.0f, 1.0f); 41 table->getByRowCol(0, 0)->setMinimumSize(100.0f, 100.0f); 42 table->getByRowCol(0, 1)->setMinimumSize(100.0f, 100.0f); 43 table->getByRowCol(1, 0)->setMinimumSize(100.0f, 100.0f); 44 table->getByRowCol(1, 1)->setMinimumSize(100.0f, 100.0f); 45 45 46 frame->setWindow(table);46 frame->setWindow(table); 47 47 48 // Give frame some nice textures.49 // TODO: This has to be done after setWindow(); wtf?50 frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);48 // Give frame some nice textures. 49 // TODO: This has to be done after setWindow(); wtf? 50 frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); 51 51 52 osgWidget::Widget* l = frame->getBorder(osgWidget::Frame::BORDER_LEFT);53 osgWidget::Widget* r = frame->getBorder(osgWidget::Frame::BORDER_RIGHT);54 osgWidget::Widget* t = frame->getBorder(osgWidget::Frame::BORDER_TOP);55 osgWidget::Widget* b = frame->getBorder(osgWidget::Frame::BORDER_BOTTOM);52 osgWidget::Widget* l = frame->getBorder(osgWidget::Frame::BORDER_LEFT); 53 osgWidget::Widget* r = frame->getBorder(osgWidget::Frame::BORDER_RIGHT); 54 osgWidget::Widget* t = frame->getBorder(osgWidget::Frame::BORDER_TOP); 55 osgWidget::Widget* b = frame->getBorder(osgWidget::Frame::BORDER_BOTTOM); 56 56 57 l->setImage("../examples/osgwidgetframe/images/border-left.tga", true);58 r->setImage("../examples/osgwidgetframe/images/border-right.tga", true);59 t->setImage("../examples/osgwidgetframe/images/border-top.tga", true);60 b->setImage("../examples/osgwidgetframe/images/border-bottom.tga", true);57 l->setImage("../examples/osgwidgetframe/images/border-left.tga", true); 58 r->setImage("../examples/osgwidgetframe/images/border-right.tga", true); 59 t->setImage("../examples/osgwidgetframe/images/border-top.tga", true); 60 b->setImage("../examples/osgwidgetframe/images/border-bottom.tga", true); 61 61 62 l->setTexCoordWrapVertical();63 r->setTexCoordWrapVertical();64 t->setTexCoordWrapHorizontal();65 b->setTexCoordWrapHorizontal();62 l->setTexCoordWrapVertical(); 63 r->setTexCoordWrapVertical(); 64 t->setTexCoordWrapHorizontal(); 65 b->setTexCoordWrapHorizontal(); 66 66 67 // Create the bottom, XArt panel.68 osgWidget::Widget* left = new osgWidget::Widget("left", 512.0f, 256.0f);69 osgWidget::Widget* center = new osgWidget::Widget("center", 256.0f, 256.0f);70 osgWidget::Widget* right = new osgWidget::Widget("right", 512.0f, 256.0f);67 // Create the bottom, XArt panel. 68 osgWidget::Widget* left = new osgWidget::Widget("left", 512.0f, 256.0f); 69 osgWidget::Widget* center = new osgWidget::Widget("center", 256.0f, 256.0f); 70 osgWidget::Widget* right = new osgWidget::Widget("right", 512.0f, 256.0f); 71 71 72 left->setImage("../examples/osgwidgetframe/images/panel-left.tga", true);73 center->setImage("../examples/osgwidgetframe/images/panel-center.tga", true);74 right->setImage("../examples/osgwidgetframe/images/panel-right.tga", true);72 left->setImage("../examples/osgwidgetframe/images/panel-left.tga", true); 73 center->setImage("../examples/osgwidgetframe/images/panel-center.tga", true); 74 right->setImage("../examples/osgwidgetframe/images/panel-right.tga", true); 75 75 76 center->setTexCoordWrapHorizontal();76 center->setTexCoordWrapHorizontal(); 77 77 78 bottom->addWidget(left);79 bottom->addWidget(center);80 bottom->addWidget(right);81 bottom->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);82 bottom->setOrigin(0.0f, 1024.0f - 256.0f);78 bottom->addWidget(left); 79 bottom->addWidget(center); 80 bottom->addWidget(right); 81 bottom->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); 82 bottom->setOrigin(0.0f, 1024.0f - 256.0f); 83 83 84 // Add everything to the WindowManager.85 wm->addChild(frame);86 wm->addChild(bottom);84 // Add everything to the WindowManager. 85 wm->addChild(frame); 86 wm->addChild(bottom); 87 87 88 return osgWidget::createExample(viewer, wm);88 return osgWidget::createExample(viewer, wm); 89 89 } OpenSceneGraph/trunk/examples/osgwidgetinput/osgwidgetinput.cpp
r8588 r8600 15 15 16 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!"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 20 ; 21 21 22 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/monospace.ttf");26 label->setFont("fonts/Calibri1.ttf");27 label->setPadding(2.0f);28 label->setHeight(18.0f);29 label->setCanFill(true);23 label->setFontSize(16); 24 label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); 25 // label->setFont("fonts/monospace.ttf"); 26 label->setFont("fonts/Calibri1.ttf"); 27 label->setPadding(2.0f); 28 label->setHeight(18.0f); 29 label->setCanFill(true); 30 30 } 31 31 32 32 osgWidget::Input* createTableRow( 33 osgWidget::Table* table,34 unsigned int rowNum,35 const std::string& valName33 osgWidget::Table* table, 34 unsigned int rowNum, 35 const std::string& valName 36 36 ) { 37 std::stringstream ssLabel;38 std::stringstream ssInput;37 std::stringstream ssLabel; 38 std::stringstream ssInput; 39 39 40 ssLabel << "Label_Row" << rowNum;41 ssInput << "Input_Row" << rowNum;40 ssLabel << "Label_Row" << rowNum; 41 ssInput << "Input_Row" << rowNum; 42 42 43 osgWidget::Label* label = new osgWidget::Label(ssLabel.str(), valName);44 osgWidget::Input* input = new osgWidget::Input(ssInput.str(), "", 20);43 osgWidget::Label* label = new osgWidget::Label(ssLabel.str(), valName); 44 osgWidget::Input* input = new osgWidget::Input(ssInput.str(), "", 20); 45 45 46 setupLabel(label);47 setupLabel(input);46 setupLabel(label); 47 setupLabel(input); 48 48 49 label->setWidth(50.0f);50 label->setColor(0.1f, 0.1f, 0.1f, 1.0f);49 label->setWidth(50.0f); 50 label->setColor(0.1f, 0.1f, 0.1f, 1.0f); 51 51 52 input->setWidth(150.0f);53 input->setColor(0.4f, 0.4f, 0.4f, 1.0f);52 input->setWidth(150.0f); 53 input->setColor(0.4f, 0.4f, 0.4f, 1.0f); 54 54 55 table->addWidget(label, rowNum, 0);56 table->addWidget(input, rowNum, 1);55 table->addWidget(label, rowNum, 0); 56 table->addWidget(input, rowNum, 1); 57 57 58 return input;58 return input; 59 59 } 60 60 61 61 osgWidget::Label* createLabel(const std::string& text) { 62 osgWidget::Label* label = new osgWidget::Label("", text);62 osgWidget::Label* label = new osgWidget::Label("", text); 63 63 64 setupLabel(label);64 setupLabel(label); 65 65 66 return label;66 return label; 67 67 } 68 68 69 69 class Button: public osgWidget::Label { 70 70 public: 71 typedef std::vector<osgWidget::Input*> Inputs;71 typedef std::vector<osgWidget::Input*> Inputs; 72 72 73 73 private: 74 Inputs _xyz;74 Inputs _xyz; 75 75 76 76 public: 77 Button(const std::string& text, const Inputs& inputs):78 osgWidget::Label("", text),79 _xyz(inputs) {80 setupLabel(this);77 Button(const std::string& text, const Inputs& inputs): 78 osgWidget::Label("", text), 79 _xyz(inputs) { 80 setupLabel(this); 81 81 82 setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK);83 setShadow(0.1f);84 addHeight(4.0f);85 }82 setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK); 83 setShadow(0.1f); 84 addHeight(4.0f); 85 } 86 86 87 bool mousePush(double, double, osgWidget::WindowManager*) {88 osgWidget::warn()89 << "x: " << _xyz[0]->getLabel() << std::endl90 << "y: " << _xyz[1]->getLabel() << std::endl91 << "z: " << _xyz[2]->getLabel() << std::endl92 ;87 bool mousePush(double, double, osgWidget::WindowManager*) { 88 osgWidget::warn() 89 << "x: " << _xyz[0]->getLabel() << std::endl 90 << "y: " << _xyz[1]->getLabel() << std::endl 91 << "z: " << _xyz[2]->getLabel() << std::endl 92 ; 93 93 94 return false;95 }94 return false; 95 } 96 96 }; 97 97 98 98 // TODO: Testing our _parent/EmbeddedWindow stuff. 99 99 bool info(osgWidget::Event& ev) { 100 osgWidget::warn() << "MousePush @ Window: " << ev.getWindow()->getName() << std::endl;100 osgWidget::warn() << "MousePush @ Window: " << ev.getWindow()->getName() << std::endl; 101 101 102 return true;102 return true; 103 103 } 104 104 105 105 int main(int argc, char** argv) { 106 osgViewer::Viewer viewer;106 osgViewer::Viewer viewer; 107 107 108 osgWidget::WindowManager* wm = new osgWidget::WindowManager(109 &viewer,110 1280.0f,111 1024.0f,112 MASK_2D,113 osgWidget::WindowManager::WM_PICK_DEBUG114 );115 116 osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);117 osgWidget::Table* table = new osgWidget::Table("table", 3, 2);118 osgWidget::Box* lbox1 = new osgWidget::Box("lbox1", osgWidget::Box::HORIZONTAL);119 osgWidget::Box* lbox2 = new osgWidget::Box("lbox2", osgWidget::Box::HORIZONTAL);120 osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture(121 "frame",122 "osgWidget/theme.png",123 64.0f,124 64.0f,125 16.0f,126 16.0f,127 100.0f,128 100.0f129 );108 osgWidget::WindowManager* wm = new osgWidget::WindowManager( 109 &viewer, 110 1280.0f, 111 1024.0f, 112 MASK_2D, 113 osgWidget::WindowManager::WM_PICK_DEBUG 114 ); 115 116 osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL); 117 osgWidget::Table* table = new osgWidget::Table("table", 3, 2); 118 osgWidget::Box* lbox1 = new osgWidget::Box("lbox1", osgWidget::Box::HORIZONTAL); 119 osgWidget::Box* lbox2 = new osgWidget::Box("lbox2", osgWidget::Box::HORIZONTAL); 120 osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture( 121 "frame", 122 "osgWidget/theme.png", 123 64.0f, 124 64.0f, 125 16.0f, 126 16.0f, 127 100.0f, 128 100.0f 129 ); 130 130 131 osgWidget::Input* x = createTableRow(table, 0, "X Position");132 osgWidget::Input* y = createTableRow(table, 1, "Y Position");133 osgWidget::Input* z = createTableRow(table, 2, "Z Position");134 135 Button::Inputs inputs;131 osgWidget::Input* x = createTableRow(table, 0, "X Position"); 132 osgWidget::Input* y = createTableRow(table, 1, "Y Position"); 133 osgWidget::Input* z = createTableRow(table, 2, "Z Position"); 134 135 Button::Inputs inputs; 136 136 137 inputs.push_back(x);138 inputs.push_back(y);139 inputs.push_back(z);137 inputs.push_back(x); 138 inputs.push_back(y); 139 inputs.push_back(z); 140 140 141 table->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH));141 table->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH)); 142 142 143 lbox1->addWidget(createLabel(INFO));144 lbox2->addWidget(new Button("Add To Scene...", inputs));143 lbox1->addWidget(createLabel(INFO)); 144 lbox2->addWidget(new Button("Add To Scene...", inputs)); 145 145 146 box->addWidget(lbox1->embed());147 box->addWidget(table->embed());148 box->addWidget(lbox2->embed());149 box->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH));146 box->addWidget(lbox1->embed()); 147 box->addWidget(table->embed()); 148 box->addWidget(lbox2->embed()); 149 box->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH)); 150 150 151 frame->setWindow(box);152 frame->getEmbeddedWindow()->setSize(box->getWidth(), box->getHeight());153 frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);154 frame->attachTabFocusCallback();151 frame->setWindow(box); 152 frame->getEmbeddedWindow()->setSize(box->getWidth(), box->getHeight()); 153 frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); 154 frame->attachTabFocusCallback(); 155 155 156 for(osgWidget::Frame::Iterator i = frame->begin(); i != frame->end(); i++) {157 if(i->valid()) i->get()->setColor(0.5f, 0.7f, 1.0f, 1.0f);158 }156 for(osgWidget::Frame::Iterator i = frame->begin(); i != frame->end(); i++) { 157 if(i->valid()) i->get()->setColor(0.5f, 0.7f, 1.0f, 1.0f); 158 } 159 159 160 wm->addChild(frame);160 wm->addChild(frame); 161 161 162 /*163 // Print out our focus list, it should just have 3 widgets.164 osgWidget::WidgetList wl;162 /* 163 // Print out our focus list, it should just have 3 widgets. 164 osgWidget::WidgetList wl; 165 165 166 box->getFocusList(wl);166 box->getFocusList(wl); 167 167 168 for(osgWidget::WidgetList::iterator i = wl.begin(); i != wl.end(); i++) {169 osgWidget::warn() << i->get()->getName() << std::endl;170 }171 */172 173 lbox1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);174 lbox1->getBackground()->setColor(0.0f, 1.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT);175 lbox1->getBackground()->setColor(0.0f, 0.0f, 1.0f, 1.0f, osgWidget::Widget::LOWER_RIGHT);176 lbox1->getBackground()->setColor(1.0f, 1.0f, 1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);177 lbox1->setVisibilityMode(osgWidget::Window::VM_ENTIRE);178 lbox1->update();168 for(osgWidget::WidgetList::iterator i = wl.begin(); i != wl.end(); i++) { 169 osgWidget::warn() << i->get()->getName() << std::endl; 170 } 171 */ 172 173 lbox1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT); 174 lbox1->getBackground()->setColor(0.0f, 1.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT); 175 lbox1->getBackground()->setColor(0.0f, 0.0f, 1.0f, 1.0f, osgWidget::Widget::LOWER_RIGHT); 176 lbox1->getBackground()->setColor(1.0f, 1.0f, 1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT); 177 lbox1->setVisibilityMode(osgWidget::Window::VM_ENTIRE); 178 lbox1->update(); 179 179 180 int r = osgWidget::createExample(viewer, wm);180 int r = osgWidget::createExample(viewer, wm); 181 181 182 // osgWidget::writeWindowManagerNode(wm);183 // osgDB::writeNodeFile(*box, "osgWidget.osg");182 // osgWidget::writeWindowManagerNode(wm); 183 // osgDB::writeNodeFile(*box, "osgWidget.osg"); 184 184 185 return r;185 return r; 186 186 } OpenSceneGraph/trunk/examples/osgwidgetlabel/osgwidgetlabel.cpp
r8588 r8600 11 11 12 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..."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 17 ; 18 18 19 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"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 23 ; 24 24 25 25 osgWidget::Label* createLabel(const std::string& l, unsigned int size=13) { 26 osgWidget::Label* label = new osgWidget::Label("", "");26 osgWidget::Label* label = new osgWidget::Label("", ""); 27 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);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 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 */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 38 39 return label;39 return label; 40 40 } 41 41 42 42 int main(int argc, char** argv) { 43 osgViewer::Viewer viewer;43 osgViewer::Viewer viewer; 44 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_Y52 );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);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 58 59 // Setup the labels for horizontal box.60 label1->setPadding(10.0f);61 label2->setPadding(10.0f);59 // Setup the labels for horizontal box. 60 label1->setPadding(10.0f); 61 label2->setPadding(10.0f); 62 62 63 label1->addSize(21.0f, 22.0f);64 label2->addSize(21.0f, 22.0f);63 label1->addSize(21.0f, 22.0f); 64 label2->addSize(21.0f, 22.0f); 65 65 66 label1->setColor(1.0f, 0.5f, 0.0f, 0.0f);67 label2->setColor(1.0f, 0.5f, 0.0f, 0.0f);66 label1->setColor(1.0f, 0.5f, 0.0f, 0.0f); 67 label2->setColor(1.0f, 0.5f, 0.0f, 0.0f); 68 68 69 box->addWidget(label1);70 box->addWidget(label2);71 box->attachMoveCallback();72 box->attachScaleCallback();73 box->attachRotateCallback();69 box->addWidget(label1); 70 box->addWidget(label2); 71 box->attachMoveCallback(); 72 box->attachScaleCallback(); 73 box->attachRotateCallback(); 74 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);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 79 80 label3->setPadding(3.0f);81 label4->setPadding(3.0f);82 label5->setPadding(3.0f);80 label3->setPadding(3.0f); 81 label4->setPadding(3.0f); 82 label5->setPadding(3.0f); 83 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);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 90 91 // Test our label copy construction...92 osgWidget::Label* label6 = label5->cloneAs("label6");91 // Test our label copy construction... 92 osgWidget::Label* label6 = label5->cloneAs("label6"); 93 93 94 label6->setLabel("abcdefghijklmnopqrs");94 label6->setLabel("abcdefghijklmnopqrs"); 95 95 96 vbox->addWidget(label3);97 vbox->addWidget(label4);98 vbox->addWidget(label5);99 vbox->addWidget(label6);100 vbox->attachMoveCallback();101 vbox->attachScaleCallback();96 vbox->addWidget(label3); 97 vbox->addWidget(label4); 98 vbox->addWidget(label5); 99 vbox->addWidget(label6); 100 vbox->attachMoveCallback(); 101 vbox->attachScaleCallback(); 102 102 103 vbox->resize();103 vbox->resize(); 104 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);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 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);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 114 115 wm->addChild(box);116 wm->addChild(vbox);117 wm->addChild(clonedBox);115 wm->addChild(box); 116 wm->addChild(vbox); 117 wm->addChild(clonedBox); 118 118 119 return osgWidget::createExample(viewer, wm);119 return osgWidget::createExample(viewer, wm); 120 120 } OpenSceneGraph/trunk/examples/osgwidgetmenu/osgwidgetmenu.cpp
r8588 r8600 16 16 17 17 struct ColorLabel: public osgWidget::Label { 18 ColorLabel(const char* label):19 osgWidget::Label("", "") {20 setFont("fonts/Calibri1.ttf");21 setFontSize(14);22 setFontColor(1.0f, 1.0f, 1.0f, 1.0f);23 setColor(0.3f, 0.3f, 0.3f, 1.0f);24 addHeight(18.0f);25 setCanFill(true);26 setLabel(label);27 setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MASK_MOUSE_MOVE);28 }18 ColorLabel(const char* label): 19 osgWidget::Label("", "") { 20 setFont("fonts/Calibri1.ttf"); 21 setFontSize(14); 22 setFontColor(1.0f, 1.0f, 1.0f, 1.0f); 23 setColor(0.3f, 0.3f, 0.3f, 1.0f); 24 addHeight(18.0f); 25 setCanFill(true); 26 setLabel(label); 27 setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MASK_MOUSE_MOVE); 28 } 29 29 30 bool mousePush(double, double, osgWidget::WindowManager*) {31 return true;32 }30 bool mousePush(double, double, osgWidget::WindowManager*) { 31 return true; 32 } 33 33 34 bool mouseEnter(double, double, osgWidget::WindowManager*) {35 setColor(0.6f, 0.6f, 0.6f, 1.0f);36 37 return true;38 }34 bool mouseEnter(double, double, osgWidget::WindowManager*) { 35 setColor(0.6f, 0.6f, 0.6f, 1.0f); 36 37 return true; 38 } 39 39 40 bool mouseLeave(double, double, osgWidget::WindowManager*) {41 setColor(0.3f, 0.3f, 0.3f, 1.0f);42 43 return true;44 }40 bool mouseLeave(double, double, osgWidget::WindowManager*) { 41 setColor(0.3f, 0.3f, 0.3f, 1.0f); 42
