Skip to content

Commit 3f99df1

Browse files
mardyWinterMute
authored andcommitted
ogc: maintain scale of mouse cursor
The mouse cursor need to get scaled accordingly to the screen resolution: it was designed for a resolution of 640x480, but on video modes having a different aspect ratio (such as 640x240) or a different scale (such as 320x240) it will appear deformed or huge. Use a model view matrix to transform it appropriately.
1 parent cb7464c commit 3f99df1

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/video/ogc/SDL_ogcmouse.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ typedef struct _OGC_CursorData
4343
int w, h;
4444
} OGC_CursorData;
4545

46-
static void draw_cursor_rect(OGC_CursorData *curdata, int x, int y)
46+
static void draw_cursor_rect(OGC_CursorData *curdata)
4747
{
4848
GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
49-
GX_Position2s16(x, y);
49+
GX_Position2s16(-curdata->hot_x, -curdata->hot_y);
5050
GX_TexCoord2u8(0, 0);
51-
GX_Position2s16(x + curdata->w, y);
51+
GX_Position2s16(curdata->w - curdata->hot_x, -curdata->hot_y);
5252
GX_TexCoord2u8(1, 0);
53-
GX_Position2s16(x + curdata->w, y + curdata->h);
53+
GX_Position2s16(curdata->w - curdata->hot_x, curdata->h - curdata->hot_y);
5454
GX_TexCoord2u8(1, 1);
55-
GX_Position2s16(x, y + curdata->h);
55+
GX_Position2s16(-curdata->hot_x, curdata->h - curdata->hot_y);
5656
GX_TexCoord2u8(0, 1);
5757
GX_End();
5858
}
@@ -172,19 +172,26 @@ void OGC_draw_cursor(_THIS)
172172
{
173173
SDL_Mouse *mouse = SDL_GetMouse();
174174
OGC_CursorData *curdata;
175-
int x, y;
175+
Mtx mv;
176+
int screen_w, screen_h;
176177

177178
if (!mouse || !mouse->cursor_shown ||
178179
!mouse->cur_cursor || !mouse->cur_cursor->driverdata) {
179180
return;
180181
}
181182

183+
screen_w = _this->displays[0].current_mode.w;
184+
screen_h = _this->displays[0].current_mode.h;
185+
182186
curdata = mouse->cur_cursor->driverdata;
183-
x = mouse->x - curdata->hot_x;
184-
y = mouse->y - curdata->hot_y;
185187
OGC_load_texture(curdata->texels, curdata->w, curdata->h, GX_TF_RGBA8,
186188
SDL_ScaleModeNearest);
187189

190+
guMtxIdentity(mv);
191+
guMtxScaleApply(mv, mv, screen_w / 640.0f, screen_h / 480.0f, 1.0f);
192+
guMtxTransApply(mv, mv, mouse->x, mouse->y, 0);
193+
GX_LoadPosMtxImm(mv, GX_PNMTX1);
194+
188195
GX_ClearVtxDesc();
189196
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
190197
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
@@ -198,7 +205,9 @@ void OGC_draw_cursor(_THIS)
198205
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
199206

200207
GX_SetNumTexGens(1);
201-
draw_cursor_rect(curdata, x, y);
208+
GX_SetCurrentMtx(GX_PNMTX1);
209+
draw_cursor_rect(curdata);
210+
GX_SetCurrentMtx(GX_PNMTX0);
202211
GX_DrawDone();
203212
}
204213

0 commit comments

Comments
 (0)