| 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 |
#include <string.h> |
| 21 |
#include "ctrl/agg_cbox_ctrl.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace agg |
| 25 |
{ |
| 26 |
|
| 27 |
//------------------------------------------------------------------------ |
| 28 |
cbox_ctrl_impl::cbox_ctrl_impl(double x, double y, |
| 29 |
const char* l, |
| 30 |
bool flip_y) : |
| 31 |
ctrl(x, y, x + 9.0 * 1.5, y + 9.0 * 1.5, flip_y), |
| 32 |
m_text_thickness(1.5), |
| 33 |
m_text_height(9.0), |
| 34 |
m_text_width(0.0), |
| 35 |
m_status(false), |
| 36 |
m_text_poly(m_text) |
| 37 |
{ |
| 38 |
label(l); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
//------------------------------------------------------------------------ |
| 43 |
void cbox_ctrl_impl::text_size(double h, double w) |
| 44 |
{ |
| 45 |
m_text_width = w; |
| 46 |
m_text_height = h; |
| 47 |
} |
| 48 |
|
| 49 |
//------------------------------------------------------------------------ |
| 50 |
void cbox_ctrl_impl::label(const char* l) |
| 51 |
{ |
| 52 |
unsigned len = strlen(l); |
| 53 |
if(len > 127) len = 127; |
| 54 |
memcpy(m_label, l, len); |
| 55 |
m_label[len] = 0; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
//------------------------------------------------------------------------ |
| 60 |
bool cbox_ctrl_impl::on_mouse_button_down(double x, double y) |
| 61 |
{ |
| 62 |
inverse_transform_xy(&x, &y); |
| 63 |
if(x >= m_x1 && y >= m_y1 && x <= m_x2 && y <= m_y2) |
| 64 |
{ |
| 65 |
m_status = !m_status; |
| 66 |
return true; |
| 67 |
} |
| 68 |
return false; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
//------------------------------------------------------------------------ |
| 73 |
bool cbox_ctrl_impl::on_mouse_move(double, double, bool) |
| 74 |
{ |
| 75 |
return false; |
| 76 |
} |
| 77 |
|
| 78 |
//------------------------------------------------------------------------ |
| 79 |
bool cbox_ctrl_impl::in_rect(double x, double y) const |
| 80 |
{ |
| 81 |
inverse_transform_xy(&x, &y); |
| 82 |
return x >= m_x1 && y >= m_y1 && x <= m_x2 && y <= m_y2; |
| 83 |
} |
| 84 |
|
| 85 |
//------------------------------------------------------------------------ |
| 86 |
bool cbox_ctrl_impl::on_mouse_button_up(double, double) |
| 87 |
{ |
| 88 |
return false; |
| 89 |
} |
| 90 |
|
| 91 |
//------------------------------------------------------------------------ |
| 92 |
bool cbox_ctrl_impl::on_arrow_keys(bool, bool, bool, bool) |
| 93 |
{ |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
//------------------------------------------------------------------------ |
| 99 |
void cbox_ctrl_impl::rewind(unsigned idx) |
| 100 |
{ |
| 101 |
m_idx = idx; |
| 102 |
|
| 103 |
double d2; |
| 104 |
double t; |
| 105 |
|
| 106 |
switch(idx) |
| 107 |
{ |
| 108 |
default: |
| 109 |
case 0: // Border |
| 110 |
m_vertex = 0; |
| 111 |
m_vx[0] = m_x1; |
| 112 |
m_vy[0] = m_y1; |
| 113 |
m_vx[1] = m_x2; |
| 114 |
m_vy[1] = m_y1; |
| 115 |
m_vx[2] = m_x2; |
| 116 |
m_vy[2] = m_y2; |
| 117 |
m_vx[3] = m_x1; |
| 118 |
m_vy[3] = m_y2; |
| 119 |
m_vx[4] = m_x1 + m_text_thickness; |
| 120 |
m_vy[4] = m_y1 + m_text_thickness; |
| 121 |
m_vx[5] = m_x1 + m_text_thickness; |
| 122 |
m_vy[5] = m_y2 - m_text_thickness; |
| 123 |
m_vx[6] = m_x2 - m_text_thickness; |
| 124 |
m_vy[6] = m_y2 - m_text_thickness; |
| 125 |
m_vx[7] = m_x2 - m_text_thickness; |
| 126 |
m_vy[7] = m_y1 + m_text_thickness; |
| 127 |
break; |
| 128 |
|
| 129 |
case 1: // Text |
| 130 |
m_text.text(m_label); |
| 131 |
m_text.start_point(m_x1 + m_text_height * 2.0, m_y1 + m_text_height / 5.0); |
| 132 |
m_text.size(m_text_height, m_text_width); |
| 133 |
m_text_poly.width(m_text_thickness); |
| 134 |
m_text_poly.line_join(round_join); |
| 135 |
m_text_poly.line_cap(round_cap); |
| 136 |
m_text_poly.rewind(0); |
| 137 |
break; |
| 138 |
|
| 139 |
case 2: // Active item |
| 140 |
m_vertex = 0; |
| 141 |
d2 = (m_y2 - m_y1) / 2.0; |
| 142 |
t = m_text_thickness * 1.5; |
| 143 |
m_vx[0] = m_x1 + m_text_thickness; |
| 144 |
m_vy[0] = m_y1 + m_text_thickness; |
| 145 |
m_vx[1] = m_x1 + d2; |
| 146 |
m_vy[1] = m_y1 + d2 - t; |
| 147 |
m_vx[2] = m_x2 - m_text_thickness; |
| 148 |
m_vy[2] = m_y1 + m_text_thickness; |
| 149 |
m_vx[3] = m_x1 + d2 + t; |
| 150 |
m_vy[3] = m_y1 + d2; |
| 151 |
m_vx[4] = m_x2 - m_text_thickness; |
| 152 |
m_vy[4] = m_y2 - m_text_thickness; |
| 153 |
m_vx[5] = m_x1 + d2; |
| 154 |
m_vy[5] = m_y1 + d2 + t; |
| 155 |
m_vx[6] = m_x1 + m_text_thickness; |
| 156 |
m_vy[6] = m_y2 - m_text_thickness; |
| 157 |
m_vx[7] = m_x1 + d2 - t; |
| 158 |
m_vy[7] = m_y1 + d2; |
| 159 |
break; |
| 160 |
|
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
//------------------------------------------------------------------------ |
| 168 |
unsigned cbox_ctrl_impl::vertex(double* x, double* y) |
| 169 |
{ |
| 170 |
unsigned cmd = path_cmd_line_to; |
| 171 |
switch(m_idx) |
| 172 |
{ |
| 173 |
case 0: |
| 174 |
if(m_vertex == 0 || m_vertex == 4) cmd = path_cmd_move_to; |
| 175 |
if(m_vertex >= 8) cmd = path_cmd_stop; |
| 176 |
*x = m_vx[m_vertex]; |
| 177 |
*y = m_vy[m_vertex]; |
| 178 |
m_vertex++; |
| 179 |
break; |
| 180 |
|
| 181 |
case 1: |
| 182 |
cmd = m_text_poly.vertex(x, y); |
| 183 |
break; |
| 184 |
|
| 185 |
case 2: |
| 186 |
if(m_status) |
| 187 |
{ |
| 188 |
if(m_vertex == 0) cmd = path_cmd_move_to; |
| 189 |
if(m_vertex >= 8) cmd = path_cmd_stop; |
| 190 |
*x = m_vx[m_vertex]; |
| 191 |
*y = m_vy[m_vertex]; |
| 192 |
m_vertex++; |
| 193 |
} |
| 194 |
else |
| 195 |
{ |
| 196 |
cmd = path_cmd_stop; |
| 197 |
} |
| 198 |
break; |
| 199 |
|
| 200 |
default: |
| 201 |
cmd = path_cmd_stop; |
| 202 |
break; |
| 203 |
} |
| 204 |
|
| 205 |
if(!is_stop(cmd)) |
| 206 |
{ |
| 207 |
transform_xy(x, y); |
| 208 |
} |
| 209 |
return cmd; |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|