From 808e021c2cf261ad01cd42c9f5617b4e00c80753 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 17 Jun 2023 02:01:46 +0300 Subject: [PATCH] fixed simple draw_cursor --- src/app.c | 2 -- src/dos/main.c | 38 +++++++++++++++++++++++++++++++++++++- src/modern/main.c | 26 +++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/app.c b/src/app.c index 8676218..6f7e250 100644 --- a/src/app.c +++ b/src/app.c @@ -154,8 +154,6 @@ void app_display(void) time_msec = app_getmsec(); cur_scr->display(); - - app_swap_buffers(); } void app_reshape(int x, int y) diff --git a/src/dos/main.c b/src/dos/main.c index a11de39..e167a21 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -28,6 +28,8 @@ along with this program. If not, see . #include "options.h" #include "cpuid.h" +static void draw_cursor(int x, int y); + static uint32_t *vmem; static int quit, disp_pending; @@ -55,7 +57,9 @@ int main(int argc, char **argv) return 1; } set_mouse_limits(0, 0, 639, 479); - set_mouse(320, 240); + mx = 320; + my = 240; + set_mouse(mx, my); add_log_file("retroray.log"); @@ -80,16 +84,31 @@ int main(int argc, char **argv) disp_pending = 1; app_reshape(win_width, win_height); + read_mouse(&mx, &my); for(;;) { int key; + + if(kb_isdown(KEY_ALT)) { + modkeys |= KEY_MOD_ALT; + } + if(kb_isdown(KEY_CTRL)) { + modkeys |= KEY_MOD_CTRL; + } + if(kb_isdown(KEY_SHIFT)) { + modkeys |= KEY_MOD_SHIFT; + } + while((key = kb_getkey()) != -1) { app_keyboard(key, 1); if(quit) goto break_evloop; } + draw_cursor(mx, my); + bnstate = read_mouse(&mx, &my); bndiff = bnstate ^ prev_bnstate; + prev_bnstate = bnstate; if(bndiff & 1) app_mouse(0, bnstate & 1, mx, my); if(bndiff & 2) app_mouse(1, bnstate & 2, mx, my); @@ -99,6 +118,9 @@ int main(int argc, char **argv) disp_pending = 0; app_display(); } + + draw_cursor(mx, my); + app_swap_buffers(); } break_evloop: @@ -140,3 +162,17 @@ void app_fullscreen(int fs) void app_vsync(int vsync) { } + +static void draw_cursor(int x, int y) +{ + int i; + uint32_t *fbptr = framebuf + y * win_width + x; + + for(i=0; i<3; i++) { + int offs = i + 1; + if(y > offs) fbptr[-win_width * offs] ^= 0xffffff; + if(y < win_height - offs - 1) fbptr[win_width * offs] ^= 0xffffff; + if(x > offs) fbptr[-offs] ^= 0xffffff; + if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff; + } +} diff --git a/src/modern/main.c b/src/modern/main.c index 65b5eed..e60329f 100644 --- a/src/modern/main.c +++ b/src/modern/main.c @@ -22,6 +22,7 @@ along with this program. If not, see . #include "app.h" #include "logger.h" +static void display(void); static void reshape(int x, int y); static void keydown(unsigned char key, int x, int y); static void keyup(unsigned char key, int x, int y); @@ -30,6 +31,7 @@ static void skeyup(int key, int x, int y); static void mouse(int bn, int st, int x, int y); static void motion(int x, int y); static int translate_skey(int key); +static void draw_cursor(int x, int y); #if defined(__unix__) || defined(unix) #include @@ -53,7 +55,7 @@ int main(int argc, char **argv) glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("RetroRay"); - glutDisplayFunc(app_display); + glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keydown); glutKeyboardUpFunc(keyup); @@ -178,6 +180,14 @@ void app_vsync(int vsync) #endif +static void display(void) +{ + app_display(); + + draw_cursor(mouse_x, mouse_y); + + app_swap_buffers(); +} static void reshape(int x, int y) { @@ -252,3 +262,17 @@ static int translate_skey(int key) return -1; } + +static void draw_cursor(int x, int y) +{ + int i; + uint32_t *fbptr = framebuf + y * win_width + x; + + for(i=0; i<3; i++) { + int offs = i + 1; + if(y > offs) fbptr[-win_width * offs] ^= 0xffffff; + if(y < win_height - offs - 1) fbptr[win_width * offs] ^= 0xffffff; + if(x > offs) fbptr[-offs] ^= 0xffffff; + if(x < win_width - offs - 1) fbptr[offs] ^= 0xffffff; + } +} -- 1.7.10.4