From f285f18f29335bd8f604a875cd4e091bde4bb6e8 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 9 Sep 2008 18:55:37 +0200 Subject: check for more than 3 control points --- src/CurveEditor.cxx | 10 +++++++--- src/pnmcurvedit.cxx | 6 +----- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/CurveEditor.cxx b/src/CurveEditor.cxx index a9bb7a5..b095d3d 100644 --- a/src/CurveEditor.cxx +++ b/src/CurveEditor.cxx @@ -24,6 +24,9 @@ CurveEditor::CurveEditor(int my_x, int my_y, int my_w, int my_h) : n = 0; acc = gsl_interp_accel_alloc(); spline = NULL; + add_point(0.0, 0.0); + add_point(0.5, 0.5); + add_point(1.0, 1.0); } void @@ -83,8 +86,9 @@ CurveEditor::handle(int event) { case FL_DRAG: if (marked_point < 0) return 1; - if (marked_point > 0 && mark_x <= X[marked_point - 1] || - marked_point < n - 1 && mark_x >= X[marked_point + 1]) { + if (n >= 3 && + (marked_point > 0 && mark_x <= X[marked_point - 1] || + marked_point < n - 1 && mark_x >= X[marked_point + 1])) { remove_point(marked_point); marked_point = -1; if (cb) @@ -94,7 +98,7 @@ CurveEditor::handle(int event) { return 1; case FL_RELEASE: if (marked_point >= 0) { - if (cb) + if (n >= 3 && cb) cb(this, cb_data); marked_point = -1; } diff --git a/src/pnmcurvedit.cxx b/src/pnmcurvedit.cxx index c6a974b..c04979c 100644 --- a/src/pnmcurvedit.cxx +++ b/src/pnmcurvedit.cxx @@ -66,13 +66,9 @@ int main(int argc, char **argv) { Fl_Double_Window window(300, 300, "pnmcurvedit"); ce = new CurveEditor(0, 0, 300, 300); - ce->add_point(0.0, 0.0); - ce->add_point(0.5, 0.5); - ce->add_point(1.0, 1.0); ce->callback(editor_cb, NULL); - + window.resizable(ce); window.show(argc, argv); - Fl::add_fd(0, FL_READ, stdin_cb); return Fl::run(); -- cgit v1.2.3