1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Generalize stretch mode mouse scaling fix

This puts the code to fix mouse coordinates in stretch mode directly
inside KeyPoll::Poll, preventing the need for any other instances of
mouse coordinate usage to copy-paste code.
This commit is contained in:
Misa 2023-08-17 19:57:54 -07:00
parent 100662612b
commit 8e3e29a14c
3 changed files with 39 additions and 26 deletions

View file

@ -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);

View file

@ -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)

View file

@ -63,7 +63,8 @@ public:
bool controllerWantsDown(void);
int leftbutton, rightbutton, middlebutton;
int mx, my;
int mousex;
int mousey;
bool textentry(void);
bool pressedbackspace;