From cab5439e133f109ceceb5e09eeb3c8653a4b17ba Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Sun, 20 Jul 2003 10:18:41 +0000 Subject: [PATCH] Sped up XOR animation by ignoring some motion events, if needed. --- docs/CHANGES.txt | 4 ++++ src/tuxpaint.c | 33 +++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index bc62bb6f5..0ab5d1c58 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -42,6 +42,10 @@ http://www.newbreedsoftware.com/tuxpaint/ * Simplified CFLAGS variable in Makefile. Ben Armstrong + * Made main event loop ignore motion events if the loop has spun too long. + (Fixes problems where shape or stamp tools take forver to 'catch up' with + the mouse; especially noticable on slow machines over remote X display.) + 2003.Jun.17 (0.9.11) * Windows bugfixes. diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 7b668de5b..f3180a3a4 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -737,13 +737,14 @@ void mainloop(void) shape_ctr_x, shape_ctr_y, shape_outer_x, shape_outer_y; int num_things, thing_scroll, cur_thing, old_thing, do_draw, old_tool, tmp_int; - int cur_time, last_print_time, scrolling; + int cur_time, last_print_time, scrolling, ignoring_motion; SDL_TimerID scrolltimer; SDL_Event event; SDLKey key, key_down; Uint16 key_unicode; SDLMod mod; - Uint32 last_cursor_blink, cur_cursor_blink; + Uint32 last_cursor_blink, cur_cursor_blink, + pre_event_time, current_event_time; num_things = 0; @@ -776,8 +777,19 @@ void mainloop(void) do { + ignoring_motion = 0; + + pre_event_time = SDL_GetTicks(); + + while (SDL_PollEvent(&event)) { + current_event_time = SDL_GetTicks(); + + if (current_event_time > pre_event_time + 250) + ignoring_motion = 1; + + if (event.type == SDL_QUIT) { done = do_quit(); @@ -1703,7 +1715,7 @@ void mainloop(void) old_y + (img_stamps[cur_stamp]->h / 2)); #else stamp_xor(old_x - (img_stamps[cur_stamp]->w / 2), - old_y - (img_stamps[cur_stamp]->h / 2)); + old_y - (img_stamps[cur_stamp]->h / 2)); #endif playsound(1, SND_STAMP, 1); @@ -2145,7 +2157,7 @@ void mainloop(void) button_down = 0; } - else if (event.type == SDL_MOUSEMOTION) + else if (event.type == SDL_MOUSEMOTION && !ignoring_motion) { new_x = event.button.x - 96; new_y = event.button.y; @@ -2373,10 +2385,10 @@ void mainloop(void) stamp_xor(old_x - w / 2, old_y - h / 2); else rect_xor(old_x - w / 2, old_y - h / 2, - old_x + w / 2, old_y + h / 2); + old_x + w / 2, old_y + h / 2); #else rect_xor(old_x - w / 2, old_y - h / 2, - old_x + w / 2, old_y + h / 2); + old_x + w / 2, old_y + h / 2); #endif update_screen(old_x - w / 2 + 96, old_y - h / 2, old_x + w / 2 + 96, old_y + h / 2); @@ -6004,7 +6016,7 @@ void line_xor(int x1, int y1, int x2, int y2) /* Kludgey, but it works: */ - SDL_LockSurface(screen); + //SDL_LockSurface(screen); dx = x2 - x1; dy = y2 - y1; @@ -6038,8 +6050,10 @@ void line_xor(int x1, int y1, int x2, int y2) { num_drawn++; if (num_drawn < 10 || dont_do_xor == 0) + { clipped_putpixel(screen, x1 + 96, y, 0xFFFFFFFF - getpixel(screen, x1 + 96, y)); + } } x1 = x1 + dx; @@ -6075,7 +6089,7 @@ void line_xor(int x1, int y1, int x2, int y2) } } - SDL_UnlockSurface(screen); + //SDL_UnlockSurface(screen); } @@ -7736,7 +7750,6 @@ void update_shape(int cx, int ox1, int ox2, int cy, int oy1, int oy2, int fix) } - /* Draw a shape! */ void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush) @@ -7851,7 +7864,7 @@ void do_shape(int cx, int cy, int ox, int oy, int rotn, int use_brush) if (!use_brush) { /* (XOR) */ - + line_xor(x1, y1, x2, y2); } else