1 // Aseprite 2 // Copyright (C) 2001-2017 David Capello 3 // 4 // This program is distributed under the terms of 5 // the End-User License Agreement for Aseprite. 6 7 #ifndef APP_TOOLS_INK_H_INCLUDED 8 #define APP_TOOLS_INK_H_INCLUDED 9 #pragma once 10 11 #include "app/tools/stroke.h" 12 13 namespace gfx { 14 class Region; 15 } 16 17 namespace app { 18 namespace tools { 19 20 class ToolLoop; 21 22 // Class used to paint directly in the destination image (loop->getDstImage()) 23 // 24 // The main task of this class is to draw scanlines through its 25 // inkHline function member. 26 class Ink { 27 public: ~Ink()28 virtual ~Ink() { } 29 30 // Creates a copy of the ink to avoid sharing state between 31 // different ToolLoop implementations. (e.g. PaintInk::m_proc is 32 // set in PaintInk::prepareInk() member function, so we cannot 33 // share the same PaintInk instance.) 34 virtual Ink* clone() = 0; 35 36 // Returns true if this ink modifies the selection/mask isSelection()37 virtual bool isSelection() const { return false; } 38 39 // Returns true if this ink modifies the destination image isPaint()40 virtual bool isPaint() const { return false; } 41 42 // Returns true if this ink is an effect (is useful to know if a ink 43 // is a effect so the Editor can display the cursor bounds) isEffect()44 virtual bool isEffect() const { return false; } 45 46 // Returns true if this ink acts like an eraser isEraser()47 virtual bool isEraser() const { return false; } 48 49 // Returns true if this ink picks colors from the image isEyedropper()50 virtual bool isEyedropper() const { return false; } 51 52 // Returns true if this ink is shading isShading()53 virtual bool isShading() const { return false; } 54 55 // Returns true if this ink moves the scroll only isScrollMovement()56 virtual bool isScrollMovement() const { return false; } 57 58 // Returns true if this ink is zoom isZoom()59 virtual bool isZoom() const { return false; } 60 61 // Returns true if this ink moves cels isCelMovement()62 virtual bool isCelMovement() const { return false; } 63 64 // Returns true if this ink is used to mark slices isSlice()65 virtual bool isSlice() const { return false; } 66 67 // Returns true if this tool uses the dithering options withDitheringOptions()68 virtual bool withDitheringOptions() const { return false; } 69 70 // Returns true if inkHline() needs source cel coordinates 71 // instead of sprite coordinates (i.e. relative to 72 // ToolLoop::getCelOrigin()). needsCelCoordinates()73 virtual bool needsCelCoordinates() const { return true; } 74 75 // Returns true if this ink needs a special source area. For 76 // example, blur tool needs one extra pixel to all sides of the 77 // modified area, so it can use a 3x3 convolution matrix. needsSpecialSourceArea()78 virtual bool needsSpecialSourceArea() const { return false; } createSpecialSourceArea(const gfx::Region & dirtyArea,gfx::Region & sourceArea)79 virtual void createSpecialSourceArea(const gfx::Region& dirtyArea, gfx::Region& sourceArea) const { } 80 81 // It is called when the tool-loop start (generally when the user 82 // presses a mouse button over a sprite editor) prepareInk(ToolLoop * loop)83 virtual void prepareInk(ToolLoop* loop) { } 84 85 // It is used in the final stage of the tool-loop, it is called twice 86 // (first with state=true and then state=false) setFinalStep(ToolLoop * loop,bool state)87 virtual void setFinalStep(ToolLoop* loop, bool state) { } 88 89 // It is used to paint scanlines in the destination image. 90 // PointShapes call this method when they convert a mouse-point 91 // to a shape (e.g. pen shape) with various scanlines. 92 virtual void inkHline(int x1, int y, int x2, ToolLoop* loop) = 0; 93 94 // Called when we have to start using the ink for a new set of 95 // strokes (e.g. color gradients is adjusted depending on the 96 // first/last stroke points). prepareForStrokes(ToolLoop * loop,Strokes & strokes)97 virtual void prepareForStrokes(ToolLoop* loop, Strokes& strokes) { } 98 99 // Called for each point shape. prepareForPointShape(ToolLoop * loop,bool firstPoint,int x,int y)100 virtual void prepareForPointShape(ToolLoop* loop, bool firstPoint, int x, int y) { } 101 102 }; 103 104 } // namespace tools 105 } // namespace app 106 107 #endif // TOOLS_INK_H_INCLUDED 108