1// Aseprite
2// Copyright (C) 2020-2022 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_UI_EDITOR_TRANSFORM_HANDLES_H_INCLUDED
9#define APP_UI_EDITOR_TRANSFORM_HANDLES_H_INCLUDED
10#pragma once
11
12#include "app/transformation.h"
13#include "app/ui/editor/handle_type.h"
14#include "gfx/point.h"
15
16#include <vector>
17
18namespace ui {
19 class Graphics;
20}
21
22namespace app {
23 class Editor;
24
25 // Helper class to do hit-detection and render transformation handles
26 // and rotation pivot.
27 class TransformHandles {
28 public:
29 // Returns the handle in the given mouse point (pt) when the user
30 // has applied the given transformation to the selection.
31 HandleType getHandleAtPoint(Editor* editor, const gfx::Point& pt, const Transformation& transform);
32
33 void drawHandles(Editor* editor, ui::Graphics* g,
34 const Transformation& transform);
35 void invalidateHandles(Editor* editor, const Transformation& transform);
36
37 private:
38 gfx::Rect getPivotHandleBounds(Editor* editor,
39 const Transformation& transform,
40 const Transformation::Corners& corners);
41
42 bool inHandle(const gfx::Point& pt, int x, int y, int gfx_w, int gfx_h, double angle);
43 void drawHandle(Editor* editor, ui::Graphics* g, int x, int y, double angle);
44 void adjustHandle(int& x, int& y, int handle_w, int handle_h, double angle);
45 bool visiblePivot(double angle) const;
46 void getScreenPoints(
47 Editor* editor,
48 const Transformation::Corners& corners,
49 std::vector<gfx::Point>& screenPoints) const;
50 };
51
52} // namespace app
53
54#endif
55