| 1 | // Aseprite | 
|---|
| 2 | // Copyright (C) 2020  Igara Studio S.A. | 
|---|
| 3 | // Copyright (C) 2001-2018  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_CONTROLLER_H_INCLUDED | 
|---|
| 9 | #define APP_TOOLS_CONTROLLER_H_INCLUDED | 
|---|
| 10 | #pragma once | 
|---|
| 11 |  | 
|---|
| 12 | #include "app/tools/stroke.h" | 
|---|
| 13 | #include "app/tools/trace_policy.h" | 
|---|
| 14 | #include "gfx/point.h" | 
|---|
| 15 |  | 
|---|
| 16 | #include <string> | 
|---|
| 17 | #include <vector> | 
|---|
| 18 |  | 
|---|
| 19 | namespace app { | 
|---|
| 20 | namespace tools { | 
|---|
| 21 |  | 
|---|
| 22 | class ToolLoop; | 
|---|
| 23 |  | 
|---|
| 24 | // This class controls user input. | 
|---|
| 25 | class Controller { | 
|---|
| 26 | public: | 
|---|
| 27 | virtual ~Controller() { } | 
|---|
| 28 |  | 
|---|
| 29 | virtual bool canSnapToGrid() { return true; } | 
|---|
| 30 | virtual bool isFreehand() { return false; } | 
|---|
| 31 | virtual bool isOnePoint() { return false; } | 
|---|
| 32 | virtual bool isTwoPoints() { return false; } | 
|---|
| 33 |  | 
|---|
| 34 | virtual void prepareController(ToolLoop* loop) { } | 
|---|
| 35 |  | 
|---|
| 36 | // Called when the user starts drawing and each time a new button is | 
|---|
| 37 | // pressed. The controller could be sure that this method is called | 
|---|
| 38 | // at least one time. The point is a position relative to sprite | 
|---|
| 39 | // bounds. | 
|---|
| 40 | virtual void pressButton(ToolLoop* loop, Stroke& stroke, const Stroke::Pt& pt) = 0; | 
|---|
| 41 |  | 
|---|
| 42 | // Called each time a mouse button is released. | 
|---|
| 43 | virtual bool releaseButton(Stroke& stroke, const Stroke::Pt& pt) = 0; | 
|---|
| 44 |  | 
|---|
| 45 | // Called when the mouse is moved. | 
|---|
| 46 | virtual void movement(ToolLoop* loop, Stroke& stroke, const Stroke::Pt& pt) = 0; | 
|---|
| 47 |  | 
|---|
| 48 | // The input and output strokes are relative to sprite coordinates. | 
|---|
| 49 | virtual void getStrokeToInterwine(const Stroke& input, Stroke& output) = 0; | 
|---|
| 50 | virtual void getStatusBarText(ToolLoop* loop, const Stroke& stroke, std::string& text) = 0; | 
|---|
| 51 |  | 
|---|
| 52 | // Last point used by this controller, useful to save the last | 
|---|
| 53 | // point of a freehand tool. | 
|---|
| 54 | virtual Stroke::Pt getLastPoint() const { return gfx::Point(0, 0); } | 
|---|
| 55 |  | 
|---|
| 56 | // Special trace policy that can change in the middle of the | 
|---|
| 57 | // ToolLoop. This is for LineFreehandController which uses a | 
|---|
| 58 | // TracePolicy::Last for TwoPoints controller (Line-like tool) | 
|---|
| 59 | // and then a TracePolicy::Accumulate for freehand (Pencil tool). | 
|---|
| 60 | virtual bool handleTracePolicy() const { return false; } | 
|---|
| 61 | virtual TracePolicy getTracePolicy() const { return TracePolicy::Accumulate; } | 
|---|
| 62 |  | 
|---|
| 63 | // Returns the angle for a shape-like intertwiner (rectangles, | 
|---|
| 64 | // ellipses, etc.). | 
|---|
| 65 | virtual double getShapeAngle() const { return 0.0; } | 
|---|
| 66 | }; | 
|---|
| 67 |  | 
|---|
| 68 | } // namespace tools | 
|---|
| 69 | } // namespace app | 
|---|
| 70 |  | 
|---|
| 71 | #endif  // APP_TOOLS_CONTROLLER_H_INCLUDED | 
|---|
| 72 |  | 
|---|