| 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 rbox_ctrl_impl, rbox_ctrl |
| 17 |
// |
| 18 |
//---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
#ifndef AGG_RBOX_CTRL_INCLUDED |
| 21 |
#define AGG_RBOX_CTRL_INCLUDED |
| 22 |
|
| 23 |
#include "agg_array.h" |
| 24 |
#include "agg_ellipse.h" |
| 25 |
#include "agg_conv_stroke.h" |
| 26 |
#include "agg_gsv_text.h" |
| 27 |
#include "agg_trans_affine.h" |
| 28 |
#include "agg_color_rgba.h" |
| 29 |
#include "agg_ctrl.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
namespace agg |
| 34 |
{ |
| 35 |
|
| 36 |
//------------------------------------------------------------------------ |
| 37 |
class rbox_ctrl_impl : public ctrl |
| 38 |
{ |
| 39 |
public: |
| 40 |
rbox_ctrl_impl(double x1, double y1, double x2, double y2, bool flip_y=false); |
| 41 |
|
| 42 |
void border_width(double t, double extra=0.0); |
| 43 |
void text_thickness(double t) { m_text_thickness = t; } |
| 44 |
void text_size(double h, double w=0.0); |
| 45 |
|
| 46 |
void add_item(const char* text); |
| 47 |
int cur_item() const { return m_cur_item; } |
| 48 |
void cur_item(int i) { m_cur_item = i; } |
| 49 |
|
| 50 |
virtual bool in_rect(double x, double y) const; |
| 51 |
virtual bool on_mouse_button_down(double x, double y); |
| 52 |
virtual bool on_mouse_button_up(double x, double y); |
| 53 |
virtual bool on_mouse_move(double x, double y, bool button_flag); |
| 54 |
virtual bool on_arrow_keys(bool left, bool right, bool down, bool up); |
| 55 |
|
| 56 |
// Vertex soutce interface |
| 57 |
unsigned num_paths() { return 5; }; |
| 58 |
void rewind(unsigned path_id); |
| 59 |
unsigned vertex(double* x, double* y); |
| 60 |
|
| 61 |
private: |
| 62 |
void calc_rbox(); |
| 63 |
|
| 64 |
double m_border_width; |
| 65 |
double m_border_extra; |
| 66 |
double m_text_thickness; |
| 67 |
double m_text_height; |
| 68 |
double m_text_width; |
| 69 |
pod_array<char> m_items[32]; |
| 70 |
unsigned m_num_items; |
| 71 |
int m_cur_item; |
| 72 |
|
| 73 |
double m_xs1; |
| 74 |
double m_ys1; |
| 75 |
double m_xs2; |
| 76 |
double m_ys2; |
| 77 |
|
| 78 |
double m_vx[32]; |
| 79 |
double m_vy[32]; |
| 80 |
unsigned m_draw_item; |
| 81 |
double m_dy; |
| 82 |
|
| 83 |
ellipse m_ellipse; |
| 84 |
conv_stroke<ellipse> m_ellipse_poly; |
| 85 |
gsv_text m_text; |
| 86 |
conv_stroke<gsv_text> m_text_poly; |
| 87 |
|
| 88 |
unsigned m_idx; |
| 89 |
unsigned m_vertex; |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
//------------------------------------------------------------------------ |
| 95 |
template<class ColorT> class rbox_ctrl : public rbox_ctrl_impl |
| 96 |
{ |
| 97 |
public: |
| 98 |
rbox_ctrl(double x1, double y1, double x2, double y2, bool flip_y=false) : |
| 99 |
rbox_ctrl_impl(x1, y1, x2, y2, flip_y), |
| 100 |
m_background_color(rgba(1.0, 1.0, 0.9)), |
| 101 |
m_border_color(rgba(0.0, 0.0, 0.0)), |
| 102 |
m_text_color(rgba(0.0, 0.0, 0.0)), |
| 103 |
m_inactive_color(rgba(0.0, 0.0, 0.0)), |
| 104 |
m_active_color(rgba(0.4, 0.0, 0.0)) |
| 105 |
{ |
| 106 |
m_colors[0] = &m_background_color; |
| 107 |
m_colors[1] = &m_border_color; |
| 108 |
m_colors[2] = &m_text_color; |
| 109 |
m_colors[3] = &m_inactive_color; |
| 110 |
m_colors[4] = &m_active_color; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
void background_color(const ColorT& c) { m_background_color = c; } |
| 115 |
void border_color(const ColorT& c) { m_border_color = c; } |
| 116 |
void text_color(const ColorT& c) { m_text_color = c; } |
| 117 |
void inactive_color(const ColorT& c) { m_inactive_color = c; } |
| 118 |
void active_color(const ColorT& c) { m_active_color = c; } |
| 119 |
|
| 120 |
const ColorT& color(unsigned i) const { return *m_colors[i]; } |
| 121 |
|
| 122 |
private: |
| 123 |
rbox_ctrl(const rbox_ctrl<ColorT>&); |
| 124 |
const rbox_ctrl<ColorT>& operator = (const rbox_ctrl<ColorT>&); |
| 125 |
|
| 126 |
ColorT m_background_color; |
| 127 |
ColorT m_border_color; |
| 128 |
ColorT m_text_color; |
| 129 |
ColorT m_inactive_color; |
| 130 |
ColorT m_active_color; |
| 131 |
ColorT* m_colors[5]; |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
#endif |
| 141 |
|