Skip to content

Commit

Permalink
Fix mouse coordinates in stretch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
AllyTally committed Aug 13, 2023
1 parent 1da5e20 commit e2c3ab9
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions desktop_version/src/LevelDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "KeyPoll.h"
#include "Localization.h"
#include "Map.h"
#include "Screen.h"
#include "Script.h"
#include "UtilityClass.h"
#include "VFormat.h"
Expand All @@ -25,6 +26,8 @@ namespace level_debugger
int held_block = -1;
int grabber_offset_x = 0;
int grabber_offset_y = 0;
int mx = 0;
int my = 0;

bool right_mouse_held = false;

Expand All @@ -45,7 +48,8 @@ namespace level_debugger

bool mouse_within(SDL_Rect* rect)
{
SDL_Point mouse = { key.mx, key.my };
SDL_Point mouse = { mx, my };

return SDL_PointInRect(&mouse, rect);
}

Expand Down Expand Up @@ -93,6 +97,17 @@ namespace level_debugger
tab_held = false;
}

mx = key.mx;
my = key.my;

if (gameScreen.scalingMode == SCALING_STRETCH) {
// In this mode specifically, we have to fix the mouse coordinates
int screenwidth, screenheight;
gameScreen.GetScreenSize(&screenwidth, &screenheight);
mx = mx * 320 / screenwidth;
my = my * 240 / screenheight;
}

for (int i = 0; i < (int) obj.entities.size(); i++)
{
SDL_Rect bounding_box = {
Expand All @@ -110,8 +125,8 @@ namespace level_debugger
{
mouse_held = true;
held_entity = i;
grabber_offset_x = key.mx - obj.entities[i].xp;
grabber_offset_y = key.my - obj.entities[i].yp;
grabber_offset_x = mx - obj.entities[i].xp;
grabber_offset_y = my - obj.entities[i].yp;

if (!key.keymap[SDLK_LSHIFT] && !key.keymap[SDLK_RSHIFT])
{
Expand Down Expand Up @@ -172,8 +187,8 @@ namespace level_debugger
{
mouse_held = true;
held_block = i;
grabber_offset_x = key.mx - obj.blocks[i].rect.x;
grabber_offset_y = key.my - obj.blocks[i].rect.y;
grabber_offset_x = mx - obj.blocks[i].rect.x;
grabber_offset_y = my - obj.blocks[i].rect.y;
}
break;
}
Expand All @@ -190,10 +205,11 @@ namespace level_debugger

void logic(void)
{

if (INBOUNDS_VEC(held_entity, obj.entities))
{
int new_xp = key.mx - grabber_offset_x;
int new_yp = key.my - grabber_offset_y;
int new_xp = mx - grabber_offset_x;
int new_yp = my - grabber_offset_y;

if (key.isDown(SDLK_LSHIFT) || key.isDown(SDLK_RSHIFT))
{
Expand All @@ -211,8 +227,8 @@ namespace level_debugger

if (INBOUNDS_VEC(held_block, obj.blocks))
{
int new_xp = key.mx - grabber_offset_x;
int new_yp = key.my - grabber_offset_y;
int new_xp = mx - grabber_offset_x;
int new_yp = my - grabber_offset_y;

if (key.isDown(SDLK_LSHIFT) || key.isDown(SDLK_RSHIFT))
{
Expand Down Expand Up @@ -325,7 +341,7 @@ namespace level_debugger
else if (hovered == -1)
{
render_coords(line++, "Room", game.roomx % 100, game.roomy % 100);
render_coords(line++, "Cursor", key.mx, key.my);
render_coords(line++, "Cursor", mx, my);
render_info(line++, "Entities", help.String(obj.entities.size()));
line++;

Expand Down

0 comments on commit e2c3ab9

Please sign in to comment.