1
//----------------------------------------------------------------------------
2
// Anti-Grain Geometry - Version 2.3
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 rbox_ctrl_impl, rbox_ctrl
18
//----------------------------------------------------------------------------
21
#include "ctrl/agg_rbox_ctrl.h"
26
//------------------------------------------------------------------------
27
rbox_ctrl_impl::~rbox_ctrl_impl()
31
char** item = m_items + m_num_items - 1;
41
//------------------------------------------------------------------------
42
rbox_ctrl_impl::rbox_ctrl_impl(double x1, double y1,
43
double x2, double y2, bool flip_y) :
44
ctrl(x1, y1, x2, y2, flip_y),
47
m_text_thickness(1.5),
52
m_ellipse_poly(m_ellipse),
61
//------------------------------------------------------------------------
62
void rbox_ctrl_impl::calc_rbox()
64
m_xs1 = m_x1 + m_border_width;
65
m_ys1 = m_y1 + m_border_width;
66
m_xs2 = m_x2 - m_border_width;
67
m_ys2 = m_y2 - m_border_width;
71
//------------------------------------------------------------------------
72
void rbox_ctrl_impl::add_item(const char* text)
76
m_items[m_num_items] = new char[strlen(text) + 1];
77
strcpy(m_items[m_num_items], text);
83
//------------------------------------------------------------------------
84
void rbox_ctrl_impl::border_width(double t, double extra)
87
m_border_extra = extra;
92
//------------------------------------------------------------------------
93
void rbox_ctrl_impl::text_size(double h, double w)
101
//------------------------------------------------------------------------
102
void rbox_ctrl_impl::rewind(unsigned idx)
105
m_dy = m_text_height * 2.0;
112
case 0: // Background
114
m_vx[0] = m_x1 - m_border_extra;
115
m_vy[0] = m_y1 - m_border_extra;
116
m_vx[1] = m_x2 + m_border_extra;
117
m_vy[1] = m_y1 - m_border_extra;
118
m_vx[2] = m_x2 + m_border_extra;
119
m_vy[2] = m_y2 + m_border_extra;
120
m_vx[3] = m_x1 - m_border_extra;
121
m_vy[3] = m_y2 + m_border_extra;
134
m_vx[4] = m_x1 + m_border_width;
135
m_vy[4] = m_y1 + m_border_width;
136
m_vx[5] = m_x1 + m_border_width;
137
m_vy[5] = m_y2 - m_border_width;
138
m_vx[6] = m_x2 - m_border_width;
139
m_vy[6] = m_y2 - m_border_width;
140
m_vx[7] = m_x2 - m_border_width;
141
m_vy[7] = m_y1 + m_border_width;
145
m_text.text(m_items[0]);
146
m_text.start_point(m_xs1 + m_dy * 1.5, m_ys1 + m_dy / 2.0);
147
m_text.size(m_text_height, m_text_width);
148
m_text_poly.width(m_text_thickness);
149
m_text_poly.line_join(round_join);
150
m_text_poly.line_cap(round_cap);
151
m_text_poly.rewind(0);
154
case 3: // Inactive items
155
m_ellipse.init(m_xs1 + m_dy / 1.3,
158
m_text_height / 1.5, 32);
159
m_ellipse_poly.width(m_text_thickness);
160
m_ellipse_poly.rewind(0);
164
case 4: // Active Item
167
m_ellipse.init(m_xs1 + m_dy / 1.3,
168
m_ys1 + m_dy * m_cur_item + m_dy / 1.3,
170
m_text_height / 2.0, 32);
179
//------------------------------------------------------------------------
180
unsigned rbox_ctrl_impl::vertex(double* x, double* y)
182
unsigned cmd = path_cmd_line_to;
186
if(m_vertex == 0) cmd = path_cmd_move_to;
187
if(m_vertex >= 4) cmd = path_cmd_stop;
194
if(m_vertex == 0 || m_vertex == 4) cmd = path_cmd_move_to;
195
if(m_vertex >= 8) cmd = path_cmd_stop;
202
cmd = m_text_poly.vertex(x, y);
206
if(m_draw_item >= m_num_items)
212
m_text.text(m_items[m_draw_item]);
213
m_text.start_point(m_xs1 + m_dy * 1.5,
214
m_ys1 + m_dy * (m_draw_item + 1) - m_dy / 2.0);
216
m_text_poly.rewind(0);
217
cmd = m_text_poly.vertex(x, y);
223
cmd = m_ellipse_poly.vertex(x, y);
227
if(m_draw_item >= m_num_items)
233
m_ellipse.init(m_xs1 + m_dy / 1.3,
234
m_ys1 + m_dy * m_draw_item + m_dy / 1.3,
236
m_text_height / 1.5, 32);
237
m_ellipse_poly.rewind(0);
238
cmd = m_ellipse_poly.vertex(x, y);
247
cmd = m_ellipse.vertex(x, y);
269
//------------------------------------------------------------------------
270
bool rbox_ctrl_impl::in_rect(double x, double y) const
272
inverse_transform_xy(&x, &y);
273
return x >= m_x1 && x <= m_x2 && y >= m_y1 && y <= m_y2;
278
//------------------------------------------------------------------------
279
bool rbox_ctrl_impl::on_mouse_button_down(double x, double y)
281
inverse_transform_xy(&x, &y);
283
for(i = 0; i < m_num_items; i++)
285
double xp = m_xs1 + m_dy / 1.3;
286
double yp = m_ys1 + m_dy * i + m_dy / 1.3;
287
if(calc_distance(x, y, xp, yp) <= m_text_height / 1.5)
297
//------------------------------------------------------------------------
298
bool rbox_ctrl_impl::on_mouse_move(double, double, bool)
303
//------------------------------------------------------------------------
304
bool rbox_ctrl_impl::on_mouse_button_up(double, double)
309
//------------------------------------------------------------------------
310
bool rbox_ctrl_impl::on_arrow_keys(bool left, bool right, bool down, bool up)
317
if(m_cur_item >= int(m_num_items))
329
m_cur_item = m_num_items - 1;