-rw-r--r-- | noncore/graphics/drawpad/filldrawmode.cpp | 68 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filldrawmode.h | 5 |
2 files changed, 25 insertions, 48 deletions
diff --git a/noncore/graphics/drawpad/filldrawmode.cpp b/noncore/graphics/drawpad/filldrawmode.cpp index 1f81cd5..6ae0e58 100644 --- a/noncore/graphics/drawpad/filldrawmode.cpp +++ b/noncore/graphics/drawpad/filldrawmode.cpp | |||
@@ -37,13 +37,9 @@ void FillDrawMode::mousePressEvent(QMouseEvent* e) | |||
37 | m_fillRgb = m_pDrawPad->brush().color().rgb(); | 37 | m_fillRgb = m_pDrawPad->brush().color().rgb(); |
38 | m_oldRgb = m_image.pixel(x, y); | 38 | m_oldRgb = m_image.pixel(x, y); |
39 | 39 | ||
40 | if (m_oldRgb != m_fillRgb) { | 40 | if (m_oldRgb != m_fillRgb) { |
41 | m_image.setPixel(x, y, m_fillRgb); | 41 | fillLine(x, y); |
42 | fillEast(x + 1, y); | ||
43 | fillSouth(x, y + 1); | ||
44 | fillWest(x - 1, y); | ||
45 | fillNorth(x, y - 1); | ||
46 | 42 | ||
47 | m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); | 43 | m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); |
48 | m_pDrawPadCanvas->viewport()->update(); | 44 | m_pDrawPadCanvas->viewport()->update(); |
49 | } | 45 | } |
@@ -58,51 +54,35 @@ void FillDrawMode::mouseMoveEvent(QMouseEvent* e) | |||
58 | { | 54 | { |
59 | Q_UNUSED(e) | 55 | Q_UNUSED(e) |
60 | } | 56 | } |
61 | 57 | ||
62 | void FillDrawMode::fillEast(int x, int y) | 58 | void FillDrawMode::fillLine(int x, int y) |
63 | { | 59 | { |
64 | if (x < m_image.width()) { | 60 | if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { |
65 | if (m_image.pixel(x, y) == m_oldRgb) { | 61 | if (m_image.pixel(x, y) == m_oldRgb) { |
66 | m_image.setPixel(x, y, m_fillRgb); | 62 | int x1, x2; |
67 | fillEast(x + 1, y); | ||
68 | fillSouth(x, y + 1); | ||
69 | fillNorth(x, y - 1); | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | 63 | ||
74 | void FillDrawMode::fillSouth(int x, int y) | 64 | x1 = x - 1; |
75 | { | 65 | x2 = x + 1; |
76 | if (y < m_image.height()) { | ||
77 | if (m_image.pixel(x, y) == m_oldRgb) { | ||
78 | m_image.setPixel(x, y, m_fillRgb); | ||
79 | fillEast(x + 1, y); | ||
80 | fillSouth(x, y + 1); | ||
81 | fillWest(x - 1, y); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | 66 | ||
86 | void FillDrawMode::fillWest(int x, int y) | 67 | while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) { |
87 | { | 68 | x1--; |
88 | if (x >= 0) { | 69 | } |
89 | if (m_image.pixel(x, y) == m_oldRgb) { | ||
90 | m_image.setPixel(x, y, m_fillRgb); | ||
91 | fillSouth(x, y + 1); | ||
92 | fillWest(x - 1, y); | ||
93 | fillNorth(x, y - 1); | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | 70 | ||
98 | void FillDrawMode::fillNorth(int x, int y) | 71 | while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) { |
99 | { | 72 | x2++; |
100 | if (y >= 0) { | 73 | } |
101 | if (m_image.pixel(x, y) == m_oldRgb) { | 74 | |
102 | m_image.setPixel(x, y, m_fillRgb); | 75 | for (int i = x1 + 1; i < x2; i++) { |
103 | fillEast(x + 1, y); | 76 | m_image.setPixel(i, y, m_fillRgb); |
104 | fillWest(x - 1, y); | 77 | } |
105 | fillNorth(x, y - 1); | 78 | |
79 | for (int i = x1 + 1; i < x2; i++) { | ||
80 | fillLine(i, y - 1); | ||
81 | } | ||
82 | |||
83 | for (int i = x1 + 1; i < x2; i++) { | ||
84 | fillLine(i, y + 1); | ||
85 | } | ||
106 | } | 86 | } |
107 | } | 87 | } |
108 | } | 88 | } |
diff --git a/noncore/graphics/drawpad/filldrawmode.h b/noncore/graphics/drawpad/filldrawmode.h index 1b7e7b5..604f9c7 100644 --- a/noncore/graphics/drawpad/filldrawmode.h +++ b/noncore/graphics/drawpad/filldrawmode.h | |||
@@ -28,12 +28,9 @@ public: | |||
28 | void mouseReleaseEvent(QMouseEvent* e); | 28 | void mouseReleaseEvent(QMouseEvent* e); |
29 | void mouseMoveEvent(QMouseEvent* e); | 29 | void mouseMoveEvent(QMouseEvent* e); |
30 | 30 | ||
31 | private: | 31 | private: |
32 | void fillEast(int x, int y); | 32 | void fillLine(int x, int y); |
33 | void fillSouth(int x, int y); | ||
34 | void fillWest(int x, int y); | ||
35 | void fillNorth(int x, int y); | ||
36 | 33 | ||
37 | QImage m_image; | 34 | QImage m_image; |
38 | QRgb m_fillRgb; | 35 | QRgb m_fillRgb; |
39 | QRgb m_oldRgb; | 36 | QRgb m_oldRgb; |