Skip to content
Snippets Groups Projects
Commit cedc67bb authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix for SourceForge issue 134

Translation from mouse coordinates to screen coordinates had issues
with internal vs. external scaling and for when there are gutters
(ie: black bars) on the edges.

This change snaps all gutter clicks to the nearest position inside
the window instead of discarding them, and ensures the calculations
are correct regardless of scaling mode.

Win32GDI mode was not tested, the only change there was to stop
ignoring mouse positions in the gutters.
parent 3e9534f8
No related branches found
No related tags found
No related merge requests found
Pipeline #6072 passed
......@@ -842,44 +842,54 @@ static void sdl_mouse_thread(void *data)
}
}
static int win_to_text_xpos(int winpos, struct video_stats *vs)
static int win_to_res_xpos(int winpos, struct video_stats *vs)
{
int ret;
int w, h;
ret = winpos/(((float)vs->winwidth)/vs->cols)+1;
if (ret > vs->cols)
ret = vs->cols;
if (ret < 1)
ret = 1;
bitmap_get_scaled_win_size(vs->scaling, &w, &h, 0, 0);
int xoff = (vs->winwidth - w) / 2;
if (xoff < 0)
xoff = 0;
if (winpos < xoff)
winpos = 0;
else
winpos -= xoff;
if (winpos >= w)
winpos = w - 1;
ret = winpos * vs->scrnwidth / w;
return ret;
}
static int win_to_text_ypos(int winpos, struct video_stats *vs)
static int win_to_res_ypos(int winpos, struct video_stats *vs)
{
int ret;
int w, h;
ret = winpos/(((float)vs->winheight)/vs->rows)+1;
if (ret > vs->rows)
ret = vs->rows;
if (ret < 1)
ret = 1;
bitmap_get_scaled_win_size(vs->scaling, &w, &h, 0, 0);
int yoff = (vs->winheight - h) / 2;
if (yoff < 0)
yoff = 0;
if (winpos < yoff)
winpos = 0;
else
winpos -= yoff;
if (winpos >= h)
winpos = h - 1;
ret = winpos * vs->scrnheight / h;
return ret;
}
static int win_to_res_xpos(int winpos, struct video_stats *vs)
static int win_to_text_xpos(int winpos, struct video_stats *vs)
{
int ret;
ret = winpos * (vs->scrnwidth) / vs->winwidth;
return ret;
winpos = win_to_res_xpos(winpos, vs);
return (winpos * vs->cols / vs->scrnwidth) + 1;
}
static int win_to_res_ypos(int winpos, struct video_stats *vs)
static int win_to_text_ypos(int winpos, struct video_stats *vs)
{
int ret;
ret = winpos * (vs->scrnheight) / vs->winheight;
return ret;
winpos = win_to_res_ypos(winpos, vs);
return (winpos * vs->rows / vs->scrnheight) + 1;
}
void sdl_video_event_thread(void *data)
......
......@@ -479,22 +479,22 @@ win_to_pos(LPARAM lParam, struct gdi_mouse_pos *p)
cx = lParam & 0xffff;
pthread_mutex_lock(&off_lock);
if (cx < xoff || cy < yoff) {
pthread_mutex_unlock(&off_lock);
return false;
}
if (cx < xoff)
cx = xoff;
if (cy < yoff)
cy = yoff;
cx -= xoff;
cy -= yoff;
p->tx = (int)(cx / (((float)dwidth) / cols) + 1);
if (p->tx > cols)
ret = false;
p->tx = cols;
p->px = cx * (scrnwidth) / dwidth;
p->ty = (int)(cy / (((float)dheight) / rows) + 1);
if (p->ty > rows)
ret = false;
p->ty = rows;
p->py = cy * (scrnheight) / dheight;
pthread_mutex_unlock(&off_lock);
......
......@@ -1515,30 +1515,32 @@ static bool
xlat_mouse_xy(int *x, int *y)
{
int xoff, yoff;
int xw, xh;
pthread_mutex_lock(&vstatlock);
xoff = (vstat.winwidth - xim->width) / 2;
bitmap_get_scaled_win_size(vstat.scaling, &xw, &xh, 0, 0);
xoff = (vstat.winwidth - xw) / 2;
if (xoff < 0)
xoff = 0;
yoff = (vstat.winheight - xim->height) / 2;
yoff = (vstat.winheight - xh) / 2;
if (yoff < 0)
yoff = 0;
pthread_mutex_unlock(&vstatlock);
if (*x < xoff)
return false;
*x = xoff;
if (*y < yoff)
return false;
*y = yoff;
*x -= xoff;
*y -= yoff;
if (*x >= xim->width)
return false;
if (*y >= xim->height)
return false;
if (*x >= xw)
*x = xw - 1;
if (*y >= xh)
*y = xh - 1;
*x *= x_cvstat.scrnwidth;
*y *= x_cvstat.scrnheight;
*x /= xim->width;
*y /= xim->height;
*x /= xw;
*y /= xh;
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment