Invariably, I forget to add *something* to the tree. :(

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9947 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2004-11-12 22:29:39 +00:00
parent d37e284187
commit 328b390762
8 changed files with 1070 additions and 0 deletions

View File

@ -0,0 +1,112 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// classes cbox_ctrl_impl, cbox_ctrl
//
//----------------------------------------------------------------------------
#ifndef AGG_CBOX_CTRL_INCLUDED
#define AGG_CBOX_CTRL_INCLUDED
#include "agg_basics.h"
#include "agg_conv_stroke.h"
#include "agg_gsv_text.h"
#include "agg_trans_affine.h"
#include "agg_color_rgba.h"
#include "agg_ctrl.h"
namespace agg
{
//----------------------------------------------------------cbox_ctrl_impl
class cbox_ctrl_impl : public ctrl
{
public:
cbox_ctrl_impl(double x, double y, const char* label, bool flip_y=false);
void text_thickness(double t) { m_text_thickness = t; }
void text_size(double h, double w=0.0);
const char* label() { return m_label; }
void label(const char* l);
bool status() const { return m_status; }
void status(bool st) { m_status = st; }
virtual bool in_rect(double x, double y) const;
virtual bool on_mouse_button_down(double x, double y);
virtual bool on_mouse_button_up(double x, double y);
virtual bool on_mouse_move(double x, double y, bool button_flag);
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
// Vertex soutce interface
unsigned num_paths() { return 3; };
void rewind(unsigned id);
unsigned vertex(double* x, double* y);
private:
double m_text_thickness;
double m_text_height;
double m_text_width;
char m_label[128];
bool m_status;
double m_vx[32];
double m_vy[32];
gsv_text m_text;
conv_stroke<gsv_text> m_text_poly;
unsigned m_idx;
unsigned m_vertex;
};
//----------------------------------------------------------cbox_ctrl_impl
template<class ColorT> class cbox_ctrl : public cbox_ctrl_impl
{
public:
cbox_ctrl(double x, double y, const char* label, bool flip_y=false) :
cbox_ctrl_impl(x, y, label, flip_y),
m_text_color(rgba(0.0, 0.0, 0.0)),
m_inactive_color(rgba(0.0, 0.0, 0.0)),
m_active_color(rgba(0.4, 0.0, 0.0))
{
m_colors[0] = &m_inactive_color;
m_colors[1] = &m_text_color;
m_colors[2] = &m_active_color;
}
void text_color(const ColorT& c) { m_text_color = c; }
void inactive_color(const ColorT& c) { m_inactive_color = c; }
void active_color(const ColorT& c) { m_active_color = c; }
const ColorT& color(unsigned i) const { return *m_colors[i]; }
private:
cbox_ctrl(const cbox_ctrl<ColorT>&);
const cbox_ctrl<ColorT>& operator = (const cbox_ctrl<ColorT>&);
ColorT m_text_color;
ColorT m_inactive_color;
ColorT m_active_color;
ColorT* m_colors[3];
};
}
#endif

View File

@ -0,0 +1,100 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Function render_ctrl
//
//----------------------------------------------------------------------------
#ifndef AGG_CTRL_INCLUDED
#define AGG_CTRL_INCLUDED
#include "agg_trans_affine.h"
#include "agg_renderer_scanline.h"
namespace agg
{
//--------------------------------------------------------------------ctrl
class ctrl
{
public:
//--------------------------------------------------------------------
ctrl(double x1, double y1, double x2, double y2, bool flip_y) :
m_x1(x1), m_y1(y1), m_x2(x2), m_y2(y2),
m_flip_y(flip_y),
m_mtx(0)
{
}
//--------------------------------------------------------------------
virtual bool in_rect(double x, double y) const = 0;
virtual bool on_mouse_button_down(double x, double y) = 0;
virtual bool on_mouse_button_up(double x, double y) = 0;
virtual bool on_mouse_move(double x, double y, bool button_flag) = 0;
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up) = 0;
//--------------------------------------------------------------------
void transform(const trans_affine& mtx) { m_mtx = &mtx; }
void no_transform() { m_mtx = 0; }
//--------------------------------------------------------------------
void transform_xy(double* x, double* y) const
{
if(m_flip_y) *y = m_y1 + m_y2 - *y;
if(m_mtx) m_mtx->transform(x, y);
}
//--------------------------------------------------------------------
void inverse_transform_xy(double* x, double* y) const
{
if(m_mtx) m_mtx->inverse_transform(x, y);
if(m_flip_y) *y = m_y1 + m_y2 - *y;
}
private:
ctrl(const ctrl&);
const ctrl& operator = (const ctrl&);
protected:
double m_x1;
double m_y1;
double m_x2;
double m_y2;
private:
bool m_flip_y;
const trans_affine* m_mtx;
};
//--------------------------------------------------------------------
template<class Rasterizer, class Scanline, class Renderer, class Ctrl>
void render_ctrl(Rasterizer& ras, Scanline& sl, Renderer& r, Ctrl& c)
{
unsigned i;
for(i = 0; i < c.num_paths(); i++)
{
ras.reset();
ras.add_path(c, i);
r.color(c.color(i));
render_scanlines(ras, sl, r);
}
}
}
#endif

