Mouse events blocked by button event

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Mouse events blocked by button event

Post by Arclamp »

Hey,

I've copied out CGUISpinBox etc to make a button list, as it suggests, an array of buttons.

When buttons are drawn then the mouse down / move / up events don't appear. If no buttons are drawn then mouse events are received.

Is this because of how they are set up as subelements, or just because of their button event return, etc...

Any which way, what's the correct / best way to deal with this?

(Before, I used IGUIStaticText instead and handled rect testing myself)

Cheers
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Mouse events blocked by button event

Post by CuteAlien »

Who does not get events? The button, an element below the button, your application?

Events are still send out - the questions is who gets and handles them. The element below the mouse receives it first - and then decides to pass it on to it's parent (or not in case it eats the event).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Mouse events blocked by button event

Post by Arclamp »

Yes, I believe the mouse event is being eaten by the sub element button event. That is technically how it should be.

I'm sort of looking how to also get the mouse event after the button event. e.g. both track button click and list drag (but in separate elements)

Since the event is consumed, I half wondered if the button sends a new mouse event (maybe straight to parent after your mention), or, return false if parent is a buttonlist (too custom!)


A working example would be using a list of IGUIStaticText's, because they don't consume the mouse event. Then I instruct the background change from the parent element.

No matter, I'll go with the StaticText method so as to not change things too drastically...
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Mouse events blocked by button event

Post by Arclamp »

Here's how it looks at close tonight, I've swapped in IGUIStaticPanel (IGUIStaticText) instead of IGUIItem (IGUIButton) to show a working example.

IGUIButtonList.h

Code: Select all

 
// Copyright (C) 2006-2012 Michael Zeilfelder
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
 
#ifndef __I_GUI_BUTTON_LIST_H_INCLUDED__
#define __I_GUI_BUTTON_LIST_H_INCLUDED__
 
#include "IGUIElement.h"
 
namespace irr
{
namespace gui
{
    class IGUIEditBox;
 
    //! Single line edit box + spin buttons
    /** \par This element can create the following events of type EGUI_EVENT_TYPE:
    \li EGET_SPINBOX_CHANGED
    */
    class IGUIButtonList : public IGUIElement
    {
    public:
 
        //! constructor
        IGUIButtonList(IGUIEnvironment* environment, IGUIElement* parent,
                    s32 id, core::rect<s32> rectangle)
            : IGUIElement(EGUIET_BUTTON_LIST, environment, parent, id, rectangle) {}
 
        virtual void set_styles(io::IAttributes *attr, bool do_refresh=true) = 0;
        virtual void set_style(core::stringc key, core::stringc value, bool do_refresh=true) = 0;
        virtual core::stringc get_style(core::stringc key) const = 0;
        
        virtual void clear_items(bool do_refresh=true) = 0;
        virtual void set_items(core::array<io::IAttributes*> new_items) = 0;
        virtual void add_item(io::IAttributes *item, bool do_refresh=true) = 0;
        
        virtual io::IAttributes *get_last_event() = 0;
    };
} // end namespace gui
} // end namespace irr
 
#endif // __I_GUI_SPIN_BOX_H_INCLUDED__
 
CGUIButtonList.h

Code: Select all

 
// Copyright (C) 2006-2012 Michael Zeilfelder
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
 
#ifndef __C_GUI_BUTTON_LIST_H_INCLUDED__
#define __C_GUI_BUTTON_LIST_H_INCLUDED__
 
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
 
#include "IGUIButtonList.h"
 
#include "IGUIStaticPanel.h"
//#include "IGUIEditBoxd.h"
#include "IGUIItem.h"
 
//#include "IWriteFile.h"
//#include "IReadFile.h"
 
//#include "IFileList.h"
#include "IFileSystem.h"
 
namespace irr
{
namespace gui
{
    class IGUIEditBox;
    class IGUIButton;
    
    //class IGUIEditBoxd;
    class IGUIStaticPanel;
    class IGUIItem;
    
    class CGUIButtonList : public IGUIButtonList
    {
    public:
 
        //! constructor
        CGUIButtonList(const wchar_t* text, bool border, IGUIEnvironment* environment,
            IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);
 
        //! destructor
        virtual ~CGUIButtonList();
 
