summaryrefslogtreecommitdiff
path: root/noncore/graphics/drawpad/filldrawmode.cpp
Unidiff
Diffstat (limited to 'noncore/graphics/drawpad/filldrawmode.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/filldrawmode.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/noncore/graphics/drawpad/filldrawmode.cpp b/noncore/graphics/drawpad/filldrawmode.cpp
new file mode 100644
index 0000000..db86b63
--- a/dev/null
+++ b/noncore/graphics/drawpad/filldrawmode.cpp
@@ -0,0 +1,108 @@
1/***************************************************************************
2 * *
3 * DrawPad - a drawing program for Opie Environment *
4 * *
5 * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> *
6 * *
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 *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13
14#include "filldrawmode.h"
15
16#include "drawpad.h"
17#include "drawpadcanvas.h"
18
19#include <qimage.h>
20#include <qpixmap.h>
21
22FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas)
23 : DrawMode(drawPad, drawPadCanvas)
24{
25}
26
27FillDrawMode::~FillDrawMode()
28{
29}
30
31void FillDrawMode::mousePressEvent(QMouseEvent* e)
32{
33 int x = e->x();
34 int y = e->y();
35
36 m_image = m_pDrawPadCanvas->currentPage()->convertToImage();
37 m_fillRgb = m_pDrawPad->brush().color().rgb();
38 m_oldRgb = m_image.pixel(x, y);
39
40 if (m_oldRgb != m_fillRgb) {
41 m_image.setPixel(x, y, m_fillRgb);
42 fillEast(x + 1, y);
43 fillSouth(x, y + 1);
44 fillWest(x - 1, y);
45 fillNorth(x, y - 1);
46
47 m_pDrawPadCanvas->currentPage()->convertFromImage(m_image);
48 m_pDrawPadCanvas->repaint();
49 }
50}
51
52void FillDrawMode::mouseReleaseEvent(QMouseEvent* e)
53{
54 Q_UNUSED(e);
55}
56
57void FillDrawMode::mouseMoveEvent(QMouseEvent* e)
58{
59 Q_UNUSED(e);
60}
61
62void FillDrawMode::fillEast(int x, int y)
63{
64 if (x < m_image.width()) {
65 if (m_image.pixel(x, y) == m_oldRgb) {
66 m_image.setPixel(x, y, m_fillRgb);
67 fillEast(x + 1, y);
68 fillSouth(x, y + 1);
69 fillNorth(x, y - 1);
70 }
71 }
72}
73
74void FillDrawMode::fillSouth(int x, int y)
75{
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
86void FillDrawMode::fillWest(int x, int y)
87{
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 }
95 }
96}
97
98void FillDrawMode::fillNorth(int x, int y)
99{
100 if (y >= 0) {
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 }
107 }
108}