From 55ac920fdd64668b453955c7708028a04d942b3e Mon Sep 17 00:00:00 2001 From: pixel Date: Sun, 9 Mar 2003 17:58:46 +0000 Subject: Testing mouse --- lib/engine.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lib/engine.cc') 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; +} -- cgit v1.2.3