From 55ac920fdd64668b453955c7708028a04d942b3e Mon Sep 17 00:00:00 2001 From: pixel Date: Sun, 9 Mar 2003 17:58:46 +0000 Subject: Testing mouse --- include/engine.h | 7 +++++++ lib/engine.cc | 26 +++++++++++++++++++++++++- lib/sprite.cc | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/engine.h b/include/engine.h index cc78fc3..64e823d 100644 --- a/include/engine.h +++ b/include/engine.h @@ -18,12 +18,19 @@ namespace mogltk { static void setcursorvisible(bool); static bool getcursorvisible(); static bool quitrequested(); + static int mouseX(); + static int mouseY(); + static int mousebuttons(); private: static bool inited; static bool postsetuped; static bool appactive; static bool cursorvisible; static bool quitrequest; + static int mx; + static int my; + static int mbuttons; + static void updatemouse(); }; }; 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; +} diff --git a/lib/sprite.cc b/lib/sprite.cc index 26b57dd..fce982b 100644 --- a/lib/sprite.cc +++ b/lib/sprite.cc @@ -132,6 +132,8 @@ void mogltk::Sprite::draw(int dx, int dy, Color c) { if (!was2D) mogltk::glbase::Enter2DMode(); + + c.Bind(); tlist->Bind(); glBegin(GL_TRIANGLE_STRIP); -- cgit v1.2.3