summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c8
-rw-r--r--render.h2
-rwxr-xr-xrender_sdl.c14
3 files changed, 21 insertions, 3 deletions
diff --git a/io.c b/io.c
index b64da46..260ccb5 100644
--- a/io.c
+++ b/io.c
@@ -412,9 +412,11 @@ void handle_mouse_moved(int mouse, uint16_t x, uint16_t y)
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 --git a/render.h b/render.h
index b8e28b3..02e8730 100644
--- a/render.h
+++ b/render.h
@@ -57,6 +57,8 @@ void process_events();
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 --git a/render_sdl.c b/render_sdl.c
index 9973371..dbd7389 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -22,6 +22,8 @@ SDL_Texture *main_texture;
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 @@ int render_num_joysticks()
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 @@ void render_init(int width, int height, char * title, uint32_t fps, uint8_t full
width = mode.w;
height = mode.h;
}
+ main_width = width;
+ main_height = height;
render_gl = 0;