        //! called if an event happened.
        virtual bool OnEvent(const SEvent& event);
 
        //! Draws the element and its children.
        virtual void draw();
 
        //! Writes attributes of the element.
        virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
 
        //! Reads attributes of the element
        virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
        
        
        
        virtual void set_styles(io::IAttributes *attr, bool do_refresh=true);
        virtual void set_style(core::stringc key, core::stringc value, bool do_refresh=true);
        virtual core::stringc get_style(core::stringc key) const;
        
        virtual void clear_items(bool do_refresh=true);
        virtual void set_items(core::array<io::IAttributes*> new_items);
        virtual void add_item(io::IAttributes *item, bool do_refresh=true);
        
        virtual io::IAttributes *get_last_event();
        
    protected:
        
        IGUIStaticPanel *e_root;
        IGUIStaticPanel *e_wrap;
        IGUIItem *e_scroll_top;
        IGUIItem *e_scroll_bottom;
        
        u32 last_event;
        io::IAttributes *attr_styles;
        core::array<io::IAttributes*> items;
        //core::array<IGUIItem*> buttons;       //  replace with IGUIButton
        core::array<IGUIStaticPanel*> buttons;  //  replace with IGUIStaticText
        
        s32 btn_h;
        s32 dragging;
        s32 dragging_pos;
        s32 scroll_pos;
        s32 i_scrollspeed;
        
        void refresh();
        void handle_scroll(s32 n=0);
    };
} // end namespace gui
} // end namespace irr
 
#endif // _IRR_COMPILE_WITH_GUI_
 
#endif // __C_GUI_SPIN_BOX_H_INCLUDED__
 
CGUIButtonList.cpp

Code: Select all

 
// Copyright (C) 2006-2012 Michael Zeilfelder
// This file uses the licence of the Irrlicht Engine.
 
#include "CGUIButtonList.h"
#ifdef _IRR_COMPILE_WITH_GUI_
 
