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