From 9e7b057eb9b053a03534c10bc490bb9beef5efef Mon Sep 17 00:00:00 2001 From: Laurent Carlier Date: Sat, 2 Apr 2011 17:28:48 +0000 Subject: [PATCH] [GB.SDL] * NEW: Now Mouse class gives mouse buttons and modifiers. git-svn-id: svn://localhost/gambas/trunk@3728 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.sdl/src/Cmouse.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++ gb.sdl/src/Cmouse.h | 1 + gb.sdl/src/Cwindow.cpp | 4 +++ 3 files changed, 80 insertions(+) diff --git a/gb.sdl/src/Cmouse.cpp b/gb.sdl/src/Cmouse.cpp index d5d63eba6..9416d3ba6 100644 --- a/gb.sdl/src/Cmouse.cpp +++ b/gb.sdl/src/Cmouse.cpp @@ -119,12 +119,14 @@ END_PROPERTY BEGIN_PROPERTY(CMOUSE_x) + CHECK_VALID() GB.ReturnInteger(CMOUSE_info.x); END_PROPERTY BEGIN_PROPERTY(CMOUSE_y) + CHECK_VALID() GB.ReturnInteger(CMOUSE_info.y); END_PROPERTY @@ -143,6 +145,69 @@ BEGIN_PROPERTY(CMOUSE_starty) END_PROPERTY +BEGIN_PROPERTY(CMOUSE_left) + + CHECK_VALID() + GB.ReturnBoolean(CMOUSE_info.state == SDL_BUTTON_LEFT); + +END_PROPERTY + +BEGIN_PROPERTY(CMOUSE_right) + + CHECK_VALID() + GB.ReturnBoolean(CMOUSE_info.state == SDL_BUTTON_RIGHT); + +END_PROPERTY + +BEGIN_PROPERTY(CMOUSE_middle) + + CHECK_VALID() + GB.ReturnBoolean(CMOUSE_info.state == SDL_BUTTON_MIDDLE); + +END_PROPERTY + +BEGIN_PROPERTY(CMOUSE_button) + + CHECK_VALID() + GB.ReturnInteger(CMOUSE_info.state); + +END_PROPERTY + +BEGIN_PROPERTY(CMOUSE_shift) + + CHECK_VALID() + GB.ReturnBoolean(CMOUSE_info.keymod & KMOD_SHIFT); + +END_PROPERTY + +BEGIN_PROPERTY(CMOUSE_control) + + CHECK_VALID() + GB.ReturnBoolean(CMOUSE_info.keymod & KMOD_CTRL); + +END_PROPERTY + +BEGIN_PROPERTY(CMOUSE_alt) + + CHECK_VALID() + GB.ReturnBoolean(CMOUSE_info.keymod & KMOD_ALT); + +END_PROPERTY + +BEGIN_PROPERTY(CMOUSE_meta) + + CHECK_VALID() + GB.ReturnBoolean(CMOUSE_info.keymod & KMOD_META); + +END_PROPERTY + +BEGIN_PROPERTY(CMOUSE_normal) + + CHECK_VALID() + GB.ReturnBoolean(CMOUSE_info.keymod < KMOD_NUM); + +END_PROPERTY + /***************************************************************************/ GB_DESC CCursor[] = @@ -171,6 +236,16 @@ GB_DESC CMouse[] = GB_STATIC_PROPERTY_READ("X", "i", CMOUSE_x), GB_STATIC_PROPERTY_READ("Y", "i", CMOUSE_y), + GB_STATIC_PROPERTY_READ("Left", "b", CMOUSE_left), + GB_STATIC_PROPERTY_READ("Right", "b", CMOUSE_right), + GB_STATIC_PROPERTY_READ("Middle", "b", CMOUSE_middle), + GB_STATIC_PROPERTY_READ("Button", "i", CMOUSE_button), + GB_STATIC_PROPERTY_READ("Shift", "b", CMOUSE_shift), + GB_STATIC_PROPERTY_READ("Control", "b", CMOUSE_control), + GB_STATIC_PROPERTY_READ("Alt", "b", CMOUSE_alt), + GB_STATIC_PROPERTY_READ("Meta", "b", CMOUSE_meta), + GB_STATIC_PROPERTY_READ("Normal", "b", CMOUSE_normal), + GB_CONSTANT("Default", "i", SDL::DefaultCursor), GB_CONSTANT("Custom", "i", SDL::CustomCursor), GB_CONSTANT("Blank", "i", SDL::BlankCursor), diff --git a/gb.sdl/src/Cmouse.h b/gb.sdl/src/Cmouse.h index 0b0a31525..3ddd3098f 100644 --- a/gb.sdl/src/Cmouse.h +++ b/gb.sdl/src/Cmouse.h @@ -37,6 +37,7 @@ typedef int relx; int rely; int state; + SDLMod keymod; } CMOUSE_INFO; diff --git a/gb.sdl/src/Cwindow.cpp b/gb.sdl/src/Cwindow.cpp index 0538782b0..511eb1589 100644 --- a/gb.sdl/src/Cwindow.cpp +++ b/gb.sdl/src/Cwindow.cpp @@ -451,6 +451,8 @@ void myWin::MouseButtonEvent(SDL_MouseButtonEvent *mouseEvent) CMOUSE_info.valid = true; CMOUSE_info.x = mouseEvent->x; CMOUSE_info.y = mouseEvent->y; + CMOUSE_info.state = mouseEvent->button; + CMOUSE_info.keymod = SDL_GetModState(); if (mouseEvent->type == SDL_MOUSEBUTTONDOWN) GB.Raise(hWindow, EVENT_MouseDown,0); @@ -473,6 +475,8 @@ void myWin::MouseMotionEvent(SDL_MouseMotionEvent *mouseEvent) CMOUSE_info.valid = true; CMOUSE_info.x = mouseEvent->x; CMOUSE_info.y = mouseEvent->y; + CMOUSE_info.state = mouseEvent->state; + CMOUSE_info.keymod = SDL_GetModState(); GB.Raise(hWindow, EVENT_MouseMove,0); CMOUSE_info.valid = false; }