Skip to content

Commit e43074e

Browse files
committed
gfxlib2: sf.net # 569: gfxlib2: GetMouse/SetMouse scaling problem in QB modes Screen 2 & 8
- Adjust GETMOUSE and SETMOUSE by scanline size (screen modes 2 and 8) - internally, gfxlib2 uses single scan lines in memory for modes 2 and 8 and then blits to the device doubling the scan lines - adjust the GetMouse 'y' return value by dividing by number of scanlines - adjust the SetMouse 'y' parameter by multiplying by number of scanlines
1 parent 8d9c1ba commit e43074e

File tree

8 files changed

+34
-3
lines changed

8 files changed

+34
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Version 1.10.0
128128
- fbc: #cmdline "-c ..." needs to restart parser since code generation is affected. The implicit main was being emitted even when '-c' was give in #cmdline and was working differently than when '-c' given on the actual command line.
129129
- fbc: extend lifetime of temporary variables in WITH TYPE(...) expressions to the END WITH statement
130130
- fbc: #cmdline "-r -rr -R -RR -o objfile ..." needs to restart the parser and handle changes in keeping the ASM file. In the case of '-o objfile' a major restart is needed since some initialization of filenames is done before parsing starts. By default the temporary ASM file was being kept even if #cmdline options indicate to keep it.
131+
- sf.net #569: gfxlib2: GetMouse/SetMouse scaling problem in QB modes Screen 2 & 8 - adjust GetMouse/SetMouse by internal scanline_size
131132

132133

133134
Version 1.09.0

src/gfxlib2/dos/gfx_dos.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ static int fb_dos_timer_handler(unsigned irq)
354354

355355
mouse_x = fb_dos_mouse_x;
356356
mouse_y = fb_dos_mouse_y;
357+
358+
if ( fb_dos.mouse_ok ) {
359+
if( __fb_gfx->scanline_size != 1 ) {
360+
mouse_y /= __fb_gfx->scanline_size;
361+
}
362+
}
363+
357364
if ( fb_dos.mouse_ok && fb_dos.mouse_cursor ) {
358365
fb_hSoftCursorPut(mouse_x, mouse_y);
359366
}
@@ -367,7 +374,7 @@ static int fb_dos_timer_handler(unsigned irq)
367374

368375
e.type = 0;
369376

370-
if ( fb_dos.mouse_ok ) {
377+
if ( fb_dos.mouse_ok ) {
371378

372379
if ( (fb_dos.mouse_x_old != mouse_x) || (fb_dos.mouse_y_old != mouse_y) ) {
373380
e.type = EVENT_MOUSE_MOVE;

src/gfxlib2/gfx_getmouse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ int fb_GfxGetMouse(int *x, int *y, int *z, int *buttons, int *clip)
1111
if ((__fb_gfx) && (__fb_gfx->driver->get_mouse)) {
1212
DRIVER_LOCK();
1313
failure = __fb_gfx->driver->get_mouse(x, y, z, buttons, clip);
14+
if( y && !failure && (__fb_gfx->scanline_size != 1) ) {
15+
*y /= __fb_gfx->scanline_size;
16+
}
1417
DRIVER_UNLOCK();
1518
}
1619

src/gfxlib2/gfx_setmouse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ int fb_GfxSetMouse(int x, int y, int cursor, int clip)
1212
}
1313

1414
DRIVER_LOCK();
15+
if( __fb_gfx->scanline_size != 1 ) {
16+
y *= __fb_gfx->scanline_size;
17+
}
1518
__fb_gfx->driver->set_mouse(x, y, cursor, clip);
1619
DRIVER_UNLOCK();
1720

src/gfxlib2/js/gfx_events.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ void fb_js_events_check(void)
2727
.dx = event.motion.xrel,
2828
.dy = event.motion.yrel,
2929
};
30+
if( __fb_gfx->scanline_size != 1 ) {
31+
e.y /= __fb_gfx->scanline_size;
32+
e.dy /= __fb_gfx->scanline_size;
33+
}
3034

3135
fb_hPostEvent(&e);
3236
break;

src/gfxlib2/linux/gfx_driver_fbdev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ static void *driver_thread(void *arg)
226226
mouse_y += e.dy;
227227
e.x = mouse_x = MID(0, mouse_x, __fb_gfx->w - 1);
228228
e.y = mouse_y = MID(0, mouse_y, __fb_gfx->h - 1);
229+
if( __fb_gfx->scanline_size != 1 ) {
230+
e.y /= __fb_gfx->scanline_size;
231+
e.dy /= __fb_gfx->scanline_size;
232+
}
229233
if (e.dx || e.dy) {
230234
e.type = EVENT_MOUSE_MOVE;
231235
fb_hPostEvent(&e);

src/gfxlib2/unix/gfx_x11.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ static void *window_thread(void *arg)
181181
mouse_y_root = event.xmotion.y_root;
182182
mouse_x = event.xmotion.x;
183183
mouse_y = event.xmotion.y - fb_x11.display_offset;
184-
mouse_on = ((mouse_x >= 0) && (mouse_x < fb_x11.w) && (mouse_y >= 0) && (mouse_y < fb_x11.h));
184+
mouse_on = ((mouse_x >= 0) && (mouse_x < fb_x11.w) && (mouse_y >= 0) && (mouse_y < fb_x11.h));
185185
if (has_focus) {
186186
e.type = EVENT_MOUSE_MOVE;
187187
e.x = mouse_x;
188188
e.y = mouse_y;
189+
if( __fb_gfx->scanline_size != 1 ) {
190+
e.y /= __fb_gfx->scanline_size;
191+
e.dy /= __fb_gfx->scanline_size;
192+
}
189193
}
190194
break;
191195

src/gfxlib2/win32/gfx_win32.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,14 @@ LRESULT CALLBACK fb_hWin32WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
231231
e.dx = mouse_pos.x - last_mouse_pos.x;
232232
e.dy = mouse_pos.y - last_mouse_pos.y;
233233
}
234+
if( __fb_gfx->scanline_size != 1 ) {
235+
e.y /= __fb_gfx->scanline_size;
236+
e.dy /= __fb_gfx->scanline_size;
237+
}
234238
last_mouse_pos = mouse_pos;
235-
if (((!e.dx) && (!e.dy)) || (!fb_win32.is_active))
239+
if (((!e.dx) && (!e.dy)) || (!fb_win32.is_active)) {
236240
e.type = 0;
241+
}
237242
break;
238243

239244
case WM_MOUSELEAVE:

0 commit comments

Comments
 (0)