author | leseb <leseb> | 2002-03-21 20:39:42 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-03-21 20:39:42 (UTC) |
commit | 23663a914f1b831134d907dfa9f367381718bdc7 (patch) (side-by-side diff) | |
tree | 685dbbe1f1ff77b288b99901228be87249da841d | |
parent | fb34e5636c9bd56019f7f365ee75ab3da495e1f4 (diff) | |
download | opie-23663a914f1b831134d907dfa9f367381718bdc7.zip opie-23663a914f1b831134d907dfa9f367381718bdc7.tar.gz opie-23663a914f1b831134d907dfa9f367381718bdc7.tar.bz2 |
Fix/change fill algorithm
-rw-r--r-- | noncore/graphics/drawpad/filldrawmode.cpp | 60 | ||||
-rw-r--r-- | noncore/graphics/drawpad/filldrawmode.h | 5 |
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 @@ -1,108 +1,88 @@ /*************************************************************************** * * * DrawPad - a drawing program for Opie Environment * * * * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "filldrawmode.h" #include "drawpad.h" #include "drawpadcanvas.h" #include <qimage.h> #include <qpixmap.h> FillDrawMode::FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas) : DrawMode(drawPad, drawPadCanvas) { } FillDrawMode::~FillDrawMode() { } void FillDrawMode::mousePressEvent(QMouseEvent* e) { int x = e->x(); int y = e->y(); m_image = m_pDrawPadCanvas->currentPage()->convertToImage(); m_fillRgb = m_pDrawPad->brush().color().rgb(); m_oldRgb = m_image.pixel(x, y); if (m_oldRgb != m_fillRgb) { - m_image.setPixel(x, y, m_fillRgb); - fillEast(x + 1, y); - fillSouth(x, y + 1); - fillWest(x - 1, y); - fillNorth(x, y - 1); + fillLine(x, y); m_pDrawPadCanvas->currentPage()->convertFromImage(m_image); m_pDrawPadCanvas->viewport()->update(); } } void FillDrawMode::mouseReleaseEvent(QMouseEvent* e) { Q_UNUSED(e) } void FillDrawMode::mouseMoveEvent(QMouseEvent* e) { Q_UNUSED(e) } -void FillDrawMode::fillEast(int x, int y) +void FillDrawMode::fillLine(int x, int y) { - if (x < m_image.width()) { + if ((x >= 0) && (x < m_image.width()) && (y >= 0) && (y < m_image.height())) { if (m_image.pixel(x, y) == m_oldRgb) { - m_image.setPixel(x, y, m_fillRgb); - fillEast(x + 1, y); - fillSouth(x, y + 1); - fillNorth(x, y - 1); - } - } -} + int x1, x2; -void FillDrawMode::fillSouth(int x, int y) -{ - if (y < m_image.height()) { - if (m_image.pixel(x, y) == m_oldRgb) { - m_image.setPixel(x, y, m_fillRgb); - fillEast(x + 1, y); - fillSouth(x, y + 1); - fillWest(x - 1, y); - } - } + x1 = x - 1; + x2 = x + 1; + + while ((x1 >= 0) && (m_image.pixel(x1, y) == m_oldRgb)) { + x1--; } -void FillDrawMode::fillWest(int x, int y) -{ - if (x >= 0) { - if (m_image.pixel(x, y) == m_oldRgb) { - m_image.setPixel(x, y, m_fillRgb); - fillSouth(x, y + 1); - fillWest(x - 1, y); - fillNorth(x, y - 1); + while ((x2 < m_image.width()) && (m_image.pixel(x2, y) == m_oldRgb)) { + x2++; } + + for (int i = x1 + 1; i < x2; i++) { + m_image.setPixel(i, y, m_fillRgb); } + + for (int i = x1 + 1; i < x2; i++) { + fillLine(i, y - 1); } -void FillDrawMode::fillNorth(int x, int y) -{ - if (y >= 0) { - if (m_image.pixel(x, y) == m_oldRgb) { - m_image.setPixel(x, y, m_fillRgb); - fillEast(x + 1, y); - fillWest(x - 1, y); - fillNorth(x, y - 1); + for (int i = x1 + 1; i < x2; i++) { + fillLine(i, y + 1); + } } } } 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 @@ /*************************************************************************** * * * DrawPad - a drawing program for Opie Environment * * * * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef FILLDRAWMODE_H #define FILLDRAWMODE_H #include "drawmode.h" #include <qimage.h> class FillDrawMode : public DrawMode { public: FillDrawMode(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas); ~FillDrawMode(); void mousePressEvent(QMouseEvent* e); void mouseReleaseEvent(QMouseEvent* e); void mouseMoveEvent(QMouseEvent* e); private: - void fillEast(int x, int y); - void fillSouth(int x, int y); - void fillWest(int x, int y); - void fillNorth(int x, int y); + void fillLine(int x, int y); QImage m_image; QRgb m_fillRgb; QRgb m_oldRgb; }; #endif // FILLDRAWMODE_H |