summaryrefslogtreecommitdiff
path: root/noncore/graphics
authorleseb <leseb>2002-03-21 20:39:42 (UTC)
committer leseb <leseb>2002-03-21 20:39:42 (UTC)
commit23663a914f1b831134d907dfa9f367381718bdc7 (patch) (unidiff)
tree685dbbe1f1ff77b288b99901228be87249da841d /noncore/graphics
parentfb34e5636c9bd56019f7f365ee75ab3da495e1f4 (diff)
downloadopie-23663a914f1b831134d907dfa9f367381718bdc7.zip
opie-23663a914f1b831134d907dfa9f367381718bdc7.tar.gz
opie-23663a914f1b831134d907dfa9f367381718bdc7.tar.bz2
Fix/change fill algorithm
Diffstat (limited to 'noncore/graphics') (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/drawpad/filldrawmode.cpp60
-rw-r--r--noncore/graphics/drawpad/filldrawmode.h5
2 files changed, 21 insertions, 44 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
@@ -35,17 +35,13 @@ void FillDrawMode::mousePressEvent(QMouseEvent* e)
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
@@ -56,53 +52,37 @@ void FillDrawMode::mouseReleaseEvent(QMouseEvent* e)
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()) { 66
77 if (m_image.pixel(x, y) == m_oldRgb) { 67 while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) {
78 m_image.setPixel(x, y, m_fillRgb); 68 x1--;
79 fillEast(x + 1, y);
80 fillSouth(x, y + 1);
81 fillWest(x - 1, y);
82 }
83 }
84} 69}
85 70
86void FillDrawMode::fillWest(int x, int y) 71 while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) {
87{ 72 x2++;
88 if (x >= 0) {
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 } 73 }
74
75 for (int i = x1 + 1; i < x2; i++) {
76 m_image.setPixel(i, y, m_fillRgb);
95 } 77 }
78
79 for (int i = x1 + 1; i < x2; i++) {
80 fillLine(i, y - 1);
96} 81}
97 82
98void FillDrawMode::fillNorth(int x, int y) 83 for (int i = x1 + 1; i < x2; i++) {
99{ 84 fillLine(i, y + 1);
100 if (y >= 0) { 85 }
101 if (m_image.pixel(x, y) == m_oldRgb) {
102 m_image.setPixel(x, y, m_fillRgb);
103 fillEast(x + 1, y);
104 fillWest(x - 1, y);
105 fillNorth(x, y - 1);
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
@@ -26,16 +26,13 @@ public:
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