1 #pragma once 2 3 #include "trastercm.h" 4 #include "ttilesaver.h" 5 #include "tstopwatch.h" 6 #include <fstream> 7 #include <QSet> 8 #undef DVAPI 9 #undef DVVAR 10 #ifdef TOONZLIB_EXPORTS 11 #define DVAPI DV_EXPORT_API 12 #define DVVAR DV_EXPORT_VAR 13 #else 14 #define DVAPI DV_IMPORT_API 15 #define DVVAR DV_IMPORT_VAR 16 #endif 17 18 enum Tasks { BRUSH, ERASE, PAINTBRUSH, FINGER }; 19 20 enum ColorType { INK, PAINT, INKNPAINT, NONE }; 21 22 class DVAPI RasterStrokeGenerator { 23 typedef std::vector<TThickPoint>::iterator Iterator; 24 25 TRasterCM32P 26 m_raster; // L'immagine raster sulla quale dobbiamo disegnare lo stroke 27 std::vector<TThickPoint> m_points; // Il vettore di punti che rappresentano 28 // la spina dorsale dello stroke 29 int m_styleId; // L'ink-style dello stroke 30 bool m_selective; 31 TRect m_boxOfRaster; // Un rettangolo della stessa dimensione di "m_raster" 32 ColorType m_colorType; 33 Tasks m_task; 34 int m_eraseStyle; 35 int m_selectedStyle; 36 bool m_keepAntiAlias; 37 bool m_doAnArc; 38 bool m_isPaletteOrder; // Used in the Draw Order option of Brush Tool, 39 // use style order to define line stacking order 40 QSet<int> m_aboveStyleIds; 41 42 // Ricalcola i punti in un nuovo sistema di riferimento 43 void translatePoints(std::vector<TThickPoint> &points, 44 const TPoint &newOrigin) const; 45 46 // Effettua la over. 47 void placeOver(const TRasterCM32P &out, const TRasterCM32P &in, 48 const TPoint &p) const; 49 50 public: 51 RasterStrokeGenerator(const TRasterCM32P &raster, Tasks task, 52 ColorType colorType, int styleId, const TThickPoint &p, 53 bool selective, int selectedStyle, bool keepAntialias, 54 bool isPaletteOrder = false); 55 ~RasterStrokeGenerator(); setRaster(const TRasterCM32P & ras)56 void setRaster(const TRasterCM32P &ras) { m_raster = ras; } setStyle(int styleId)57 void setStyle(int styleId) { m_styleId = styleId; } getStyleId()58 int getStyleId() const { return m_styleId; } isSelective()59 bool isSelective() { return m_selective; } 60 isPaletteOrder()61 bool isPaletteOrder() { return m_isPaletteOrder; } setAboveStyleIds(QSet<int> & ids)62 void setAboveStyleIds(QSet<int> &ids) { m_aboveStyleIds = ids; } 63 64 // Inserisce un punto in "m_points" 65 void add(const TThickPoint &p); 66 67 // Disegna il tratto interamente 68 void generateStroke(bool isPencil) const; 69 70 // Ritorna m_points getPointsSequence()71 std::vector<TThickPoint> getPointsSequence() { return m_points; } setPointsSequence(const std::vector<TThickPoint> & points)72 void setPointsSequence(const std::vector<TThickPoint> &points) { 73 m_points = points; 74 } 75 76 // Ritorna il rettangolo contenente i dischi generati con centri in "points" e 77 // raggio "points.thick" +2 pixel a bordo 78 TRect getBBox(const std::vector<TThickPoint> &points) const; 79 80 TRect getLastRect() const; 81 82 TRect generateLastPieceOfStroke(bool isPencil, bool closeStroke = false); 83 }; 84