summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2017-06-14 20:46:11 -0700
committerMichael Pavone <pavone@retrodev.com>2017-06-14 20:46:11 -0700
commitf1fca3e3dc8d77ccc740bab5084cf4bbc715b48f (patch)
tree67fd5901b7523e2151f6c9bfd9e1b68291b34388
parentee59b3c6b69e9b5cfb0f5135dfb5fe3ce9a1a8c9 (diff)
Fix absolute mouse mode when non-default overscan settings are used
-rw-r--r--io.c13
-rw-r--r--render.h5
-rwxr-xr-xrender_sdl.c22
3 files changed, 34 insertions, 6 deletions
diff --git a/io.c b/io.c
index 70a80c8..8363e16 100644
--- a/io.c
+++ b/io.c
@@ -614,11 +614,14 @@ void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16
case MOUSE_NONE:
break;
case MOUSE_ABSOLUTE: {
- float scale_x = 640.0 / ((float)render_width());
- float scale_y = 480.0 / ((float)render_height());
- float scale = scale_x > scale_y ? scale_y : scale_x;
- mice[mouse].motion_port->device.mouse.cur_x = x * scale_x;
- mice[mouse].motion_port->device.mouse.cur_y = y * scale_y;
+ float scale_x = (render_emulated_width() * 2.0f) / ((float)render_width());
+ float scale_y = (render_emulated_height() * 2.0f) / ((float)render_height());
+ int32_t adj_x = x * scale_x + 2 * render_overscan_left() - 2 * BORDER_LEFT;
+ int32_t adj_y = y * scale_y + 2 * render_overscan_top() - 4;
+ if (adj_x >= 0 && adj_y >= 0) {
+ mice[mouse].motion_port->device.mouse.cur_x = adj_x;
+ mice[mouse].motion_port->device.mouse.cur_y = adj_y;
+ }
break;
}
case MOUSE_RELATIVE: {
diff --git a/render.h b/render.h
index 873ff72..026c3f1 100644
--- a/render.h
+++ b/render.h
@@ -99,7 +99,10 @@ uint8_t render_direction_part(int32_t input);
void render_errorbox(char *title, char *message);
void render_warnbox(char *title, char *message);
void render_infobox(char *title, char *message);
-
+uint32_t render_emulated_width();
+uint32_t render_emulated_height();
+uint32_t render_overscan_top();
+uint32_t render_overscan_left();
#endif //RENDER_H_
diff --git a/render_sdl.c b/render_sdl.c
index 8e1e7f6..607a83e 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -567,9 +567,11 @@ uint8_t events_processed;
#define FPS_INTERVAL 1000
#endif
+static uint32_t last_width;
void render_framebuffer_updated(uint8_t which, int width)
{
static uint8_t last;
+ last_width = width;
uint32_t height = which <= FRAMEBUFFER_EVEN
? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard])
: 240;
@@ -692,6 +694,26 @@ void render_framebuffer_updated(uint8_t which, int width)
events_processed = 0;
}
+uint32_t render_emulated_width()
+{
+ return last_width - overscan_left[video_standard] - overscan_right[video_standard];
+}
+
+uint32_t render_emulated_height()
+{
+ return (video_standard == VID_NTSC ? 243 : 294) - overscan_top[video_standard] - overscan_bot[video_standard];
+}
+
+uint32_t render_overscan_left()
+{
+ return overscan_left[video_standard];
+}
+
+uint32_t render_overscan_top()
+{
+ return overscan_top[video_standard];
+}
+
void render_wait_quit(vdp_context * context)
{
SDL_Event event;