1 | // Aseprite |
---|---|
2 | // Copyright (C) 2020 Igara Studio S.A. |
3 | // Copyright (C) 2001-2016 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "app/ui/editor/pivot_helpers.h" |
13 | |
14 | #include "app/pref/preferences.h" |
15 | #include "app/transformation.h" |
16 | |
17 | namespace app { |
18 | |
19 | void set_pivot_from_preferences(Transformation& t) |
20 | { |
21 | auto corners = t.transformedCorners(); |
22 | gfx::PointT<double> nw(corners[Transformation::Corners::LEFT_TOP]); |
23 | gfx::PointT<double> ne(corners[Transformation::Corners::RIGHT_TOP]); |
24 | gfx::PointT<double> sw(corners[Transformation::Corners::LEFT_BOTTOM]); |
25 | gfx::PointT<double> se(corners[Transformation::Corners::RIGHT_BOTTOM]); |
26 | gfx::PointT<double> pivotPos((nw + se) / 2); |
27 | |
28 | app::gen::PivotPosition pivot = Preferences::instance().selection.pivotPosition(); |
29 | switch (pivot) { |
30 | case app::gen::PivotPosition::NORTHWEST: |
31 | pivotPos = nw; |
32 | break; |
33 | case app::gen::PivotPosition::NORTH: |
34 | pivotPos = (nw + ne) / 2.0; |
35 | break; |
36 | case app::gen::PivotPosition::NORTHEAST: |
37 | pivotPos = ne; |
38 | break; |
39 | case app::gen::PivotPosition::WEST: |
40 | pivotPos = (nw + sw) / 2.0; |
41 | break; |
42 | case app::gen::PivotPosition::EAST: |
43 | pivotPos = (ne + se) / 2.0; |
44 | break; |
45 | case app::gen::PivotPosition::SOUTHWEST: |
46 | pivotPos = sw; |
47 | break; |
48 | case app::gen::PivotPosition::SOUTH: |
49 | pivotPos = (sw + se) / 2.0; |
50 | break; |
51 | case app::gen::PivotPosition::SOUTHEAST: |
52 | pivotPos = se; |
53 | break; |
54 | } |
55 | |
56 | t.displacePivotTo(gfx::PointF(pivotPos)); |
57 | } |
58 | |
59 | } // namespace app |
60 |