| 1 |
//---------------------------------------------------------------------------- |
| 2 |
// Anti-Grain Geometry - Version 2.4 |
| 3 |
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) |
| 4 |
// |
| 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. |
| 9 |
// |
| 10 |
//---------------------------------------------------------------------------- |
| 11 |
// Contact: [email protected] |
| 12 |
// [email protected] |
| 13 |
// http://www.antigrain.com |
| 14 |
//---------------------------------------------------------------------------- |
| 15 |
// |
| 16 |
// class gamma_ctrl |
| 17 |
// |
| 18 |
//---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
#ifndef AGG_GAMMA_CTRL_INCLUDED |
| 21 |
#define AGG_GAMMA_CTRL_INCLUDED |
| 22 |
|
| 23 |
#include "agg_basics.h" |
| 24 |
#include "agg_gamma_spline.h" |
| 25 |
#include "agg_ellipse.h" |
| 26 |
#include "agg_conv_stroke.h" |
| 27 |
#include "agg_gsv_text.h" |
| 28 |
#include "agg_trans_affine.h" |
| 29 |
#include "agg_color_rgba.h" |
| 30 |
#include "agg_ctrl.h" |
| 31 |
|
| 32 |
namespace agg |
| 33 |
{ |
| 34 |
//------------------------------------------------------------------------ |
| 35 |
// Class that can be used to create an interactive control to set up |
| 36 |
// gamma arrays. |
| 37 |
//------------------------------------------------------------------------ |
| 38 |
class gamma_ctrl_impl : public ctrl |
| 39 |
{ |
| 40 |
public: |
| 41 |
gamma_ctrl_impl(double x1, double y1, double x2, double y2, bool flip_y=false); |
| 42 |
|
| 43 |
// Set other parameters |
| 44 |
void border_width(double t, double extra=0.0); |
| 45 |
void curve_width(double t) { m_curve_width = t; } |
| 46 |
void grid_width(double t) { m_grid_width = t; } |
| 47 |
void text_thickness(double t) { m_text_thickness = t; } |
| 48 |
void text_size(double h, double w=0.0); |
| 49 |
void point_size(double s) { m_point_size = s; } |
| 50 |
|
| 51 |
// Event handlers. Just call them if the respective events |
| 52 |
// in your system occure. The functions return true if redrawing |
| 53 |
// is required. |
| 54 |
virtual bool in_rect(double x, double y) const; |
| 55 |
virtual bool on_mouse_button_down(double x, double y); |
| 56 |
virtual bool on_mouse_button_up(double x, double y); |
| 57 |
virtual bool on_mouse_move(double x, double y, bool button_flag); |
| 58 |
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up); |
| 59 |
|
| 60 |
void change_active_point(); |
| 61 |
|
| 62 |
// A copy of agg::gamma_spline interface |
| 63 |
void values(double kx1, double ky1, double kx2, double ky2); |
| 64 |
void values(double* kx1, double* ky1, double* kx2, double* ky2) const; |
| 65 |
const unsigned char* gamma() const { return m_gamma_spline.gamma(); } |
| 66 |
double y(double x) const { return m_gamma_spline.y(x); } |
| 67 |
double operator() (double x) const { return m_gamma_spline.y(x); } |
| 68 |
const gamma_spline& get_gamma_spline() const { return m_gamma_spline; } |
| 69 |
|
| 70 |
// Vertex soutce interface |
| 71 |
unsigned num_paths() { return 7; } |
| 72 |
void rewind(unsigned idx); |
| 73 |
unsigned vertex(double* x, double* y); |
| 74 |
|
| 75 |
private: |
| 76 |
void calc_spline_box(); |
| 77 |
void calc_points(); |
| 78 |
void calc_values(); |
| 79 |
|
| 80 |
gamma_spline m_gamma_spline; |
| 81 |
double m_border_width; |
| 82 |
double m_border_extra; |
| 83 |
double m_curve_width; |
| 84 |
double m_grid_width; |
| 85 |
double m_text_thickness; |
| 86 |
double m_point_size; |
| 87 |
double m_text_height; |
| 88 |
double m_text_width; |
| 89 |
double m_xc1; |
| 90 |
double m_yc1; |
| 91 |
double m_xc2; |
| 92 |
double m_yc2; |
| 93 |
double m_xs1; |
| 94 |
double m_ys1; |
| 95 |
double m_xs2; |
| 96 |
double m_ys2; |
| 97 |
double m_xt1; |
| 98 |
double m_yt1; |
| 99 |
double m_xt2; |
| 100 |
double m_yt2; |
| 101 |
conv_stroke<gamma_spline> m_curve_poly; |
| 102 |
ellipse m_ellipse; |
| 103 |
gsv_text m_text; |
| 104 |
conv_stroke<gsv_text> m_text_poly; |
| 105 |
unsigned m_idx; |
| 106 |
unsigned m_vertex; |
| 107 |
double m_vx[32]; |
| 108 |
double m_vy[32]; |
| 109 |
double m_xp1; |
| 110 |
double m_yp1; |
| 111 |
double m_xp2; |
| 112 |
double m_yp2; |
| 113 |
bool m_p1_active; |
| 114 |
unsigned m_mouse_point; |
| 115 |
double m_pdx; |
| 116 |
double m_pdy; |
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
template<class ColorT> class gamma_ctrl : public gamma_ctrl_impl |
| 122 |
{ |
| 123 |
public: |
| 124 |
gamma_ctrl(double x1, double y1, double x2, double y2, bool flip_y=false) : |
| 125 |
gamma_ctrl_impl(x1, y1, x2, y2, flip_y), |
| 126 |
m_background_color(rgba(1.0, 1.0, 0.9)), |
| 127 |
m_border_color(rgba(0.0, 0.0, 0.0)), |
| 128 |
m_curve_color(rgba(0.0, 0.0, 0.0)), |
| 129 |
m_grid_color(rgba(0.2, 0.2, 0.0)), |
| 130 |
m_inactive_pnt_color(rgba(0.0, 0.0, 0.0)), |
| 131 |
m_active_pnt_color(rgba(1.0, 0.0, 0.0)), |
| 132 |
m_text_color(rgba(0.0, 0.0, 0.0)) |
| 133 |
{ |
| 134 |
m_colors[0] = &m_background_color; |
| 135 |
m_colors[1] = &m_border_color; |
| 136 |
m_colors[2] = &m_curve_color; |
| 137 |
m_colors[3] = &m_grid_color; |
| 138 |
m_colors[4] = &m_inactive_pnt_color; |
| 139 |
m_colors[5] = &m_active_pnt_color; |
| 140 |
m_colors[6] = &m_text_color; |
| 141 |
} |
| 142 |
|
| 143 |
// Set colors |
| 144 |
void background_color(const ColorT& c) { m_background_color = c; } |
| 145 |
void border_color(const ColorT& c) { m_border_color = c; } |
| 146 |
void curve_color(const ColorT& c) { m_curve_color = c; } |
| 147 |
void grid_color(const ColorT& c) { m_grid_color = c; } |
| 148 |
void inactive_pnt_color(const ColorT& c) { m_inactive_pnt_color = c; } |
| 149 |
void active_pnt_color(const ColorT& c) { m_active_pnt_color = c; } |
| 150 |
void text_color(const ColorT& c) { m_text_color = c; } |
| 151 |
const ColorT& color(unsigned i) const { return *m_colors[i]; } |
| 152 |
|
| 153 |
private: |
| 154 |
gamma_ctrl(const gamma_ctrl<ColorT>&); |
| 155 |
const gamma_ctrl<ColorT>& operator = (const gamma_ctrl<ColorT>&); |
| 156 |
|
| 157 |
ColorT m_background_color; |
| 158 |
ColorT m_border_color; |
| 159 |
ColorT m_curve_color; |
| 160 |
ColorT m_grid_color; |
| 161 |
ColorT m_inactive_pnt_color; |
| 162 |
ColorT m_active_pnt_color; |
| 163 |
ColorT m_text_color; |
| 164 |
ColorT* m_colors[7]; |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
#endif |