View File

@ -0,0 +1,170 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// class gamma_ctrl
//
//----------------------------------------------------------------------------
#ifndef AGG_GAMMA_CTRL_INCLUDED
#define AGG_GAMMA_CTRL_INCLUDED
#include "agg_basics.h"
#include "agg_gamma_spline.h"
#include "agg_ellipse.h"
#include "agg_conv_stroke.h"
#include "agg_gsv_text.h"
#include "agg_trans_affine.h"
#include "agg_color_rgba.h"
#include "agg_ctrl.h"
namespace agg
{
//------------------------------------------------------------------------
// Class that can be used to create an interactive control to set up
// gamma arrays.
//------------------------------------------------------------------------
class gamma_ctrl_impl : public ctrl
{
public:
gamma_ctrl_impl(double x1, double y1, double x2, double y2, bool flip_y=false);
// Set other parameters
void border_width(double t, double extra=0.0);
void curve_width(double t) { m_curve_width = t; }
void grid_width(double t) { m_grid_width = t; }
void text_thickness(double t) { m_text_thickness = t; }
void text_size(double h, double w=0.0);
void point_size(double s) { m_point_size = s; }
// Event handlers. Just call them if the respective events
// in your system occure. The functions return true if redrawing
// is required.
virtual bool in_rect(double x, double y) const;
virtual bool on_mouse_button_down(double x, double y);
virtual bool on_mouse_button_up(double x, double y);
virtual bool on_mouse_move(double x, double y, bool button_flag);
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
void change_active_point();
// A copy of agg::gamma_spline interface
void values(double kx1, double ky1, double kx2, double ky2);
void values(double* kx1, double* ky1, double* kx2, double* ky2) const;
const unsigned char* gamma() const { return m_gamma_spline.gamma(); }
double y(double x) const { return m_gamma_spline.y(x); }
double operator() (double x) const { return m_gamma_spline.y(x); }
const gamma_spline& get_gamma_spline() const { return m_gamma_spline; }
// Vertex soutce interface
unsigned num_paths() { return 7; }
void rewind(unsigned idx);
unsigned vertex(double* x, double* y);
private:
void calc_spline_box();
void calc_points();
void calc_values();
gamma_spline m_gamma_spline;
double m_border_width;
double m_border_extra;
double m_curve_width;
double m_grid_width;
double m_text_thickness;
double m_point_size;
double m_text_height;
double m_text_width;
double m_xc1;
double m_yc1;
double m_xc2;
double m_yc2;
double m_xs1;
double m_ys1;
double m_xs2;
double m_ys2;
double m_xt1;
double m_yt1;
double m_xt2;
double m_yt2;
conv_stroke<gamma_spline> m_curve_poly;
ellipse m_ellipse;
gsv_text m_text;
conv_stroke<gsv_text> m_text_poly;
unsigned m_idx;
unsigned m_vertex;
double m_vx[32];
double m_vy[32];
double m_xp1;
double m_yp1;
double m_xp2;
double m_yp2;
bool m_p1_active;
unsigned m_mouse_point;
double m_pdx;
double m_pdy;
};
template<class ColorT> class gamma_ctrl : public gamma_ctrl_impl
{
public:
gamma_ctrl(double x1, double y1, double x2, double y2, bool flip_y=false) :
gamma_ctrl_impl(x1, y1, x2, y2, flip_y),
m_background_color(rgba(1.0, 1.0, 0.9)),
m_border_color(rgba(0.0, 0.0, 0.0)),
m_curve_color(rgba(0.0, 0.0, 0.0)),
m_grid_color(rgba(0.2, 0.2, 0.0)),
m_inactive_pnt_color(rgba(0.0, 0.0, 0.0)),
m_active_pnt_color(rgba(1.0, 0.0, 0.0)),
m_text_color(rgba(0.0, 0.0, 0.0))
{
m_colors[0] = &m_background_color;
m_colors[1] = &m_border_color;
m_colors[2] = &m_curve_color;
m_colors[3] = &m_grid_color;
m_colors[4] = &m_inactive_pnt_color;
m_colors[5] = &m_active_pnt_color;
m_colors[6] = &m_text_color;
}
// Set colors
void background_color(const ColorT& c) { m_background_color = c; }
void border_color(const ColorT& c) { m_border_color = c; }
void curve_color(const ColorT& c) { m_curve_color = c; }
void grid_color(const ColorT& c) { m_grid_color = c; }
void inactive_pnt_color(const ColorT& c) { m_inactive_pnt_color = c; }
void active_pnt_color(const ColorT& c) { m_active_pnt_color = c; }
void text_color(const ColorT& c) { m_text_color = c; }
const ColorT& color(unsigned i) const { return *m_colors[i]; }
private:
gamma_ctrl(const gamma_ctrl<ColorT>&);
const gamma_ctrl<ColorT>& operator = (const gamma_ctrl<ColorT>&);
ColorT m_background_color;
ColorT m_border_color;
ColorT m_curve_color;
ColorT m_grid_color;
ColorT m_inactive_pnt_color;
ColorT m_active_pnt_color;
ColorT m_text_color;
ColorT* m_colors[7];
};
}
#endif

View File

@ -0,0 +1,95 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// class gamma_spline
//
//----------------------------------------------------------------------------
#ifndef AGG_GAMMA_SPLINE_INCLUDED
#define AGG_GAMMA_SPLINE_INCLUDED
#include "agg_basics.h"
#include "agg_bspline.h"
namespace agg
{
//------------------------------------------------------------------------
// Class-helper for calculation gamma-correction arrays. A gamma-correction
// array is an array of 256 unsigned chars that determine the actual values
// of Anti-Aliasing for each pixel coverage value from 0 to 255. If all the
// values in the array are equal to its index, i.e. 0,1,2,3,... there's
// no gamma-correction. Class agg::polyfill allows you to use custom
// gamma-correction arrays. You can calculate it using any approach, and
// class gamma_spline allows you to calculate almost any reasonable shape
// of the gamma-curve with using only 4 values - kx1, ky1, kx2, ky2.
//
// kx2
// +----------------------------------+
// | | | . |
// | | | . | ky2
// | | . ------|
// | | . |
// | | . |
// |----------------.|----------------|
// | . | |
// | . | |
// |-------. | |
// ky1 | . | | |
// | . | | |
// +----------------------------------+
// kx1
//
// Each value can be in range [0...2]. Value 1.0 means one quarter of the
// bounding rectangle. Function values() calculates the curve by these
// 4 values. After calling it one can get the gamma-array with call gamma().
// Class also supports the vertex source interface, i.e rewind() and
// vertex(). It's made for convinience and used in class gamma_ctrl.
// Before calling rewind/vertex one must set the bounding box
// box() using pixel coordinates.
//------------------------------------------------------------------------
class gamma_spline
{
public:
gamma_spline();
void values(double kx1, double ky1, double kx2, double ky2);
const unsigned char* gamma() const { return m_gamma; }
double y(double x) const;
void values(double* kx1, double* ky1, double* kx2, double* ky2) const;
void box(double x1, double y1, double x2, double y2);
void rewind(unsigned);
unsigned vertex(double* x, double* y);
private:
unsigned char m_gamma[256];
double m_x[4];
double m_y[4];
bspline m_spline;
double m_x1;
double m_y1;
double m_x2;
double m_y2;
double m_cur_x;
};
}
#endif

