From 5318daf25a865fe6d4d8b51ede4b436e25e116e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Thu, 3 Jul 2014 08:32:07 +0000 Subject: [PATCH] [GB.SDL] * NEW: Window.Grabbed is a new property that allows to grab the input and confine the mouse to the window. git-svn-id: svn://localhost/gambas/trunk@6359 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.sdl/src/Cwindow.cpp | 10 ++++++++++ gb.sdl/src/SDLwindow.cpp | 10 ++++++++++ gb.sdl/src/SDLwindow.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/gb.sdl/src/Cwindow.cpp b/gb.sdl/src/Cwindow.cpp index 5caf76c52..d038335e6 100644 --- a/gb.sdl/src/Cwindow.cpp +++ b/gb.sdl/src/Cwindow.cpp @@ -215,6 +215,15 @@ BEGIN_PROPERTY(CWINDOW_id) END_PROPERTY +BEGIN_PROPERTY(Window_Grabbed) + + if (READ_PROPERTY) + GB.ReturnBoolean(WINDOWID->IsInputGrabbed()); + else + WINDOWID->GrabInput(VPROP(GB_BOOLEAN)); + +END_PROPERTY + /***************************************************************************/ GB_DESC CWindow[] = @@ -246,6 +255,7 @@ GB_DESC CWindow[] = GB_PROPERTY_READ("Handle", "i", CWINDOW_id), GB_PROPERTY_READ("Id", "i", CWINDOW_id), GB_PROPERTY_READ("Shown", "b", CWINDOW_shown), + GB_PROPERTY("Grabbed", "b", Window_Grabbed), GB_EVENT("Close", "b", NULL, &EVENT_Close), GB_EVENT("Resize", NULL, NULL, &EVENT_Resize), diff --git a/gb.sdl/src/SDLwindow.cpp b/gb.sdl/src/SDLwindow.cpp index 942cdd1c1..d44ff363c 100644 --- a/gb.sdl/src/SDLwindow.cpp +++ b/gb.sdl/src/SDLwindow.cpp @@ -98,6 +98,7 @@ void SDLwindow::Close() if (!hSurface) return; + GrabInput(false); SDLcore::RegisterWindow(NULL); hSurface = NULL; } @@ -256,3 +257,12 @@ bool SDLwindow::IsShown() return (false); } +void SDLwindow::GrabInput(bool grab) +{ + SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF); +} + +bool SDLwindow::IsInputGrabbed(void) const +{ + return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON; +} diff --git a/gb.sdl/src/SDLwindow.h b/gb.sdl/src/SDLwindow.h index 1f78154c6..8c87b92bb 100644 --- a/gb.sdl/src/SDLwindow.h +++ b/gb.sdl/src/SDLwindow.h @@ -66,6 +66,9 @@ public: bool IsResizable(void ) { return (hResizable); }; bool IsShown(void ); + void GrabInput(bool grab); + bool IsInputGrabbed(void) const; + // events :) virtual void Quit(void ) = 0; virtual void Resize(void ) = 0;