1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : di_view_matrix.hxx // |
---|
4 | // // |
---|
5 | // Institute of Microbiology (Technical University Munich) // |
---|
6 | // http://www.arb-home.de/ // |
---|
7 | // // |
---|
8 | // =============================================================== // |
---|
9 | |
---|
10 | #ifndef DI_VIEW_MATRIX_HXX |
---|
11 | #define DI_VIEW_MATRIX_HXX |
---|
12 | |
---|
13 | #ifndef AW_WINDOW_HXX |
---|
14 | #include <aw_window.hxx> |
---|
15 | #endif |
---|
16 | #ifndef DI_MATR_HXX |
---|
17 | #include "di_matr.hxx" |
---|
18 | #endif |
---|
19 | |
---|
20 | enum DI_gc { |
---|
21 | DI_G_STANDARD, |
---|
22 | DI_G_NAMES, |
---|
23 | DI_G_RULER, |
---|
24 | DI_G_RULER_DISPLAY, |
---|
25 | DI_G_BELOW_DIST, |
---|
26 | DI_G_ABOVE_DIST, |
---|
27 | DI_G_LAST // must be last |
---|
28 | }; |
---|
29 | |
---|
30 | class MatrixDisplay { |
---|
31 | GBDATA *gb_main; |
---|
32 | |
---|
33 | int screen_width; // dimensions of main screen |
---|
34 | int screen_height; |
---|
35 | |
---|
36 | int cell_width; // width and height of one cell |
---|
37 | int cell_height; |
---|
38 | |
---|
39 | int cell_paddx; // padding between cells |
---|
40 | int cell_paddy; |
---|
41 | |
---|
42 | bool leadZero; // show leading zero |
---|
43 | int digits; // digits after '.' |
---|
44 | char format_string[50]; // for digits |
---|
45 | |
---|
46 | int horiz_page_start; // number of first element in this page |
---|
47 | int vert_page_start; |
---|
48 | |
---|
49 | int vert_last_view_start; // last value of scrollbars |
---|
50 | int horiz_last_view_start; |
---|
51 | |
---|
52 | int total_cells_horiz; |
---|
53 | int total_cells_vert; |
---|
54 | |
---|
55 | int horiz_page_size; // page size in cells (how many cells per page, |
---|
56 | int vert_page_size; // vertical and horizontal) |
---|
57 | |
---|
58 | int off_dx; // offset values for scrollable area |
---|
59 | int off_dy; |
---|
60 | |
---|
61 | double min_view_dist; // m[i][j]<min_view_dist -> ascii ; else small slider |
---|
62 | double max_view_dist; // m[i][j]>max_view_dist -> ascii ; else small slider |
---|
63 | |
---|
64 | void set_scrollbar_steps(long width, long hight, long xinc, long yinc); |
---|
65 | void scroll_to(int sxpos, int sypos); |
---|
66 | |
---|
67 | public: |
---|
68 | enum UpdateFlag { // bits |
---|
69 | NEED_NOTHING = 0, |
---|
70 | NEED_CLEAR = 1, |
---|
71 | NEED_RESIZE = 2, |
---|
72 | NEED_SETUP = 4, |
---|
73 | }; |
---|
74 | private: |
---|
75 | UpdateFlag beforeUpdate; |
---|
76 | |
---|
77 | void setup(); |
---|
78 | void adapt_to_canvas_size(); // call after resize main window |
---|
79 | void draw(); |
---|
80 | |
---|
81 | enum LastAutoPop { UNKNOWN, UP, DOWN }; |
---|
82 | LastAutoPop lastautopop; |
---|
83 | |
---|
84 | bool autopop(bool show) { |
---|
85 | // handle automatic hide/show of matrix view |
---|
86 | // - avoid popup if was not auto-hidden |
---|
87 | if (!awm) return false; |
---|
88 | if (!show) { |
---|
89 | if (awm->is_shown()) { |
---|
90 | awm->hide(); lastautopop = DOWN; |
---|
91 | } |
---|
92 | } |
---|
93 | else if (!awm->is_shown() && lastautopop == DOWN) { |
---|
94 | awm->show(); lastautopop = UP; |
---|
95 | } |
---|
96 | return awm->is_shown(); |
---|
97 | } |
---|
98 | |
---|
99 | public: |
---|
100 | AW_window *awm; |
---|
101 | AW_device *device; // device to draw in |
---|
102 | |
---|
103 | MatrixDisplay(GBDATA *gb_main_) : |
---|
104 | gb_main(gb_main_), |
---|
105 | screen_width(0), |
---|
106 | screen_height(0), |
---|
107 | cell_width(0), |
---|
108 | cell_height(0), |
---|
109 | cell_paddx(0), |
---|
110 | cell_paddy(0), |
---|
111 | leadZero(false), |
---|
112 | digits(0), |
---|
113 | horiz_page_start(0), |
---|
114 | vert_page_start(0), |
---|
115 | vert_last_view_start(0), |
---|
116 | horiz_last_view_start(0), |
---|
117 | total_cells_horiz(0), |
---|
118 | total_cells_vert(0), |
---|
119 | horiz_page_size(0), |
---|
120 | vert_page_size(0), |
---|
121 | off_dx(0), |
---|
122 | off_dy(0), |
---|
123 | min_view_dist(0.0), |
---|
124 | max_view_dist(0.0), |
---|
125 | beforeUpdate(NEED_SETUP), |
---|
126 | lastautopop(UNKNOWN), |
---|
127 | awm(NULp), |
---|
128 | device(NULp) |
---|
129 | {} |
---|
130 | |
---|
131 | DI_MATRIX *get_matrix() { return GLOBAL_MATRIX.get(); } |
---|
132 | |
---|
133 | bool willShow() { |
---|
134 | if (!awm) return false; |
---|
135 | return awm->is_shown() || lastautopop == DOWN; |
---|
136 | } |
---|
137 | |
---|
138 | void monitor_vertical_scroll_cb(AW_window *); // vertical and horizontal |
---|
139 | void monitor_horizontal_scroll_cb(AW_window *); // scrollbar movements |
---|
140 | |
---|
141 | void mark(UpdateFlag needed) { beforeUpdate = UpdateFlag(beforeUpdate|needed); } |
---|
142 | |
---|
143 | void update_display() { |
---|
144 | if (beforeUpdate&NEED_SETUP) setup(); |
---|
145 | if (beforeUpdate&NEED_RESIZE) adapt_to_canvas_size(); |
---|
146 | draw(); |
---|
147 | beforeUpdate = NEED_NOTHING; |
---|
148 | } |
---|
149 | |
---|
150 | // ******************** real public section ******************* |
---|
151 | void set_slider_min(double d) { min_view_dist = d; }; |
---|
152 | void set_slider_max(double d) { max_view_dist = d; }; |
---|
153 | |
---|
154 | void handle_move(AW_event& event); |
---|
155 | void scroll_cells(int cells_x, int cells_y); |
---|
156 | }; |
---|
157 | |
---|
158 | AW_window *DI_create_view_matrix_window(AW_root *awr, MatrixDisplay *disp, save_matrix_params *sparam); |
---|
159 | |
---|
160 | |
---|
161 | #else |
---|
162 | #error di_view_matrix.hxx included twice |
---|
163 | #endif // DI_VIEW_MATRIX_HXX |
---|