View File

@ -0,0 +1,142 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// classes rbox_ctrl_impl, rbox_ctrl
//
//----------------------------------------------------------------------------
#ifndef AGG_RBOX_CTRL_INCLUDED
#define AGG_RBOX_CTRL_INCLUDED
#include "agg_basics.h"
#include "agg_ellipse.h"
#include "agg_conv_stroke.h"
#include "agg_gsv_text.h"
#include "agg_trans_affine.h"
#include "agg_color_rgba.h"
#include "agg_ctrl.h"
namespace agg
{
//------------------------------------------------------------------------
class rbox_ctrl_impl : public ctrl
{
public:
~rbox_ctrl_impl();
rbox_ctrl_impl(double x1, double y1, double x2, double y2, bool flip_y=false);
void border_width(double t, double extra=0.0);
void text_thickness(double t) { m_text_thickness = t; }
void text_size(double h, double w=0.0);
void add_item(const char* text);
int cur_item() const { return m_cur_item; }
void cur_item(int i) { m_cur_item = i; }
virtual bool in_rect(double x, double y) const;
virtual bool on_mouse_button_down(double x, double y);
virtual bool on_mouse_button_up(double x, double y);
virtual bool on_mouse_move(double x, double y, bool button_flag);
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
// Vertex soutce interface
unsigned num_paths() { return 5; };
void rewind(unsigned id);
unsigned vertex(double* x, double* y);
private:
void calc_rbox();
double m_border_width;
double m_border_extra;
double m_text_thickness;
double m_text_height;
double m_text_width;
char* m_items[32];
unsigned m_num_items;
int m_cur_item;
double m_xs1;
double m_ys1;
double m_xs2;
double m_ys2;
double m_vx[32];
double m_vy[32];
unsigned m_draw_item;
double m_dy;
ellipse m_ellipse;
conv_stroke<ellipse> m_ellipse_poly;
gsv_text m_text;
conv_stroke<gsv_text> m_text_poly;
unsigned m_idx;
unsigned m_vertex;
};
//------------------------------------------------------------------------
template<class ColorT> class rbox_ctrl : public rbox_ctrl_impl
{
public:
rbox_ctrl(double x1, double y1, double x2, double y2, bool flip_y=false) :
rbox_ctrl_impl(x1, y1, x2, y2, flip_y),
m_background_color(rgba(1.0, 1.0, 0.9)),
m_border_color(rgba(0.0, 0.0, 0.0)),
m_text_color(rgba(0.0, 0.0, 0.0)),
m_inactive_color(rgba(0.0, 0.0, 0.0)),
m_active_color(rgba(0.4, 0.0, 0.0))
{
m_colors[0] = &m_background_color;
m_colors[1] = &m_border_color;
m_colors[2] = &m_text_color;
m_colors[3] = &m_inactive_color;
m_colors[4] = &m_active_color;
}
void background_color(const ColorT& c) { m_background_color = c; }
void border_color(const ColorT& c) { m_border_color = c; }
void text_color(const ColorT& c) { m_text_color = c; }
void inactive_color(const ColorT& c) { m_inactive_color = c; }
void active_color(const ColorT& c) { m_active_color = c; }
const ColorT& color(unsigned i) const { return *m_colors[i]; }
private:
rbox_ctrl(const rbox_ctrl<ColorT>&);
const rbox_ctrl<ColorT>& operator = (const rbox_ctrl<ColorT>&);
ColorT m_background_color;
ColorT m_border_color;
ColorT m_text_color;
ColorT m_inactive_color;
ColorT m_active_color;
ColorT* m_colors[5];
};
}
#endif

