Actually do the smoothing when drawing a smoothed freehand shape

Originally committed to SVN as r6759.
This commit is contained in:
Thomas Goyne 2012-05-11 02:47:18 +00:00
parent c4e36e00a5
commit a05d469741
2 changed files with 17 additions and 13 deletions

View file

@ -248,17 +248,15 @@ void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) {
} }
} }
else if (holding) { else if (holding) {
if (event.LeftIsDown()) { if (!event.LeftIsDown()) {
UpdateHold();
need_render = true;
}
// end hold
else {
holding = false; holding = false;
parent->ReleaseMouse(); parent->ReleaseMouse();
parent->SetFocus(); parent->SetFocus();
} }
UpdateHold();
need_render = true;
Commit(); Commit();
} }

View file

@ -333,6 +333,8 @@ bool VisualToolVectorClip::InitializeHold() {
} }
void VisualToolVectorClip::UpdateHold() { void VisualToolVectorClip::UpdateHold() {
bool needs_save = true;
if (mode == 1) { if (mode == 1) {
spline.back().EndPoint() = mouse_pos; spline.back().EndPoint() = mouse_pos;
features.back().pos = mouse_pos; features.back().pos = mouse_pos;
@ -360,20 +362,24 @@ void VisualToolVectorClip::UpdateHold() {
// See if distance is enough // See if distance is enough
Vector2D const& last = spline.back().EndPoint(); Vector2D const& last = spline.back().EndPoint();
float len = (last - mouse_pos).SquareLen(); float len = (last - mouse_pos).SquareLen();
if (mode == 6 && len < 900) return; if ((mode == 6 && len >= 900) || (mode == 7 && len >= 3600)) {
if (mode == 7 && len < 3600) return; spline.push_back(SplineCurve(last, mouse_pos));
MakeFeature(--spline.end());
spline.push_back(SplineCurve(last, mouse_pos)); }
MakeFeature(--spline.end()); else
needs_save = false;
} }
if (mode == 3 || mode == 4) return; if (mode == 3 || mode == 4) return;
// Smooth spline // Smooth spline
if (!holding && mode == 7) if (!holding && mode == 7) {
spline.Smooth(); spline.Smooth();
needs_save = true;
}
Save(); if (needs_save)
Save();
// End freedraw // End freedraw
if (!holding && (mode == 6 || mode == 7)) { if (!holding && (mode == 6 || mode == 7)) {