@@ -23,6 +23,7 @@ typedef struct ALLEGRO_MOUSE_SDL
23
23
ALLEGRO_MOUSE mouse ;
24
24
ALLEGRO_MOUSE_STATE state ;
25
25
ALLEGRO_DISPLAY * display ;
26
+ float ratio ;
26
27
} ALLEGRO_MOUSE_SDL ;
27
28
28
29
static ALLEGRO_MOUSE_DRIVER * vt ;
@@ -63,12 +64,12 @@ void _al_sdl_mouse_event(SDL_Event *e)
63
64
64
65
if (e -> type == SDL_WINDOWEVENT ) {
65
66
d = find_display (e -> window .windowID );
66
- float ratio = _al_sdl_get_display_pixel_ratio (d );
67
+ mouse -> ratio = _al_sdl_get_display_pixel_ratio (d );
67
68
if (e -> window .event == SDL_WINDOWEVENT_ENTER ) {
68
69
event .mouse .type = ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY ;
69
70
SDL_GetMouseState (& event .mouse .x , & event .mouse .y );
70
- event .mouse .x *= ratio ;
71
- event .mouse .y *= ratio ;
71
+ event .mouse .x *= mouse -> ratio ;
72
+ event .mouse .y *= mouse -> ratio ;
72
73
}
73
74
else {
74
75
event .mouse .type = ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY ;
@@ -155,6 +156,7 @@ static bool sdl_init_mouse(void)
155
156
{
156
157
mouse = al_calloc (1 , sizeof * mouse );
157
158
_al_event_source_init (& mouse -> mouse .es );
159
+ mouse -> ratio = 1.0f ;
158
160
return true;
159
161
}
160
162
@@ -195,12 +197,11 @@ static bool sdl_set_mouse_axis(int which, int value)
195
197
static void sdl_get_mouse_state (ALLEGRO_MOUSE_STATE * ret_state )
196
198
{
197
199
int x , y , i ;
198
- float ratio = _al_sdl_get_display_pixel_ratio (mouse -> display );
199
200
ALLEGRO_SYSTEM_INTERFACE * sdl = _al_sdl_system_driver ();
200
201
sdl -> heartbeat ();
201
202
SDL_GetMouseState (& x , & y );
202
- ret_state -> x = x * ratio ;
203
- ret_state -> y = y * ratio ;
203
+ ret_state -> x = x * mouse -> ratio ;
204
+ ret_state -> y = y * mouse -> ratio ;
204
205
ret_state -> z = 0 ;
205
206
ret_state -> w = 0 ;
206
207
for (i = 0 ; i < ALLEGRO_MOUSE_MAX_EXTRA_AXES ; i ++ )
0 commit comments