View File

@ -0,0 +1,142 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// classes scale_ctrl_impl, scale_ctrl
//
//----------------------------------------------------------------------------
#ifndef AGG_SCALE_CTRL_INCLUDED
#define AGG_SCALE_CTRL_INCLUDED
#include "agg_basics.h"
#include "agg_math.h"
#include "agg_ellipse.h"
#include "agg_trans_affine.h"
#include "agg_color_rgba.h"
#include "agg_ctrl.h"
namespace agg
{
//------------------------------------------------------------------------
class scale_ctrl_impl : public ctrl
{
enum move_e
{
move_nothing,
move_value1,
move_value2,
move_slider
};
public:
scale_ctrl_impl(double x1, double y1, double x2, double y2, bool flip_y=false);
void border_thickness(double t, double extra=0.0);
double min_delta() const { return m_min_d; }
void min_delta(double d) { m_min_d = d; }
double value1() const { return m_value1; }
void value1(double value) { m_value1 = value; }
double value2() const { return m_value2; }
void value2(double value) { m_value2 = value; }
virtual bool in_rect(double x, double y) const;
virtual bool on_mouse_button_down(double x, double y);
virtual bool on_mouse_button_up(double x, double y);
virtual bool on_mouse_move(double x, double y, bool button_flag);
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
// Vertex soutce interface
unsigned num_paths() { return 5; };
void rewind(unsigned id);
unsigned vertex(double* x, double* y);
private:
void calc_box();
double m_border_thickness;
double m_border_extra;
double m_value1;
double m_value2;
double m_min_d;
double m_xs1;
double m_ys1;
double m_xs2;
double m_ys2;
double m_pdx;
move_e m_move_what;
double m_vx[32];
double m_vy[32];
ellipse m_ellipse;
unsigned m_idx;
unsigned m_vertex;
};
//------------------------------------------------------------------------
template<class ColorT> class scale_ctrl : public scale_ctrl_impl
{
public:
scale_ctrl(double x1, double y1, double x2, double y2, bool flip_y=false) :
scale_ctrl_impl(x1, y1, x2, y2, flip_y),
m_background_color(rgba(1.0, 0.9, 0.8)),
m_border_color(rgba(0.0, 0.0, 0.0)),
m_pointers_color(rgba(0.8, 0.0, 0.0, 0.8)),
m_slider_color(rgba(0.2, 0.1, 0.0, 0.8))
{
m_colors[0] = &m_background_color;
m_colors[1] = &m_border_color;
m_colors[2] = &m_pointers_color;
m_colors[3] = &m_pointers_color;
m_colors[4] = &m_slider_color;
}
void background_color(const ColorT& c) { m_background_color = c; }
void border_color(const ColorT& c) { m_border_color = c; }
void pointers_color(const ColorT& c) { m_pointers_color = c; }
void slider_color(const ColorT& c) { m_slider_color = c; }
const ColorT& color(unsigned i) const { return *m_colors[i]; }
private:
scale_ctrl(const scale_ctrl<ColorT>&);
const scale_ctrl<ColorT>& operator = (const scale_ctrl<ColorT>&);
ColorT m_background_color;
ColorT m_border_color;
ColorT m_pointers_color;
ColorT m_slider_color;
ColorT* m_colors[5];
};
}
#endif

View File

