Add simple support for separate mouse buttons
This commit is contained in:
parent
eff7f085c9
commit
65ad6ede62
@ -229,10 +229,10 @@ static void mouse_button_callback(GLFWwindow *window, int button, int action, in
|
||||
last_y = y;
|
||||
last_time = time;
|
||||
|
||||
GetBackend(window)->GetRoot()->InvokePointerDown(x, y, counter, modifier, ShouldEmulateTouchEvent());
|
||||
GetBackend(window)->GetRoot()->InvokePointerDown(MOUSE_BUTTON_LEFT, x, y, counter, modifier, ShouldEmulateTouchEvent());
|
||||
}
|
||||
else
|
||||
GetBackend(window)->GetRoot()->InvokePointerUp(x, y, 1, modifier, ShouldEmulateTouchEvent());
|
||||
GetBackend(window)->GetRoot()->InvokePointerUp(MOUSE_BUTTON_LEFT, x, y, 1, modifier, ShouldEmulateTouchEvent());
|
||||
}
|
||||
else if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_RELEASE)
|
||||
{
|
||||
|
@ -390,10 +390,10 @@ bool AppBackendSDL2::HandleSDLEvent(SDL_Event & event)
|
||||
int counter = event.button.clicks;
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
m_app->GetRoot()->InvokePointerDown(x, y, counter, modifier, ShouldEmulateTouchEvent());
|
||||
m_app->GetRoot()->InvokePointerDown(MOUSE_BUTTON_LEFT, x, y, counter, modifier, ShouldEmulateTouchEvent());
|
||||
}
|
||||
else
|
||||
m_app->GetRoot()->InvokePointerUp(x, y, counter, modifier, ShouldEmulateTouchEvent());
|
||||
m_app->GetRoot()->InvokePointerUp(MOUSE_BUTTON_LEFT, x, y, counter, modifier, ShouldEmulateTouchEvent());
|
||||
}
|
||||
else if (event.button.button == SDL_BUTTON_RIGHT && event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
|
@ -187,9 +187,9 @@ JNI_VOID_TB_LIB(OnPointer)(JNIEnv *env, jobject obj, jfloat x, jfloat y, jint do
|
||||
|
||||
int counter = 1;
|
||||
if (down)
|
||||
root->InvokePointerDown(x, y, counter, TB_MODIFIER_NONE, true);
|
||||
root->InvokePointerDown(MOUSE_BUTTON_LEFT, x, y, counter, TB_MODIFIER_NONE, true);
|
||||
else
|
||||
root->InvokePointerUp(x, y, TB_MODIFIER_NONE, true);
|
||||
root->InvokePointerUp(MOUSE_BUTTON_LEFT, x, y, TB_MODIFIER_NONE, true);
|
||||
}
|
||||
|
||||
JNI_VOID_TB_LIB(OnPointer2)(JNIEnv *env, jobject obj, jfloat x, jfloat y, jint down)
|
||||
|
@ -187,9 +187,9 @@ JNI_VOID_TB_LIB(OnPointer)(JNIEnv *env, jobject obj, jfloat x, jfloat y, jint do
|
||||
|
||||
int counter = 1;
|
||||
if (down)
|
||||
root->InvokePointerDown(x, y, counter, TB_MODIFIER_NONE, true);
|
||||
root->InvokePointerDown(MOUSE_BUTTON_LEFT, x, y, counter, TB_MODIFIER_NONE, true);
|
||||
else
|
||||
root->InvokePointerUp(x, y, counter, TB_MODIFIER_NONE, true);
|
||||
root->InvokePointerUp(MOUSE_BUTTON_LEFT, x, y, counter, TB_MODIFIER_NONE, true);
|
||||
}
|
||||
|
||||
JNI_VOID_TB_LIB(OnPointer2)(JNIEnv *env, jobject obj, jfloat x, jfloat y, jint down)
|
||||
|
@ -1283,7 +1283,7 @@ void TBWidget::StopLongClickTimer()
|
||||
m_long_click_timer = nullptr;
|
||||
}
|
||||
|
||||
bool TBWidget::InvokePointerDown(int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch)
|
||||
bool TBWidget::InvokePointerDown(MOUSE_BUTTON button, int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch)
|
||||
{
|
||||
if (!captured_widget)
|
||||
{
|
||||
@ -1337,6 +1337,7 @@ bool TBWidget::InvokePointerDown(int x, int y, int click_count, MODIFIER_KEYS mo
|
||||
pointer_move_widget_x = pointer_down_widget_x = x;
|
||||
pointer_move_widget_y = pointer_down_widget_y = y;
|
||||
TBWidgetEvent ev(EVENT_TYPE_POINTER_DOWN, x, y, touch, modifierkeys);
|
||||
ev.mouse_button = button;
|
||||
ev.count = click_count;
|
||||
captured_widget->InvokeEvent(ev);
|
||||
|
||||
@ -1347,13 +1348,14 @@ bool TBWidget::InvokePointerDown(int x, int y, int click_count, MODIFIER_KEYS mo
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TBWidget::InvokePointerUp(int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch)
|
||||
bool TBWidget::InvokePointerUp(MOUSE_BUTTON button, int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch)
|
||||
{
|
||||
if (captured_widget)
|
||||
{
|
||||
captured_widget->ConvertFromRoot(x, y);
|
||||
TBWidgetEvent ev_up(EVENT_TYPE_POINTER_UP, x, y, touch, modifierkeys);
|
||||
TBWidgetEvent ev_click(EVENT_TYPE_CLICK, x, y, touch, modifierkeys);
|
||||
ev_up.mouse_button = button;
|
||||
ev_up.count = click_count;
|
||||
ev_click.count = click_count;
|
||||
captured_widget->InvokeEvent(ev_up);
|
||||
|
@ -110,6 +110,14 @@ enum SPECIAL_KEY
|
||||
TB_KEY_F7, TB_KEY_F8, TB_KEY_F9, TB_KEY_F10, TB_KEY_F11, TB_KEY_F12
|
||||
};
|
||||
|
||||
enum MOUSE_BUTTON
|
||||
{
|
||||
MOUSE_BUTTON_NONE = 0,
|
||||
MOUSE_BUTTON_LEFT,
|
||||
MOUSE_BUTTON_RIGHT,
|
||||
MOUSE_BUTTON_MIDDLE,
|
||||
};
|
||||
|
||||
class TBWidgetEvent : public TBTypedObject
|
||||
{
|
||||
public:
|
||||
@ -129,6 +137,7 @@ public:
|
||||
/// EVENT_TYPE_FINGER_* is the finger number.
|
||||
SPECIAL_KEY special_key;
|
||||
MODIFIER_KEYS modifierkeys;
|
||||
MOUSE_BUTTON mouse_button;
|
||||
TBID ref_id; ///< Sometimes (when documented) events have a ref_id (The id that caused this event)
|
||||
bool touch; ///< Set for pointer events. True if the event is a touch event (finger or pen on screen)
|
||||
///< False if mouse or other cursor input.
|
||||
@ -136,12 +145,12 @@ public:
|
||||
TBOBJECT_SUBCLASS(TBWidgetEvent, TBTypedObject);
|
||||
|
||||
TBWidgetEvent(EVENT_TYPE type) : target(nullptr), type(type), target_x(0), target_y(0), delta_x(0), delta_y(0), count(1),
|
||||
key(0), special_key(TB_KEY_UNDEFINED), modifierkeys(TB_MODIFIER_NONE), touch(false) {}
|
||||
key(0), special_key(TB_KEY_UNDEFINED), modifierkeys(TB_MODIFIER_NONE), mouse_button(MOUSE_BUTTON_NONE), touch(false) {}
|
||||
|
||||
TBWidgetEvent(EVENT_TYPE type, int x, int y, bool touch, MODIFIER_KEYS modifierkeys = TB_MODIFIER_NONE) :
|
||||
target(nullptr), type(type), target_x(x), target_y(y), delta_x(0), delta_y(0),
|
||||
count(1), key(0), special_key(TB_KEY_UNDEFINED), modifierkeys(modifierkeys),
|
||||
touch(touch) {}
|
||||
mouse_button(MOUSE_BUTTON_NONE), touch(touch) {}
|
||||
|
||||
/** The count value may be 1 to infinity. If you f.ex want to see which count it is for something
|
||||
handling click and double click, call GetCountCycle(2). If you also handle triple click, call
|
||||
@ -1061,9 +1070,9 @@ public:
|
||||
bool InvokeEvent(TBWidgetEvent &ev);
|
||||
|
||||
/** See TBWidget::InvokeEvent */
|
||||
bool InvokePointerDown(int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch);
|
||||
bool InvokePointerDown(MOUSE_BUTTON button, int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch);
|
||||
/** See TBWidget::InvokeEvent */
|
||||
bool InvokePointerUp(int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch);
|
||||
bool InvokePointerUp(MOUSE_BUTTON button, int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch);
|
||||
/** See TBWidget::InvokeEvent */
|
||||
void InvokePointerMove(int x, int y, MODIFIER_KEYS modifierkeys, bool touch);
|
||||
/** See TBWidget::InvokeEvent */
|
||||
|
Loading…
Reference in New Issue
Block a user