summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/engine.h6
-rw-r--r--lib/engine.cc44
-rw-r--r--src/test.cc3
3 files changed, 42 insertions, 11 deletions
diff --git a/include/engine.h b/include/engine.h
index 58ca46f..cc78fc3 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -9,6 +9,7 @@ namespace mogltk {
class engine : public Base {
public:
static int setup() throw(GeneralException);
+ static int postsetup() throw(GeneralException);
static int GetInited();
static SDL_RWops * RWFromHandle(Handle *) throw (GeneralException);
static void pollevents();
@@ -16,10 +17,13 @@ namespace mogltk {
static bool getappactive();
static void setcursorvisible(bool);
static bool getcursorvisible();
+ static bool quitrequested();
private:
- static int inited;
+ static bool inited;
+ static bool postsetuped;
static bool appactive;
static bool cursorvisible;
+ static bool quitrequest;
};
};
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;
+}
+
diff --git a/src/test.cc b/src/test.cc
index bd98ef3..a25f7a1 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -6,6 +6,7 @@
#include "glbase.h"
#include "gltexture.h"
#include "glfont.h"
+#include "engine.h"
CODE_BEGINS
virtual int startup() throw (GeneralException) {
@@ -21,7 +22,7 @@ virtual int startup() throw (GeneralException) {
mogltk::texture * mytex = new mogltk::texture(pattern, true);
delete pattern;
- while (true) {
+ while (!mogltk::engine::quitrequested()) {
mogltk::glbase::Enter2DMode();
mytex->Bind();