Allow configure event callback for widgets based on input type
This will allow for example touch screen tapping to not triggering kart selection in mobile STK
This commit is contained in:
parent
2b0b941219
commit
89a57e6e19
@ -380,7 +380,7 @@ void EventHandler::processGUIAction(const PlayerAction action,
|
||||
if (w == NULL) break;
|
||||
|
||||
// FIXME : consider returned value?
|
||||
onWidgetActivated( w, playerID );
|
||||
onWidgetActivated(w, playerID, type);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -780,7 +780,7 @@ void EventHandler::sendEventToUser(GUIEngine::Widget* widget, std::string& name,
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int playerID)
|
||||
EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int playerID, Input::InputType type)
|
||||
{
|
||||
if (w->onActivationInput(playerID) == EVENT_BLOCK)
|
||||
return EVENT_BLOCK;
|
||||
@ -831,7 +831,8 @@ EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int
|
||||
parent event handler says so */
|
||||
if (parent->transmitEvent(w, w->m_properties[PROP_ID], playerID) == EVENT_LET)
|
||||
{
|
||||
sendEventToUser(parent, parent->m_properties[PROP_ID], playerID);
|
||||
if (parent->isEventCallbackActive(type))
|
||||
sendEventToUser(parent, parent->m_properties[PROP_ID], playerID);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -841,7 +842,8 @@ EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int
|
||||
if (w->transmitEvent(w, id, playerID) == EVENT_LET)
|
||||
{
|
||||
assert(w->ok());
|
||||
sendEventToUser(w, id, playerID);
|
||||
if (w->isEventCallbackActive(type))
|
||||
sendEventToUser(w, id, playerID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -881,7 +883,7 @@ EventPropagation EventHandler::onGUIEvent(const SEvent& event)
|
||||
|
||||
// These events are only triggered by mouse (or so I hope)
|
||||
// The player that owns the mouser receives "game master" priviledges
|
||||
return onWidgetActivated(w, PLAYER_ID_GAME_MASTER);
|
||||
return onWidgetActivated(w, PLAYER_ID_GAME_MASTER, Input::IT_MOUSEBUTTON);
|
||||
|
||||
// These events are only triggered by keyboard/mouse (or so I hope...)
|
||||
//const int playerID = input_manager->getPlayerKeyboardID();
|
||||
|
@ -70,7 +70,7 @@ namespace GUIEngine
|
||||
bool m_accept_events;
|
||||
|
||||
EventPropagation onGUIEvent(const irr::SEvent& event);
|
||||
EventPropagation onWidgetActivated(Widget* w, const int playerID);
|
||||
EventPropagation onWidgetActivated(Widget* w, const int playerID, Input::InputType type);
|
||||
void sendNavigationEvent(const NavigationDirection nav, const int playerID);
|
||||
void navigate(const NavigationDirection nav, const int playerID);
|
||||
|
||||
|
@ -55,6 +55,9 @@ using namespace GUIEngine;
|
||||
|
||||
Widget::Widget(WidgetType type, bool reserve_id)
|
||||
{
|
||||
// Accept all input by default
|
||||
m_active_event_callback.flip();
|
||||
m_active_event_callback[Input::IT_NONE] = false;
|
||||
m_magic_number = 0xCAFEC001;
|
||||
|
||||
m_x = -1;
|
||||
@ -120,6 +123,18 @@ Widget::~Widget()
|
||||
m_magic_number = 0xDEADBEEF;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Widget::setEventCallbackActive(Input::InputType type, bool active)
|
||||
{
|
||||
m_active_event_callback[type] = active;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool Widget::isEventCallbackActive(Input::InputType type) const
|
||||
{
|
||||
return m_active_event_callback[type];
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void Widget::setText(const irr::core::stringw &s)
|
||||
{
|
||||
|
@ -25,6 +25,7 @@ namespace irr
|
||||
{
|
||||
namespace gui { class IGUIElement; }
|
||||
}
|
||||
#include <bitset>
|
||||
#include <map>
|
||||
|
||||
#include "guiengine/event_handler.hpp"
|
||||
@ -140,6 +141,10 @@ namespace GUIEngine
|
||||
protected:
|
||||
unsigned int m_magic_number;
|
||||
|
||||
// Used to limit event callback on this widget based on input type
|
||||
// At the moment used for continue button in kart selection
|
||||
std::bitset<Input::IT_LAST + 1> m_active_event_callback;
|
||||
|
||||
// FIXME: find better ways than hackish "friend"?
|
||||
friend class EventHandler;
|
||||
friend class Screen;
|
||||
@ -340,6 +345,16 @@ namespace GUIEngine
|
||||
Widget(WidgetType type, bool reserve_id = false);
|
||||
virtual ~Widget();
|
||||
|
||||
/**
|
||||
* Allow (or not) an event callback for this widget based on input type.
|
||||
*/
|
||||
virtual void setEventCallbackActive(Input::InputType type, bool active);
|
||||
|
||||
/**
|
||||
* Return if there should be an event callback for this widget based on input type.
|
||||
*/
|
||||
virtual bool isEventCallbackActive(Input::InputType type) const;
|
||||
|
||||
/**
|
||||
* Set the irrlicht widget to be used as parent of this widget next time Widget::add()
|
||||
* is invoked on this widget.
|
||||
|
Loading…
x
Reference in New Issue
Block a user