diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2008-01-13 12:52:35 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2008-01-13 12:52:35 +0100 |
| commit | 8cdc05b1a227a2a1185eb6b33acb22e36e6a42f5 (patch) | |
| tree | b1e7e93ea4d1e3e6c96710523467096662a5ed1c /src/CurveEditor.cxx | |
| parent | dfa9e1677f24e06e8da8a136bc568c2f0be1d050 (diff) | |
parse -C argument in flcurve
Diffstat (limited to 'src/CurveEditor.cxx')
| -rw-r--r-- | src/CurveEditor.cxx | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/CurveEditor.cxx b/src/CurveEditor.cxx index 8ff8671..cfa6592 100644 --- a/src/CurveEditor.cxx +++ b/src/CurveEditor.cxx @@ -18,19 +18,12 @@ CurveEditor::CurveEditor(int my_x, int my_y, int my_w, int my_h) : marked_point = -1; - n = 5; - X = (double*) calloc(n, sizeof(double)); - Y = (double*) calloc(n, sizeof(double)); - - - for (int i = 0; i < n; i++) { - X[i] = (double) i / (n - 1); - Y[i] = (double) i / (n - 1); - } + n = 0; + X = NULL; + Y = NULL; acc = gsl_interp_accel_alloc (); - spline = gsl_spline_alloc (gsl_interp_cspline, n); - gsl_spline_init (spline, X, Y, n); + spline = NULL; } void @@ -83,7 +76,7 @@ CurveEditor::handle(int event) { return 1; break; case FL_DRAG: - set(marked_point, (double) mark_x / w(), 1.0 - (double) mark_y / h()); + set_point(marked_point, (double) mark_x / w(), 1.0 - (double) mark_y / h()); return 1; break; @@ -102,7 +95,28 @@ CurveEditor::handle(int event) { } void -CurveEditor::set(int i, double _x, double _y) { +CurveEditor::add_point(double _x, double _y) { + if ((_x < 0.0 || _x > 1.0 || _y < 0.0 || _y > 1.0) || + n > 0 && _x <= X[n]) { + return; + } + n++; + X = (double*) realloc(X, n * sizeof(double)); + Y = (double*) realloc(Y, n * sizeof(double)); + + X[n - 1] = _x; + Y[n - 1] = _y; +} + +void +CurveEditor::init() { + if (spline) gsl_spline_free(spline); + spline = gsl_spline_alloc (gsl_interp_cspline, n); + gsl_spline_init (spline, X, Y, n); +} + +void +CurveEditor::set_point(int i, double _x, double _y) { if (i >= n || (_x < 0.0 || _x > 1.0 || _y < 0.0 || _y > 1.0) || (i < n - 1 && _x >= X[i + 1]) || |
