Skip to content

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

C

Fix Ctrl+Alt brush resizing across level types

Rodney5989bf2ead06
diff --git a/toonz/sources/tnztools/fullcolorbrushtool.cpp b/toonz/sources/tnztools/fullcolorbrushtool.cpp
index b3a2f5888..7b42939b0 100644
--- a/toonz/sources/tnztools/fullcolorbrushtool.cpp
+++ b/toonz/sources/tnztools/fullcolorbrushtool.cpp
@@ -478,7 +478,12 @@ void FullColorBrushTool::inputMouseMove(const TPointD &position,
}
} locals = {this};
- if (state.isKeyPressed(TKey::control) && state.isKeyPressed(TKey::alt)) {
+ const bool resizeBrush =
+ Preferences::instance()->useCtrlAltToResizeBrushEnabled() &&
+ state.isKeyPressed(TKey::control) && state.isKeyPressed(TKey::alt) &&
+ !state.isKeyPressed(TKey::shift);
+
+ if (resizeBrush) {
const TPointD &diff = position - m_mousePos;
if (getBrushStyle()) {
locals.add(m_modifierSize, 0.01 * diff.x);
diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cpp
index 2e76f380c..131b1ac23 100644
--- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp
+++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp
@@ -1466,12 +1466,15 @@ void ToonzRasterBrushTool::inputMouseMove(const TPointD &position,
struct Locals {
ToonzRasterBrushTool *m_this;
+ void notify(TProperty &prop) {
+ m_this->onPropertyChanged(prop.getName());
+ TTool::getApplication()->getCurrentTool()->notifyToolChanged();
+ }
+
void setValue(TDoublePairProperty &prop,
const TDoublePairProperty::Value &value) {
prop.setValue(value);
-
- m_this->onPropertyChanged(prop.getName());
- TTool::getApplication()->getCurrentTool()->notifyToolChanged();
+ notify(prop);
}
void addMinMax(TDoublePairProperty &prop, double min, double max) {
@@ -1487,6 +1490,14 @@ void ToonzRasterBrushTool::inputMouseMove(const TPointD &position,
setValue(prop, value);
}
+
+ void add(TDoubleProperty &prop, double amount) {
+ if (amount == 0.0) return;
+ const TDoubleProperty::Range &range = prop.getRange();
+ prop.setValue(
+ tcrop<double>(prop.getValue() + amount, range.first, range.second));
+ notify(prop);
+ }
} locals = {this};
double thickness =
@@ -1494,26 +1505,32 @@ void ToonzRasterBrushTool::inputMouseMove(const TPointD &position,
TPointD halfThick(thickness * 0.5, thickness * 0.5);
TRectD invalidateRect(m_brushPos - halfThick, m_brushPos + halfThick);
- if (Preferences::instance()->useCtrlAltToResizeBrushEnabled() &&
+ const bool resizeBrush =
+ Preferences::instance()->useCtrlAltToResizeBrushEnabled() &&
state.isKeyPressed(TKey::control) && state.isKeyPressed(TKey::alt) &&
- !state.isKeyPressed(TKey::shift)) {
+ !state.isKeyPressed(TKey::shift);
+
+ if (resizeBrush) {
// Resize the brush if CTRL+ALT is pressed and the preference is enabled.
const TPointD &diff = position - m_mousePos;
- double max = diff.x / 2;
- double min = diff.y / 2;
-
- locals.addMinMax(m_rasThickness, min, max);
-
- double radius = m_rasThickness.getValue().second * 0.5;
+ double radius;
+ if (m_isMyPaintStyleSelected) {
+ locals.add(m_modifierSize, 0.01 * diff.x);
+ radius = (m_maxCursorThick + 1) * 0.5;
+ } else {
+ locals.addMinMax(m_rasThickness, diff.y / 2, diff.x / 2);
+ radius = m_rasThickness.getValue().second * 0.5;
+ }
invalidateRect += TRectD(m_brushPos - TPointD(radius, radius),
m_brushPos + TPointD(radius, radius));
-
} else {
- m_brushPos = m_mousePos = position;
+ m_brushPos = position;
invalidateRect += TRectD(position - halfThick, position + halfThick);
}
+ m_mousePos = position;
+
invalidate(invalidateRect.enlarge(20));
if (m_minThick == 0 && m_maxThick == 0) {
@@ -1700,6 +1717,8 @@ bool ToonzRasterBrushTool::onPropertyChanged(std::string propertyName) {
BrushLockAlpha = m_modifierLockAlpha.getValue();
RasterBrushAssistants = m_assistants.getValue();
+ if (propertyName == m_modifierSize.getName()) updateCurrentStyle();
+
// Recalculate/reset based on changed settings
if (propertyName == m_rasThickness.getName()) {
m_minThick = m_rasThickness.getValue().first;
diff --git a/toonz/sources/tnztools/toonzvectorbrushtool.cpp b/toonz/sources/tnztools/toonzvectorbrushtool.cpp
index 30b27455d..3b4a20268 100644
--- a/toonz/sources/tnztools/toonzvectorbrushtool.cpp
+++ b/toonz/sources/tnztools/toonzvectorbrushtool.cpp
@@ -771,29 +771,32 @@ void ToonzVectorBrushTool::inputMouseMove(
} locals = {this};
- TPointD halfThick(m_maxThick * 0.5, m_maxThick * 0.5);
+ const double pixelToStage = Stage::inch / m_cameraDpi;
+ TPointD halfThick(m_maxThick * 0.5 * pixelToStage,
+ m_maxThick * 0.5 * pixelToStage);
TRectD invalidateRect(m_brushPos - halfThick, m_brushPos + halfThick);
- bool alt = state.isKeyPressed(TInputState::Key::alt);
- bool shift = state.isKeyPressed(TInputState::Key::shift);
- bool control = state.isKeyPressed(TInputState::Key::control);
-
- if ( alt && control && !shift
- && Preferences::instance()->useCtrlAltToResizeBrushEnabled() )
- {
+ const bool resizeBrush =
+ Preferences::instance()->useCtrlAltToResizeBrushEnabled() &&
+ state.isKeyPressed(TKey::control) && state.isKeyPressed(TKey::alt) &&
+ !state.isKeyPressed(TKey::shift);
+
+ if (resizeBrush) {
// Resize the brush if CTRL+ALT is pressed and the preference is enabled.
const TPointD &diff = position - m_mousePos;
- double max = diff.x / 2;
- double min = diff.y / 2;
+ double max = diff.x / (2.0 * pixelToStage);
+ double min = diff.y / (2.0 * pixelToStage);
locals.addMinMax(m_thickness, min, max);
- double radius = m_thickness.getValue().second * 0.5;
+ double radius = m_thickness.getValue().second * 0.5 * pixelToStage;
halfThick = TPointD(radius, radius);
} else {
- m_brushPos = m_mousePos = position;
+ m_brushPos = position;
}
-
+
+ m_mousePos = position;
+
invalidateRect += TRectD(m_brushPos - halfThick, m_brushPos + halfThick);
if (m_minThick == 0 && m_maxThick == 0) {