changeset 914:28ec32e720b2

Scale mouse data based on window size
author Michael Pavone <pavone@retrodev.com>
date Mon, 14 Dec 2015 19:36:01 -0800
parents a5a51465f8b0
children 9e882eca717e
files io.c render.h render_sdl.c
diffstat 3 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/io.c	Tue Dec 08 19:33:58 2015 -0800
+++ b/io.c	Mon Dec 14 19:36:01 2015 -0800
@@ -412,9 +412,11 @@
 		return;
 	}
 	//TODO: relative mode
-	//TODO: scale based on window size
-	mice[mouse].motion_port->device.mouse.cur_x = x;
-	mice[mouse].motion_port->device.mouse.cur_y = y;
+	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;
 }
 
 int parse_binding_target(char * target, tern_node * padbuttons, tern_node *mousebuttons, int * ui_out, int * padnum_out, int * padbutton_out)
--- a/render.h	Tue Dec 08 19:33:58 2015 -0800
+++ b/render.h	Mon Dec 14 19:36:01 2015 -0800
@@ -57,6 +57,8 @@
 int render_joystick_num_buttons(int joystick);
 int render_joystick_num_hats(int joystick);
 int render_num_joysticks();
+int render_width();
+int render_height();
 void process_events();
 void render_errorbox(char *title, char *message);
 void render_warnbox(char *title, char *message);
--- a/render_sdl.c	Tue Dec 08 19:33:58 2015 -0800
+++ b/render_sdl.c	Mon Dec 14 19:36:01 2015 -0800
@@ -22,6 +22,8 @@
 SDL_Rect      main_clip;
 SDL_GLContext *main_context;
 
+int main_width, main_height;
+
 uint8_t render_dbg = 0;
 uint8_t debug_pal = 0;
 uint8_t render_gl = 1;
@@ -96,6 +98,16 @@
 	return num_joysticks;
 }
 
+int render_width()
+{
+	return main_width;
+}
+
+int render_height()
+{
+	return main_height;
+}
+
 uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b)
 {
 	return 255 << 24 | r << 16 | g << 8 | b;
@@ -251,6 +263,8 @@
 		width = mode.w;
 		height = mode.h;
 	}
+	main_width = width;
+	main_height = height;
 
 	render_gl = 0;