diff --git a/desktop_version/src/Editor.cpp b/desktop_version/src/Editor.cpp index 3b0c279c..7fa298e9 100644 --- a/desktop_version/src/Editor.cpp +++ b/desktop_version/src/Editor.cpp @@ -3128,16 +3128,8 @@ void editorinput(void) ed.old_tilex = ed.tilex; ed.old_tiley = ed.tiley; - ed.tilex = (key.mx - (key.mx % 8)) / 8; - ed.tiley = (key.my - (key.my % 8)) / 8; - - if (gameScreen.scalingMode == SCALING_STRETCH) { - // In this mode specifically, we have to fix the mouse coordinates - int screenwidth, screenheight; - gameScreen.GetScreenSize(&screenwidth, &screenheight); - ed.tilex = ed.tilex * 320 / screenwidth; - ed.tiley = ed.tiley * 240 / screenheight; - } + ed.tilex = key.mousex / 8; + ed.tiley = key.mousey / 8; bool up_pressed = key.isDown(SDLK_UP) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_UP); bool down_pressed = key.isDown(SDLK_DOWN) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_DOWN); diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index 7da97080..9f2dc810 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -5,6 +5,7 @@ #include "Alloc.h" #include "ButtonGlyphs.h" +#include "Constants.h" #include "Exit.h" #include "Game.h" #include "GlitchrunnerMode.h" @@ -45,7 +46,8 @@ KeyPoll::KeyPoll(void) keybuffer=""; leftbutton=0; rightbutton=0; middlebutton=0; - mx=0; my=0; + mousex = 0; + mousey = 0; resetWindow = 0; pressedbackspace=false; @@ -135,6 +137,8 @@ static int changemousestate( void KeyPoll::Poll(void) { + static int raw_mousex = 0; + static int raw_mousey = 0; static int mousetoggletimeout = 0; bool showmouse = false; bool hidemouse = false; @@ -224,25 +228,25 @@ void KeyPoll::Poll(void) /* Mouse Input */ case SDL_MOUSEMOTION: - mx = evt.motion.x; - my = evt.motion.y; + raw_mousex = evt.motion.x; + raw_mousey = evt.motion.y; break; case SDL_MOUSEBUTTONDOWN: switch (evt.button.button) { case SDL_BUTTON_LEFT: - mx = evt.button.x; - my = evt.button.y; + raw_mousex = evt.button.x; + raw_mousey = evt.button.y; leftbutton = 1; break; case SDL_BUTTON_RIGHT: - mx = evt.button.x; - my = evt.button.y; + raw_mousex = evt.button.x; + raw_mousey = evt.button.y; rightbutton = 1; break; case SDL_BUTTON_MIDDLE: - mx = evt.button.x; - my = evt.button.y; + raw_mousex = evt.button.x; + raw_mousey = evt.button.y; middlebutton = 1; break; } @@ -251,18 +255,18 @@ void KeyPoll::Poll(void) switch (evt.button.button) { case SDL_BUTTON_LEFT: - mx = evt.button.x; - my = evt.button.y; + raw_mousex = evt.button.x; + raw_mousey = evt.button.y; leftbutton=0; break; case SDL_BUTTON_RIGHT: - mx = evt.button.x; - my = evt.button.y; + raw_mousex = evt.button.x; + raw_mousey = evt.button.y; rightbutton=0; break; case SDL_BUTTON_MIDDLE: - mx = evt.button.x; - my = evt.button.y; + raw_mousex = evt.button.x; + raw_mousey = evt.button.y; middlebutton=0; break; } @@ -440,6 +444,22 @@ void KeyPoll::Poll(void) { toggleFullscreen(); } + + if (gameScreen.scalingMode == SCALING_STRETCH) + { + /* In this mode specifically, we have to fix the mouse coordinates */ + int actualscreenwidth; + int actualscreenheight; + gameScreen.GetScreenSize(&actualscreenwidth, &actualscreenheight); + + mousex = raw_mousex * SCREEN_WIDTH_PIXELS / actualscreenwidth; + mousey = raw_mousey * SCREEN_HEIGHT_PIXELS / actualscreenheight; + } + else + { + mousex = raw_mousex; + mousey = raw_mousey; + } } bool KeyPoll::isDown(SDL_Keycode key) diff --git a/desktop_version/src/KeyPoll.h b/desktop_version/src/KeyPoll.h index d6c40b99..5718ebf0 100644 --- a/desktop_version/src/KeyPoll.h +++ b/desktop_version/src/KeyPoll.h @@ -63,7 +63,8 @@ public: bool controllerWantsDown(void); int leftbutton, rightbutton, middlebutton; - int mx, my; + int mousex; + int mousey; bool textentry(void); bool pressedbackspace;