-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 | |||
@@ -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 | ||
22 | FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) | 22 | FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) |
23 | : DrawMode(drawPad, drawPadCanvas) | 23 | : DrawMode(drawPad, drawPadCanvas) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | FillDrawMode::~FillDrawMode() | 27 | FillDrawMode::~FillDrawMode() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | void FillDrawMode::mousePressEvent(QMouseEvent* e) | 31 | void 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 | ||
52 | void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) | 48 | void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) |
53 | { | 49 | { |
54 | Q_UNUSED(e) | 50 | Q_UNUSED(e) |
55 | } | 51 | } |
56 | 52 | ||
57 | void FillDrawMode::mouseMoveEvent(QMouseEvent* e) | 53 | 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 | |||
@@ -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 | ||
21 | class FillDrawMode : public DrawMode | 21 | class FillDrawMode : public DrawMode |
22 | { | 22 | { |
23 | public: | 23 | 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 | ||
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; |
40 | }; | 37 | }; |
41 | 38 | ||
42 | #endif // FILLDRAWMODE_H | 39 | #endif // FILLDRAWMODE_H |