From e398a1f21fc6152598142a46e3848c7b1c9afe8d Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 7 May 2015 12:18:58 -0300 Subject: [PATCH] Allow any size of boundaries for brushes As now the eraser must show the boundaries of custom brushes, the fixed maximum limit we were using (MAX_SAVED) for boundaries is not enough. So now we use a std::vector for saved pixels. --- src/app/ui/editor/cursor.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/app/ui/editor/cursor.cpp b/src/app/ui/editor/cursor.cpp index 53cc4fb22..d549a2745 100644 --- a/src/app/ui/editor/cursor.cpp +++ b/src/app/ui/editor/cursor.cpp @@ -52,9 +52,6 @@ using namespace ui; // Returns true if the cursor of the editor needs subpixel movement. #define IS_SUBPIXEL(editor) ((editor)->m_zoom.scale() >= 4.0) -// Maximum quantity of colors to save pixels overlapped by the cursor. -#define MAX_SAVED 4096 - static struct { int nseg; BoundSeg* seg; @@ -70,7 +67,7 @@ enum { static int cursor_type = CURSOR_THINCROSS; static int cursor_negative; -static gfx::Color saved_pixel[MAX_SAVED]; +static std::vector saved_pixel; static int saved_pixel_n; // These clipping regions are shared between all editors, so we cannot @@ -584,13 +581,21 @@ static void trace_brush_bounds(ui::Graphics* g, Editor* editor, static void savepixel(ui::Graphics* g, const gfx::Point& pt, gfx::Color color) { - if (saved_pixel_n < MAX_SAVED && clipping_region.contains(pt)) - saved_pixel[saved_pixel_n++] = g->getPixel(pt.x, pt.y); + if (clipping_region.contains(pt)) { + color_t c = g->getPixel(pt.x, pt.y); + + if (saved_pixel_n < (int)saved_pixel.size()) + saved_pixel[saved_pixel_n] = c; + else + saved_pixel.push_back(c); + + ++saved_pixel_n; + } } static void drawpixel(ui::Graphics* graphics, const gfx::Point& pt, gfx::Color color) { - if (saved_pixel_n < MAX_SAVED && clipping_region.contains(pt)) { + if (saved_pixel_n < (int)saved_pixel.size() && clipping_region.contains(pt)) { if (cursor_negative) { int c = saved_pixel[saved_pixel_n++]; int r = gfx::getr(c); @@ -607,7 +612,7 @@ static void drawpixel(ui::Graphics* graphics, const gfx::Point& pt, gfx::Color c static void clearpixel(ui::Graphics* g, const gfx::Point& pt, gfx::Color color) { - if (saved_pixel_n < MAX_SAVED) { + if (saved_pixel_n < (int)saved_pixel.size()) { if (clipping_region.contains(pt)) g->putPixel(saved_pixel[saved_pixel_n++], pt.x, pt.y); else if (!old_clipping_region.isEmpty() &&