root/OpenSceneGraph/trunk/examples/osgwidgetmenu/osgwidgetmenu.cpp @ 12697

Revision 12697, 3.5 kB (checked in by robert, 3 years ago)

From Alberto Luacas, typo fixes

  • Property svn:eol-style set to native
RevLine 
[8588]1// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
2// $Id: osgwidgetmenu.cpp 66 2008-07-14 21:54:09Z cubicool $
3
4#include <iostream>
5#include <osgDB/ReadFile>
6#include <osgWidget/Util>
7#include <osgWidget/WindowManager>
8#include <osgWidget/Box>
9#include <osgWidget/Label>
10
11// For now this is just an example, but osgWidget::Menu will later be it's own Window.
12// I just wanted to get this out there so that people could see it was possible.
13
14const unsigned int MASK_2D = 0xF0000000;
15const unsigned int MASK_3D = 0x0F000000;
16
17struct ColorLabel: public osgWidget::Label {
[8600]18    ColorLabel(const char* label):
19    osgWidget::Label("", "") {
[8602]20        setFont("fonts/Vera.ttf");
[8600]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    }
[8588]29
[12310]30    bool mousePush(double, double, const osgWidget::WindowManager*) {
[8600]31        return true;
32    }
[8588]33
[12310]34    bool mouseEnter(double, double, const osgWidget::WindowManager*) {
[8600]35        setColor(0.6f, 0.6f, 0.6f, 1.0f);
36       
37        return true;
38    }
[8588]39
[12310]40    bool mouseLeave(double, double, const osgWidget::WindowManager*) {
[8600]41        setColor(0.3f, 0.3f, 0.3f, 1.0f);
42       
43        return true;
44    }
[8588]45};
46
47class ColorLabelMenu: public ColorLabel {
[8600]48    osg::ref_ptr<osgWidget::Window> _window;
[8588]49
50public:
[8600]51    ColorLabelMenu(const char* label):
52    ColorLabel(label) {
53        _window = new osgWidget::Box(
54            std::string("Menu_") + label,
55            osgWidget::Box::VERTICAL,
56            true
57        );
[8588]58
[8600]59        _window->addWidget(new ColorLabel("Open Some Stuff"));
60        _window->addWidget(new ColorLabel("Do It Now"));
61        _window->addWidget(new ColorLabel("Hello, How Are U?"));
62        _window->addWidget(new ColorLabel("Hmmm..."));
63        _window->addWidget(new ColorLabel("Option 5"));
[8588]64
[8600]65        _window->resize();
[8588]66
[8600]67        setColor(0.8f, 0.8f, 0.8f, 0.8f);
68    }
[8588]69
[8600]70    void managed(osgWidget::WindowManager* wm) {
71        osgWidget::Label::managed(wm);
[8588]72
[8600]73        wm->addChild(_window.get());
[8588]74
[8600]75        _window->hide();
76    }
[8588]77
[8600]78    void positioned() {
79        osgWidget::Label::positioned();
[8588]80
[8600]81        _window->setOrigin(getX(), getHeight());
82        _window->resize(getWidth());
83    }
[8588]84
[12310]85    bool mousePush(double, double, const osgWidget::WindowManager*) {
[8600]86        if(!_window->isVisible()) _window->show();
[8588]87
[8600]88        else _window->hide();
[8588]89
[8600]90        return true;
91    }
[8588]92
[12310]93    bool mouseLeave(double, double, const osgWidget::WindowManager*) {
[8600]94        if(!_window->isVisible()) setColor(0.8f, 0.8f, 0.8f, 0.8f);
[8588]95
[8600]96        return true;
97    }
[8588]98};
99
100int main(int argc, char** argv) {
[8600]101    osgViewer::Viewer viewer;
[8588]102
[8600]103    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
104        &viewer,
105        1280.0f,
106        1024.0f,
107        MASK_2D,
[9289]108        osgWidget::WindowManager::WM_PICK_DEBUG
[8600]109    );
[8588]110
[8600]111    osgWidget::Window* menu = new osgWidget::Box("menu", osgWidget::Box::HORIZONTAL);
[8588]112
[8600]113    menu->addWidget(new ColorLabelMenu("Pick me!"));
114    menu->addWidget(new ColorLabelMenu("No, wait, pick me!"));
[12697]115    menu->addWidget(new ColorLabelMenu("Don't pick them..."));
[8600]116    menu->addWidget(new ColorLabelMenu("Grarar!?!"));
[8588]117
[8600]118    wm->addChild(menu);
119   
120    menu->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);
121    menu->resizePercent(100.0f);
[8588]122
[12529]123    osg::Node* model = osgDB::readNodeFile("osgcool.osgt");
[8588]124
[8600]125    model->setNodeMask(MASK_3D);
[8588]126
[8600]127    return osgWidget::createExample(viewer, wm, model);
[8588]128}
Note: See TracBrowser for help on using the browser.