00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KIS_PAINTER_H_
00021 #define KIS_PAINTER_H_
00022
00023 #include <kcommand.h>
00024
00025 #include "kis_color.h"
00026 #include "kis_global.h"
00027 #include "kis_types.h"
00028 #include "kis_paint_device.h"
00029 #include "kis_point.h"
00030 #include "kis_filter.h"
00031 #include "kis_progress_subject.h"
00032 #include "kis_paintop.h"
00033 #include "kis_color.h"
00034
00035 #include <koffice_export.h>
00036
00037 class QRect;
00038 class KisTransaction;
00039 class KisBrush;
00040 class KisPattern;
00041
00056 class KRITACORE_EXPORT KisPainter : public KisProgressSubject {
00057 typedef KisProgressSubject super;
00058
00059 public:
00061 KisPainter();
00063 KisPainter(KisPaintDeviceSP device);
00064 virtual ~KisPainter();
00065
00066 private:
00067
00068 virtual void cancel() { m_cancelRequested = true; }
00069
00070 public:
00074 void begin(KisPaintDeviceSP device);
00075
00079 KCommand *end();
00080
00082 void beginTransaction(const QString& customName = QString::null);
00083
00085 KCommand *endTransaction();
00086
00088 void beginTransaction( KisTransaction* command);
00089
00091 KisTransaction * transaction() { return m_transaction; }
00092
00093
00095 KisPaintDeviceSP device() const { return m_device; }
00096
00097
00098
00099
00100
00101
00105 void bitBlt(Q_INT32 dx, Q_INT32 dy,
00106 const KisCompositeOp& op,
00107 KisPaintDeviceSP src,
00108 Q_INT32 sx, Q_INT32 sy,
00109 Q_INT32 sw, Q_INT32 sh)
00110 {
00111 bitBlt(dx, dy, op, src, OPACITY_OPAQUE, sx, sy, sw, sh);
00112 }
00113
00118 void bitBlt(Q_INT32 dx, Q_INT32 dy,
00119 const KisCompositeOp& op,
00120 KisPaintDeviceSP src,
00121 Q_UINT8 opacity,
00122 Q_INT32 sx, Q_INT32 sy,
00123 Q_INT32 sw, Q_INT32 sh);
00124
00129 void bltMask(Q_INT32 dx, Q_INT32 dy,
00130 const KisCompositeOp &op,
00131 KisPaintDeviceSP src,
00132 KisPaintDeviceSP selMask,
00133 Q_UINT8 opacity,
00134 Q_INT32 sx, Q_INT32 sy,
00135 Q_INT32 sw, Q_INT32 sh);
00136
00141 void bltSelection(Q_INT32 dx, Q_INT32 dy,
00142 const KisCompositeOp &op,
00143 KisPaintDeviceSP src,
00144 KisSelectionSP selMask,
00145 Q_UINT8 opacity,
00146 Q_INT32 sx, Q_INT32 sy,
00147 Q_INT32 sw, Q_INT32 sh);
00148
00149
00153 void bltSelection(Q_INT32 dx, Q_INT32 dy,
00154 const KisCompositeOp &op,
00155 KisPaintDeviceSP src,
00156 Q_UINT8 opacity,
00157 Q_INT32 sx, Q_INT32 sy,
00158 Q_INT32 sw, Q_INT32 sh);
00159
00160
00169 QRect dirtyRect();
00170
00174 QRect addDirtyRect(QRect r) { m_dirtyRect |= r; return m_dirtyRect; }
00175
00176
00177
00181 void paintPolyline(const QValueVector <KisPoint> &points,
00182 int index = 0, int numPoints = -1);
00183
00191 double paintLine(const KisPoint &pos1,
00192 const double pressure1,
00193 const double xTilt1,
00194 const double yTilt1,
00195 const KisPoint &pos2,
00196 const double pressure2,
00197 const double xTilt2,
00198 const double yTilt2,
00199 const double savedDist = -1);
00200
00208 double paintBezierCurve(const KisPoint &pos1,
00209 const double pressure1,
00210 const double xTilt1,
00211 const double yTilt1,
00212 const KisPoint &control1,
00213 const KisPoint &control2,
00214 const KisPoint &pos2,
00215 const double pressure2,
00216 const double xTilt2,
00217 const double yTilt2,
00218 const double savedDist = -1);
00219
00224 void getBezierCurvePoints(const KisPoint &pos1,
00225 const KisPoint &control1,
00226 const KisPoint &control2,
00227 const KisPoint &pos2,
00228 vKisPoint& points);
00229
00230
00234 void paintRect(const KisPoint &startPoint,
00235 const KisPoint &endPoint,
00236 const double pressure,
00237 const double xTilt,
00238 const double yTilt);
00239
00240
00244 void paintEllipse(const KisPoint &startPoint,
00245 const KisPoint &endPoint,
00246 const double pressure,
00247 const double ,
00248 const double );
00249
00254 void paintPolygon(const vKisPoint& points);
00255
00257 void paintAt(const KisPoint &pos,
00258 const double pressure,
00259 const double ,
00260 const double );
00261
00262
00263
00264
00265
00268 void setVaryBrushSpacingWithPressureWhenDrawingALine( bool varyBrushSpacingWithPressureWhenDrawingALine )
00269 { m_varyBrushSpacingWithPressureWhenDrawingALine = varyBrushSpacingWithPressureWhenDrawingALine; }
00270 bool varyBrushSpacingWithPressureWhenDrawingALine() { return m_varyBrushSpacingWithPressureWhenDrawingALine; }
00271
00273 void setBrush(KisBrush* brush) { m_brush = brush; }
00275 KisBrush * brush() const { return m_brush; }
00276
00278 void setPattern(KisPattern * pattern) { m_pattern = pattern; }
00280 KisPattern * pattern() const { return m_pattern; }
00281
00283 void setPaintColor(const KisColor& color) { m_paintColor = color;}
00284
00286 KisColor paintColor() const { return m_paintColor; }
00287
00289 void setBackgroundColor(const KisColor& color) {m_backgroundColor = color; }
00291 KisColor backgroundColor() const { return m_backgroundColor; }
00292
00294 void setFillColor(const KisColor& color) { m_fillColor = color; }
00296 KisColor fillColor() const { return m_fillColor; }
00297
00298
00300 enum FillStyle {
00301 FillStyleNone,
00302 FillStyleForegroundColor,
00303 FillStyleBackgroundColor,
00304 FillStylePattern,
00305 FillStyleGradient,
00306 FillStyleStrokes
00307 };
00308
00310 void setFillStyle(FillStyle fillStyle) { m_fillStyle = fillStyle; }
00312 FillStyle fillStyle() const { return m_fillStyle; }
00313
00315 enum StrokeStyle {
00316 StrokeStyleNone,
00317 StrokeStyleBrush
00318 };
00319
00321 void setStrokeStyle(StrokeStyle strokeStyle) { m_strokeStyle = strokeStyle; }
00323 StrokeStyle strokeStyle() const { return m_strokeStyle; }
00324
00326 void setOpacity(Q_UINT8 opacity) { m_opacity = opacity; }
00328 Q_UINT8 opacity() const { return m_opacity; }
00329
00334 void setCompositeOp(const KisCompositeOp& op) { m_compositeOp = op; }
00336 KisCompositeOp compositeOp() const { return m_compositeOp; }
00337
00339 void setFilter(KisFilterSP filter) { m_filter = filter; }
00341 KisFilterSP filter() { return m_filter; }
00342
00347
00348 void setDuplicateOffset(const KisPoint& offset) { m_duplicateOffset = offset; }
00350 KisPoint duplicateOffset(){ return m_duplicateOffset; }
00351
00352 inline void setDuplicateHealing(bool v) { m_duplicateHealing = v; }
00353 inline bool duplicateHealing() { return m_duplicateHealing; }
00354
00355 inline void setDuplicateHealingRadius(int r) { m_duplicateHealingRadius = r; }
00356 inline int duplicateHealingRadius() { return m_duplicateHealingRadius; }
00357
00358 inline void setDuplicatePerspectiveCorrection(bool v) { m_duplicatePerspectiveCorrection = v; }
00359 inline bool duplicatePerspectiveCorrection() { return m_duplicatePerspectiveCorrection; }
00360
00361 void setDuplicateStart(const KisPoint start) { m_duplicateStart = start;}
00362 KisPoint duplicateStart() { return m_duplicateStart;}
00363
00365 void setPressure(double pressure) { m_pressure = pressure; }
00367 double pressure() { return m_pressure; }
00368
00374 void setPaintOp(KisPaintOp * paintOp) { delete m_paintOp; m_paintOp = paintOp; }
00376 KisPaintOp * paintOp() const { return m_paintOp; }
00377
00379 void setDab(KisPaintDeviceSP dab) { m_dab = dab; }
00381 KisPaintDeviceSP dab() const { return m_dab; }
00382
00384 bool cancelRequested() const { return m_cancelRequested; }
00385
00386 protected:
00388 void init();
00389 KisPainter(const KisPainter&);
00390 KisPainter& operator=(const KisPainter&);
00391
00393 static double pointToLineDistance(const KisPoint& p, const KisPoint& l0, const KisPoint& l1);
00394
00396 void fillPolygon(const vKisPoint& points, FillStyle fillStyle);
00397
00398 protected:
00399 KisPaintDeviceSP m_device;
00400 KisTransaction *m_transaction;
00401
00402 QRect m_dirtyRect;
00403
00404 KisColor m_paintColor;
00405 KisColor m_backgroundColor;
00406 KisColor m_fillColor;
00407 FillStyle m_fillStyle;
00408 StrokeStyle m_strokeStyle;
00409 KisBrush *m_brush;
00410 KisPattern *m_pattern;
00411 KisPoint m_duplicateOffset;
00412 KisPoint m_duplicateStart;
00413 bool m_duplicateHealing;
00414 int m_duplicateHealingRadius;
00415 bool m_duplicatePerspectiveCorrection;
00416 Q_UINT8 m_opacity;
00417 KisCompositeOp m_compositeOp;
00418 KisFilterSP m_filter;
00419 KisPaintOp * m_paintOp;
00420 double m_pressure;
00421 bool m_cancelRequested;
00422 Q_INT32 m_pixelSize;
00423 KisColorSpace * m_colorSpace;
00424 KisProfile * m_profile;
00425 KisPaintDeviceSP m_dab;
00426 bool m_varyBrushSpacingWithPressureWhenDrawingALine;
00427
00428 };
00429
00430
00431 #endif // KIS_PAINTER_H_
00432