From 3bf187fe037df34459f04bf4e625f38afb80fcf8 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 3 Jul 2023 05:42:16 +0300 Subject: [PATCH] rubber band in platform-specific code --- src/dos/main.c | 38 +++++++++++++++++++++++--------------- src/modern/main.c | 40 ++++++++++++++++++++++++++++++++++++---- src/rtk.c | 25 +++++++++++++++++++++++++ src/rtk.h | 1 + src/scr_mod.c | 35 +++-------------------------------- 5 files changed, 88 insertions(+), 51 deletions(-) diff --git a/src/dos/main.c b/src/dos/main.c index 50c876f..e6e2346 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -44,7 +44,7 @@ static uint32_t *vmem; static int quit, disp_pending, dirty_valid; static rtk_rect dirty; static int mx, my; -static rtk_rect rband; +static rtk_rect rband, prev_rband; int main(int argc, char **argv) @@ -200,20 +200,28 @@ void app_swap_buffers(void) if(opt.vsync) { vid_vsync(); } - if(!dirty_valid) return; - if(dirty.width < win_width || dirty.height < win_height) { - uint32_t *src = framebuf + dirty.y * win_width + dirty.x; - vid_blit32(dirty.x, dirty.y, dirty.width, dirty.height, src, 0); + if(dirty_valid) { + if(dirty.width < win_width || dirty.height < win_height) { + uint32_t *src = framebuf + dirty.y * win_width + dirty.x; + vid_blit32(dirty.x, dirty.y, dirty.width, dirty.height, src, 0); - if(mx >= dirty.x && my >= dirty.y && mx < dirty.x + dirty.width && my < dirty.y + dirty.height) { + if(mx >= dirty.x && my >= dirty.y && mx < dirty.x + dirty.width && my < dirty.y + dirty.height) { + draw_cursor(mx, my); + } + } else { + vid_blitfb32(framebuf, 0); draw_cursor(mx, my); } - } else { - vid_blitfb32(framebuf, 0); - draw_cursor(mx, my); + dirty_valid = 0; } - dirty_valid = 0; + if(rband.width) { + if(prev_rband.width) { + draw_rband(&prev_rband); + } + draw_rband(&rband); + prev_rband = rband; + } } void app_quit(void) @@ -237,6 +245,7 @@ void app_rband(int x, int y, int w, int h) { if(!(w | h)) { w = h = 0; + prev_rband.width = 0; } rband.x = x; @@ -259,16 +268,16 @@ static void draw_cursor(int x, int y) } } -static void draw_rband(void) +static void draw_rband(rtk_rect *r) { int i; rtk_rect rect; uint32_t *fbptr, *bptr; - rect = rband; - fix_rect(&rect); + rect = *r; + rtk_fix_rect(&rect); - fbptr = framebuf + rect.y * win_width + rect.x; + fbptr = vmem + rect.y * win_width + rect.x; bptr = fbptr + win_width * (rect.height - 1); for(i=0; i. #include #include "miniglut.h" #include "app.h" +#include "rtk.h" #include "logger.h" static void display(void); @@ -45,6 +46,7 @@ static void (*glx_swap_interval_sgi)(); static PROC wgl_swap_interval_ext; #endif +static rtk_rect rband; int main(int argc, char **argv) @@ -101,17 +103,17 @@ long app_getmsec(void) void app_redisplay(int x, int y, int w, int h) { - dbgmsg("fakeupd: %d,%d (%dx%d)\n", x, y, w, h); + /*dbgmsg("fakeupd: %d,%d (%dx%d)\n", x, y, w, h);*/ glutPostRedisplay(); } void app_swap_buffers(void) { + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); glRasterPos2i(-1, 1); glPixelZoom(1, -1); @@ -120,7 +122,27 @@ void app_swap_buffers(void) glDrawPixels(win_width, win_height, GL_BGRA, GL_UNSIGNED_BYTE, framebuf); glDisable(GL_ALPHA_TEST); - glMatrixMode(GL_PROJECTION); + if(rband.width | rband.height) { + glOrtho(0, win_width, win_height, 0, -1, 1); + + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glEnable(GL_COLOR_LOGIC_OP); + glLogicOp(GL_XOR); + + glBegin(GL_LINE_LOOP); + glColor3f(1, 1, 1); + glVertex2f(rband.x, rband.y); + glVertex2f(rband.x + rband.width, rband.y); + glVertex2f(rband.x + rband.width, rband.y + rband.height); + glVertex2f(rband.x, rband.y + rband.height); + glEnd(); + + glPopAttrib(); + } + glPopMatrix(); glMatrixMode(GL_MODELVIEW); @@ -180,6 +202,16 @@ void app_vsync(int vsync) } #endif +void app_rband(int x, int y, int w, int h) +{ + rband.x = x; + rband.y = y; + rband.width = w; + rband.height = h; + + glutPostRedisplay(); +} + static void display(void) { diff --git a/src/rtk.c b/src/rtk.c index 4bb93c8..2ed29e9 100644 --- a/src/rtk.c +++ b/src/rtk.c @@ -818,6 +818,31 @@ int rtk_input_mmotion(rtk_widget *w, int x, int y) return 0; } +void rtk_fix_rect(rtk_rect *rect) +{ + int x, y, w, h; + + x = rect->x; + y = rect->y; + + if(rect->width < 0) { + w = -rect->width; + x += rect->width; + } else { + w = rect->width; + } + if(rect->height < 0) { + h = -rect->height; + y += rect->height; + } else { + h = rect->height; + } + + rect->x = x; + rect->y = y; + rect->width = w; + rect->height = h; +} void rtk_rect_union(rtk_rect *a, const rtk_rect *b) { diff --git a/src/rtk.h b/src/rtk.h index aad342e..2ebdef2 100644 --- a/src/rtk.h +++ b/src/rtk.h @@ -105,6 +105,7 @@ int rtk_input_mbutton(rtk_widget *w, int bn, int press, int x, int y); int rtk_input_mmotion(rtk_widget *w, int x, int y); /* misc */ +void rtk_fix_rect(rtk_rect *r); void rtk_rect_union(rtk_rect *a, const rtk_rect *b); #endif /* RTK_H_ */ diff --git a/src/scr_mod.c b/src/scr_mod.c index 5a33e45..ae6de9b 100644 --- a/src/scr_mod.c +++ b/src/scr_mod.c @@ -90,7 +90,6 @@ static void act_settool(int tidx); static void act_addobj(void); static void act_rmobj(void); -static void fix_rect(rtk_rect *rect); static void draw_rband(void); static void moveobj(struct object *obj, int px0, int py0, int px1, int py1); @@ -259,10 +258,6 @@ static void mdl_display(void) /* GUI */ rtk_draw_widget(toolbar); - - if(rband_valid) { - draw_rband(); - } } static void draw_object(struct object *obj) @@ -391,6 +386,7 @@ static void mdl_mouse(int bn, int press, int x, int y) if(rband_valid) { rband_valid = 0; + app_rband(0, 0, 0, 0); if(cur_tool == TOOL_REND_AREA) { if(prev_tool >= 0) { @@ -398,7 +394,7 @@ static void mdl_mouse(int bn, int press, int x, int y) } rendering = 1; rend_size(win_width, win_height); - fix_rect(&rband); + rtk_fix_rect(&rband); rendrect = rband; rend_begin(rband.x, rband.y, rband.width, rband.height); } @@ -457,6 +453,7 @@ static void mdl_motion(int x, int y) rband.width = x - rband.x; rband.height = y - rband.y; rband_valid = 1; + app_rband(rband.x, rband.y, rband.width, rband.height); } break; @@ -557,32 +554,6 @@ static void act_rmobj(void) } } -static void fix_rect(rtk_rect *rect) -{ - int x, y, w, h; - - x = rband.x; - y = rband.y; - - if(rband.width < 0) { - w = -rband.width; - x += rband.width; - } else { - w = rband.width; - } - if(rband.height < 0) { - h = -rband.height; - y += rband.height; - } else { - h = rband.height; - } - - rect->x = x; - rect->y = y; - rect->width = w; - rect->height = h; -} - void primray(cgm_ray *ray, int x, int y) { -- 1.7.10.4