#include "CGUIEditBox.h"
#include "CGUIButton.h"
#include "IGUIEnvironment.h"
#include "IEventReceiver.h"
#include "fast_atof.h"
#include <wchar.h>
 
 
namespace irr
{
namespace gui
{
 
//! constructor
CGUIButtonList::CGUIButtonList(const wchar_t* text, bool border,IGUIEnvironment* environment,
            IGUIElement* parent, s32 id, const core::rect<s32>& rectangle)
: IGUIButtonList(environment, parent, id, rectangle),
    e_root(0),e_wrap(0),e_scroll_top(0),e_scroll_bottom(0),
    attr_styles(0)
{
    #ifdef _DEBUG
    setDebugName("CGUIButtonList");
    #endif
    
    //  INITS
    last_event = -1;
    dragging = 0;
    dragging_pos = 0;
    scroll_pos = 0;
    
    i_scrollspeed = 5;
    
    /*
    //  GEN INITIAL FAKE DATA
    irr::io::IFileSystem *fs = Environment->getFileSystem();
    io::IAttributes *attr;  // = fs->createEmptyAttributes(NULL);       //  driver);    //  disallows internal loading of textures
    
    attr = fs->createEmptyAttributes(NULL);
    attr->addString("label", "Hello");
    //attr->addString("src", "");               //  change to texture...
    items.push_back(attr);
    
    attr = fs->createEmptyAttributes(NULL);
    attr->addString("label", "Goodbye");
    //attr->addString("src", "");               //  change to texture...
    items.push_back(attr);
    */
    
    //  CREATE ELEMENTS
    refresh();
}
 
//! Refresh
void CGUIButtonList::refresh()
{
    
    
    //  DELETE OLD ROOT PANEL
    //IGUIStaticPanel *e_root;
    if(e_root)
    {
        e_root->drop();
        e_root = NULL;
    }
    
    
    //  DELETE OLD BUTTONS
    for(u32 i = 0; i < buttons.size(); i++)
    {
        //std::cout << "" << points[i].c_str() << std::endl;
        //delete items[i];
        //items[i] = NULL;
        
        buttons[i]->setVisible(false);
        
        buttons[i]->drop();
    }
    buttons.clear();
    
    if(e_scroll_top)
    {
        e_scroll_top->drop();
        e_scroll_top = NULL;
    }
    
    if(e_scroll_bottom)
    {
        e_scroll_bottom->drop();
        e_scroll_bottom = NULL;
    }
    
    if(e_wrap)
    {
        e_wrap->drop();
        e_wrap = NULL;
    }
    
    
    //  DEFAULTS
    bool show_buttons = false;  //false;
    s32 btn_h = 20;
    s32 btn_scroll = 0;
    s32 btn_scroll_h = 0;
    
    
    //  PARSE CORE STYLES
    if(attr_styles)
    {
        s32 id = attr_styles->findAttribute("h");
        if(id >= 0){        btn_h = attr_styles->getAttributeAsInt(id);     }
        
        id = attr_styles->findAttribute("show_buttons");
        if(id >= 0){        show_buttons = attr_styles->getAttributeAsBool(id);     }
        
        id = attr_styles->findAttribute("button_h");
        if(id >= 0){        btn_scroll_h = attr_styles->getAttributeAsInt(id);      }
    }
    
    
    //s32 btn_scroll = 0;
    if(show_buttons)
    {
        
        btn_scroll = btn_h;
        if(btn_scroll_h > 0)
        {
            btn_scroll = btn_scroll_h;  //  USE OVERRIDE
        }
        
        
        //e_scroll_top = Environment->addButton(core::rect<s32>(0, btn_h*i, AbsoluteRect.getWidth(), btn_h*(i+1)), e_root);
        e_scroll_top = Environment->addItem(core::rect<s32>(0, 0, AbsoluteRect.getWidth(), btn_scroll), this);
        e_scroll_top->grab();
        e_scroll_top->setSubElement(true);
        e_scroll_top->setTabStop(false);
        //e_scroll_top->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_CENTER);
        //e_scroll_top->setText(items[i]->getAttributeAsStringW("label").c_str());
        
        //e_scroll_bottom = Environment->addButton(core::rect<s32>(0, btn_h*i, AbsoluteRect.getWidth(), btn_h*(i+1)), e_root);
        e_scroll_bottom = Environment->addItem(core::rect<s32>(0, AbsoluteRect.getHeight()-btn_scroll, AbsoluteRect.getWidth(), AbsoluteRect.getHeight()), this);
        e_scroll_bottom->grab();
        e_scroll_bottom->setSubElement(true);
        e_scroll_bottom->setTabStop(false);
        //e_scroll_bottom->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_CENTER);
        //e_scroll_bottom->setText(items[i]->getAttributeAsStringW("label").c_str());
    }
    
    //  ADD WRAP PANEL
    e_wrap = Environment->addStaticPanel(L"", core::rect<s32>(0,btn_scroll,AbsoluteRect.getWidth(),AbsoluteRect.getHeight()-btn_scroll), false, false, this, -1, true);
    e_wrap->grab();
    e_wrap->setSubElement(true);
    //e_wrap->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);      //  left, right, top, bottom
    e_wrap->setBackgroundColor(video::SColor(255,255,255,0));
    e_wrap->setDrawBackground(true);
    
    
    //  ADD ROOT PANEL
    e_root = Environment->addStaticPanel(L"", core::rect<s32>(0,0,e_wrap->getRelativePosition().getWidth(),e_wrap->getRelativePosition().getHeight()), false, false, e_wrap, -1, true);
    e_root->grab();
    e_root->setSubElement(true);
    //e_root->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);      //  left, right, top, bottom
    e_root->setBackgroundColor(video::SColor(255,255,0,255));
    e_root->setDrawBackground(true);
    
    
    s32 tot_h = 0;
    
    //  ADD BUTTONS
    //IGUIButton *btn;
    //IGUIItem *btn;
    IGUIStaticPanel *btn;
    for(u32 i = 0; i < items.size(); i++)
    {
        //btn = Environment->addButton(core::rect<s32>(0, btn_h*i, AbsoluteRect.getWidth(), btn_h*(i+1)), e_root);
        //btn = Environment->addItem(core::rect<s32>(0, btn_h*i, e_wrap->getRelativePosition().getWidth(), btn_h*(i+1)), e_root);
        btn = Environment->addStaticPanel(items[i]->getAttributeAsStringW("label").c_str(), core::rect<s32>(0, btn_h*i, e_wrap->getRelativePosition().getWidth(), btn_h*(i+1)), false, false, e_root, true);
        btn->grab();
        btn->setSubElement(true);
        btn->setTabStop(false);
        //btn->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_CENTER);
        //btn->setText(items[i]->getAttributeAsStringW("label").c_str());
        buttons.push_back(btn);
        
        tot_h += btn_h;
    }
    
    
    //  RESIZE ROOT PANEL
    if(tot_h > e_wrap->getRelativePosition().getHeight())
    {
        //this->setRelativePosition(core::rect<s32>(0,0,AbsoluteRect.getWidth(),tot_h));
        e_root->setRelativePosition(core::rect<s32>(0,0,e_wrap->getRelativePosition().getWidth(),tot_h));
        //void setRelativePosition (const core::rect< s32 > &r)
        //void setRelativePosition (const core::position2di &position);
    }
    
    //  RESET GLOBALS
    scroll_pos = 0;
    dragging_pos = 0;
    
}
 
void CGUIButtonList::handle_scroll(s32 n)
{
    s32 h = e_root->getRelativePosition().getHeight();
    s32 eh = e_wrap->getRelativePosition().getHeight();
    //if(h > AbsoluteRect.getHeight())
    if(h > eh)
    {
        //  SCROLLABLE
        
        scroll_pos += (n*i_scrollspeed);
        
        if(scroll_pos > 0)
        {
            scroll_pos = 0;
        }
        else
        if(scroll_pos < -(h-eh))
        {
            scroll_pos = -(h-eh);
        }
        
        e_root->setRelativePosition(core::position2di(0, scroll_pos));
        
    }
    else
    {
        //  IGNORE
    }
}
 
//! destructor
CGUIButtonList::~CGUIButtonList()
{
    
    for(u32 i = 0; i < items.size(); i++)
    {
        items[i]->drop();
        items[i] = NULL;
    }
    items.clear();
    
    
    for(u32 i = 0; i < buttons.size(); i++)
    {
        buttons[i]->drop();
        buttons[i] = NULL;
    }
    buttons.clear();
    
    
    if(e_scroll_top)
    {
        e_scroll_top->drop();
        e_scroll_top = NULL;
    }
    
    if(e_scroll_bottom)
    {
        e_scroll_bottom->drop();
        e_scroll_bottom = NULL;
    }
    
    if(e_root)
    {
        e_root->drop();
        e_root = NULL;
    }
    
    if(e_wrap)
    {
        e_wrap->drop();
        e_wrap = NULL;
    }
    
}
 
bool CGUIButtonList::OnEvent(const SEvent& event)
{
    if (IsEnabled)
    {
        switch(event.EventType)
        {
        case EET_MOUSE_INPUT_EVENT:
            switch(event.MouseInput.Event)
            {
            case EMIE_MOUSE_WHEEL:
                {
                    handle_scroll((event.MouseInput.Wheel < 0 ? -1.f : 1.f));
                }
                break;
                
            case  EMIE_LMOUSE_PRESSED_DOWN:
                {
                    if(e_wrap->isPointInside(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
                    {
                        printf("MOUSE DOWN: INSIDE\n");
                        dragging = 1;
                        
                        dragging_pos = event.MouseInput.Y;  //  STORE
                    }
                }
                break;
            case  EMIE_MOUSE_MOVED:
                {
                    
                    core::position2di mpos = core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y);
                    if(dragging >= 1)   // && e_wrap->isPointInside(mpos))
                    {
                        dragging = 2;
                        s32 diff = dragging_pos - mpos.Y;
                        
                        scroll_pos -= diff; //  UPDATE HERE
                        handle_scroll(0);   //  PASS ZERO!!
                        
                        dragging_pos = mpos.Y;  //  STORE
                    }
                }
                break;
            case  EMIE_LMOUSE_LEFT_UP:
                {
                    if(dragging == 1)   //  NO DRAG
                    {
                        if(e_wrap->isPointInside(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
                        {
                            IGUIElement *e = Environment->getRootGUIElement()->getElementFromPoint(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y));
                            if(e && e != Environment->getRootGUIElement())
                            {
                                for(u32 i = 0; i < buttons.size(); i++)
                                {
                                    if(buttons[i] == e)
                                    {
                                        printf("Found our button....! %d \n", i);
                                        
                                        //  STORE
                                        last_event = i;
                                        
                                        //  SEND EVENT
                                        SEvent e;
                                        e.EventType = EET_GUI_EVENT;
                                        e.GUIEvent.Caller = this;
                                        e.GUIEvent.Element = 0;
                                        e.GUIEvent.EventType = EGET_BUTTONLIST_CLICKED;
                                        if ( Parent )
                                            Parent->OnEvent(e);
                                        
                                        //  CLEAR
                                        dragging = 0;
                                        dragging_pos = 0;
                                        
                                        //  CLAIM THIS EVENT
                                        return true;
                                        //break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    if(dragging == 2)   //  DRAG HAPPENED
                    {
                        //printf("Dragging happened!\n");
                    }
                    
                    //  CLEAR
                    dragging = 0;
                    dragging_pos = 0;
                }
                break;
                
            default:
                break;
            }
            break;
 
        case EET_GUI_EVENT:
            if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
            {
                /*
                for(u32 i = 0; i < buttons.size(); i++)
                {
                    if(event.GUIEvent.Caller == buttons[i])
                    {
                        printf("Found\n");
                        
                        //virtual io::IAttributes *get_last_event();
                        last_event = i;
                        
                        SEvent e;
                        e.EventType = EET_GUI_EVENT;
                        e.GUIEvent.Caller = this;
                        e.GUIEvent.Element = 0;
                        e.GUIEvent.EventType = EGET_BUTTONLIST_CLICKED;
                        if ( Parent )
                            Parent->OnEvent(e);
                        
                        return true;
                    }
                }
                */
                //  SCROLL BUTTON TESTING
                if(e_scroll_top && event.GUIEvent.Caller == e_scroll_top)
                {
                    handle_scroll(1);
                    return true;
                }
                else
                if(e_scroll_bottom && event.GUIEvent.Caller == e_scroll_bottom)
                {
                    handle_scroll(-1);
                    return true;
                }
            }
            break;
        default:
        break;
        }
    }
    return IGUIElement::OnEvent(event);
}
 
void CGUIButtonList::draw()
{
    if ( !isVisible() )
        return;
    
    IGUIButtonList::draw();
}
 
//! Writes attributes of the element.
void CGUIButtonList::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
    IGUIElement::serializeAttributes(out, options);
    /*
    out->addFloat("Min", getMin());
    out->addFloat("Max", getMax());
    out->addFloat("Step", getStepSize());
    out->addInt("DecimalPlaces", DecimalPlaces);
    */
}
 
//! Reads attributes of the element
void CGUIButtonList::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
    IGUIElement::deserializeAttributes(in, options);
    /*
    setRange(in->getAttributeAsFloat("Min"), in->getAttributeAsFloat("Max"));
    setStepSize(in->getAttributeAsFloat("Step"));
    setDecimalPlaces(in->getAttributeAsInt("DecimalPlaces"));
    */
}
 
void CGUIButtonList::set_styles(io::IAttributes *attr, bool do_refresh)
{
    attr_styles = attr;
    
    if(attr_styles)
    {
        s32 id = attr_styles->findAttribute("scrollspeed");
        if(id >= 0){        i_scrollspeed = attr_styles->getAttributeAsInt(id);     }
    }
    
    if(do_refresh)
    {
        //  REFRESH
        refresh();
    }
}
 
void CGUIButtonList::set_style(core::stringc key, core::stringc value, bool do_refresh)
{
    //attr_styles
}
 
core::stringc CGUIButtonList::get_style(core::stringc key) const
{
    
    return "";
}
 
void CGUIButtonList::clear_items(bool do_refresh)
{
    //  DELETE
    for(u32 i = 0; i < items.size(); i++)
    {
        items[i]->drop();
        items[i] = NULL;
    }
    items.clear();
    
    last_event = -1;
    
    if(do_refresh)
    {
        //  REFRESH
        refresh();
    }
}
 
void CGUIButtonList::set_items(core::array<io::IAttributes*> new_items)
{
    //  DELETE OLD
    clear_items(false);
    //  SET ITEM
    items = new_items;
    //  REFRESH
    refresh();
}
 
void CGUIButtonList::add_item(io::IAttributes *item, bool do_refresh)
{
    if(item)
    {
        //  ADD
        items.push_back(item);
        
        if(do_refresh)
        {
            //  REFRESH
            refresh();
        }
    }
}
 
//! Returns the item and not the button
io::IAttributes *CGUIButtonList::get_last_event()
{
    if(last_event >= 0 && last_event < items.size())
    {
        return items[last_event];
    }
    return NULL;
}
} // end namespace gui
} // end namespace irr
 
#endif // _IRR_COMPILE_WITH_GUI_
 
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Mouse events blocked by button event

Post by Arclamp »

Oh, some usage:

Code: Select all

 
 
    //  BUTTON LIST
    //  =========================================================
    
    //IGUIButtonList
    btnlist = env->addButtonList(L"0", core::rect<s32>(30,100,400,100+100), true, 0, 514);
    
    
    IAttributes *attr;
    
    attr = nub->new_attr();
    attr->addInt("h", 30);
    //attr->addString("bg", "media/tex/stones.jpg");                //  change to texture...
    attr->addInt("scrollspeed", 10);
    attr->addInt("show_buttons", true);
    attr->addInt("button_h", 10);
    btnlist->set_styles(attr);
    
    
    
    attr = nub->new_attr();
    attr->addString("label", "Yoyo");
    //attr->addString("src", "");               //  change to texture...
    btnlist->add_item(attr);
    
    
    btnlist->clear_items();
    
    core::array<io::IAttributes*> new_items;
    
    attr = nub->new_attr();
    attr->addString("label", "One");
    new_items.push_back(attr);
    
    attr = nub->new_attr();
    attr->addString("label", "Two");
    new_items.push_back(attr);
    
    attr = nub->new_attr();
    attr->addString("label", "Three");
    new_items.push_back(attr);
    
    attr = nub->new_attr();
    attr->addString("label", "Four");
    new_items.push_back(attr);
    
    attr = nub->new_attr();
    attr->addString("label", "Five");
    new_items.push_back(attr);
    
    attr = nub->new_attr();
    attr->addString("label", "Six");
    new_items.push_back(attr);
    
    attr = nub->new_attr();
    attr->addString("label", "Seven");
    new_items.push_back(attr);
    
    attr = nub->new_attr();
    attr->addString("label", "Eight");
    new_items.push_back(attr);
    
    btnlist->set_items(new_items);
    
 
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Mouse events blocked by button event

Post by CuteAlien »

Buttons don't pass on mouse-events when they use them. But they do send a EGET_BUTTON_CLICKED in that case. Maybe you can use that?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Mouse events blocked by button event

Post by Arclamp »

Think it'd need an EGET_BUTTON_DOWN event too!?
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Mouse events blocked by button event

Post by Arclamp »

Not tried yet but maybe EGET_ELEMENT_FOCUSED would be triggered?
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Mouse events blocked by button event

Post by CuteAlien »

Focused is also triggered on tab-switches probably. Notice that button-clicks also can be triggered by <enter> and <space> keys.
Handling events like that additional to button is really tricky. Maybe Irrlicht elements need some "do not eat mouse-click events"-flag? (edit: this sounds useful and not much work, so if you want I can add that to svn-trunk) You could also cheat by adding invisible elements with same size as childs to the button - which passes events on to the button but also catches it first (yeah... ugly). Invisible element same size as buttonlist would also work - if you move the invisible element then always to the end of the child-list (but risky stuff as invisible elements can really confuse users).

On an unrelated side-note... why is your code copyright by me? :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Arclamp
Posts: 71
Joined: Thu Oct 10, 2013 7:45 pm

Re: Mouse events blocked by button event

Post by Arclamp »

Mmmm, invisible panels do sound fussy and extra processing for limited usage, and that's the beauty of Irrlicht, it handles the essentials, fast... and on that note, did I mention I'm dyslexic++ and generally too mashed to know my own name :D

I have recently taught myself svn, but not really got into using it yet since I've been going to so many "do not eat the mouse-clique events".

Image

Back to reality, I'll do some more tests, see if EGET_ELEMENT_FOCUSED does the trick (there's always a way in Irrlicht lol), and for that, many many thanks
Post Reply