summaryrefslogtreecommitdiff
path: root/lib/engine.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/engine.cc')
-rw-r--r--lib/engine.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/engine.cc b/lib/engine.cc
index e012468..ed52d8c 100644
--- a/lib/engine.cc
+++ b/lib/engine.cc
@@ -4,6 +4,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::setup() throw(GeneralException) {
if (inited) {
@@ -111,20 +112,28 @@ void mogltk::engine::pollevents() {
while(true) {
if (hastoreturn)
- if (!SDL_PollEvent(NULL))
+ if (!SDL_PollEvent(NULL)) {
+ updatemouse();
return;
+ }
SDL_WaitEvent(&event);
switch(event.type) {
case SDL_ACTIVEEVENT:
switch (event.active.state) {
case SDL_APPMOUSEFOCUS:
printm(M_INFO, String("Application ") + (event.active.gain ? "gained" : "loosed") + " mouse focus\n");
+ if (cursorvisible)
+ hastoreturn = true;
break;
case SDL_APPINPUTFOCUS:
printm(M_INFO, String("Application ") + (event.active.gain ? "gained" : "loosed") + " input focus\n");
+ if (cursorvisible)
+ hastoreturn = true;
break;
case SDL_APPACTIVE:
printm(M_INFO, String("Application was ") + (event.active.gain ? "restored" : "iconified"));
+ if (cursorvisible)
+ hastoreturn = true;
break;
}
break;
@@ -173,3 +182,18 @@ bool mogltk::engine::quitrequested() {
return quitrequest;
}
+void mogltk::engine::updatemouse() {
+ mbuttons = SDL_GetMouseState(&mx, &my);
+}
+
+int mogltk::engine::mouseX() {
+ return mx;
+}
+
+int mogltk::engine::mouseY() {
+ return my;
+}
+
+int mogltk::engine::mousebuttons() {
+ return mbuttons;
+}