summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/filldrawmode.cpp68
-rw-r--r--noncore/graphics/drawpad/filldrawmode.h5
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
@@ -33,76 +33,56 @@ void FillDrawMode::mousePressEvent(QMouseEvent* e)
33 int x = e->x(); 33 int x = e->x();
34 int y = e->y(); 34 int y = e->y();
35 35
36 m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); 36 m_image = m_pDrawPadCanvas->currentPage()->convertToImage();
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 }
50} 46}
51 47
52void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) 48void FillDrawMode::mouseReleaseEvent(QMouseEvent* e)
53{ 49{
54 Q_UNUSED(e) 50 Q_UNUSED(e)
55} 51}
56 52
57void FillDrawMode::mouseMoveEvent(QMouseEvent* e) 53void FillDrawMode::mouseMoveEvent(QMouseEvent* e)
58{ 54{
59 Q_UNUSED(e) 55 Q_UNUSED(e)
60} 56}
61 57
62void FillDrawMode::fillEast(int x, int y) 58void 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
74void 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
86void 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
98void 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
@@ -24,19 +24,16 @@ public:
24 FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); 24 FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas);
25 ~FillDrawMode(); 25 ~FillDrawMode();
26 26
27 void mousePressEvent(QMouseEvent* e); 27 void mousePressEvent(QMouseEvent* e);
28 void mouseReleaseEvent(QMouseEvent* e); 28 void mouseReleaseEvent(QMouseEvent* e);
29 void mouseMoveEvent(QMouseEvent* e); 29 void mouseMoveEvent(QMouseEvent* e);
30 30
31private: 31private:
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;
40}; 37};
41 38
42#endif // FILLDRAWMODE_H 39#endif // FILLDRAWMODE_H