From 97ec70da939ace8fa7a076fa31f0d1548e489ba1 Mon Sep 17 00:00:00 2001 From: pixel Date: Thu, 13 Mar 2003 00:58:29 +0000 Subject: lock mouse effect --- include/engine.h | 3 +++ lib/engine.cc | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/engine.h b/include/engine.h index f950314..56c9279 100644 --- a/include/engine.h +++ b/include/engine.h @@ -22,6 +22,8 @@ namespace mogltk { static int mouseY(); static int mousebuttons(); static double FPS(); + static void lockmouse(); + static void unlockmouse(); private: static bool inited; static bool postsetuped; @@ -34,6 +36,7 @@ namespace mogltk { static int frames; static double curfps; static Uint32 curticks; + static int locked; static void updatemouse(); }; }; diff --git a/lib/engine.cc b/lib/engine.cc index 2d53beb..53be179 100644 --- a/lib/engine.cc +++ b/lib/engine.cc @@ -5,7 +5,7 @@ bool mogltk::engine::inited = false, mogltk::engine::postsetuped = false; bool mogltk::engine::appactive = false, mogltk::engine::cursorvisible = false, mogltk::engine::quitrequest = false; int mogltk::engine::mx, mogltk::engine::my, mogltk::engine::mbuttons; -int mogltk::engine::frames; +int mogltk::engine::frames, mogltk::engine::locked = 0; double mogltk::engine::curfps = -1; Uint32 mogltk::engine::curticks; @@ -160,6 +160,11 @@ void mogltk::engine::pollevents() { break; case SDL_MOUSEMOTION: printm(M_INFO, "Mouse slept over the screen - (%i, %i)\n", event.motion.x, event.motion.y); + if (locked) { + if (!((event.motion.x == mx) && (event.motion.y == my))) { + SDL_WrapMouse(mx, my); + } + } if (cursorvisible) hastoreturn = true; break; @@ -217,3 +222,12 @@ int mogltk::engine::mousebuttons() { double mogltk::engine::FPS() { return curfps; } + +void mogltk::engine::lockmouse() { + locked = 1; +} + +void mogltk::engine::unlockmouse() { + locked = 0; +} + -- cgit v1.2.3