From 4a5fec79ed7bedbcaed5348e2a10bb7148f9c36b Mon Sep 17 00:00:00 2001 From: johncoswell Date: Mon, 4 Sep 2006 15:43:24 +0000 Subject: [PATCH] Add ability to force canvas to perform a full, non-interruptible redraw --- src/display/sp-canvas.cpp | 35 +++++++++++++++++++++++++++++++++-- src/display/sp-canvas.h | 4 ++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 91712e633..6cb3990dd 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -977,6 +977,8 @@ sp_canvas_init (SPCanvas *canvas) canvas->redraw_aborted.y1 = -NR_HUGE_L; canvas->redraw_count = 0; + + canvas->forced_full_redraw_count = 0; canvas->slowest_buffer = 0; } @@ -1690,8 +1692,9 @@ sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1) // INTERRUPTIBLE DISPLAY: // Process events that may have arrived while we were busy drawing; - // only if we're drawing multiple buffers, and only if this one was not very fast - if (multiple_buffers && this_buffer > 25000) { + // only if we're drawing multiple buffers, and only if this one was not very fast, + // and only if we're allowed to interrupt this redraw + if (multiple_buffers && this_buffer > 25000 && !canvas->forced_full_redraw_count) { // Run at most max_iterations of the main loop; we cannot process ALL events // here because some things (e.g. rubberband) flood with dirtying events but will @@ -1718,10 +1721,38 @@ sp_canvas_paint_rect (SPCanvas *canvas, int xx0, int yy0, int xx1, int yy1) } } + // We've finished a redraw; decrement the full redraw counter + if (canvas->forced_full_redraw_count > 0) { + canvas->forced_full_redraw_count--; + } + // Remember the slowest buffer of this paint in canvas canvas->slowest_buffer = slowest_buffer; } +/** + * Force the next several screen redraws to not be interruptible. + * Used when having an accurate representation of the drawing canvas + * is more important than speed. + * + * In the future, this should be a toggle switch to be enabled/disabled + * when precise object drawing is necessary. + */ +void +sp_canvas_force_full_redraws(SPCanvas *canvas, unsigned int count) { + canvas->forced_full_redraw_count += count; +} + +/** + * Flush all forced full redraw requests. + * Used when accurate representation of the drawing canvas is no + * longer needed. + */ +void +sp_canvas_clear_forced_full_redraws(SPCanvas *canvas) { + canvas->forced_full_redraw_count = 0; +} + /** * The canvas widget's expose callback. */ diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index 1375cf272..f9f4330fc 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -161,6 +161,8 @@ struct SPCanvas { long redraw_count; glong slowest_buffer; + unsigned int forced_full_redraw_count; + /* For use by internal pick_current_item() function */ unsigned int left_grabbed_item : 1; /* For use by internal pick_current_item() function */ @@ -187,6 +189,8 @@ void sp_canvas_scroll_to(SPCanvas *canvas, double cx, double cy, unsigned int cl void sp_canvas_update_now(SPCanvas *canvas); void sp_canvas_request_redraw(SPCanvas *canvas, int x1, int y1, int x2, int y2); +void sp_canvas_force_full_redraws(SPCanvas *canvas, unsigned int count); +void sp_canvas_clear_forced_full_redraws(SPCanvas *canvas); void sp_canvas_window_to_world(SPCanvas const *canvas, double winx, double winy, double *worldx, double *worldy); void sp_canvas_world_to_window(SPCanvas const *canvas, double worldx, double worldy, double *winx, double *winy); -- 2.30.2