Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • managers
overlaymanager.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#include "editor.h"
19#include "overlaymanager.h"
20
21#include <QTransform>
22
23OverlayManager::OverlayManager(Editor *editor): BaseManager(editor, __FUNCTION__)
24{
25 mEditor = editor;
26
27 mSinglePerspectivePoint = QPointF(0.1, 0.1);
28 mLeftPerspectivePoint = QPointF(-300.0, 0.0);
29 mRightPerspectivePoint = QPointF(300.0, 0.0);
30 mMiddlePerspectivePoint = QPointF(0.0, 200.0);
31}
32
33OverlayManager::~OverlayManager()
34{
35}
36
37bool OverlayManager::init()
38{
39 return true;
40}
41
42Status OverlayManager::load(Object*)
43{
44 return Status::OK;
45}
46
47Status OverlayManager::save(Object*)
48{
49 return Status::OK;
50}
51
52void OverlayManager::workingLayerChanged(Layer *)
53{
54}
55
56void OverlayManager::settingsUpdated(SETTING setting, bool state)
57{
58 switch (setting) {
59 case SETTING::OVERLAY_PERSPECTIVE1:
60 mSinglePerspectiveEnabled = state;
61 break;
62 case SETTING::OVERLAY_PERSPECTIVE2:
63 mTwoPointPerspectiveEnabled = state;
64 break;
65 case SETTING::OVERLAY_PERSPECTIVE3:
66 mThreePointPerspectiveEnabled = state;
67 break;
68 default:
69 // We intentiallly leave everything else out as only overlay settings are important
70 break;
71 }
72}
73
74MoveMode OverlayManager::getMoveModeForPoint(const QPointF& pos, const QTransform& transform)
75{
76 const double calculatedSelectionTol = selectionTolerance();
77 MoveMode mode = MoveMode::NONE;
78
79 if (mSinglePerspectiveEnabled && QLineF(pos, transform.inverted().map(mSinglePerspectivePoint)).length() < calculatedSelectionTol)
80 {
81 mode = MoveMode::PERSP_SINGLE;
82 }
83 else if ((mTwoPointPerspectiveEnabled || mThreePointPerspectiveEnabled) && QLineF(pos, transform.inverted().map(mLeftPerspectivePoint)).length() < calculatedSelectionTol)
84 {
85 mode = MoveMode::PERSP_LEFT;
86 }
87 else if ((mTwoPointPerspectiveEnabled || mThreePointPerspectiveEnabled) && QLineF(pos, transform.inverted().map(mRightPerspectivePoint)).length() < calculatedSelectionTol)
88 {
89 mode = MoveMode::PERSP_RIGHT;
90 }
91 else if (mThreePointPerspectiveEnabled && QLineF(pos, transform.inverted().map(mMiddlePerspectivePoint)).length() < calculatedSelectionTol)
92 {
93 mode = MoveMode::PERSP_MIDDLE;
94 }
95
96 return mode;
97}
98
99double OverlayManager::selectionTolerance()
100{
101 return qAbs(mSelectionTolerance * mEditor->viewScaleInversed());
102}
103
104void OverlayManager::updatePerspective(const QPointF& point)
105{
106 switch (mMoveMode) {
107 case MoveMode::PERSP_SINGLE:
108 mSinglePerspectivePoint = point;
109 break;
110 case MoveMode::PERSP_LEFT:
111 mLeftPerspectivePoint = point;
112 mRightPerspectivePoint = QPointF(getRightPerspectivePoint().x(), point.y());
113 break;
114 case MoveMode::PERSP_RIGHT:
115 mRightPerspectivePoint = point;
116 mLeftPerspectivePoint = QPointF(getLeftPerspectivePoint().x(), point.y());
117 break;
118 case MoveMode::PERSP_MIDDLE:
119 mMiddlePerspectivePoint = point;
120 break;
121 default:
122 break;
123 }
124}
BaseManager
Definition: basemanager.h:29
Editor
Definition: editor.h:71
Layer
Definition: layer.h:33
Object
Definition: object.h:42
Status
Definition: pencilerror.h:40
QLineF
QLineF::length
qreal length() const const
QPointF
QPointF::y
qreal y() const const
QTransform
QTransform::inverted
QTransform inverted(bool *invertible) const const
QTransform::map
QPoint map(const QPoint &point) const const
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39