# HG changeset patch # User Michael Pavone # Date 1450150561 28800 # Node ID 28ec32e720b233f3be87c3fcd9dbef5fe8094167 # Parent a5a51465f8b06f1fce49ca4523bddfd408d2c312 Scale mouse data based on window size diff -r a5a51465f8b0 -r 28ec32e720b2 io.c --- 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) diff -r a5a51465f8b0 -r 28ec32e720b2 render.h --- 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); diff -r a5a51465f8b0 -r 28ec32e720b2 render_sdl.c --- 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;