1
//----------------------------------------------------------------------------
2
// Anti-Grain Geometry - Version 2.4
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5
// Permission to copy, use, modify, sell and distribute this software
6
// is granted provided this copyright notice appears in all copies.
7
// This software is provided "as is" without express or implied
8
// warranty, and with no claim as to its suitability for any purpose.
10
//----------------------------------------------------------------------------
11
// Contact: mcseem@antigrain.com
12
// mcseemagg@yahoo.com
13
// http://www.antigrain.com
14
//----------------------------------------------------------------------------
16
// classes spline_ctrl_impl, spline_ctrl
18
//----------------------------------------------------------------------------
20
#ifndef AGG_SPLINE_CTRL_INCLUDED
21
#define AGG_SPLINE_CTRL_INCLUDED
23
#include "agg_basics.h"
24
#include "agg_ellipse.h"
25
#include "agg_bspline.h"
26
#include "agg_conv_stroke.h"
27
#include "agg_path_storage.h"
28
#include "agg_trans_affine.h"
29
#include "agg_color_rgba.h"
35
//------------------------------------------------------------------------
36
// Class that can be used to create an interactive control to set up
38
//------------------------------------------------------------------------
39
class spline_ctrl_impl : public ctrl
42
spline_ctrl_impl(double x1, double y1, double x2, double y2,
43
unsigned num_pnt, bool flip_y=false);
45
// Set other parameters
46
void border_width(double t, double extra=0.0);
47
void curve_width(double t) { m_curve_width = t; }
48
void point_size(double s) { m_point_size = s; }
50
// Event handlers. Just call them if the respective events
51
// in your system occure. The functions return true if redrawing
53
virtual bool in_rect(double x, double y) const;
54
virtual bool on_mouse_button_down(double x, double y);
55
virtual bool on_mouse_button_up(double x, double y);
56
virtual bool on_mouse_move(double x, double y, bool button_flag);
57
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
59
void active_point(int i);
61
const double* spline() const { return m_spline_values; }
62
const int8u* spline8() const { return m_spline_values8; }
63
double value(double x) const;
64
void value(unsigned idx, double y);
65
void point(unsigned idx, double x, double y);
66
void x(unsigned idx, double x) { m_xp[idx] = x; }
67
void y(unsigned idx, double y) { m_yp[idx] = y; }
68
double x(unsigned idx) const { return m_xp[idx]; }
69
double y(unsigned idx) const { return m_yp[idx]; }
72
// Vertex soutce interface
73
unsigned num_paths() { return 5; }
74
void rewind(unsigned path_id);
75
unsigned vertex(double* x, double* y);
78
void calc_spline_box();
80
double calc_xp(unsigned idx);
81
double calc_yp(unsigned idx);
82
void set_xp(unsigned idx, double val);
83
void set_yp(unsigned idx, double val);
89
double m_spline_values[256];
90
int8u m_spline_values8[256];
91
double m_border_width;
92
double m_border_extra;
99
path_storage m_curve_pnt;
100
conv_stroke<path_storage> m_curve_poly;
110
const trans_affine* m_mtx;
114
template<class ColorT> class spline_ctrl : public spline_ctrl_impl
117
spline_ctrl(double x1, double y1, double x2, double y2,
118
unsigned num_pnt, bool flip_y=false) :
119
spline_ctrl_impl(x1, y1, x2, y2, num_pnt, flip_y),
120
m_background_color(rgba(1.0, 1.0, 0.9)),
121
m_border_color(rgba(0.0, 0.0, 0.0)),
122
m_curve_color(rgba(0.0, 0.0, 0.0)),
123
m_inactive_pnt_color(rgba(0.0, 0.0, 0.0)),
124
m_active_pnt_color(rgba(1.0, 0.0, 0.0))
126
m_colors[0] = &m_background_color;
127
m_colors[1] = &m_border_color;
128
m_colors[2] = &m_curve_color;
129
m_colors[3] = &m_inactive_pnt_color;
130
m_colors[4] = &m_active_pnt_color;
134
void background_color(const ColorT& c) { m_background_color = c; }
135
void border_color(const ColorT& c) { m_border_color = c; }
136
void curve_color(const ColorT& c) { m_curve_color = c; }
137
void inactive_pnt_color(const ColorT& c) { m_inactive_pnt_color = c; }
138
void active_pnt_color(const ColorT& c) { m_active_pnt_color = c; }
139
const ColorT& color(unsigned i) const { return *m_colors[i]; }
142
spline_ctrl(const spline_ctrl<ColorT>&);
143
const spline_ctrl<ColorT>& operator = (const spline_ctrl<ColorT>&);
145
ColorT m_background_color;
146
ColorT m_border_color;
147
ColorT m_curve_color;
148
ColorT m_inactive_pnt_color;
149
ColorT m_active_pnt_color;