summaryrefslogtreecommitdiff
authorleseb <leseb>2002-03-21 20:39:42 (UTC)
committer leseb <leseb>2002-03-21 20:39:42 (UTC)
commit23663a914f1b831134d907dfa9f367381718bdc7 (patch) (unidiff)
tree685dbbe1f1ff77b288b99901228be87249da841d
parentfb34e5636c9bd56019f7f365ee75ab3da495e1f4 (diff)
downloadopie-23663a914f1b831134d907dfa9f367381718bdc7.zip
opie-23663a914f1b831134d907dfa9f367381718bdc7.tar.gz
opie-23663a914f1b831134d907dfa9f367381718bdc7.tar.bz2
Fix/change fill algorithm
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
@@ -1,108 +1,88 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * DrawPad - a drawing program for Opie Environment * 3 * DrawPad - a drawing program for Opie Environment *
4 * * 4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * 5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * * 6 * *
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 * * 11 * *
12 ***************************************************************************/ 12 ***************************************************************************/
13 13
14#include "filldrawmode.h" 14#include "filldrawmode.h"
15 15
16#include "drawpad.h" 16#include "drawpad.h"
17#include "drawpadcanvas.h" 17#include "drawpadcanvas.h"
18 18
19#include <qimage.h> 19#include <qimage.h>
20#include <qpixmap.h> 20#include <qpixmap.h>
21 21
22FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) 22FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas) 23 : DrawMode(drawPad, drawPadCanvas)
24{ 24{
25} 25}
26 26
27FillDrawMode::~FillDrawMode() 27FillDrawMode::~FillDrawMode()
28{ 28{
29} 29}
30 30
31void FillDrawMode::mousePressEvent(QMouseEvent* e) 31void FillDrawMode::mousePressEvent(QMouseEvent* e)
32{ 32{
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
@@ -1,42 +1,39 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * DrawPad - a drawing program for Opie Environment * 3 * DrawPad - a drawing program for Opie Environment *
4 * * 4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * 5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * * 6 * *
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 * * 11 * *
12 ***************************************************************************/ 12 ***************************************************************************/
13 13
14#ifndef FILLDRAWMODE_H 14#ifndef FILLDRAWMODE_H
15#define FILLDRAWMODE_H 15#define FILLDRAWMODE_H
16 16
17#include "drawmode.h" 17#include "drawmode.h"
18 18
19#include <qimage.h> 19#include <qimage.h>
20 20
21class FillDrawMode : public DrawMode 21class FillDrawMode : public DrawMode
22{ 22{
23public: 23public:
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