chalk

kis_fill_painter.h
1/*
2 * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
3 * Copyright (c) 2004 Bart Coppens <kde@bartcoppens.be>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#ifndef KIS_FILL_PAINTER_H_
20#define KIS_FILL_PAINTER_H_
21
22#include <tqrect.h>
23
24#include "kis_meta_registry.h"
25#include "kis_color.h"
26#include "kis_colorspace_factory_registry.h"
27#include "kis_painter.h"
28#include "kis_types.h"
29#include <koffice_export.h>
30
31class KisPattern;
32
33// XXX: Filling should set dirty rect.
38class KRITACORE_EXPORT KisFillPainter : public KisPainter
39{
40
41 typedef KisPainter super;
42
43public:
44
53 KisFillPainter(KisPaintDeviceSP device);
54
58 void eraseRect(TQ_INT32 x1, TQ_INT32 y1, TQ_INT32 w, TQ_INT32 h);
62 void eraseRect(const TQRect& rc);
63
67 void fillRect(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, const KisColor& c);
71 void fillRect(const TQRect& rc, const KisColor& c);
72
76 void fillRect(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, const KisColor& c, TQ_UINT8 opacity);
80 void fillRect(const TQRect& rc, const KisColor& c, TQ_UINT8 opacity);
81
86 void fillRect(TQ_INT32 x1, TQ_INT32 y1, TQ_INT32 w, TQ_INT32 h, KisPattern * pattern);
90 void fillRect(const TQRect& rc, KisPattern * pattern);
91
96 void fillColor(int startX, int startY);
97
102 void fillPattern(int startX, int startY);
103
107 KisSelectionSP createFloodSelection(int startX, int startY);
108
113 void setFillThreshold(int threshold);
115 int fillThreshold() const { return m_threshold; }
116
118 void setWidth(int w) { m_width = w; }
119
121 void setHeight(int h) { m_height = h; }
122
125 bool sampleMerged() const { return m_sampleMerged; }
127 void setSampleMerged(bool set) { m_sampleMerged = set; }
128
130 bool careForSelection() const { return m_careForSelection; }
132 void setCareForSelection(bool set) { m_careForSelection = set; }
133
139 bool fuzzyFill() const { return m_fuzzy; }
141 void setFuzzyFill(bool set) { m_fuzzy = set; }
142
143private:
144 // for floodfill
145 void genericFillStart(int startX, int startY);
146 void genericFillEnd(KisPaintDeviceSP filled);
147
148 KisSelectionSP m_selection;
149
150 int m_threshold;
151 int m_size;
152 int m_width, m_height;
153 TQRect m_rect;
154 bool m_sampleMerged;
155 bool m_careForSelection;
156 bool m_fuzzy;
157};
158
159
160inline
161void KisFillPainter::fillRect(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, const KisColor& c)
162{
163 fillRect(x, y, w, h, c, OPACITY_OPAQUE);
164}
165
166inline
167void KisFillPainter::fillRect(const TQRect& rc, const KisColor& c)
168{
169 fillRect(rc.x(), rc.y(), rc.width(), rc.height(), c, OPACITY_OPAQUE);
170}
171
172inline
173void KisFillPainter::eraseRect(TQ_INT32 x1, TQ_INT32 y1, TQ_INT32 w, TQ_INT32 h)
174{
175 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
176 KisColor c(TQt::black, cs);
177 fillRect(x1, y1, w, h, c, OPACITY_TRANSPARENT);
178}
179
180inline
181void KisFillPainter::eraseRect(const TQRect& rc)
182{
183 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
184 KisColor c(TQt::black, cs);
185 fillRect(rc.x(), rc.y(), rc.width(), rc.height(), c, OPACITY_TRANSPARENT);
186}
187
188inline
189void KisFillPainter::fillRect(const TQRect& rc, const KisColor& c, TQ_UINT8 opacity)
190{
191 fillRect(rc.x(), rc.y(), rc.width(), rc.height(), c, opacity);
192}
193
194inline
195void KisFillPainter::fillRect(const TQRect& rc, KisPattern *pattern)
196{
197 fillRect(rc.x(), rc.y(), rc.width(), rc.height(), pattern);
198}
199
200inline
202{
203 m_threshold = threshold;
204}
205
206
207#endif //KIS_FILL_PAINTER_H_
A colorspace is the definition of a certain color model in Chalk.
A KisColor describes a color in a certain colorspace.
Definition kis_color.h:33
bool careForSelection() const
If true, floodfill doesn't fill outside the selected area of a layer.
void setWidth(int w)
Sets the width of the layer.
void fillPattern(int startX, int startY)
Fills the enclosed area around the point with the set pattern.
KisFillPainter()
Construct an empty painter.
void setHeight(int h)
Sets the height of the layer.
void setFillThreshold(int threshold)
Set the threshold for floodfill.
void setSampleMerged(bool set)
Set sample merged.
KisSelectionSP createFloodSelection(int startX, int startY)
Returns a selection mask for the floodfill starting at the specified position.
void setFuzzyFill(bool set)
Sets the fuzzyfill parameter.
int fillThreshold() const
Returns the fill threshold, see setFillThreshold for details.
void setCareForSelection(bool set)
Set caring for selection.
void eraseRect(TQ_INT32 x1, TQ_INT32 y1, TQ_INT32 w, TQ_INT32 h)
Fill a rectangle with black transparent pixels (0, 0, 0, 0 for RGBA).
bool sampleMerged() const
If sample merged is set to true, the paint device will get the bounds of the floodfill from the compl...
bool fuzzyFill() const
If true, the floodfill will be fuzzy.
void fillRect(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, const KisColor &c)
Fill a rectangle with a certain color.
KisPattern * pattern() const
Returns the currently set pattern.
KisPaintDeviceSP device() const
Returns the current paint device.
Definition kis_painter.h:95
TQ_UINT8 opacity() const
Returns the opacity that is used in painting.
KisColor fillColor() const
Returns the current fill color.
KisPainter()
Construct painter without a device.