Fixed eraser tool adding to mesh in rare cases
This commit is contained in:
parent
c48531238e
commit
ff99878755
3 changed files with 21 additions and 9 deletions
|
|
@ -374,13 +374,18 @@ CanvasComponentEraseDetailResult MeshCanvasComponent::erase_detail(const SkPath&
|
||||||
bool intersectsAABB = d.meshPath.getBounds().intersects(eraseAgainst.getBounds());
|
bool intersectsAABB = d.meshPath.getBounds().intersects(eraseAgainst.getBounds());
|
||||||
if(!intersectsAABB)
|
if(!intersectsAABB)
|
||||||
return CanvasComponentEraseDetailResult::NO_CHANGE;
|
return CanvasComponentEraseDetailResult::NO_CHANGE;
|
||||||
std::optional<SkPath> newPath = Op(d.meshPath, eraseAgainst, SkPathOp::kDifference_SkPathOp);
|
std::optional<SkPath> newPath = Op(Simplify(d.meshPath).value(), Simplify(eraseAgainst).value(), SkPathOp::kDifference_SkPathOp);
|
||||||
if(newPath.has_value()) {
|
if(newPath.has_value()) {
|
||||||
auto oldPath = d.meshPath;
|
if(newPath.value().isEmpty()) {
|
||||||
d.meshPath = newPath.value();
|
d.meshPath = newPath.value();
|
||||||
if(d.meshPath.isEmpty())
|
|
||||||
return CanvasComponentEraseDetailResult::REMOVED;
|
return CanvasComponentEraseDetailResult::REMOVED;
|
||||||
return CanvasComponentEraseDetailResult::CHANGED;
|
}
|
||||||
|
else if(!d.meshPath.getBounds().contains(newPath.value().getBounds())) // If bounds of erased path is larger than bounds of original path (can happen when difference op bugs out with big eraser paths), dont change the path
|
||||||
|
return CanvasComponentEraseDetailResult::NO_CHANGE;
|
||||||
|
else {
|
||||||
|
d.meshPath = newPath.value();
|
||||||
|
return CanvasComponentEraseDetailResult::CHANGED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return CanvasComponentEraseDetailResult::NO_CHANGE;
|
return CanvasComponentEraseDetailResult::NO_CHANGE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,17 +89,18 @@ void EraserTool::input_mouse_button_on_canvas_callback(const InputManager::Mouse
|
||||||
BrushComponentCode::mouse_button(drawP, genData, drawP.world.drawData.cam.c, button, relativeWidthResult.first.value());
|
BrushComponentCode::mouse_button(drawP, genData, drawP.world.drawData.cam.c, button, relativeWidthResult.first.value());
|
||||||
// NOTE: Must set erase path when isErasing is set to true to make sure that the Circle path from not erasing part doesn't reach the erase_on_path code
|
// NOTE: Must set erase path when isErasing is set to true to make sure that the Circle path from not erasing part doesn't reach the erase_on_path code
|
||||||
erasePath = BrushComponentCode::brush_stroke_to_skpath(genData.brushPoints, drawP.world.main.toolConfig.brush.hasRoundCaps);
|
erasePath = BrushComponentCode::brush_stroke_to_skpath(genData.brushPoints, drawP.world.main.toolConfig.brush.hasRoundCaps);
|
||||||
isErasing = true;
|
eraserChanged = isErasing = true;
|
||||||
}
|
}
|
||||||
else if(!button.down && isErasing) {
|
else if(!button.down && isErasing) {
|
||||||
// If not real time eraser, we can benefit from simplifying the path
|
// If not real time eraser, we can benefit from simplifying the path
|
||||||
std::optional<SkPath> simplified = Simplify(erasePath);
|
std::optional<SkPath> simplified = Simplify(erasePath);
|
||||||
if(simplified.has_value())
|
if(simplified.has_value())
|
||||||
erasePath = simplified.value();
|
erasePath = simplified.value();
|
||||||
erase_on_path();
|
if(eraserChanged)
|
||||||
|
erase_on_path();
|
||||||
reset_erasing_stroke();
|
reset_erasing_stroke();
|
||||||
commit_erase();
|
commit_erase();
|
||||||
isErasing = false;
|
eraserChanged = isErasing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,6 +109,7 @@ void EraserTool::input_mouse_motion_callback(const InputManager::MouseMotionCall
|
||||||
if(isErasing) {
|
if(isErasing) {
|
||||||
auto& toolConfig = drawP.world.main.toolConfig;
|
auto& toolConfig = drawP.world.main.toolConfig;
|
||||||
BrushComponentCode::mouse_motion(drawP, genData, motion.pos, toolConfig.get_relative_width_stroke_size(drawP, genData.coords.inverseScale).first.value());
|
BrushComponentCode::mouse_motion(drawP, genData, motion.pos, toolConfig.get_relative_width_stroke_size(drawP, genData.coords.inverseScale).first.value());
|
||||||
|
eraserChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +120,7 @@ void EraserTool::input_pen_axis_callback(const InputManager::PenAxisCallbackArgs
|
||||||
auto& toolConfig = drawP.world.main.toolConfig;
|
auto& toolConfig = drawP.world.main.toolConfig;
|
||||||
float width = toolConfig.get_relative_width_stroke_size(drawP, genData.coords.inverseScale).first.value();
|
float width = toolConfig.get_relative_width_stroke_size(drawP, genData.coords.inverseScale).first.value();
|
||||||
BrushComponentCode::pen_pressure(drawP, genData, width);
|
BrushComponentCode::pen_pressure(drawP, genData, width);
|
||||||
|
eraserChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -281,7 +284,10 @@ void EraserTool::commit_data() {
|
||||||
if(isErasing) {
|
if(isErasing) {
|
||||||
erasePath = BrushComponentCode::brush_stroke_to_skpath(genData.brushPoints, drawP.world.main.toolConfig.brush.hasRoundCaps);
|
erasePath = BrushComponentCode::brush_stroke_to_skpath(genData.brushPoints, drawP.world.main.toolConfig.brush.hasRoundCaps);
|
||||||
if(drawP.world.main.conf.realTimeEraser) {
|
if(drawP.world.main.conf.realTimeEraser) {
|
||||||
erase_on_path();
|
if(eraserChanged) {
|
||||||
|
erase_on_path();
|
||||||
|
eraserChanged = false;
|
||||||
|
}
|
||||||
reset_erasing_stroke();
|
reset_erasing_stroke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,5 @@ class EraserTool : public DrawingProgramToolBase {
|
||||||
void commit_erase();
|
void commit_erase();
|
||||||
void commit_data();
|
void commit_data();
|
||||||
bool isErasing = false;
|
bool isErasing = false;
|
||||||
|
bool eraserChanged = false;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue