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:
parent
100662612b
commit
8e3e29a14c
3 changed files with 39 additions and 26 deletions
|
@ -3128,16 +3128,8 @@ void editorinput(void)
|
||||||
ed.old_tilex = ed.tilex;
|
ed.old_tilex = ed.tilex;
|
||||||
ed.old_tiley = ed.tiley;
|
ed.old_tiley = ed.tiley;
|
||||||
|
|
||||||
ed.tilex = (key.mx - (key.mx % 8)) / 8;
|
ed.tilex = key.mousex / 8;
|
||||||
ed.tiley = (key.my - (key.my % 8)) / 8;
|
ed.tiley = key.mousey / 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool up_pressed = key.isDown(SDLK_UP) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_UP);
|
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);
|
bool down_pressed = key.isDown(SDLK_DOWN) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "Alloc.h"
|
#include "Alloc.h"
|
||||||
#include "ButtonGlyphs.h"
|
#include "ButtonGlyphs.h"
|
||||||
|
#include "Constants.h"
|
||||||
#include "Exit.h"
|
#include "Exit.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "GlitchrunnerMode.h"
|
#include "GlitchrunnerMode.h"
|
||||||
|
@ -45,7 +46,8 @@ KeyPoll::KeyPoll(void)
|
||||||
|
|
||||||
keybuffer="";
|
keybuffer="";
|
||||||
leftbutton=0; rightbutton=0; middlebutton=0;
|
leftbutton=0; rightbutton=0; middlebutton=0;
|
||||||
mx=0; my=0;
|
mousex = 0;
|
||||||
|
mousey = 0;
|
||||||
resetWindow = 0;
|
resetWindow = 0;
|
||||||
pressedbackspace=false;
|
pressedbackspace=false;
|
||||||
|
|
||||||
|
@ -135,6 +137,8 @@ static int changemousestate(
|
||||||
|
|
||||||
void KeyPoll::Poll(void)
|
void KeyPoll::Poll(void)
|
||||||
{
|
{
|
||||||
|
static int raw_mousex = 0;
|
||||||
|
static int raw_mousey = 0;
|
||||||
static int mousetoggletimeout = 0;
|
static int mousetoggletimeout = 0;
|
||||||
bool showmouse = false;
|
bool showmouse = false;
|
||||||
bool hidemouse = false;
|
bool hidemouse = false;
|
||||||
|
@ -224,25 +228,25 @@ void KeyPoll::Poll(void)
|
||||||
|
|
||||||
/* Mouse Input */
|
/* Mouse Input */
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
mx = evt.motion.x;
|
raw_mousex = evt.motion.x;
|
||||||
my = evt.motion.y;
|
raw_mousey = evt.motion.y;
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
switch (evt.button.button)
|
switch (evt.button.button)
|
||||||
{
|
{
|
||||||
case SDL_BUTTON_LEFT:
|
case SDL_BUTTON_LEFT:
|
||||||
mx = evt.button.x;
|
raw_mousex = evt.button.x;
|
||||||
my = evt.button.y;
|
raw_mousey = evt.button.y;
|
||||||
leftbutton = 1;
|
leftbutton = 1;
|
||||||
break;
|
break;
|
||||||
case SDL_BUTTON_RIGHT:
|
case SDL_BUTTON_RIGHT:
|
||||||
mx = evt.button.x;
|
raw_mousex = evt.button.x;
|
||||||
my = evt.button.y;
|
raw_mousey = evt.button.y;
|
||||||
rightbutton = 1;
|
rightbutton = 1;
|
||||||
break;
|
break;
|
||||||
case SDL_BUTTON_MIDDLE:
|
case SDL_BUTTON_MIDDLE:
|
||||||
mx = evt.button.x;
|
raw_mousex = evt.button.x;
|
||||||
my = evt.button.y;
|
raw_mousey = evt.button.y;
|
||||||
middlebutton = 1;
|
middlebutton = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -251,18 +255,18 @@ void KeyPoll::Poll(void)
|
||||||
switch (evt.button.button)
|
switch (evt.button.button)
|
||||||
{
|
{
|
||||||
case SDL_BUTTON_LEFT:
|
case SDL_BUTTON_LEFT:
|
||||||
mx = evt.button.x;
|
raw_mousex = evt.button.x;
|
||||||
my = evt.button.y;
|
raw_mousey = evt.button.y;
|
||||||
leftbutton=0;
|
leftbutton=0;
|
||||||
break;
|
break;
|
||||||
case SDL_BUTTON_RIGHT:
|
case SDL_BUTTON_RIGHT:
|
||||||
mx = evt.button.x;
|
raw_mousex = evt.button.x;
|
||||||
my = evt.button.y;
|
raw_mousey = evt.button.y;
|
||||||
rightbutton=0;
|
rightbutton=0;
|
||||||
break;
|
break;
|
||||||
case SDL_BUTTON_MIDDLE:
|
case SDL_BUTTON_MIDDLE:
|
||||||
mx = evt.button.x;
|
raw_mousex = evt.button.x;
|
||||||
my = evt.button.y;
|
raw_mousey = evt.button.y;
|
||||||
middlebutton=0;
|
middlebutton=0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -440,6 +444,22 @@ void KeyPoll::Poll(void)
|
||||||
{
|
{
|
||||||
toggleFullscreen();
|
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)
|
bool KeyPoll::isDown(SDL_Keycode key)
|
||||||
|
|
|
@ -63,7 +63,8 @@ public:
|
||||||
bool controllerWantsDown(void);
|
bool controllerWantsDown(void);
|
||||||
|
|
||||||
int leftbutton, rightbutton, middlebutton;
|
int leftbutton, rightbutton, middlebutton;
|
||||||
int mx, my;
|
int mousex;
|
||||||
|
int mousey;
|
||||||
|
|
||||||
bool textentry(void);
|
bool textentry(void);
|
||||||
bool pressedbackspace;
|
bool pressedbackspace;
|
||||||
|
|
Loading…
Reference in a new issue