@ -0,0 +1,150 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// classes slider_ctrl_impl, slider_ctrl
//
//----------------------------------------------------------------------------
#ifndef AGG_SLIDER_CTRL_INCLUDED
#define AGG_SLIDER_CTRL_INCLUDED
#include "agg_basics.h"
#include "agg_math.h"
#include "agg_ellipse.h"
#include "agg_trans_affine.h"
#include "agg_color_rgba.h"
#include "agg_gsv_text.h"
#include "agg_conv_stroke.h"
#include "agg_path_storage.h"
#include "agg_ctrl.h"
namespace agg
{
//--------------------------------------------------------slider_ctrl_impl
class slider_ctrl_impl : public ctrl
{
public:
slider_ctrl_impl(double x1, double y1, double x2, double y2, bool flip_y=false);
void border_width(double t, double extra=0.0);
void range(double min, double max) { m_min = min; m_max = max; }
void num_steps(unsigned num) { m_num_steps = num; }
void label(const char* fmt);
void text_thickness(double t) { m_text_thickness = t; }
bool descending() const { return m_descending; }
void descending(bool v) { m_descending = v; }
double value() const { return m_value * (m_max - m_min) + m_min; }
void value(double value);
virtual bool in_rect(double x, double y) const;
virtual bool on_mouse_button_down(double x, double y);
virtual bool on_mouse_button_up(double x, double y);
virtual bool on_mouse_move(double x, double y, bool button_flag);
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
// Vertex source interface
unsigned num_paths() { return 6; };
void rewind(unsigned id);
unsigned vertex(double* x, double* y);
private:
void calc_box();
bool normalize_value(bool preview_value_flag);
double m_border_width;
double m_border_extra;
double m_text_thickness;
double m_value;
double m_preview_value;
double m_min;
double m_max;
unsigned m_num_steps;
bool m_descending;
char m_label[64];
double m_xs1;
double m_ys1;
double m_xs2;
double m_ys2;
double m_pdx;
bool m_mouse_move;
double m_vx[32];
double m_vy[32];
ellipse m_ellipse;
unsigned m_idx;
unsigned m_vertex;
gsv_text m_text;
conv_stroke<gsv_text> m_text_poly;
path_storage m_storage;
};
//----------------------------------------------------------slider_ctrl
template<class ColorT> class slider_ctrl : public slider_ctrl_impl
{
public:
slider_ctrl(double x1, double y1, double x2, double y2, bool flip_y=false) :
slider_ctrl_impl(x1, y1, x2, y2, flip_y),
m_background_color(rgba(1.0, 0.9, 0.8)),
m_triangle_color(rgba(0.7, 0.6, 0.6)),
m_text_color(rgba(0.0, 0.0, 0.0)),
m_pointer_preview_color(rgba(0.6, 0.4, 0.4, 0.4)),
m_pointer_color(rgba(0.8, 0.0, 0.0, 0.6))
{
m_colors[0] = &m_background_color;
m_colors[1] = &m_triangle_color;
m_colors[2] = &m_text_color;
m_colors[3] = &m_pointer_preview_color;
m_colors[4] = &m_pointer_color;
m_colors[5] = &m_text_color;
}
void background_color(const ColorT& c) { m_background_color = c; }
void pointer_color(const ColorT& c) { m_pointer_color = c; }
const ColorT& color(unsigned i) const { return *m_colors[i]; }
private:
slider_ctrl(const slider_ctrl<ColorT>&);
const slider_ctrl<ColorT>& operator = (const slider_ctrl<ColorT>&);
ColorT m_background_color;
ColorT m_triangle_color;
ColorT m_text_color;
ColorT m_pointer_preview_color;
ColorT m_pointer_color;
ColorT* m_colors[6];
};
}
#endif

View File

