chalk

kis_painter.h
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 * Copyright (c) 2004 Clarence Dang <dang@kde.org>
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
20#ifndef KIS_PAINTER_H_
21#define KIS_PAINTER_H_
22
23#include <kcommand.h>
24
25#include "kis_color.h"
26#include "kis_global.h"
27#include "kis_types.h"
28#include "kis_paint_device.h"
29#include "kis_point.h"
30#include "kis_filter.h"
31#include "kis_progress_subject.h"
32#include "kis_paintop.h"
33#include "kis_color.h"
34
35#include <koffice_export.h>
36
37class TQRect;
38class KisTransaction;
39class KisBrush;
40class KisPattern;
41
56class KRITACORE_EXPORT KisPainter : public KisProgressSubject {
57 typedef KisProgressSubject super;
58
59public:
61 KisPainter();
63 KisPainter(KisPaintDeviceSP device);
64 virtual ~KisPainter();
65
66private:
67 // Implement KisProgressSubject
68 virtual void cancel() { m_cancelRequested = true; }
69
70public:
74 void begin(KisPaintDeviceSP device);
75
79 KCommand *end();
80
82 void beginTransaction(const TQString& customName = TQString());
83
85 KCommand *endTransaction();
86
88 void beginTransaction( KisTransaction* command);
89
91 KisTransaction * transaction() { return m_transaction; }
92
93
95 KisPaintDeviceSP device() const { return m_device; }
96
97
98 // -----------------------------------------------------------------
99 // Native paint methods that are undo/redo-able,
100 // use the color strategies and the composite operations.
101
105 void bitBlt(TQ_INT32 dx, TQ_INT32 dy,
106 const KisCompositeOp& op,
107 KisPaintDeviceSP src,
108 TQ_INT32 sx, TQ_INT32 sy,
109 TQ_INT32 sw, TQ_INT32 sh)
110 {
111 bitBlt(dx, dy, op, src, OPACITY_OPAQUE, sx, sy, sw, sh);
112 }
113
118 void bitBlt(TQ_INT32 dx, TQ_INT32 dy,
119 const KisCompositeOp& op,
120 KisPaintDeviceSP src,
121 TQ_UINT8 opacity,
122 TQ_INT32 sx, TQ_INT32 sy,
123 TQ_INT32 sw, TQ_INT32 sh);
124
129 void bltMask(TQ_INT32 dx, TQ_INT32 dy,
130 const KisCompositeOp &op,
131 KisPaintDeviceSP src,
132 KisPaintDeviceSP selMask,
133 TQ_UINT8 opacity,
134 TQ_INT32 sx, TQ_INT32 sy,
135 TQ_INT32 sw, TQ_INT32 sh);
136
141 void bltSelection(TQ_INT32 dx, TQ_INT32 dy,
142 const KisCompositeOp &op,
143 KisPaintDeviceSP src,
144 KisSelectionSP selMask,
145 TQ_UINT8 opacity,
146 TQ_INT32 sx, TQ_INT32 sy,
147 TQ_INT32 sw, TQ_INT32 sh);
148
149
153 void bltSelection(TQ_INT32 dx, TQ_INT32 dy,
154 const KisCompositeOp &op,
155 KisPaintDeviceSP src,
156 TQ_UINT8 opacity,
157 TQ_INT32 sx, TQ_INT32 sy,
158 TQ_INT32 sw, TQ_INT32 sh);
159
160
169 TQRect dirtyRect();
170
174 TQRect addDirtyRect(TQRect r) { m_dirtyRect |= r; return m_dirtyRect; }
175
176
177
181 void paintPolyline(const TQValueVector <KisPoint> &points,
182 int index = 0, int numPoints = -1);
183
191 double paintLine(const KisPoint &pos1,
192 const double pressure1,
193 const double xTilt1,
194 const double yTilt1,
195 const KisPoint &pos2,
196 const double pressure2,
197 const double xTilt2,
198 const double yTilt2,
199 const double savedDist = -1);
200
208 double paintBezierCurve(const KisPoint &pos1,
209 const double pressure1,
210 const double xTilt1,
211 const double yTilt1,
212 const KisPoint &control1,
213 const KisPoint &control2,
214 const KisPoint &pos2,
215 const double pressure2,
216 const double xTilt2,
217 const double yTilt2,
218 const double savedDist = -1);
219
224 void getBezierCurvePoints(const KisPoint &pos1,
225 const KisPoint &control1,
226 const KisPoint &control2,
227 const KisPoint &pos2,
228 vKisPoint& points);
229
230
234 void paintRect(const KisPoint &startPoint,
235 const KisPoint &endPoint,
236 const double pressure,
237 const double xTilt,
238 const double yTilt);
239
240
244 void paintEllipse(const KisPoint &startPoint,
245 const KisPoint &endPoint,
246 const double pressure,
247 const double /*xTilt*/,
248 const double /*yTilt*/);
249
254 void paintPolygon(const vKisPoint& points);
255
257 void paintAt(const KisPoint &pos,
258 const double pressure,
259 const double /*xTilt*/,
260 const double /*yTilt*/);
261
262
263 // ------------------------------------------------------------------------
264 // Set the parameters for the higher level graphics primitives.
265
268 void setVaryBrushSpacingWithPressureWhenDrawingALine( bool varyBrushSpacingWithPressureWhenDrawingALine )
269 { m_varyBrushSpacingWithPressureWhenDrawingALine = varyBrushSpacingWithPressureWhenDrawingALine; }
270 bool varyBrushSpacingWithPressureWhenDrawingALine() { return m_varyBrushSpacingWithPressureWhenDrawingALine; }
271
273 void setBrush(KisBrush* brush) { m_brush = brush; }
275 KisBrush * brush() const { return m_brush; }
276
278 void setPattern(KisPattern * pattern) { m_pattern = pattern; }
280 KisPattern * pattern() const { return m_pattern; }
281
283 void setPaintColor(const KisColor& color) { m_paintColor = color;}
284
286 KisColor paintColor() const { return m_paintColor; }
287
289 void setBackgroundColor(const KisColor& color) {m_backgroundColor = color; }
291 KisColor backgroundColor() const { return m_backgroundColor; }
292
294 void setFillColor(const KisColor& color) { m_fillColor = color; }
296 KisColor fillColor() const { return m_fillColor; }
297
298
301 FillStyleNone,
302 FillStyleForegroundColor,
303 FillStyleBackgroundColor,
304 FillStylePattern,
305 FillStyleGradient,
306 FillStyleStrokes
307 };
308
310 void setFillStyle(FillStyle fillStyle) { m_fillStyle = fillStyle; }
312 FillStyle fillStyle() const { return m_fillStyle; }
313
316 StrokeStyleNone,
317 StrokeStyleBrush
318 };
319
323 StrokeStyle strokeStyle() const { return m_strokeStyle; }
324
326 void setOpacity(TQ_UINT8 opacity) { m_opacity = opacity; }
328 TQ_UINT8 opacity() const { return m_opacity; }
329
334 void setCompositeOp(const KisCompositeOp& op) { m_compositeOp = op; }
336 KisCompositeOp compositeOp() const { return m_compositeOp; }
337
339 void setFilter(KisFilterSP filter) { m_filter = filter; }
341 KisFilterSP filter() { return m_filter; }
342
347 // TODO: this is an hack ! it must be fix, the following functions have nothing to do here
348 void setDuplicateOffset(const KisPoint& offset) { m_duplicateOffset = offset; }
350 KisPoint duplicateOffset(){ return m_duplicateOffset; }
351
352 inline void setDuplicateHealing(bool v) { m_duplicateHealing = v; }
353 inline bool duplicateHealing() { return m_duplicateHealing; }
354
355 inline void setDuplicateHealingRadius(int r) { m_duplicateHealingRadius = r; }
356 inline int duplicateHealingRadius() { return m_duplicateHealingRadius; }
357
358 inline void setDuplicatePerspectiveCorrection(bool v) { m_duplicatePerspectiveCorrection = v; }
359 inline bool duplicatePerspectiveCorrection() { return m_duplicatePerspectiveCorrection; }
360
361 void setDuplicateStart(const KisPoint start) { m_duplicateStart = start;}
362 KisPoint duplicateStart() { return m_duplicateStart;}
363
365 void setPressure(double pressure) { m_pressure = pressure; }
367 double pressure() { return m_pressure; }
368
374 void setPaintOp(KisPaintOp * paintOp) { delete m_paintOp; m_paintOp = paintOp; }
376 KisPaintOp * paintOp() const { return m_paintOp; }
377
379 void setDab(KisPaintDeviceSP dab) { m_dab = dab; }
381 KisPaintDeviceSP dab() const { return m_dab; }
382
384 bool cancelRequested() const { return m_cancelRequested; }
385
386protected:
388 void init();
389 KisPainter(const KisPainter&);
390 KisPainter& operator=(const KisPainter&);
391
393 static double pointToLineDistance(const KisPoint& p, const KisPoint& l0, const KisPoint& l1);
394
396 void fillPolygon(const vKisPoint& points, FillStyle fillStyle);
397
398protected:
399 KisPaintDeviceSP m_device;
400 KisTransaction *m_transaction;
401
402 TQRect m_dirtyRect;
403
404 KisColor m_paintColor;
405 KisColor m_backgroundColor;
406 KisColor m_fillColor;
407 FillStyle m_fillStyle;
408 StrokeStyle m_strokeStyle;
409 KisBrush *m_brush;
410 KisPattern *m_pattern;
411 KisPoint m_duplicateOffset;
412 KisPoint m_duplicateStart;
413 bool m_duplicateHealing;
414 int m_duplicateHealingRadius;
415 bool m_duplicatePerspectiveCorrection;
416 TQ_UINT8 m_opacity;
417 KisCompositeOp m_compositeOp;
418 KisFilterSP m_filter;
419 KisPaintOp * m_paintOp;
420 double m_pressure;
421 bool m_cancelRequested;
422 TQ_INT32 m_pixelSize;
423 KisColorSpace * m_colorSpace;
424 KisProfile * m_profile;
425 KisPaintDeviceSP m_dab;
426 bool m_varyBrushSpacingWithPressureWhenDrawingALine;
427
428};
429
430
431#endif // KIS_PAINTER_H_
432
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
KisPainter contains the graphics primitives necessary to draw on a KisPaintDevice.
Definition kis_painter.h:56
TQRect addDirtyRect(TQRect r)
Add the r to the current dirty rect, and return the dirtyRect after adding r to it.
FillStyle
This enum contains the styles with which we can fill things like polygons and ellipses.
KisPaintDeviceSP dab() const
Get the currently set dab.
KisColor paintColor() const
Returns the color that will be used to paint with.
StrokeStyle strokeStyle() const
Returns the current brush stroke style.
void setFillColor(const KisColor &color)
Set the current fill color.
void setPressure(double pressure)
Sets the current pressure for things that like to use this.
KisColor backgroundColor() const
Returns the current background color.
KisPattern * pattern() const
Returns the currently set pattern.
void setBackgroundColor(const KisColor &color)
Set the current background color.
void setPaintColor(const KisColor &color)
Set the color that will be used to paint with.
void setCompositeOp(const KisCompositeOp &op)
Sets the current composite operation.
void setStrokeStyle(StrokeStyle strokeStyle)
Set the current brush stroke style.
KisTransaction * transaction()
Return the current transcation.
Definition kis_painter.h:91
KCommand * end()
Finish painting on the current device.
KisCompositeOp compositeOp() const
Returns the current composite operation.
KisPaintDeviceSP device() const
Returns the current paint device.
Definition kis_painter.h:95
KisPaintOp * paintOp() const
Returns the current paint operation.
bool cancelRequested() const
Is cancel Requested by the KisProgressSubject for this painter.
void setDab(KisPaintDeviceSP dab)
Set a current 'dab'. This usually is a paint device containing a rendered brush.
TQ_UINT8 opacity() const
Returns the opacity that is used in painting.
void setVaryBrushSpacingWithPressureWhenDrawingALine(bool varyBrushSpacingWithPressureWhenDrawingALine)
Determines whether the brush spacing should vary when drawing lines with the pressure.
FillStyle fillStyle() const
Returns the current fill style.
double pressure()
Returns the current pressure.
void bitBlt(TQ_INT32 dx, TQ_INT32 dy, const KisCompositeOp &op, KisPaintDeviceSP src, TQ_INT32 sx, TQ_INT32 sy, TQ_INT32 sw, TQ_INT32 sh)
Blast the specified region from src onto the current paint device.
StrokeStyle
The style of the brush stroke around polygons and so.
void setFilter(KisFilterSP filter)
Sets the current KisFilter, used by the paintops that support it (like KisFilterOp).
KisColor fillColor() const
Returns the current fill color.
KisFilterSP filter()
Returns the current KisFilter.
void setOpacity(TQ_UINT8 opacity)
Set the opacity which is used in painting (like filling polygons).
void setFillStyle(FillStyle fillStyle)
Set the current style with which to fill.
void beginTransaction(const TQString &customName=TQString())
Begin an undoable paint operation.
void begin(KisPaintDeviceSP device)
Start painting on the specified device.
KisPoint duplicateOffset()
Returns the offset for duplication.
KisBrush * brush() const
Returns the currently set brush.
KisPainter()
Construct painter without a device.
void setPattern(KisPattern *pattern)
Set the current pattern.
void setDuplicateOffset(const KisPoint &offset)
The offset for paint operations that use it (like KisDuplicateOp).
void setPaintOp(KisPaintOp *paintOp)
Set the current paint operation.
KCommand * endTransaction()
Finish the undoable paint operation.
void setBrush(KisBrush *brush)
Set the current brush.
A double-based point class that can return it's coordinates approximated to integers.
Definition kis_point.h:28