diff --git a/src/world.c b/src/world.c index 94d645a..56c53ee 100644 --- a/src/world.c +++ b/src/world.c @@ -45,6 +45,9 @@ static int mouseMovedInFrame; static double _mouseX; static double _mouseY; +static int _mouseScrolledX; +static int _mouseScrolledY; + static const char* keyAliases[][2] = { // as user asked | as internally stored // @@ -196,6 +199,10 @@ int mouseWentDown(const char *code) { return keyEventCheck(KEYEVENT_MOUSE_WENTDOWN, code); } int mouseWentUp(const char *code) { return keyEventCheck(KEYEVENT_MOUSE_WENTUP, code); } +int mouseScrolledX() + { return _mouseScrolledX; } +int mouseScrolledY() + { return _mouseScrolledY; } double mouseX() { return _mouseX; } double mouseY() @@ -365,6 +372,7 @@ int askText(const char *question, char *answer, int maxAnswerSize) static void resetEvents() { dialog.newText[0] = 0; + _mouseScrolledX = _mouseScrolledY = 0; heliArrayClear(&keyEvents[KEYEVENT_KEY_WENTDOWN]); heliArrayClear(&keyEvents[KEYEVENT_KEY_WENTUP]); heliArrayClear(&keyEvents[KEYEVENT_MOUSE_WENTDOWN]); @@ -556,6 +564,10 @@ static void handleEvent(SDL_Event *e) { _mouseX = e->motion.x; _mouseY = e->motion.y; } else + if (e->type == SDL_MOUSEWHEEL) { + _mouseScrolledX += e->wheel.x; + _mouseScrolledY += e->wheel.y; + } else if (e->type == SDL_TEXTINPUT) { if (dialog.shown) { int len = strlen(dialog.newText); @@ -639,12 +651,11 @@ void worldRun() { resetState(); heliDoTests(); - if (initCallback) { - viewportByWindow(); - projectionByViewport(); - heliDrawingPrepareFrame(); - initCallback(); - } + viewportByWindow(); + projectionByViewport(); + heliDrawingPrepareFrame(); + + if (initCallback) initCallback(); run(); if (deinitCallback) deinitCallback(); @@ -660,6 +671,7 @@ void worldRun() { deinit(); + _mouseScrolledX = _mouseScrolledY = 0; for(int i = 0; i < keyEventsCount; ++i) heliArrayDestroy(&keyEvents[i]); } diff --git a/src/world.h b/src/world.h index 294a5be..c931c9b 100644 --- a/src/world.h +++ b/src/world.h @@ -30,6 +30,8 @@ int mouseDidMove(); int mouseDown(const char *code); int mouseWentDown(const char *code); int mouseWentUp(const char *code); +int mouseScrolledX(); +int mouseScrolledY(); double mouseX(); double mouseY();