21 AW_device_click::AW_device_click(
AW_common *common_)
31 max_distance_line = max_distance;
32 max_distance_text = max_distance;
37 opt_polygon = AW_clicked_polygon();
45 if (!(filteri & filter))
return false;
49 bool drawflag = clip(transLine, clippedLine);
51 double nearest_rel_pos;
53 double distance =
Distance(mouse, nearest);
55 if (distance < max_distance_line) {
56 max_distance_line = distance;
57 opt_line.assign(Line, distance, nearest_rel_pos, click_cd);
64 if (!(filteri & filter))
return false;
71 if (!generic_box(gc, rect, filteri))
return false;
72 if (!opt_line.does_exist())
return true;
74 dist = opt_line.get_distance();
79 return box_impl(gc, FillStyle::EMPTY, rect, filteri);
85 if (!opt_box.does_exist() || dist<opt_box.get_distance()) {
86 opt_box.assign(rect, dist, 0.0, click_cd);
96 return d>0 ? -1 : (d<0 ? 1 : 0);
108 for (
int i = 1; i<npos; ++i) {
115 if (!(filteri & filter))
return false;
124 if (!generic_polygon(gc, npos, pos, filteri))
return false;
125 if (!opt_line.does_exist())
return true;
127 dist = opt_line.get_distance();
133 for (
int i = 0; i<npos; ++i) {
134 tpos[i] = transform(pos[i]);
141 return polygon_impl(gc, FillStyle::EMPTY, npos, pos, filteri);
147 if (!opt_polygon.does_exist() || dist<opt_polygon.get_distance()) {
148 opt_polygon.assign(npos, pos, dist, 0.0, click_cd);
154 if (!(filteri & filter))
return false;
157 this->transform(pos.
xpos(), pos.
ypos(), X0, Y0);
159 const AW_GC *gcm = get_common()->map_gc(gc);
167 if (clipRect.
t == 0) {
168 if (Y1 < clipRect.
t)
return false;
171 if (Y0 < clipRect.
t)
return false;
174 if (clipRect.
b == get_common()->get_screen().b) {
175 if (Y0 > clipRect.
b)
return false;
178 if (Y1 > clipRect.
b)
return false;
185 if (mouse.ypos() > Y1) {
186 int ydist = mouse.ypos()-Y1;
187 if (ydist > max_distance_text)
return false;
190 else if (mouse.ypos() < Y0) {
191 int ydist = Y0-mouse.ypos();
192 if (ydist > max_distance_text)
return false;
197 int text_width = gcm->get_string_size(cstr);
200 AW_pos X1 = X0+text_width;
203 if (X1 < clipRect.
l)
return false;
204 if (X0 > clipRect.
r)
return false;
207 if (mouse.xpos() > X1) {
208 int xdist = mouse.xpos()-X1;
209 if (xdist > max_distance_text)
return false;
210 dist2text =
std::max(xdist, dist2text);
212 else if (mouse.xpos() < X0) {
213 int xdist = X0-mouse.xpos();
214 if (xdist > max_distance_text)
return false;
215 dist2text =
std::max(xdist, dist2text);
218 max_distance_text = dist2text;
220 if (!opt_text.does_exist() ||
221 (opt_text.get_distance()>dist2text))
225 LineVector orientation = textArea.bigger_extent();
228 bool visible = clip(orientation, clippedOrientation);
230 double nearest_rel_pos;
233 opt_text.assign(rtransform(textArea), max_distance_text, nearest_rel_pos, click_cd);
249 if (prefer == PREFER_LINE && opt_line.does_exist()) bestClick = &opt_line;
250 if (prefer == PREFER_TEXT && opt_text.does_exist()) bestClick = &opt_text;
261 for (
size_t i = 0; i<
ARRAY_ELEMS(maybeClicked); ++i) {
262 if (maybeClicked[i]->does_exist()) {
263 if (!bestClick || maybeClicked[i]->get_distance()<bestClick->
get_distance()) {
264 bestClick = maybeClicked[i];
275 for (
int i = 2; i<npos; ++i) {
282 return d->
line(gc, line);
290 int AW_clicked_polygon::indicate_selected(
AW_device *d,
int gc)
const {
double kpt2(const Position &a, const Position &b, const Position &c)
Rectangle bounding_box(const Rectangle &r1, const Rectangle &r2)
Position nearest_linepoint(const Position &pos, const LineVector &line, double &factor)
const AW_bitset AW_ALL_DEVICES
bool polygon(int gc, AW::FillStyle filled, int npoints, const AW_pos *points, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
#define ARRAY_ELEMS(array)
const double & ypos() const
ValueCounter< double > Distance
bool line(int gc, const AW::LineVector &Line, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
static bool polygon_contains(const Position &mouse, int npos, const Position *pos)
int indicate_selected(AW_device *d, int gc) const OVERRIDE
bool is_between(const double &coord1, const double &between, const double &coord2)
bool contains(const Position &pos) const
const double & xpos() const
double KreuzProdTest(const Position &a, const Position &b, const Position &c)
bool box(int gc, AW::FillStyle filled, const AW::Rectangle &rect, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
int indicate_selected(AW_device *d, int gc) const OVERRIDE
AW_pos x_alignment(AW_pos x_pos, AW_pos x_size, AW_pos alignment)
int indicate_selected(AW_device *d, int gc) const OVERRIDE