From ac4600dbd1260c0703c59d46512656ad3823f848 Mon Sep 17 00:00:00 2001 From: pixel Date: Wed, 22 Jan 2003 01:11:50 +0000 Subject: commit of the day --- lib/engine.cc | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'lib/engine.cc') diff --git a/lib/engine.cc b/lib/engine.cc index fac660e..741deee 100644 --- a/lib/engine.cc +++ b/lib/engine.cc @@ -2,12 +2,12 @@ #define _(x) x -int mogltk::engine::inited = 0; -bool mogltk::engine::appactive = false, mogltk::engine::cursorvisible = false; +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::setup() throw(GeneralException) { if (inited) { - printm(M_WARNING, "mogltk::engine::startup() called twice, ignoring second call.\n"); + printm(M_WARNING, "mogltk::engine::setup() called twice, ignoring second call.\n"); return -1; } if (SDL_Init(0) < 0) { @@ -15,7 +15,20 @@ int mogltk::engine::setup() throw(GeneralException) { } atexit(SDL_Quit); - inited = 1; + inited = true; + + return 0; +} + +int mogltk::engine::postsetup() throw(GeneralException) { + if (postsetuped) { + printm(M_WARNING, "mogltk::engine::postsetup() called twice, ignoring second call.\n"); + return -1; + } + + SDL_EnableUNICODE(1); + + postsetuped = true; return 0; } @@ -93,6 +106,9 @@ void mogltk::engine::pollevents() { SDL_Event event; bool hastoreturn = appactive; + if (!postsetuped) + postsetup(); + while(true) { if (hastoreturn) if (!SDL_PollEvent(NULL)) @@ -104,14 +120,10 @@ void mogltk::engine::pollevents() { hastoreturn = true; break; case SDL_MOUSEMOTION: - printm(M_INFO, "Mouse has gone over the screen - (%i, %i)\n", event.motion.x, event.motion.y); + printm(M_INFO, "Mouse slept over the screen - (%i, %i)\n", event.motion.x, event.motion.y); if (cursorvisible) hastoreturn = true; break; - case SDL_QUIT: - printm(M_INFO, "Quit requested\n"); - exit(0); - break; case SDL_ACTIVEEVENT: switch (event.active.state) { case SDL_APPMOUSEFOCUS: @@ -125,6 +137,15 @@ void mogltk::engine::pollevents() { break; } break; + case SDL_KEYDOWN: + case SDL_KEYUP: + printm(M_INFO, String("Key ") + event.key.keysym.scancode + " on keyboard " + event.key.which + (event.key.state == SDL_PRESSED ? " pressed" : " released") + "\n"); + printm(M_INFO, "SDL keysym: %i - Unicode: %04x - modifiers: %04x\n", event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod); + break; + case SDL_QUIT: + printm(M_INFO, "Quit requested\n"); + hastoreturn = quitrequest = true; + break; default: printm(M_INFO, "Unknow event: %i\n", event.type); break; @@ -147,3 +168,8 @@ void mogltk::engine::setcursorvisible(bool p) { bool mogltk::engine::getcursorvisible() { return cursorvisible; } + +bool mogltk::engine::quitrequested() { + return quitrequest; +} + -- cgit v1.2.3