| 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 |
// classes slider_ctrl_impl, slider_ctrl |
| 17 |
// |
| 18 |
//---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
#ifndef AGG_SLIDER_CTRL_INCLUDED |
| 21 |
#define AGG_SLIDER_CTRL_INCLUDED |
| 22 |
|
| 23 |
#include "agg_basics.h" |
| 24 |
#include "agg_math.h" |
| 25 |
#include "agg_ellipse.h" |
| 26 |
#include "agg_trans_affine.h" |
| 27 |
#include "agg_color_rgba.h" |
| 28 |
#include "agg_gsv_text.h" |
| 29 |
#include "agg_conv_stroke.h" |
| 30 |
#include "agg_path_storage.h" |
| 31 |
#include "agg_ctrl.h" |
| 32 |
|
| 33 |
|
| 34 |
namespace agg |
| 35 |
{ |
| 36 |
|
| 37 |
//--------------------------------------------------------slider_ctrl_impl |
| 38 |
class slider_ctrl_impl : public ctrl |
| 39 |
{ |
| 40 |
public: |
| 41 |
slider_ctrl_impl(double x1, double y1, double x2, double y2, bool flip_y=false); |
| 42 |
|
| 43 |
void border_width(double t, double extra=0.0); |
| 44 |
|
| 45 |
void range(double min, double max) { m_min = min; m_max = max; } |
| 46 |
void num_steps(unsigned num) { m_num_steps = num; } |
| 47 |
void label(const char* fmt); |
| 48 |
void text_thickness(double t) { m_text_thickness = t; } |
| 49 |
|
| 50 |
bool descending() const { return m_descending; } |
| 51 |
void descending(bool v) { m_descending = v; } |
| 52 |
|
| 53 |
double value() const { return m_value * (m_max - m_min) + m_min; } |
| 54 |
void value(double value); |
| 55 |
|
| 56 |
virtual bool in_rect(double x, double y) const; |
| 57 |
virtual bool on_mouse_button_down(double x, double y); |
| 58 |
virtual bool on_mouse_button_up(double x, double y); |
| 59 |
virtual bool on_mouse_move(double x, double y, bool button_flag); |
| 60 |
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up); |
| 61 |
|
| 62 |
// Vertex source interface |
| 63 |
unsigned num_paths() { return 6; }; |
| 64 |
void rewind(unsigned path_id); |
| 65 |
unsigned vertex(double* x, double* y); |
| 66 |
|
| 67 |
private: |
| 68 |
void calc_box(); |
| 69 |
bool normalize_value(bool preview_value_flag); |
| 70 |
|
| 71 |
double m_border_width; |
| 72 |
double m_border_extra; |
| 73 |
double m_text_thickness; |
| 74 |
double m_value; |
| 75 |
double m_preview_value; |
| 76 |
double m_min; |
| 77 |
double m_max; |
| 78 |
unsigned m_num_steps; |
| 79 |
bool m_descending; |
| 80 |
char m_label[64]; |
| 81 |
double m_xs1; |
| 82 |
double m_ys1; |
| 83 |
double m_xs2; |
| 84 |
double m_ys2; |
| 85 |
double m_pdx; |
| 86 |
bool m_mouse_move; |
| 87 |
double m_vx[32]; |
| 88 |
double m_vy[32]; |
| 89 |
|
| 90 |
ellipse m_ellipse; |
| 91 |
|
| 92 |
unsigned m_idx; |
| 93 |
unsigned m_vertex; |
| 94 |
|
| 95 |
gsv_text m_text; |
| 96 |
conv_stroke<gsv_text> m_text_poly; |
| 97 |
path_storage m_storage; |
| 98 |
|
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
//----------------------------------------------------------slider_ctrl |
| 104 |
template<class ColorT> class slider_ctrl : public slider_ctrl_impl |
| 105 |
{ |
| 106 |
public: |
| 107 |
slider_ctrl(double x1, double y1, double x2, double y2, bool flip_y=false) : |
| 108 |
slider_ctrl_impl(x1, y1, x2, y2, flip_y), |
| 109 |
m_background_color(rgba(1.0, 0.9, 0.8)), |
| 110 |
m_triangle_color(rgba(0.7, 0.6, 0.6)), |
| 111 |
m_text_color(rgba(0.0, 0.0, 0.0)), |
| 112 |
m_pointer_preview_color(rgba(0.6, 0.4, 0.4, 0.4)), |
| 113 |
m_pointer_color(rgba(0.8, 0.0, 0.0, 0.6)) |
| 114 |
{ |
| 115 |
m_colors[0] = &m_background_color; |
| 116 |
m_colors[1] = &m_triangle_color; |
| 117 |
m_colors[2] = &m_text_color; |
| 118 |
m_colors[3] = &m_pointer_preview_color; |
| 119 |
m_colors[4] = &m_pointer_color; |
| 120 |
m_colors[5] = &m_text_color; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
void background_color(const ColorT& c) { m_background_color = c; } |
| 125 |
void pointer_color(const ColorT& c) { m_pointer_color = c; } |
| 126 |
|
| 127 |
const ColorT& color(unsigned i) const { return *m_colors[i]; } |
| 128 |
|
| 129 |
private: |
| 130 |
slider_ctrl(const slider_ctrl<ColorT>&); |
| 131 |
const slider_ctrl<ColorT>& operator = (const slider_ctrl<ColorT>&); |
| 132 |
|
| 133 |
ColorT m_background_color; |
| 134 |
ColorT m_triangle_color; |
| 135 |
ColorT m_text_color; |
| 136 |
ColorT m_pointer_preview_color; |
| 137 |
ColorT m_pointer_color; |
| 138 |
ColorT* m_colors[6]; |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
#endif |
| 150 |
|