Use dynamics for brush preview only for freehand tools (fix #4178)

This fixes a problem where the smaller brush size of the dynamics was
used for tools like line/rectangle/etc. where the dynamics option
aren't used.

We've added some comments for a possible future #4186 too,
implementing dynamics for the contour tool (which is freehand, but the
result is filled).
This commit is contained in:
David Capello 2023-11-30 12:56:46 -03:00
parent 5ae2e444f2
commit 10738b32c3
3 changed files with 28 additions and 17 deletions

View File

@ -379,6 +379,7 @@ Stroke::Pt ToolLoopManager::getSpriteStrokePt(const Pointer& pointer)
bool ToolLoopManager::useDynamics() const bool ToolLoopManager::useDynamics() const
{ {
return (m_dynamics.isDynamic() && return (m_dynamics.isDynamic() &&
// TODO add support for dynamics to contour tool
!m_toolLoop->getFilled() && !m_toolLoop->getFilled() &&
m_toolLoop->getController()->isFreehand()); m_toolLoop->getController()->isFreehand());
} }

View File

@ -1203,7 +1203,6 @@ public:
} }
void setOptionsGridVisibility(bool state) { void setOptionsGridVisibility(bool state) {
m_optionsGridVisibility = state;
if (m_popup) if (m_popup)
m_popup->setOptionsGridVisibility(state); m_popup->setOptionsGridVisibility(state);
} }
@ -1299,7 +1298,6 @@ private:
std::unique_ptr<DynamicsPopup> m_popup; std::unique_ptr<DynamicsPopup> m_popup;
ContextBar* m_ctxBar; ContextBar* m_ctxBar;
mutable tools::DynamicsOptions m_dynamics; mutable tools::DynamicsOptions m_dynamics;
bool m_optionsGridVisibility = true;
bool m_sameInAllTools = false; bool m_sameInAllTools = false;
}; };
@ -2170,6 +2168,10 @@ void ContextBar::updateForTool(tools::Tool* tool)
(tool->getController(0)->isFreehand() || (tool->getController(0)->isFreehand() ||
tool->getController(1)->isFreehand()); tool->getController(1)->isFreehand());
const bool isFilled = tool &&
(tool->getFill(0) == tools::FillAlways ||
tool->getFill(1) == tools::FillAlways);
const bool showOpacity = const bool showOpacity =
(supportOpacity) && (supportOpacity) &&
((isPaint && (hasInkWithOpacity || hasImageBrush)) || ((isPaint && (hasInkWithOpacity || hasImageBrush)) ||
@ -2179,9 +2181,11 @@ void ContextBar::updateForTool(tools::Tool* tool)
(tool->getInk(0)->withDitheringOptions() || (tool->getInk(0)->withDitheringOptions() ||
tool->getInk(1)->withDitheringOptions()); tool->getInk(1)->withDitheringOptions());
// True if the brush supports dynamics // True if the tool & brush support dynamics
// TODO add support for dynamics in custom brushes in the future const bool supportDynamics =
const bool supportDynamics = (!hasImageBrush); (isFreehand &&
!isFilled && // TODO add support for dynamics to contour tool
!hasImageBrush); // TODO add support for dynamics in custom brushes
// Show/Hide fields // Show/Hide fields
m_zoomButtons->setVisible(needZoomButtons(tool)); m_zoomButtons->setVisible(needZoomButtons(tool));
@ -2196,7 +2200,7 @@ void ContextBar::updateForTool(tools::Tool* tool)
m_inkShades->setVisible(hasInkShades); m_inkShades->setVisible(hasInkShades);
m_eyedropperField->setVisible(isEyedropper); m_eyedropperField->setVisible(isEyedropper);
m_autoSelectLayer->setVisible(isMove); m_autoSelectLayer->setVisible(isMove);
m_dynamics->setVisible(isFreehand && supportDynamics); m_dynamics->setVisible(supportDynamics);
m_dynamics->setOptionsGridVisibility(isFreehand && !hasSelectOptions); m_dynamics->setOptionsGridVisibility(isFreehand && !hasSelectOptions);
m_freehandBox->setVisible(isFreehand && (supportOpacity || hasSelectOptions)); m_freehandBox->setVisible(isFreehand && (supportOpacity || hasSelectOptions));
m_toleranceLabel->setVisible(hasTolerance); m_toleranceLabel->setVisible(hasTolerance);

View File

@ -163,7 +163,8 @@ void BrushPreview::show(const gfx::Point& screenPos)
BrushRef brush = getCurrentBrush(); BrushRef brush = getCurrentBrush();
const bool isFloodfill = m_editor->getCurrentEditorTool()->getPointShape(0)->isFloodFill(); tools::Tool* tool = m_editor->getCurrentEditorTool();
const bool isFloodfill = tool->getPointShape(0)->isFloodFill();
// TODO add support for "tile-brushes" // TODO add support for "tile-brushes"
gfx::Rect origBrushBounds = gfx::Rect origBrushBounds =
((isFloodfill && brush->type() != BrushType::kImageBrushType) || ((isFloodfill && brush->type() != BrushType::kImageBrushType) ||
@ -190,21 +191,26 @@ void BrushPreview::show(const gfx::Point& screenPos)
// Get current tilemap mode // Get current tilemap mode
TilemapMode tilemapMode = ColorBar::instance()->tilemapMode(); TilemapMode tilemapMode = ColorBar::instance()->tilemapMode();
const auto& dynamics = App::instance()->contextBar()->getDynamics();
// Setup the cursor type depending on several factors (current tool, // Setup the cursor type depending on several factors (current tool,
// foreground color, layer transparency, brush size, etc.). // foreground color, layer transparency, brush size, etc.).
color_t brush_color = getBrushColor(sprite, layer); color_t brush_color = getBrushColor(sprite, layer);
color_t mask_index = sprite->transparentColor(); color_t mask_index = sprite->transparentColor();
if (brush->type() != doc::kImageBrushType && // Check dynamics option for freehand tools
(dynamics.size != tools::DynamicSensor::Static || if (tool &&
dynamics.angle != tools::DynamicSensor::Static)) { tool->getController(0)->isFreehand() &&
brush.reset( // TODO add support for dynamics to contour tool
new Brush( tool->getFill(0) == tools::FillNone) {
brush->type(), const auto& dynamics = App::instance()->contextBar()->getDynamics();
(dynamics.size != tools::DynamicSensor::Static ? dynamics.minSize: brush->size()), if (brush->type() != doc::kImageBrushType &&
(dynamics.angle != tools::DynamicSensor::Static ? dynamics.minAngle: brush->angle()))); (dynamics.size != tools::DynamicSensor::Static ||
dynamics.angle != tools::DynamicSensor::Static)) {
brush.reset(
new Brush(
brush->type(),
(dynamics.size != tools::DynamicSensor::Static ? dynamics.minSize: brush->size()),
(dynamics.angle != tools::DynamicSensor::Static ? dynamics.minAngle: brush->angle())));
}
} }
if (ink->isSelection() || ink->isSlice()) { if (ink->isSelection() || ink->isSlice()) {