1
// ================================================================ //
3
// File : aw_device_click.hxx //
4
// Purpose : Detect which graphical element is "nearby" //
5
// a given mouse position //
7
// Institute of Microbiology (Technical University Munich) //
8
// http://www.arb-home.de/ //
10
// ================================================================ //
12
#ifndef AW_DEVICE_CLICK_HXX
13
#define AW_DEVICE_CLICK_HXX
16
#include "aw_device.hxx"
19
// @@@ TODO: elements of the following classes should go private!
21
class AW_clicked_element {
25
public: // @@@ make private
27
bool exists; // true if a drawn element was clicked, else false
28
int distance; // distance in pixel to nearest line/text
30
AW_pos nearest_rel_pos; // 0 = at left(upper) small-side, 1 = at right(lower) small-side of textArea
42
AW_clicked_element() { init(); }
43
virtual ~AW_clicked_element() {}
45
virtual void clear() = 0;
49
AW_CL cd1() const { return client_data1; }
50
AW_CL cd2() const { return client_data2; }
52
void copy_cds(const AW_click_cd *click_cd) {
54
client_data1 = click_cd->get_cd1();
55
client_data2 = click_cd->get_cd2();
63
virtual AW::Position get_attach_point() const = 0;
64
virtual bool is_text() const = 0;
66
bool is_line() const { return !is_text(); }
68
double get_rel_pos() const { return nearest_rel_pos; }
69
void set_rel_pos(double rel) { aw_assert(rel >= 0.0 && rel <= 1.0); nearest_rel_pos = rel; }
71
AW::LineVector get_connecting_line(const AW_clicked_element& other) const {
72
//! determine LineVector between two clicked elements (e.g. for drag&drop)
73
return AW::LineVector(get_attach_point(), other.get_attach_point());
76
virtual int indicate_selected(AW_device *d, int gc) const = 0;
79
class AW_clicked_line : public AW_clicked_element {
81
AW_pos x0, y0, x1, y1; // @@@ make this a LineVector and private!
89
AW_clicked_line() { init(); }
90
void clear() OVERRIDE { AW_clicked_element::init(); init(); }
92
bool is_text() const OVERRIDE { return false; }
93
bool operator == (const AW_clicked_line& other) const { return nearlyEqual(get_line(), other.get_line()); }
95
AW::Position get_attach_point() const OVERRIDE {
96
double nrp = get_rel_pos();
97
return AW::Position(x0*(1-nrp)+x1*nrp,
101
AW::LineVector get_line() const { return AW::LineVector(x0, y0, x1, y1); }
102
int indicate_selected(AW_device *d, int gc) const OVERRIDE;
105
class AW_clicked_text : public AW_clicked_element {
106
public: // @@@ make members private
107
AW::Rectangle textArea; // world coordinates of text
108
int cursor; // which letter was selected, from 0 to strlen-1 [or -1 if not 'exactHit']
109
bool exactHit; // true -> real click inside text bounding-box (not only near text) (@@@ redundant: exactHit == (distance == 0))
112
textArea = AW::Rectangle();
118
AW_clicked_text() { init(); }
119
void clear() OVERRIDE { AW_clicked_element::init(); init(); }
121
bool is_text() const OVERRIDE { return true; }
122
bool operator == (const AW_clicked_text& other) const { return nearlyEqual(textArea, other.textArea); }
124
AW::Position get_attach_point() const OVERRIDE {
125
return textArea.centroid(); // @@@ uses center atm - should attach to bounding box
127
int indicate_selected(AW_device *d, int gc) const OVERRIDE;
130
#define AWT_CATCH 30 // max-pixel distance to graphical element (to accept a click or command)
131
#define AWT_NO_CATCH -1
133
class AW_device_click : public AW_simple_device {
134
AW_pos mouse_x, mouse_y; // @@@ use 'int' instead
135
int max_distance_line;
136
int max_distance_text;
138
bool line_impl(int gc, const AW::LineVector& Line, AW_bitset filteri) OVERRIDE;
139
bool text_impl(int gc, const char *str, const AW::Position& pos, AW_pos alignment, AW_bitset filteri, long opt_strlen) OVERRIDE;
140
bool invisible_impl(const AW::Position& pos, AW_bitset filteri) OVERRIDE { return generic_invisible(pos, filteri); }
142
void specific_reset() OVERRIDE {}
145
AW_clicked_line opt_line; // @@@ make private
146
AW_clicked_text opt_text;
148
AW_device_click(AW_common *common_);
150
AW_DEVICE_TYPE type() OVERRIDE;
152
void init_click(AW_pos mousex, AW_pos mousey, int max_distance, AW_bitset filteri);
154
void get_clicked_line(class AW_clicked_line *ptr) const; // @@@ make real accessors returning const&
155
void get_clicked_text(class AW_clicked_text *ptr) const;
159
#error aw_device_click.hxx included twice
160
#endif // AW_DEVICE_CLICK_HXX