diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2008-01-12 23:12:41 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2008-01-12 23:12:41 +0100 |
| commit | e9dce46bed3cc0ec6993d09183ac858a32d619e2 (patch) | |
| tree | 003441f0f915bea8d7b1e2cb2d116bc243d93361 /src | |
| parent | 7ba1feb416a47b0266615de08b69e1733e18e3a5 (diff) | |
draw a spline
Diffstat (limited to 'src')
| -rw-r--r-- | src/CurveEditor.H | 8 | ||||
| -rw-r--r-- | src/CurveEditor.cxx | 38 | ||||
| -rw-r--r-- | src/flcurve.cxx | 3 |
3 files changed, 45 insertions, 4 deletions
diff --git a/src/CurveEditor.H b/src/CurveEditor.H index 4e58e6e..e774310 100644 --- a/src/CurveEditor.H +++ b/src/CurveEditor.H @@ -8,13 +8,19 @@ #define CurveEditor_H #include <FL/Fl_Widget.H> +#include <gsl/gsl_spline.h> class CurveEditor : public Fl_Widget { private: + double *X; + double *Y; + int n; + gsl_interp_accel *acc; + gsl_spline *spline; public: CurveEditor(int _x, int _y, int _w, int _h); - + void draw(); }; #endif diff --git a/src/CurveEditor.cxx b/src/CurveEditor.cxx index edc3a46..699261d 100644 --- a/src/CurveEditor.cxx +++ b/src/CurveEditor.cxx @@ -5,15 +5,49 @@ // of the GNU General Public License, incorporated herein by reference. #include <stdio.h> -#include <string.h> +#include <stdlib.h> #include <FL/Fl.H> +#include <FL/fl_draw.H> #include "CurveEditor.H" - CurveEditor::CurveEditor(int my_x, int my_y, int my_w, int my_h) : Fl_Widget(my_x, my_y, my_w, my_h) { + n = 3; + X = (double*) calloc(n, sizeof(double)); + Y = (double*) calloc(n, sizeof(double)); + + X[0] = 0.0; + Y[0] = 0.0; + + X[1] = 0.2; + Y[1] = 0.4; + + X[2] = 0.8; + Y[2] = 0.6; + + acc = gsl_interp_accel_alloc (); + spline = gsl_spline_alloc (gsl_interp_cspline, n); + gsl_spline_init (spline, X, Y, n); } +void +CurveEditor::draw() { + fl_color(FL_BLACK); + fl_rectf(x(), y(), w(), h()); + + fl_color(FL_WHITE); + fl_begin_line(); + for (double _x = 0.0; _x < 1.0; _x = _x + 0.01) { + double _y = gsl_spline_eval(spline, _x, acc); + + fl_vertex(x() + _x * w(), y() + h() * _y); + } + fl_end_line(); + + for (int i = 0; i < n; i++) { + fl_rect(x() + w() * X[i] - 2, y() + h() * Y[i] - 2, 4, 4); + } +} diff --git a/src/flcurve.cxx b/src/flcurve.cxx index ca0f8ff..ce8de6a 100644 --- a/src/flcurve.cxx +++ b/src/flcurve.cxx @@ -15,6 +15,7 @@ #include <../config.h> +#include "CurveEditor.H" void usage() { @@ -46,9 +47,9 @@ main(int argc, char **argv) { } Fl_Window window(800, 600); + CurveEditor ce(10, 10, 780, 580); window.end(); - window.show(1, argv); return Fl::run(); |
