Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Rotate: Introduce custom stepping to command and rotate tool

Abel You1552a5ffd130
diff --git a/toonz/sources/tnztools/viewtools.cpp b/toonz/sources/tnztools/viewtools.cpp
index 03616d532..a5e8b5a98 100644
--- a/toonz/sources/tnztools/viewtools.cpp
+++ b/toonz/sources/tnztools/viewtools.cpp
@@ -10,6 +10,7 @@
#include "tgl.h"
TEnv::IntVar RotateOnCameraCenter("RotateOnCameraCenter", 0);
+TEnv::DoubleVar RotateAngle("RotateAngle", 0);
namespace {
@@ -138,19 +139,25 @@ RotateTool::RotateTool(std::string name)
: TTool(name)
, m_dragging(false)
, m_cameraCentered("Rotate On Camera Center", false)
+ , m_rotateAngle("Rotate Angle:", 0, 360, 0, true)
, m_angle(0) {
bind(TTool::AllTargets);
m_cameraCentered.setId("RotateOnCamCenter");
+ m_rotateAngle.setId("Rotate Angle");
+
m_prop.bind(m_cameraCentered);
+ m_prop.bind(m_rotateAngle);
}
void RotateTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {
if (!m_viewer) return;
- m_angle = 0.0;
- m_dragging = true;
- m_oldPos = pos;
- m_oldMousePos = e.m_pos;
+ m_isCtrlPressed = e.isCtrlPressed();
+ m_isAltPressed = e.isAltPressed();
+ m_angle = 0.0;
+ m_dragging = true;
+ m_oldPos = pos;
+ m_oldMousePos = e.m_pos;
// m_center = TPointD(0,0);
m_sw.start(true);
invalidate();
@@ -165,6 +172,7 @@ void RotateTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
if (m_sw.getTotalTime() < 50) return;
m_sw.stop();
m_sw.start(true);
+
TPointD p = pos;
if (m_viewer->is3DView()) {
TPointD d = e.m_pos - m_oldMousePos;
@@ -175,9 +183,19 @@ void RotateTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
TPointD a = p - m_center;
TPointD b = m_oldPos - m_center;
if (norm2(a) > 0 && norm2(b) > 0) {
- double ang = asin(cross(b, a) / (norm(a) * norm(b))) * M_180_PI;
- m_angle = m_angle + ang;
- m_viewer->rotate(m_center, m_angle);
+ double ang = asin(cross(b, a) / (norm(a) * norm(b))) * M_180_PI;
+ m_angle = m_angle + ang;
+ double finalAngle = m_angle;
+ double step = m_rotateAngle.getValue();
+
+ if (m_isAltPressed && step > 0) {
+ finalAngle = std::round(m_angle / 15) * 15;
+
+ if (e.m_pos != m_oldMousePos) {
+ m_viewer->rotate(m_center, finalAngle);
+ }
+ } else
+ m_viewer->rotate(m_center, finalAngle);
}
}
m_oldPos = p;
@@ -212,6 +230,7 @@ int RotateTool::getCursorId() const { return ToolCursor::RotateCursor; }
void RotateTool::onActivate() {
if (m_firstTime) {
m_cameraCentered.setValue(RotateOnCameraCenter != 0);
+ m_rotateAngle.setValue((double)RotateAngle);
m_firstTime = false;
}
}
@@ -219,6 +238,8 @@ void RotateTool::onActivate() {
bool RotateTool::onPropertyChanged(std::string propertyName, bool addToUndo) {
if (propertyName == "Rotate On Camera Center")
RotateOnCameraCenter = m_cameraCentered.getValue() ? 1 : 0;
+ else if (propertyName == "Rotate Angle:")
+ RotateAngle = m_rotateAngle.getValue();
return true;
}
diff --git a/toonz/sources/tnztools/viewtools.h b/toonz/sources/tnztools/viewtools.h
index ef411a310..e615c5988 100644
--- a/toonz/sources/tnztools/viewtools.h
+++ b/toonz/sources/tnztools/viewtools.h
@@ -19,8 +19,11 @@ class RotateTool final : public QObject, public TTool {
TPointD m_center;
bool m_dragging;
double m_angle;
+ bool m_isCtrlPressed;
+ bool m_isAltPressed;
TPointD m_oldMousePos;
TBoolProperty m_cameraCentered;
+ TDoubleProperty m_rotateAngle;
TPropertyGroup m_prop;
bool m_firstTime = true;
@@ -43,6 +46,7 @@ public:
void updateTranslation() override {
m_cameraCentered.setQStringName(tr("Rotate On Camera Center"));
+ m_rotateAngle.setQStringName(tr("Rotate Angle:"));
}
};
diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp
index cea04f827..d61b136a3 100644
--- a/toonz/sources/toonz/mainwindow.cpp
+++ b/toonz/sources/toonz/mainwindow.cpp
@@ -2950,8 +2950,8 @@ void MainWindow::defineActions() {
createViewerAction(V_ActualPixelSize, QT_TR_NOOP("Actual Pixel Size"), "N");
createViewerAction(V_FlipX, QT_TR_NOOP("Flip Viewer Horizontally"), "");
createViewerAction(V_FlipY, QT_TR_NOOP("Flip Viewer Vertically"), "");
- createViewerAction(V_RotateLeft, QT_TR_NOOP("Rotate Viewer 90° Left"), "");
- createViewerAction(V_RotateRight, QT_TR_NOOP("Rotate Viewer 90° Right"), "");
+ createViewerAction(V_RotateLeft, QT_TR_NOOP("Rotate Viewer Left"), "");
+ createViewerAction(V_RotateRight, QT_TR_NOOP("Rotate Viewer Right"), "");
createViewerAction(V_ShowHideFullScreen, QT_TR_NOOP("Show//Hide Full Screen"),
"Alt+F");
CommandManager::instance()->setToggleTexts(V_ShowHideFullScreen,
@@ -2989,9 +2989,9 @@ void MainWindow::defineActions() {
createVisualizationButtonAction(
VB_FlipY, QT_TR_NOOP("Flip Viewer Vertically"), "flipvert");
createVisualizationButtonAction(
- VB_RotateLeft, QT_TR_NOOP("Rotate Viewer 90° Left"), "rotateleft");
+ VB_RotateLeft, QT_TR_NOOP("Rotate View Left"), "rotateleft");
createVisualizationButtonAction(
- VB_RotateRight, QT_TR_NOOP("Rotate Viewer 90° Right"), "rotateright");
+ VB_RotateRight, QT_TR_NOOP("Rotate View Right"), "rotateright");
// Misc
diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp
index 2e6e2aaf7..fbb20accc 100644
--- a/toonz/sources/toonz/sceneviewer.cpp
+++ b/toonz/sources/toonz/sceneviewer.cpp
@@ -93,6 +93,7 @@
#include "sceneviewer.h"
TEnv::IntVar RotateOnCameraCenter("RotateOnCameraCenter", 0);
+TEnv::DoubleVar RotateAngle("RotateAngle", 90);
void drawSpline(const TAffine &viewMatrix, const TRect &clipRect, bool camera3d,
double pixelSize);
@@ -2784,7 +2785,7 @@ void SceneViewer::flipY() {
}
void SceneViewer::rotateLeft() {
- double rotationAngle = 90.0;
+ double rotationAngle = (double)RotateAngle > 0 ? RotateAngle : 90.0;
if (m_isFlippedX != m_isFlippedY) rotationAngle *= -1;
TPointD center;
@@ -2798,7 +2799,7 @@ void SceneViewer::rotateLeft() {
}
void SceneViewer::rotateRight() {
- double rotationAngle = -90.0;
+ double rotationAngle = (double)RotateAngle > 0 ? -RotateAngle : -90.0;
if (m_isFlippedX != m_isFlippedY) rotationAngle *= -1;
TPointD center;
@@ -3009,7 +3010,7 @@ void SceneViewer::resetRotation() {
double reverseRotatation = m_rotationAngle[m_viewMode] * -1;
if (m_isFlippedX) reverseRotatation *= -1;
if (m_isFlippedY) reverseRotatation *= -1;
-
+
TPointD center;
if (RotateOnCameraCenter)