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
00267 void setBrush(KisBrush* brush) { m_brush = brush; }
00269 KisBrush * brush() const { return m_brush; }
00270
00272 void setPattern(KisPattern * pattern) { m_pattern = pattern; }
00274 KisPattern * pattern() const { return m_pattern; }
00275
00277 void setPaintColor(const KisColor& color) { m_paintColor = color;}
00278
00280 KisColor paintColor() const { return m_paintColor; }
00281
00283 void setBackgroundColor(const KisColor& color) {m_backgroundColor = color; }
00285 KisColor backgroundColor() const { return m_backgroundColor; }
00286
00288 void setFillColor(const KisColor& color) { m_fillColor = color; }
00290 KisColor fillColor() const { return m_fillColor; }
00291
00292
00294 enum FillStyle {
00295 FillStyleNone,
00296 FillStyleForegroundColor,
00297 FillStyleBackgroundColor,
00298 FillStylePattern,
00299 FillStyleGradient,
00300 FillStyleStrokes
00301 };
00302
00304 void setFillStyle(FillStyle fillStyle) { m_fillStyle = fillStyle; }
00306 FillStyle fillStyle() const { return m_fillStyle; }
00307
00309 enum StrokeStyle {
00310 StrokeStyleNone,
00311 StrokeStyleBrush
00312 };
00313
00315 void setStrokeStyle(StrokeStyle strokeStyle) { m_strokeStyle = strokeStyle; }
00317 StrokeStyle strokeStyle() const { return m_strokeStyle; }
00318
00320 void setOpacity(Q_UINT8 opacity) { m_opacity = opacity; }
00322 Q_UINT8 opacity() const { return m_opacity; }
00323
00328 void setCompositeOp(const KisCompositeOp& op) { m_compositeOp = op; }
00330 KisCompositeOp compositeOp() const { return m_compositeOp; }
00331
00333 void setFilter(KisFilterSP filter) { m_filter = filter; }
00335 KisFilterSP filter() { return m_filter; }
00336
00341
00342 void setDuplicateOffset(const KisPoint& offset) { m_duplicateOffset = offset; }
00344 KisPoint duplicateOffset(){ return m_duplicateOffset; }
00345
00346 inline void setDuplicateHealing(bool v) { m_duplicateHealing = v; }
00347 inline bool duplicateHealing() { return m_duplicateHealing; }
00348
00349 inline void setDuplicateHealingRadius(int r) { m_duplicateHealingRadius = r; }
00350 inline int duplicateHealingRadius() { return m_duplicateHealingRadius; }
00351
00352 inline void setDuplicatePerspectiveCorrection(bool v) { m_duplicatePerspectiveCorrection = v; }
00353 inline bool duplicatePerspectiveCorrection() { return m_duplicatePerspectiveCorrection; }
00354
00355 void setDuplicateStart(const KisPoint start) { m_duplicateStart = start;}
00356 KisPoint duplicateStart() { return m_duplicateStart;}
00357
00359 void setPressure(double pressure) { m_pressure = pressure; }
00361 double pressure() { return m_pressure; }
00362
00368 void setPaintOp(KisPaintOp * paintOp) { delete m_paintOp; m_paintOp = paintOp; }
00370 KisPaintOp * paintOp() const { return m_paintOp; }
00371
00373 void setDab(KisPaintDeviceSP dab) { m_dab = dab; }
00375 KisPaintDeviceSP dab() const { return m_dab; }
00376
00378 bool cancelRequested() const { return m_cancelRequested; }
00379
00380 protected:
00382 void init();
00383 KisPainter(const KisPainter&);
00384 KisPainter& operator=(const KisPainter&);
00385
00387 static double pointToLineDistance(const KisPoint& p, const KisPoint& l0, const KisPoint& l1);
00388
00390 void fillPolygon(const vKisPoint& points, FillStyle fillStyle);
00391
00392 protected:
00393 KisPaintDeviceSP m_device;
00394 KisTransaction *m_transaction;
00395
00396 QRect m_dirtyRect;
00397
00398 KisColor m_paintColor;
00399 KisColor m_backgroundColor;
00400 KisColor m_fillColor;
00401 FillStyle m_fillStyle;
00402 StrokeStyle m_strokeStyle;
00403 KisBrush *m_brush;
00404 KisPattern *m_pattern;
00405 KisPoint m_duplicateOffset;
00406 KisPoint m_duplicateStart;
00407 bool m_duplicateHealing;
00408 int m_duplicateHealingRadius;
00409 bool m_duplicatePerspectiveCorrection;
00410 Q_UINT8 m_opacity;
00411 KisCompositeOp m_compositeOp;
00412 KisFilterSP m_filter;
00413 KisPaintOp * m_paintOp;
00414 double m_pressure;
00415 bool m_cancelRequested;
00416 Q_INT32 m_pixelSize;
00417 KisColorSpace * m_colorSpace;
00418 KisProfile * m_profile;
00419 KisPaintDeviceSP m_dab;
00420
00421 };
00422
00423
00424 #endif // KIS_PAINTER_H_
00425