| 1 | #ifndef AWT_CANVAS_HXX |
|---|
| 2 | #define AWT_CANVAS_HXX |
|---|
| 3 | |
|---|
| 4 | #ifndef AW_WINDOW_HXX |
|---|
| 5 | #include <aw_window.hxx> |
|---|
| 6 | #endif |
|---|
| 7 | #ifndef AW_DEVICE_HXX |
|---|
| 8 | #include <aw_device.hxx> |
|---|
| 9 | #endif |
|---|
| 10 | #ifndef AW_DEVICE_CLICK_HXX |
|---|
| 11 | #include <aw_device_click.hxx> |
|---|
| 12 | #endif |
|---|
| 13 | #ifndef ATTRIBUTES_H |
|---|
| 14 | #include <attributes.h> |
|---|
| 15 | #endif |
|---|
| 16 | |
|---|
| 17 | class AWT_canvas; |
|---|
| 18 | class AW_device; |
|---|
| 19 | class AW_clicked_line; |
|---|
| 20 | class AW_clicked_text; |
|---|
| 21 | |
|---|
| 22 | enum AWT_COMMAND_MODE { |
|---|
| 23 | AWT_MODE_NONE, |
|---|
| 24 | AWT_MODE_EMPTY, // placeholder (currently used in PARSIMONY) |
|---|
| 25 | |
|---|
| 26 | // NTREE, PARSIMONY, GENEMAP and SECEDIT: |
|---|
| 27 | AWT_MODE_ZOOM, |
|---|
| 28 | |
|---|
| 29 | // NTREE, PARSIMONY and GENEMAP: |
|---|
| 30 | AWT_MODE_SELECT, |
|---|
| 31 | |
|---|
| 32 | // NTREE, PARSIMONY and SECEDIT: |
|---|
| 33 | AWT_MODE_SETROOT, |
|---|
| 34 | |
|---|
| 35 | // NTREE and GENEMAP: |
|---|
| 36 | AWT_MODE_INFO, |
|---|
| 37 | |
|---|
| 38 | // NTREE and PARSIMONY: |
|---|
| 39 | AWT_MODE_MOVE, |
|---|
| 40 | AWT_MODE_MARK, |
|---|
| 41 | AWT_MODE_GROUP, |
|---|
| 42 | AWT_MODE_LZOOM, |
|---|
| 43 | AWT_MODE_SWAP, |
|---|
| 44 | |
|---|
| 45 | // NTREE and SECEDIT: |
|---|
| 46 | AWT_MODE_ROTATE, |
|---|
| 47 | |
|---|
| 48 | // NTREE only: |
|---|
| 49 | AWT_MODE_LINE, |
|---|
| 50 | AWT_MODE_WWW, |
|---|
| 51 | AWT_MODE_SPREAD, |
|---|
| 52 | AWT_MODE_LENGTH, |
|---|
| 53 | AWT_MODE_MULTIFURC, |
|---|
| 54 | |
|---|
| 55 | // PARSIMONY only: |
|---|
| 56 | AWT_MODE_KERNINGHAN, |
|---|
| 57 | AWT_MODE_NNI, |
|---|
| 58 | AWT_MODE_OPTIMIZE, |
|---|
| 59 | |
|---|
| 60 | // SECEDIT only: |
|---|
| 61 | AWT_MODE_FOLD, |
|---|
| 62 | AWT_MODE_CURSOR, |
|---|
| 63 | AWT_MODE_EDIT, |
|---|
| 64 | AWT_MODE_PINFO, |
|---|
| 65 | AWT_MODE_STRETCH, |
|---|
| 66 | AWT_MODE_SET_CURSOR |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | #define STANDARD_PADDING 10 |
|---|
| 70 | |
|---|
| 71 | // -------------------------------------------------------------------------------- |
|---|
| 72 | // AWT_zoom_mode + AWT_fit_mode are correlated, but not strictly coupled |
|---|
| 73 | |
|---|
| 74 | enum AWT_zoom_mode { // bit values! |
|---|
| 75 | AWT_ZOOM_NEVER = 0, |
|---|
| 76 | AWT_ZOOM_X = 1, |
|---|
| 77 | AWT_ZOOM_Y = 2, |
|---|
| 78 | AWT_ZOOM_BOTH = 3, |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | enum AWT_fit_mode { |
|---|
| 82 | AWT_FIT_NEVER, |
|---|
| 83 | AWT_FIT_LARGER, |
|---|
| 84 | AWT_FIT_SMALLER, |
|---|
| 85 | AWT_FIT_X, |
|---|
| 86 | AWT_FIT_Y, |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | // used combinations are: |
|---|
| 90 | // AWT_ZOOM_NEVER + AWT_FIT_NEVER (NDS list, others) |
|---|
| 91 | // AWT_ZOOM_X + AWT_FIT_X (dendrogram tree) |
|---|
| 92 | // AWT_ZOOM_Y + AWT_FIT_Y |
|---|
| 93 | // AWT_ZOOM_BOTH + AWT_FIT_LARGER (radial tree/gene-map; secedit) |
|---|
| 94 | // AWT_ZOOM_BOTH + AWT_FIT_SMALLER (book-style gene-map) |
|---|
| 95 | // |
|---|
| 96 | // other combinations may work as well. some combinations make no sense. |
|---|
| 97 | // -------------------------------------------------------------------------------- |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | class AWT_graphic_exports { |
|---|
| 101 | AW_borders default_padding; |
|---|
| 102 | AW_borders padding; |
|---|
| 103 | |
|---|
| 104 | public: |
|---|
| 105 | unsigned int refresh : 1; // 1 -> do a refresh |
|---|
| 106 | unsigned int resize : 1; // 1 -> size of graphic might have changed (implies refresh) |
|---|
| 107 | unsigned int structure_change : 1; // 1 -> call update_structure (implies resize) // @@@ rename -> need_reload |
|---|
| 108 | unsigned int zoom_reset : 1; // 1 -> do a zoom-reset (implies resize) |
|---|
| 109 | unsigned int save : 1; // 1 -> save structure to DB (implies structure_change) |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | AWT_zoom_mode zoom_mode; |
|---|
| 113 | AWT_fit_mode fit_mode; |
|---|
| 114 | |
|---|
| 115 | unsigned int dont_scroll : 1; // normally 0 (1 for IRS tree) |
|---|
| 116 | |
|---|
| 117 | void init(); // like clear, but resets fit, scroll state and padding |
|---|
| 118 | void clear(); |
|---|
| 119 | |
|---|
| 120 | void set_default_padding(int t, int b, int l, int r) { |
|---|
| 121 | default_padding.t = t; |
|---|
| 122 | default_padding.b = b; |
|---|
| 123 | default_padding.l = l; |
|---|
| 124 | default_padding.r = r; |
|---|
| 125 | |
|---|
| 126 | padding = default_padding; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | void set_equilateral_default_padding(int pad) { set_default_padding(pad, pad, pad, pad); } |
|---|
| 130 | void set_standard_default_padding() { set_equilateral_default_padding(STANDARD_PADDING); } |
|---|
| 131 | |
|---|
| 132 | void set_extra_text_padding(const AW_borders& text_padding) { |
|---|
| 133 | padding.t = default_padding.t + text_padding.t; |
|---|
| 134 | padding.b = default_padding.b + text_padding.b; |
|---|
| 135 | padding.l = default_padding.l + text_padding.l; |
|---|
| 136 | padding.r = default_padding.r + text_padding.r; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | int get_x_padding() const { return padding.l+padding.r; } |
|---|
| 140 | int get_y_padding() const { return padding.t+padding.b; } |
|---|
| 141 | int get_top_padding() const { return padding.t; } |
|---|
| 142 | int get_left_padding() const { return padding.l; } |
|---|
| 143 | |
|---|
| 144 | AW::Vector zoomVector(double transToFit) const { |
|---|
| 145 | return AW::Vector(zoom_mode&AWT_ZOOM_X ? transToFit : 1.0, |
|---|
| 146 | zoom_mode&AWT_ZOOM_Y ? transToFit : 1.0); |
|---|
| 147 | } |
|---|
| 148 | }; |
|---|
| 149 | |
|---|
| 150 | class AWT_graphic_event : virtual Noncopyable { |
|---|
| 151 | AWT_COMMAND_MODE M_cmd; // currently active mode |
|---|
| 152 | |
|---|
| 153 | AW_MouseButton M_button; |
|---|
| 154 | AW_key_mod M_key_modifier; |
|---|
| 155 | AW_key_code M_key_code; |
|---|
| 156 | char M_key_char; |
|---|
| 157 | AW_event_type M_type; |
|---|
| 158 | |
|---|
| 159 | AW::Position mousepos; |
|---|
| 160 | |
|---|
| 161 | const AW_clicked_line *M_cl; // text and/or |
|---|
| 162 | const AW_clicked_text *M_ct; // line selected by current mouse position |
|---|
| 163 | |
|---|
| 164 | public: |
|---|
| 165 | AWT_graphic_event(AWT_COMMAND_MODE cmd_, const AW_event& event, bool is_drag, const AW_clicked_line *cl_, const AW_clicked_text *ct_) |
|---|
| 166 | : M_cmd(cmd_), |
|---|
| 167 | M_button(event.button), |
|---|
| 168 | M_key_modifier(event.keymodifier), |
|---|
| 169 | M_key_code(event.keycode), |
|---|
| 170 | M_key_char(event.character), |
|---|
| 171 | M_type(is_drag ? AW_Mouse_Drag : event.type), |
|---|
| 172 | mousepos(event.x, event.y), |
|---|
| 173 | M_cl(cl_), |
|---|
| 174 | M_ct(ct_) |
|---|
| 175 | {} |
|---|
| 176 | |
|---|
| 177 | AWT_COMMAND_MODE cmd() const { return M_cmd; } |
|---|
| 178 | AW_MouseButton button() const { return M_button; } |
|---|
| 179 | |
|---|
| 180 | AW_key_mod key_modifier() const { return M_key_modifier; } |
|---|
| 181 | AW_key_code key_code() const { return M_key_code; } |
|---|
| 182 | char key_char() const { return M_key_char; } |
|---|
| 183 | |
|---|
| 184 | AW_event_type type() const { return M_type; } |
|---|
| 185 | |
|---|
| 186 | const AW::Position& position() const { return mousepos; } // screen-coordinates |
|---|
| 187 | |
|---|
| 188 | enum ClickPreference { PREFER_NEARER, PREFER_LINE, PREFER_TEXT }; |
|---|
| 189 | const AW_clicked_element *best_click(ClickPreference prefer = PREFER_NEARER); |
|---|
| 190 | }; |
|---|
| 191 | |
|---|
| 192 | class AWT_graphic { |
|---|
| 193 | friend class AWT_canvas; |
|---|
| 194 | |
|---|
| 195 | void refresh_by_exports(AWT_canvas *scr); |
|---|
| 196 | void postevent_handler(GBDATA *gb_main); |
|---|
| 197 | |
|---|
| 198 | protected: |
|---|
| 199 | int drag_gc; |
|---|
| 200 | |
|---|
| 201 | public: |
|---|
| 202 | AWT_graphic_exports exports; |
|---|
| 203 | |
|---|
| 204 | AWT_graphic() { exports.init(); } |
|---|
| 205 | virtual ~AWT_graphic() {} |
|---|
| 206 | |
|---|
| 207 | // pure virtual interface (methods implemented by AWT_nonDB_graphic) |
|---|
| 208 | |
|---|
| 209 | virtual GB_ERROR load(GBDATA *gb_main, const char *name, AW_CL cd1, AW_CL cd2) = 0; |
|---|
| 210 | virtual GB_ERROR save(GBDATA *gb_main, const char *name, AW_CL cd1, AW_CL cd2) = 0; |
|---|
| 211 | virtual int check_update(GBDATA *gb_main) = 0; // check whether anything changed |
|---|
| 212 | virtual void update(GBDATA *gb_main) = 0; // mark the database |
|---|
| 213 | |
|---|
| 214 | // pure virtual interface (rest) |
|---|
| 215 | |
|---|
| 216 | virtual void show(AW_device *device) = 0; |
|---|
| 217 | |
|---|
| 218 | virtual void info(AW_device *device, AW_pos x, AW_pos y, AW_clicked_line *cl, AW_clicked_text *ct) = 0; // double click |
|---|
| 219 | |
|---|
| 220 | /* init gcs, if any gc is changed you may call AWT_expose_cb(NULL, scr); or AWT_resize_cb(NULL, scr); */ |
|---|
| 221 | virtual AW_gc_manager init_devices(AW_window *, AW_device *, AWT_canvas *scr) = 0; |
|---|
| 222 | |
|---|
| 223 | virtual void handle_command(AW_device *device, AWT_graphic_event& event) = 0; |
|---|
| 224 | virtual void update_structure() = 0; // called when exports.structure_change == 1 |
|---|
| 225 | }; |
|---|
| 226 | |
|---|
| 227 | class AWT_nonDB_graphic : public AWT_graphic { // @@@ check AWT_nonDB_graphic |
|---|
| 228 | void update_structure() {} |
|---|
| 229 | // a partly implementation of AWT_graphic |
|---|
| 230 | public: |
|---|
| 231 | AWT_nonDB_graphic() {} |
|---|
| 232 | virtual ~AWT_nonDB_graphic() OVERRIDE {} |
|---|
| 233 | |
|---|
| 234 | // dummy functions, only spittings out warnings: |
|---|
| 235 | GB_ERROR load(GBDATA *gb_main, const char *name, AW_CL cd1, AW_CL cd2) OVERRIDE __ATTR__USERESULT; |
|---|
| 236 | GB_ERROR save(GBDATA *gb_main, const char *name, AW_CL cd1, AW_CL cd2) OVERRIDE __ATTR__USERESULT; |
|---|
| 237 | int check_update(GBDATA *gb_main) OVERRIDE; |
|---|
| 238 | void update(GBDATA *gb_main) OVERRIDE; |
|---|
| 239 | }; |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | #define EPS 0.0001 // div zero check |
|---|
| 243 | #define CLIP_OVERLAP 15 |
|---|
| 244 | #define AWT_ZOOM_OUT_STEP 40 // (pixel) rand um screen |
|---|
| 245 | #define AWT_MIN_WIDTH 100 // Minimum center screen (= screen-offset) |
|---|
| 246 | |
|---|
| 247 | enum { |
|---|
| 248 | AWT_d_screen = 1 |
|---|
| 249 | }; |
|---|
| 250 | |
|---|
| 251 | class AWT_canvas : virtual Noncopyable { |
|---|
| 252 | bool consider_text_for_size; |
|---|
| 253 | char *gc_base_name; |
|---|
| 254 | |
|---|
| 255 | public: |
|---|
| 256 | // too many callbacks -> public |
|---|
| 257 | // in fact: private |
|---|
| 258 | // (in real fact: needs rewrite) |
|---|
| 259 | |
|---|
| 260 | char *user_awar; // contains name of awar (awar contains name of tree displayed in canvas) |
|---|
| 261 | void init_device(AW_device *device); |
|---|
| 262 | AW_pos trans_to_fit; |
|---|
| 263 | AW_pos shift_x_to_fit; |
|---|
| 264 | AW_pos shift_y_to_fit; |
|---|
| 265 | |
|---|
| 266 | int old_hor_scroll_pos; |
|---|
| 267 | int old_vert_scroll_pos; |
|---|
| 268 | AW_screen_area rect; // screen coordinates |
|---|
| 269 | AW_world worldinfo; // real coordinates without transform. |
|---|
| 270 | AW_world worldsize; |
|---|
| 271 | int zoom_drag_sx; |
|---|
| 272 | int zoom_drag_sy; |
|---|
| 273 | int zoom_drag_ex; |
|---|
| 274 | int zoom_drag_ey; |
|---|
| 275 | int drag; |
|---|
| 276 | AW_clicked_line clicked_line; |
|---|
| 277 | AW_clicked_text clicked_text; |
|---|
| 278 | |
|---|
| 279 | void set_scrollbars(); |
|---|
| 280 | void set_dragEndpoint(int x, int y); |
|---|
| 281 | |
|---|
| 282 | void set_horizontal_scrollbar_position(AW_window *aww, int pos); |
|---|
| 283 | void set_vertical_scrollbar_position(AW_window *aww, int pos); |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | // public (read only) |
|---|
| 287 | |
|---|
| 288 | GBDATA *gb_main; |
|---|
| 289 | AW_window *aww; |
|---|
| 290 | AW_root *awr; |
|---|
| 291 | AWT_graphic *gfx; |
|---|
| 292 | |
|---|
| 293 | AW_gc_manager gc_manager; |
|---|
| 294 | int drag_gc; |
|---|
| 295 | |
|---|
| 296 | AWT_COMMAND_MODE mode; |
|---|
| 297 | |
|---|
| 298 | // real public |
|---|
| 299 | |
|---|
| 300 | AWT_canvas(GBDATA *gb_main, AW_window *aww, const char *gc_base_name_, AWT_graphic *awd, const char *user_awar); |
|---|
| 301 | |
|---|
| 302 | inline void push_transaction() const; |
|---|
| 303 | inline void pop_transaction() const; |
|---|
| 304 | |
|---|
| 305 | void refresh(); |
|---|
| 306 | |
|---|
| 307 | void recalc_size(bool adjust_scrollbars = true); |
|---|
| 308 | void recalc_size_and_refresh() { recalc_size(true); refresh(); } |
|---|
| 309 | |
|---|
| 310 | void zoom_reset(); |
|---|
| 311 | void zoom_reset_and_refresh() { zoom_reset(); refresh(); } |
|---|
| 312 | |
|---|
| 313 | void set_consider_text_for_zoom_reset(bool consider) { consider_text_for_size = consider; } |
|---|
| 314 | |
|---|
| 315 | void zoom(AW_device *device, bool zoomIn, const AW::Rectangle& wanted_part, const AW::Rectangle& current_part, int percent); |
|---|
| 316 | |
|---|
| 317 | void set_mode(AWT_COMMAND_MODE mo) { mode = mo; } |
|---|
| 318 | |
|---|
| 319 | void scroll(int delta_x, int delta_y, bool dont_update_scrollbars = false); |
|---|
| 320 | void scroll(const AW::Vector& delta, bool dont_update_scrollbars = false) { |
|---|
| 321 | scroll(int(delta.x()), int(delta.y()), dont_update_scrollbars); |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | bool handleWheelEvent(AW_device *device, const AW_event& event); |
|---|
| 325 | |
|---|
| 326 | const char *get_gc_base_name() const { return gc_base_name; } |
|---|
| 327 | |
|---|
| 328 | void postevent_handler(); |
|---|
| 329 | }; |
|---|
| 330 | |
|---|
| 331 | inline void AWT_graphic::refresh_by_exports(AWT_canvas *scr) { |
|---|
| 332 | if (exports.zoom_reset) scr->zoom_reset_and_refresh(); |
|---|
| 333 | else if (exports.resize) scr->recalc_size_and_refresh(); |
|---|
| 334 | else if (exports.refresh) scr->refresh(); |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | void AWT_expose_cb(UNFIXED, AWT_canvas *scr); |
|---|
| 338 | void AWT_resize_cb(UNFIXED, AWT_canvas *scr); |
|---|
| 339 | |
|---|
| 340 | void AWT_popup_tree_export_window(AW_window *parent_win, AWT_canvas *scr); |
|---|
| 341 | void AWT_popup_sec_export_window (AW_window *parent_win, AWT_canvas *scr); |
|---|
| 342 | void AWT_popup_print_window (AW_window *parent_win, AWT_canvas *scr); |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | #endif |
|---|