krita

kis_painter.h

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00003  *  Copyright (c) 2004 Clarence Dang <dang@kde.org>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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     // Implement KisProgressSubject
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     //  Native paint methods that are undo/redo-able,
00100     // use the color strategies and the composite operations.
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 
00125 
00130     void bltSelection(Q_INT32 dx, Q_INT32 dy,
00131                       const KisCompositeOp &op,
00132                       KisPaintDeviceSP src,
00133                       KisSelectionSP selMask,
00134                       Q_UINT8 opacity,
00135                       Q_INT32 sx, Q_INT32 sy,
00136                       Q_INT32 sw, Q_INT32 sh);
00137 
00138 
00142     void bltSelection(Q_INT32 dx, Q_INT32 dy,
00143                       const KisCompositeOp &op,
00144                       KisPaintDeviceSP src,
00145                       Q_UINT8 opacity,
00146                       Q_INT32 sx, Q_INT32 sy,
00147                       Q_INT32 sw, Q_INT32 sh);
00148 
00149 
00158     QRect dirtyRect();
00159 
00163     QRect addDirtyRect(QRect r) { m_dirtyRect |= r; return m_dirtyRect; }
00164 
00165 
00166 
00170     void paintPolyline(const QValueVector <KisPoint> &points,
00171                        int index = 0, int numPoints = -1);
00172 
00180     double paintLine(const KisPoint &pos1,
00181              const double pressure1,
00182              const double xTilt1,
00183              const double yTilt1,
00184              const KisPoint &pos2,
00185              const double pressure2,
00186              const double xTilt2,
00187              const double yTilt2,
00188              const double savedDist = -1);
00189 
00197     double paintBezierCurve(const KisPoint &pos1,
00198                 const double pressure1,
00199                 const double xTilt1,
00200                 const double yTilt1,
00201                 const KisPoint &control1,
00202                 const KisPoint &control2,
00203                 const KisPoint &pos2,
00204                 const double pressure2,
00205                 const double xTilt2,
00206                 const double yTilt2,
00207                 const double savedDist = -1);
00208 
00213     void getBezierCurvePoints(const KisPoint &pos1,
00214                   const KisPoint &control1,
00215                   const KisPoint &control2,
00216                   const KisPoint &pos2,
00217                   vKisPoint& points);
00218 
00219 
00223     void paintRect(const KisPoint &startPoint,
00224                const KisPoint &endPoint,
00225                const double pressure,
00226                const double xTilt,
00227                const double yTilt);
00228 
00229 
00233     void paintEllipse(const KisPoint &startPoint,
00234                       const KisPoint &endPoint,
00235                       const double pressure,
00236                       const double /*xTilt*/,
00237                       const double /*yTilt*/);
00238 
00243     void paintPolygon(const vKisPoint& points);
00244 
00246     void paintAt(const KisPoint &pos,
00247              const double pressure,
00248              const double /*xTilt*/,
00249              const double /*yTilt*/);
00250 
00251 
00252     // ------------------------------------------------------------------------
00253     // Set the parameters for the higher level graphics primitives.
00254 
00256     void setBrush(KisBrush* brush) { m_brush = brush; }
00258     KisBrush * brush() const { return m_brush; }
00259 
00261     void setPattern(KisPattern * pattern) { m_pattern = pattern; }
00263     KisPattern * pattern() const { return m_pattern; }
00264 
00266     void setPaintColor(const KisColor& color) { m_paintColor = color;}
00267     
00269     KisColor paintColor() const { return m_paintColor; }
00270 
00272     void setBackgroundColor(const KisColor& color) {m_backgroundColor = color; }
00274     KisColor backgroundColor() const { return m_backgroundColor; }
00275 
00277     void setFillColor(const KisColor& color) { m_fillColor = color; }
00279     KisColor fillColor() const { return m_fillColor; }
00280 
00281 
00283     enum FillStyle {
00284         FillStyleNone,
00285         FillStyleForegroundColor,
00286         FillStyleBackgroundColor,
00287         FillStylePattern,
00288         FillStyleGradient,
00289         FillStyleStrokes
00290     };
00291 
00293     void setFillStyle(FillStyle fillStyle) { m_fillStyle = fillStyle; }
00295     FillStyle fillStyle() const { return m_fillStyle; }
00296 
00298     enum StrokeStyle {
00299         StrokeStyleNone,
00300         StrokeStyleBrush
00301     };
00302 
00304     void setStrokeStyle(StrokeStyle strokeStyle) { m_strokeStyle = strokeStyle; }
00306     StrokeStyle strokeStyle() const { return m_strokeStyle; }
00307 
00309     void setOpacity(Q_UINT8 opacity) { m_opacity = opacity; }
00311     Q_UINT8 opacity() const { return m_opacity; }
00312 
00317     void setCompositeOp(const KisCompositeOp& op) { m_compositeOp = op; }
00319     KisCompositeOp compositeOp() const { return m_compositeOp; }
00320 
00322     void setFilter(KisFilterSP filter) { m_filter = filter; }
00324     KisFilterSP filter() { return m_filter; }
00325 
00330     void setDuplicateOffset(const KisPoint& offset) { m_duplicateOffset = offset; }
00332     KisPoint duplicateOffset(){ return m_duplicateOffset; }
00333 
00335     void setPressure(double pressure) { m_pressure = pressure; }
00337     double pressure() { return m_pressure; }
00338 
00344     void setPaintOp(KisPaintOp * paintOp) { delete m_paintOp; m_paintOp = paintOp; }
00346     KisPaintOp * paintOp() const { return m_paintOp; }
00347 
00349     void setDab(KisPaintDeviceSP dab) { m_dab = dab; }
00351     KisPaintDeviceSP dab() const { return m_dab; }
00352 
00354     bool cancelRequested() const { return m_cancelRequested; }
00355 
00356 protected:
00358     void init();
00359     KisPainter(const KisPainter&);
00360     KisPainter& operator=(const KisPainter&);
00361 
00363     static double pointToLineDistance(const KisPoint& p, const KisPoint& l0, const KisPoint& l1);
00364 
00366     void fillPolygon(const vKisPoint& points, FillStyle fillStyle);
00367 
00368 protected:
00369     KisPaintDeviceSP m_device;
00370     KisTransaction  *m_transaction;
00371 
00372     QRect m_dirtyRect;
00373 
00374     KisColor m_paintColor;
00375     KisColor m_backgroundColor;
00376     KisColor m_fillColor;
00377     FillStyle m_fillStyle;
00378     StrokeStyle m_strokeStyle;
00379     KisBrush *m_brush;
00380     KisPattern *m_pattern;
00381     KisPoint m_duplicateOffset;
00382     Q_UINT8 m_opacity;
00383     KisCompositeOp m_compositeOp;
00384     KisFilterSP m_filter;
00385     KisPaintOp * m_paintOp;
00386     double m_pressure;
00387     bool m_cancelRequested;
00388     Q_INT32 m_pixelSize;
00389     KisColorSpace * m_colorSpace;
00390     KisProfile *  m_profile;
00391     KisPaintDeviceSP m_dab;
00392 
00393 };
00394 
00395 
00396 #endif // KIS_PAINTER_H_
00397 
KDE Home | KDE Accessibility Home | Description of Access Keys