Hi, I'm trying to make some GUI in OSG. 

But while using OSG 3 faced with a problem. 
There is an osgWidget::WindowManager that holds only one child osgWidget::Box 
m_box. m_box itself holds 2 widgets osgWidget::Widget m_button and 
osgWidget::Input m_input. 
Simply applying osgWidget::Callback on the event EVENT_MOUSE_PUSH to m_button 
do nothing. Applying the same callback to the m_box makes the callback to be 
called on mouse push.

Step-by-step execution showed that m_box don't even try to transmit event to 
it's children or I completely didn't understand the way it should be configured 
:( .

Can anyone explain how to apply callbacks to the widgets correctly?

Here is some source:

Code:

// Callback itself
class ButtonCallback : public osgWidget::Callback
{
public:
        ButtonCallback(osgWidget::EventType event_type) : 
osgWidget::Callback(event_type) {}

        virtual bool operator () (osgWidget::Event& event)
        {
                osgWidget::Widget* widget = event.getWidget();
                const std::string name = event.getWindow()->getName();
                return false;
        }
};

MainMenu::MainMenu(osgViewer::Viewer* viewer)
{ 
        m_viewer = viewer;
        m_wm = new osgWidget::WindowManager(viewer, 800, 600, MASK_2D);
        m_box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);

        osgWidget::Widget* m_button = new osgWidget::Widget("button");
        m_button->setSize(100, 100);
        m_button->setColor(1,0,0,1);
        m_button->setCanFill(false);
        m_button->setPadBottom(10);
        m_button->addCallback(new ButtonCallback(osgWidget::EVENT_MOUSE_PUSH));

        m_box->addWidget(m_button);
        m_box->setOrigin(20, 20);               
        m_box->addCallback(new ButtonCallback(osgWidget::EVENT_MOUSE_PUSH));
        
        m_wm->addChild(m_box);

        m_viewer->setUpViewInWindow(50, 50, static_cast<int>(m_wm->getWidth()), 
static_cast<int>(m_wm->getHeight()));
        m_camera = m_wm->createParentOrthoCamera();

        m_viewer->addEventHandler(new osgWidget::MouseHandler(m_wm));
    m_viewer->addEventHandler(new osgWidget::KeyboardHandler(m_wm));
    m_viewer->addEventHandler(new osgWidget::ResizeHandler(m_wm, m_camera));
    m_viewer->addEventHandler(new osgWidget::CameraSwitchHandler(m_wm, 
m_camera));
    m_viewer->addEventHandler(new osgViewer::WindowSizeHandler());

        m_wm->resizeAllWindows();

addChild(m_camera);
}



Thank you!

Cheers,
Mikalai[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45153#45153





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to