// // Copyright 2008 Johannes Hofmann // // This software may be used and distributed according to the terms // of the GNU General Public License, incorporated herein by reference. #include #include #include #include #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); } }