1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
//
// Copyright 2008 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
#include <stdio.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);
}
}
|