@ -0,0 +1,159 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.2
// Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// classes spline_ctrl_impl, spline_ctrl
//
//----------------------------------------------------------------------------
#ifndef AGG_SPLINE_CTRL_INCLUDED
#define AGG_SPLINE_CTRL_INCLUDED
#include "agg_basics.h"
#include "agg_ellipse.h"
#include "agg_bspline.h"
#include "agg_conv_stroke.h"
#include "agg_path_storage.h"
#include "agg_trans_affine.h"
#include "agg_color_rgba.h"
#include "agg_ctrl.h"
namespace agg
{
//------------------------------------------------------------------------
// Class that can be used to create an interactive control to set up
// gamma arrays.
//------------------------------------------------------------------------
class spline_ctrl_impl : public ctrl
{
public:
spline_ctrl_impl(double x1, double y1, double x2, double y2,
unsigned num_pnt, bool flip_y=false);
// Set other parameters
void border_width(double t, double extra=0.0);
void curve_width(double t) { m_curve_width = t; }
void point_size(double s) { m_point_size = s; }
// Event handlers. Just call them if the respective events
// in your system occure. The functions return true if redrawing
// is required.
virtual bool in_rect(double x, double y) const;
virtual bool on_mouse_button_down(double x, double y);
virtual bool on_mouse_button_up(double x, double y);
virtual bool on_mouse_move(double x, double y, bool button_flag);
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up);
void active_point(int i);
const double* spline() const { return m_spline_values; }
const unsigned char* spline8() const { return m_spline_values8; }
double value(double x) const;
void value(unsigned idx, double y);
void point(unsigned idx, double x, double y);
void x(unsigned idx, double x) { m_xp[idx] = x; }
void y(unsigned idx, double y) { m_yp[idx] = y; }
double x(unsigned idx) const { return m_xp[idx]; }
double y(unsigned idx) const { return m_yp[idx]; }
void update_spline();
// Vertex soutce interface
unsigned num_paths() { return 5; }
void rewind(unsigned id);
unsigned vertex(double* x, double* y);
private:
void calc_spline_box();
void calc_curve();
double calc_xp(unsigned idx);
double calc_yp(unsigned idx);
void set_xp(unsigned idx, double val);
void set_yp(unsigned idx, double val);
unsigned m_num_pnt;
double m_xp[32];
double m_yp[32];
bspline m_spline;
double m_spline_values[256];
unsigned char m_spline_values8[256];
double m_border_width;
double m_border_extra;
double m_curve_width;
double m_point_size;
double m_xs1;
double m_ys1;
double m_xs2;
double m_ys2;
path_storage m_curve_pnt;
conv_stroke<path_storage> m_curve_poly;
ellipse m_ellipse;
unsigned m_idx;
unsigned m_vertex;
double m_vx[32];
double m_vy[32];
int m_active_pnt;
int m_move_pnt;
double m_pdx;
double m_pdy;
const trans_affine* m_mtx;
};
template<class ColorT> class spline_ctrl : public spline_ctrl_impl
{
public:
spline_ctrl(double x1, double y1, double x2, double y2,
unsigned num_pnt, bool flip_y=false) :
spline_ctrl_impl(x1, y1, x2, y2, num_pnt, flip_y),
m_background_color(rgba(1.0, 1.0, 0.9)),
m_border_color(rgba(0.0, 0.0, 0.0)),
m_curve_color(rgba(0.0, 0.0, 0.0)),
m_inactive_pnt_color(rgba(0.0, 0.0, 0.0)),
m_active_pnt_color(rgba(1.0, 0.0, 0.0))
{
m_colors[0] = &m_background_color;
m_colors[1] = &m_border_color;
m_colors[2] = &m_curve_color;
m_colors[3] = &m_inactive_pnt_color;
m_colors[4] = &m_active_pnt_color;
}
// Set colors
void background_color(const ColorT& c) { m_background_color = c; }
void border_color(const ColorT& c) { m_border_color = c; }
void curve_color(const ColorT& c) { m_curve_color = c; }
void inactive_pnt_color(const ColorT& c) { m_inactive_pnt_color = c; }
void active_pnt_color(const ColorT& c) { m_active_pnt_color = c; }
const ColorT& color(unsigned i) const { return *m_colors[i]; }
private:
spline_ctrl(const spline_ctrl<ColorT>&);
const spline_ctrl<ColorT>& operator = (const spline_ctrl<ColorT>&);
ColorT m_background_color;
ColorT m_border_color;
ColorT m_curve_color;
ColorT m_inactive_pnt_color;
ColorT m_active_pnt_color;
ColorT* m_colors[5];
};
}
#endif