summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/engine.h3
-rw-r--r--lib/engine.cc16
2 files changed, 18 insertions, 1 deletions
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;
+}
+