1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <memory.h> |
---|
4 | #include <string.h> |
---|
5 | |
---|
6 | #include <arbdb.h> |
---|
7 | #include <arbdbt.h> |
---|
8 | |
---|
9 | #include <aw_root.hxx> |
---|
10 | #include <aw_device.hxx> |
---|
11 | #include <aw_window.hxx> |
---|
12 | #include <aw_preset.hxx> |
---|
13 | #include <aw_awars.hxx> |
---|
14 | |
---|
15 | #include <awt_tree.hxx> |
---|
16 | #include <awt_canvas.hxx> |
---|
17 | #include "dist.hxx" |
---|
18 | |
---|
19 | #include <di_matr.hxx> |
---|
20 | #include <di_view_matrix.hxx> |
---|
21 | |
---|
22 | void vertical_change_cb (AW_window *aww,DI_dmatrix *dis) { dis->monitor_vertical_scroll_cb(aww); } |
---|
23 | void horizontal_change_cb(AW_window *aww,DI_dmatrix *dis) { dis->monitor_horizontal_scroll_cb(aww); } |
---|
24 | |
---|
25 | void redisplay_needed(AW_window *,DI_dmatrix *dis) { |
---|
26 | dis->display(true); |
---|
27 | } |
---|
28 | void resize_needed(AW_window *,DI_dmatrix *dis) { |
---|
29 | dis->init(); |
---|
30 | dis->resized(); |
---|
31 | dis->display(false); |
---|
32 | } |
---|
33 | |
---|
34 | DI_dmatrix::DI_dmatrix() { |
---|
35 | memset((char *) this,0,sizeof(DI_dmatrix)); |
---|
36 | } |
---|
37 | |
---|
38 | void DI_dmatrix::init (DI_MATRIX *matrix) { |
---|
39 | di_matrix = matrix; |
---|
40 | DI_MATRIX *m = get_matrix(); |
---|
41 | |
---|
42 | // calculate cell width and height |
---|
43 | { |
---|
44 | int max_cell_width = 0; |
---|
45 | int max_cell_height = 0; |
---|
46 | |
---|
47 | DI_gc gc; |
---|
48 | for (gc=DI_G_STANDARD; gc<=DI_G_LAST; gc = DI_gc(int(gc)+1)) { |
---|
49 | int height = 0; |
---|
50 | int width = 0; |
---|
51 | |
---|
52 | switch (gc) { |
---|
53 | case DI_G_STANDARD: |
---|
54 | case DI_G_BELOW_DIST: |
---|
55 | case DI_G_ABOVE_DIST: { |
---|
56 | const AW_font_information *aw_fi = device->get_font_information(DI_G_STANDARD, 0); |
---|
57 | |
---|
58 | width = aw_fi->max_letter.width*6; // normal cell contain 6 characters (e.g.: '0.0162') |
---|
59 | height = aw_fi->max_letter.height*2; |
---|
60 | break; |
---|
61 | } |
---|
62 | case DI_G_NAMES: { |
---|
63 | const AW_font_information *aw_fi = device->get_font_information(DI_G_STANDARD, 0); |
---|
64 | |
---|
65 | width = aw_fi->max_letter.width*SPECIES_NAME_LEN; // normal cell contain 6 characters (e.g.: '0.0162') |
---|
66 | height = aw_fi->max_letter.height*2; |
---|
67 | break; |
---|
68 | } |
---|
69 | default: { |
---|
70 | break; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | if (height>max_cell_height) max_cell_height = height; |
---|
75 | if (width>max_cell_width) max_cell_width = width; |
---|
76 | } |
---|
77 | |
---|
78 | cell_width = max_cell_width; |
---|
79 | cell_height = max_cell_height; |
---|
80 | } |
---|
81 | |
---|
82 | // cell_width = aw_fi->max_letter_width*SPECIES_NAME_LEN; |
---|
83 | // cell_height = aw_fi->max_letter_height*2; |
---|
84 | |
---|
85 | cell_offset = 10; // draw cell_offset pixels above cell base_line |
---|
86 | |
---|
87 | off_dx = cell_width + 2*cell_offset; |
---|
88 | off_dy = 3*cell_height; |
---|
89 | |
---|
90 | if (m){ |
---|
91 | total_cells_horiz=m->nentries; |
---|
92 | total_cells_vert=m->nentries; |
---|
93 | } |
---|
94 | set_scrollbar_steps( cell_width,cell_height,50,50); |
---|
95 | resized(); // initalize window_size dependend parameters |
---|
96 | } |
---|
97 | |
---|
98 | DI_MATRIX *DI_dmatrix::get_matrix(){ |
---|
99 | if (di_matrix) return di_matrix; |
---|
100 | return DI_MATRIX::ROOT; |
---|
101 | } |
---|
102 | |
---|
103 | void DI_dmatrix::resized(void) |
---|
104 | { |
---|
105 | AW_rectangle squ; |
---|
106 | AW_rectangle rect; |
---|
107 | long horiz_paint_size,vert_paint_size; |
---|
108 | const AW_font_information *aw_fi = device->get_font_information(DI_G_STANDARD,0); |
---|
109 | DI_MATRIX *m = get_matrix(); |
---|
110 | long n = 0; |
---|
111 | |
---|
112 | if (m) n = m->nentries; |
---|
113 | device->get_area_size(&squ); |
---|
114 | |
---|
115 | screen_width = squ.r-squ.l; |
---|
116 | screen_height = squ.b-squ.t; |
---|
117 | |
---|
118 | if (m) { |
---|
119 | horiz_paint_size = (squ.r-aw_fi->max_letter.width-off_dx)/cell_width; |
---|
120 | vert_paint_size = (squ.b-off_dy)/cell_height; |
---|
121 | horiz_page_size = (n > horiz_paint_size) ? horiz_paint_size : n; |
---|
122 | vert_page_size = (n > vert_paint_size) ? vert_paint_size : n; |
---|
123 | |
---|
124 | rect.l = 0; |
---|
125 | rect.t = 0; |
---|
126 | rect.r = (int)((n-horiz_page_size)*cell_width+squ.r); |
---|
127 | rect.b = (int)((n-vert_page_size)*cell_height+squ.b); |
---|
128 | } |
---|
129 | |
---|
130 | horiz_page_start = 0; |
---|
131 | horiz_last_view_start = 0; |
---|
132 | vert_page_start = 0; |
---|
133 | vert_last_view_start = 0; |
---|
134 | |
---|
135 | device->reset(); // clip_size == device_size |
---|
136 | device->clear(-1); |
---|
137 | device->set_right_clip_border((int)(off_dx+cell_width*horiz_page_size)); |
---|
138 | device->reset(); // reset shift_x and shift_y |
---|
139 | awm->set_vertical_scrollbar_position(0); |
---|
140 | awm->set_horizontal_scrollbar_position(0); |
---|
141 | awm->tell_scrolled_picture_size(rect); |
---|
142 | awm->calculate_scrollbars(); |
---|
143 | if (!awm->is_shown() && m) { |
---|
144 | awm->show(); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | enum ClickAction { |
---|
149 | CLICK_SELECT_SPECIES = 1, |
---|
150 | CLICK_SET_MINMAX, |
---|
151 | }; |
---|
152 | |
---|
153 | #define MINMAX_GRANULARITY 10000L |
---|
154 | #define ROUNDUP 0.00005 // in order to round to 4 digits |
---|
155 | |
---|
156 | void DI_dmatrix::handle_move(AW_event& event) { |
---|
157 | static int clickx, clicky; // original click pos |
---|
158 | static int startx, starty; // original slider position |
---|
159 | |
---|
160 | if (event.type == AW_Mouse_Press) { |
---|
161 | clickx = event.x; |
---|
162 | clicky = event.y; |
---|
163 | |
---|
164 | startx = awm->slider_pos_horizontal; |
---|
165 | starty = awm->slider_pos_vertical; |
---|
166 | } |
---|
167 | else if (event.type == AW_Mouse_Drag || event.type == AW_Mouse_Release) { |
---|
168 | int x_screen_diff = clickx - event.x; |
---|
169 | int y_screen_diff = clicky - event.y; |
---|
170 | |
---|
171 | int sxpos = startx + x_screen_diff; |
---|
172 | int sypos = starty + y_screen_diff; |
---|
173 | |
---|
174 | AW_pos maxx = awm->get_scrolled_picture_width() - screen_width; |
---|
175 | AW_pos maxy = awm->get_scrolled_picture_height() - screen_height; |
---|
176 | |
---|
177 | if (sxpos>maxx) sxpos = int(maxx); |
---|
178 | if (sypos>maxy) sypos = int(maxy); |
---|
179 | if (sxpos<0) sxpos = 0; |
---|
180 | if (sypos<0) sypos = 0; |
---|
181 | |
---|
182 | awm->set_horizontal_scrollbar_position(sxpos); |
---|
183 | awm->set_vertical_scrollbar_position(sypos); |
---|
184 | |
---|
185 | monitor_vertical_scroll_cb(awm); |
---|
186 | monitor_horizontal_scroll_cb(awm); |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | static void motion_cb(AW_window *aww, AW_CL cl_dmatrix, AW_CL) { |
---|
191 | AW_event event; |
---|
192 | aww->get_event( &event ); |
---|
193 | |
---|
194 | DI_dmatrix *dmatrix = reinterpret_cast<DI_dmatrix*>(cl_dmatrix); |
---|
195 | if (event.button == AWT_M_MIDDLE) { |
---|
196 | dmatrix->handle_move(event); |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | static void input_cb(AW_window *aww, AW_CL cl_dmatrix, AW_CL) { |
---|
201 | AW_event event; |
---|
202 | aww->get_event( &event ); |
---|
203 | |
---|
204 | DI_dmatrix *dmatrix = reinterpret_cast<DI_dmatrix*>(cl_dmatrix); |
---|
205 | if (event.button == AWT_M_MIDDLE) { |
---|
206 | dmatrix->handle_move(event); |
---|
207 | } |
---|
208 | else { |
---|
209 | AW_device *click_device = aww->get_click_device(AW_MIDDLE_AREA, event.x, event.y, 20, 20, 0); |
---|
210 | |
---|
211 | click_device->set_filter(AW_CLICK); |
---|
212 | click_device->reset(); |
---|
213 | |
---|
214 | { |
---|
215 | AW_device *oldMatrixDevice = dmatrix->device; |
---|
216 | |
---|
217 | dmatrix->device = click_device; |
---|
218 | dmatrix->display(false); // detect clicked element |
---|
219 | dmatrix->device = oldMatrixDevice; |
---|
220 | } |
---|
221 | |
---|
222 | if (event.type == AW_Mouse_Press) { |
---|
223 | AW_clicked_text clicked_text; |
---|
224 | AW_clicked_line clicked_line; |
---|
225 | click_device->get_clicked_text(&clicked_text); |
---|
226 | click_device->get_clicked_line(&clicked_line); |
---|
227 | |
---|
228 | AW_CL cd1, cd2; |
---|
229 | AW::Position clickPos(event.x, event.y); |
---|
230 | |
---|
231 | if (AW_getBestClick(clickPos, &clicked_line, &clicked_text, &cd1, &cd2)) { |
---|
232 | ClickAction action = static_cast<ClickAction>(cd1); |
---|
233 | |
---|
234 | if (action == CLICK_SELECT_SPECIES) { |
---|
235 | long idx = long(cd2); |
---|
236 | DI_MATRIX *matrix = dmatrix->get_matrix(); |
---|
237 | if (idx >= matrix->nentries) { |
---|
238 | aw_message(GBS_global_string("Illegal idx %li [allowed: 0-%li]", idx, matrix->nentries)); |
---|
239 | } |
---|
240 | else { |
---|
241 | DI_ENTRY *entry = matrix->entries[idx]; |
---|
242 | const char *species_name = entry->name; |
---|
243 | |
---|
244 | aww->get_root()->awar(AWAR_SPECIES_NAME)->write_string(species_name); |
---|
245 | } |
---|
246 | } |
---|
247 | else if (action == CLICK_SET_MINMAX) { |
---|
248 | AW_root *aw_root = aww->get_root(); |
---|
249 | AW_awar *awar_bound = 0; |
---|
250 | |
---|
251 | switch (event.button) { |
---|
252 | case AWT_M_LEFT: awar_bound = aw_root->awar(AWAR_DIST_MIN_DIST); break; |
---|
253 | case AWT_M_RIGHT: awar_bound = aw_root->awar(AWAR_DIST_MAX_DIST); break; |
---|
254 | default: break; |
---|
255 | } |
---|
256 | |
---|
257 | if (awar_bound) { |
---|
258 | double val = double(cd2)/MINMAX_GRANULARITY; |
---|
259 | awar_bound->write_float(val); |
---|
260 | } |
---|
261 | } |
---|
262 | } |
---|
263 | } |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | void DI_dmatrix::display(bool clear) // draw area |
---|
268 | { |
---|
269 | #define BUFLEN 200 |
---|
270 | char buf[BUFLEN]; |
---|
271 | long x, y, xpos, ypos; |
---|
272 | GB_transaction dummy(GLOBAL_gb_main); |
---|
273 | |
---|
274 | if (!device) return; |
---|
275 | |
---|
276 | DI_MATRIX *m = get_matrix(); |
---|
277 | if (!m) { |
---|
278 | if (awm) awm->hide(); |
---|
279 | return; |
---|
280 | } |
---|
281 | |
---|
282 | if (clear) device->clear(-1); |
---|
283 | device->set_offset(AW::Vector(off_dx, off_dy)); |
---|
284 | xpos = 0; |
---|
285 | |
---|
286 | char *selSpecies = 0; |
---|
287 | if (awm) selSpecies = awm->get_root()->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
288 | |
---|
289 | int name_display_width; { |
---|
290 | const AW_font_information *aw_fi = device->get_font_information(DI_G_NAMES,0); |
---|
291 | name_display_width = cell_width/aw_fi->max_letter.width; |
---|
292 | } |
---|
293 | gb_assert(name_display_width<BUFLEN); |
---|
294 | |
---|
295 | int sel_x_pos = -1; |
---|
296 | |
---|
297 | for (x = horiz_page_start; |
---|
298 | x < (horiz_page_start + horiz_page_size) && (x < total_cells_horiz); |
---|
299 | x++) |
---|
300 | { |
---|
301 | ypos = 0; |
---|
302 | for (y = vert_page_start; |
---|
303 | y < (vert_page_start + vert_page_size) && (y < total_cells_vert); |
---|
304 | y++) |
---|
305 | { |
---|
306 | double val2 = m->matrix->get(x, y); |
---|
307 | AW_CL cd_val = AW_CL(val2*MINMAX_GRANULARITY+1); |
---|
308 | |
---|
309 | if (val2>=min_view_dist && val2<=max_view_dist && val2>0.0) { // display ruler |
---|
310 | int maxw = (int)(cell_width * .75); |
---|
311 | int h = cell_height /2 ; |
---|
312 | int y2 = ypos * cell_height - cell_offset - 10; |
---|
313 | int x2 = xpos * cell_width; |
---|
314 | double len = ((val2-min_view_dist)/(max_view_dist-min_view_dist)) * maxw; |
---|
315 | if (len >= 0) { |
---|
316 | device->box(DI_G_RULER_DISPLAY, true, x2, y2,len, h*.8,-1,AW_CL(CLICK_SET_MINMAX), cd_val); |
---|
317 | }else{ |
---|
318 | device->text(DI_G_STANDARD, "????", xpos * cell_width, ypos * cell_height - cell_offset, 0.0, -1, AW_CL(CLICK_SET_MINMAX), cd_val); |
---|
319 | } |
---|
320 | double v; |
---|
321 | for (v = x2; v < x2 + maxw; v += maxw * .1999) { |
---|
322 | device->line (DI_G_RULER, v, y2+h*.5, v, y2 + h, -1,AW_CL(CLICK_SET_MINMAX), cd_val); |
---|
323 | } |
---|
324 | device->line(DI_G_RULER, x2, y2+h, x2+maxw-1, y2+h, -1, AW_CL(CLICK_SET_MINMAX), cd_val); |
---|
325 | } |
---|
326 | else { |
---|
327 | DI_gc gc = val2<min_view_dist ? DI_G_BELOW_DIST : (val2>max_view_dist ? DI_G_ABOVE_DIST : DI_G_STANDARD); |
---|
328 | |
---|
329 | if (val2 == 0.0 || val2 == 1.0) { |
---|
330 | sprintf(buf, "%3.1f", val2); |
---|
331 | gc = DI_G_STANDARD; |
---|
332 | } |
---|
333 | else { |
---|
334 | sprintf(buf, "%6.4f", val2); |
---|
335 | } |
---|
336 | device->text(gc, buf, xpos * cell_width, ypos * cell_height - cell_offset, 0.0, -1, AW_CL(CLICK_SET_MINMAX), cd_val); |
---|
337 | } |
---|
338 | |
---|
339 | ypos++; |
---|
340 | } |
---|
341 | //display horizontal speciesnames: |
---|
342 | |
---|
343 | strcpy(buf, m->entries[x]->name); |
---|
344 | if (selSpecies && strcmp(buf, selSpecies) == 0) sel_x_pos = xpos; // remember x-position for selected species |
---|
345 | buf[name_display_width] = 0; // cut group-names if too long |
---|
346 | device->text(DI_G_NAMES, buf, xpos * cell_width, cell_height - off_dy - cell_offset, 0.0, -1, AW_CL(CLICK_SELECT_SPECIES), AW_CL(x)); |
---|
347 | xpos++; |
---|
348 | } |
---|
349 | |
---|
350 | device->set_offset(AW::Vector(off_dx, 0)); |
---|
351 | |
---|
352 | AW::Rectangle area = device->get_area_size(); |
---|
353 | |
---|
354 | // highlight selected species (vertically) |
---|
355 | if (sel_x_pos != -1) { |
---|
356 | AW_pos linex1 = sel_x_pos*cell_width - cell_offset; |
---|
357 | AW_pos linex2 = linex1+cell_width; |
---|
358 | AW_pos height = area.height(); |
---|
359 | device->line(DI_G_STANDARD, linex1, 0, linex1, height, -1, 0, 0); |
---|
360 | device->line(DI_G_STANDARD, linex2, 0, linex2, height, -1, 0, 0); |
---|
361 | } |
---|
362 | |
---|
363 | device->set_offset(AW::Vector(0, off_dy)); |
---|
364 | |
---|
365 | // display vertical speciesnames |
---|
366 | ypos = 0; |
---|
367 | int sel_y_pos = -1; |
---|
368 | for (y = vert_page_start; y < vert_page_start + vert_page_size; y++) { |
---|
369 | strcpy(buf, m->entries[y]->name); |
---|
370 | if (selSpecies && strcmp(buf, selSpecies) == 0) sel_y_pos = ypos; // remember x-position for selected species |
---|
371 | buf[name_display_width] = 0; // cut group-names if too long |
---|
372 | device->text(DI_G_NAMES, buf, 0, ypos * cell_height - cell_offset, 0.0, -1, AW_CL(CLICK_SELECT_SPECIES), AW_CL(y)); |
---|
373 | ypos++; |
---|
374 | } |
---|
375 | |
---|
376 | // highlight selected species |
---|
377 | if (sel_y_pos != -1) { |
---|
378 | AW_pos liney1 = (sel_y_pos-1)*cell_height; |
---|
379 | AW_pos liney2 = liney1+cell_height; |
---|
380 | AW_pos width = area.width(); |
---|
381 | device->line(DI_G_STANDARD, 0, liney1, width, liney1, -1, 0, 0); |
---|
382 | device->line(DI_G_STANDARD, 0, liney2, width, liney2, -1, 0, 0); |
---|
383 | } |
---|
384 | |
---|
385 | device->set_offset(AW::Vector(0, 0)); |
---|
386 | #undef BUFLEN |
---|
387 | } |
---|
388 | |
---|
389 | void DI_dmatrix::set_scrollbar_steps(long width_h,long width_v,long page_h,long page_v) |
---|
390 | { |
---|
391 | char buffer[200]; |
---|
392 | |
---|
393 | sprintf(buffer,"window/%s/scroll_width_horizontal",awm->window_defaults_name); |
---|
394 | awm->get_root()->awar(buffer)->write_int(width_h); |
---|
395 | sprintf(buffer,"window/%s/scroll_width_vertical",awm->window_defaults_name); |
---|
396 | awm->get_root()->awar(buffer)->write_int(width_v); |
---|
397 | sprintf( buffer,"window/%s/horizontal_page_increment",awm->window_defaults_name); |
---|
398 | awm->get_root()->awar(buffer)->write_int(page_h); |
---|
399 | sprintf(buffer,"window/%s/vertical_page_increment",awm->window_defaults_name); |
---|
400 | awm->get_root()->awar(buffer)->write_int(page_v); |
---|
401 | } |
---|
402 | |
---|
403 | |
---|
404 | void DI_dmatrix::monitor_vertical_scroll_cb(AW_window *aww) { // draw area |
---|
405 | if (!device) return; |
---|
406 | |
---|
407 | long old_vert_page_start = vert_page_start; |
---|
408 | |
---|
409 | vert_last_view_start = aww->slider_pos_vertical; |
---|
410 | vert_page_start = aww->slider_pos_vertical/cell_height; |
---|
411 | |
---|
412 | long diff = vert_page_start-old_vert_page_start; |
---|
413 | if (diff) { |
---|
414 | int top_y = off_dy-cell_height; |
---|
415 | bool clear = false; |
---|
416 | |
---|
417 | if (diff>0 && diff<vert_page_size) { // scroll some positions up |
---|
418 | int keep_cells = vert_page_size-diff; |
---|
419 | |
---|
420 | device->move_region(0, top_y+diff*cell_height, screen_width, keep_cells*cell_height, 0, top_y); |
---|
421 | device->clear_part(0, top_y+keep_cells*cell_height, screen_width, diff*cell_height, -1); |
---|
422 | device->push_clip_scale(); |
---|
423 | device->set_top_clip_border((int)(top_y+keep_cells*cell_height)); |
---|
424 | } |
---|
425 | else if (diff>-vert_page_size && diff<0) { // scroll some positions down |
---|
426 | int keep_cells = vert_page_size+diff; |
---|
427 | |
---|
428 | device->move_region(0, top_y, screen_width, keep_cells*cell_height, 0, top_y+(-diff*cell_height)); |
---|
429 | device->clear_part(0, top_y, screen_width, cell_height*-diff, -1); |
---|
430 | device->push_clip_scale(); |
---|
431 | device->set_bottom_clip_border((int)(top_y+(-diff*cell_height))); |
---|
432 | } |
---|
433 | else { |
---|
434 | device->push_clip_scale(); |
---|
435 | clear = true; |
---|
436 | } |
---|
437 | |
---|
438 | display(clear); |
---|
439 | device->pop_clip_scale(); |
---|
440 | } |
---|
441 | } |
---|
442 | |
---|
443 | void DI_dmatrix::monitor_horizontal_scroll_cb(AW_window *aww) { // draw area |
---|
444 | if (!device) return; |
---|
445 | |
---|
446 | long old_horiz_page_start = horiz_page_start; |
---|
447 | |
---|
448 | horiz_last_view_start = aww->slider_pos_horizontal; |
---|
449 | horiz_page_start = aww->slider_pos_horizontal/cell_width; |
---|
450 | |
---|
451 | long diff = horiz_page_start-old_horiz_page_start; |
---|
452 | |
---|
453 | if (diff) { |
---|
454 | bool clear = false; |
---|
455 | |
---|
456 | if (diff>0 && diff<horiz_page_size) { // scroll some positions left |
---|
457 | int keep_cells = horiz_page_size-diff; |
---|
458 | |
---|
459 | device->move_region(off_dx+diff*cell_width, 0, keep_cells*cell_width, screen_height, off_dx, 0); |
---|
460 | device->clear_part(off_dx+keep_cells*cell_width, 0, diff*cell_width, screen_height, -1); |
---|
461 | device->push_clip_scale(); |
---|
462 | device->set_left_clip_border((int)(keep_cells*cell_width)); |
---|
463 | } |
---|
464 | else if (diff>-horiz_page_size && diff<0) { // scroll some positions right |
---|
465 | int keep_cells = horiz_page_size+diff; |
---|
466 | |
---|
467 | device->move_region(off_dx, 0, keep_cells*cell_width, screen_height, off_dx+cell_width*-diff, 0); |
---|
468 | device->clear_part(off_dx, 0, cell_width*-diff, screen_height, -1); |
---|
469 | device->push_clip_scale(); |
---|
470 | device->set_right_clip_border((int)(off_dx+cell_width*-diff)); |
---|
471 | } |
---|
472 | else { |
---|
473 | device->push_clip_scale(); |
---|
474 | clear = true; |
---|
475 | } |
---|
476 | |
---|
477 | display(clear); |
---|
478 | device->pop_clip_scale(); |
---|
479 | } |
---|
480 | } |
---|
481 | |
---|
482 | static int update_display_on_dist_change = 1; |
---|
483 | |
---|
484 | void di_view_set_max_d(AW_window *aww, AW_CL cl_max_d, AW_CL /*clmatr*/){ |
---|
485 | AWUSE(aww); |
---|
486 | double max_d = cl_max_d*0.01; |
---|
487 | AW_root *aw_root = aww->get_root(); |
---|
488 | |
---|
489 | update_display_on_dist_change = 0; |
---|
490 | aw_root->awar(AWAR_DIST_MIN_DIST)->write_float(0.0); |
---|
491 | update_display_on_dist_change = 1; |
---|
492 | aw_root->awar(AWAR_DIST_MAX_DIST)->write_float(max_d); |
---|
493 | } |
---|
494 | |
---|
495 | void di_view_set_distances(AW_root *awr, AW_CL cl_setmax, AW_CL cl_dmatrix) { |
---|
496 | // cl_dmatrix: 0 -> set min and fix max, 1 -> set max and fix min, 2 -> set both |
---|
497 | DI_dmatrix *dmatrix = (DI_dmatrix *)cl_dmatrix; |
---|
498 | double max_dist = awr->awar(AWAR_DIST_MAX_DIST)->read_float(); |
---|
499 | double min_dist = awr->awar(AWAR_DIST_MIN_DIST)->read_float(); |
---|
500 | int old = update_display_on_dist_change; |
---|
501 | |
---|
502 | update_display_on_dist_change = 0; |
---|
503 | |
---|
504 | switch (cl_setmax) { |
---|
505 | case 2: // both |
---|
506 | dmatrix->set_slider_max(max_dist); |
---|
507 | // fall-through |
---|
508 | case 0: // set min and fix max |
---|
509 | dmatrix->set_slider_min(min_dist); |
---|
510 | if (min_dist>max_dist) awr->awar(AWAR_DIST_MAX_DIST)->write_float(min_dist); |
---|
511 | break; |
---|
512 | case 1: // set max and fix min |
---|
513 | dmatrix->set_slider_max(max_dist); |
---|
514 | if (min_dist>max_dist) awr->awar(AWAR_DIST_MIN_DIST)->write_float(max_dist); |
---|
515 | break; |
---|
516 | |
---|
517 | default: |
---|
518 | di_assert(0); |
---|
519 | break; |
---|
520 | } |
---|
521 | |
---|
522 | update_display_on_dist_change = old; |
---|
523 | if (update_display_on_dist_change) dmatrix->display(true); |
---|
524 | } |
---|
525 | |
---|
526 | void di_change_dist(AW_window *aww, AW_CL cl_mode) { |
---|
527 | AW_root *awr = aww->get_root(); |
---|
528 | const char *awar_name; |
---|
529 | |
---|
530 | gb_assert(cl_mode>=0 && cl_mode<=3); |
---|
531 | |
---|
532 | if (cl_mode<2) { // change min |
---|
533 | awar_name = AWAR_DIST_MIN_DIST; |
---|
534 | } |
---|
535 | else { // change max |
---|
536 | awar_name = AWAR_DIST_MAX_DIST; |
---|
537 | } |
---|
538 | |
---|
539 | double dist = awr->awar(awar_name)->read_float(); |
---|
540 | double increment = 0.01; |
---|
541 | |
---|
542 | if (cl_mode%2) increment = -increment; // decrement value |
---|
543 | dist += increment; |
---|
544 | if (!(dist<0)) awr->awar(awar_name)->write_float(dist); |
---|
545 | } |
---|
546 | |
---|
547 | static void di_bind_dist_awars(AW_root *aw_root, DI_dmatrix *dmatrix) { |
---|
548 | aw_root->awar_float(AWAR_DIST_MIN_DIST)->add_callback(di_view_set_distances, 0, (AW_CL)dmatrix); |
---|
549 | aw_root->awar_float(AWAR_DIST_MAX_DIST)->add_callback(di_view_set_distances, 1, (AW_CL)dmatrix); |
---|
550 | } |
---|
551 | |
---|
552 | AW_window *DI_create_view_matrix_window(AW_root *awr, DI_dmatrix *dmatrix){ |
---|
553 | di_bind_dist_awars(awr, dmatrix); |
---|
554 | AW_window_menu *awm = new AW_window_menu(); |
---|
555 | awm->init(awr,"SHOW_MATRIX", "ARB_SHOW_MATRIX", 800,600); |
---|
556 | |
---|
557 | dmatrix->device = awm->get_device(AW_MIDDLE_AREA); |
---|
558 | dmatrix->awm = awm; |
---|
559 | |
---|
560 | awm->set_vertical_change_callback ((AW_CB2)vertical_change_cb, (AW_CL)dmatrix, 0); |
---|
561 | awm->set_horizontal_change_callback((AW_CB2)horizontal_change_cb, (AW_CL)dmatrix, 0); |
---|
562 | awm->set_focus_callback ((AW_CB) redisplay_needed, (AW_CL)dmatrix, 0); |
---|
563 | |
---|
564 | awm->set_resize_callback(AW_MIDDLE_AREA, (AW_CB2)resize_needed, (AW_CL)dmatrix, 0); |
---|
565 | awm->set_expose_callback(AW_MIDDLE_AREA, (AW_CB2)redisplay_needed, (AW_CL)dmatrix, 0); |
---|
566 | awm->set_input_callback (AW_MIDDLE_AREA, (AW_CB) input_cb, (AW_CL)dmatrix, 0); |
---|
567 | awm->set_motion_callback(AW_MIDDLE_AREA, (AW_CB) motion_cb, (AW_CL)dmatrix, 0); |
---|
568 | |
---|
569 | AW_gc_manager preset_window = |
---|
570 | AW_manage_GC (awm,dmatrix->device, DI_G_STANDARD, DI_G_LAST, AW_GCM_DATA_AREA, |
---|
571 | (AW_CB)resize_needed,(AW_CL)dmatrix,0, |
---|
572 | false, |
---|
573 | "#D0D0D0", |
---|
574 | "#Standard$#000000", |
---|
575 | "#Names$#000000", |
---|
576 | "+-Ruler$#555", "-Display$#00AA55", |
---|
577 | "#BelowDist$#008732", |
---|
578 | "#AboveDist$#DB008D", |
---|
579 | NULL); |
---|
580 | |
---|
581 | awm->create_menu("File","F"); |
---|
582 | awm->insert_menu_topic("save_matrix", "Save Matrix to File", "S","save_matrix.hlp", AWM_ALL, AW_POPUP, (AW_CL)DI_create_save_matrix_window, (AW_CL)AWAR_DIST_SAVE_MATRIX_BASE); |
---|
583 | awm->insert_menu_topic("close", "Close", "C",0, AWM_ALL, (AW_CB)AW_POPDOWN, (AW_CL)0, 0 ); |
---|
584 | |
---|
585 | awm->create_menu("Props","P"); |
---|
586 | awm->insert_menu_topic("props_matrix", "Matrix: Colors and Fonts ...", "C","neprops_data.hlp" , AWM_ALL, AW_POPUP, (AW_CL)AW_create_gc_window, (AW_CL)preset_window ); |
---|
587 | awm->insert_menu_topic("show_dist_as_ascii", "Show Dist in Ascii", "A",0 , AWM_ALL, di_view_set_max_d, 0, (AW_CL)dmatrix ); |
---|
588 | awm->insert_menu_topic("show_dist_010", "Show Dist [0,0.1]", "1",0 , AWM_ALL, di_view_set_max_d, 10, (AW_CL)dmatrix ); |
---|
589 | awm->insert_menu_topic("show_dist_025", "Show Dist [0,0.25]", "3",0 , AWM_ALL, di_view_set_max_d, 25, (AW_CL)dmatrix ); |
---|
590 | awm->insert_menu_topic("show_dist_050", "Show Dist [0,0.5]", "5",0 , AWM_ALL, di_view_set_max_d, 50, (AW_CL)dmatrix ); |
---|
591 | awm->insert_menu_topic("show_dist_100", "Show Dist [0,1.0]", "0",0 , AWM_ALL, di_view_set_max_d, 100, (AW_CL)dmatrix ); |
---|
592 | |
---|
593 | int x, y; |
---|
594 | awm->get_at_position(&x, &y); |
---|
595 | awm->button_length(3); |
---|
596 | |
---|
597 | #define FIELD_XSIZE 160 |
---|
598 | #define BUTTON_XSIZE 25 |
---|
599 | |
---|
600 | awm->label("Dist min:"); |
---|
601 | awm->create_input_field(AWAR_DIST_MIN_DIST, 7); |
---|
602 | x += FIELD_XSIZE; |
---|
603 | |
---|
604 | awm->at_x(x); |
---|
605 | awm->callback(di_change_dist, 0); |
---|
606 | awm->create_button("PLUS_MIN", "+"); |
---|
607 | x += BUTTON_XSIZE; |
---|
608 | |
---|
609 | awm->at_x(x); |
---|
610 | awm->callback(di_change_dist, 1); |
---|
611 | awm->create_button("MINUS_MIN", "-"); |
---|
612 | x += BUTTON_XSIZE; |
---|
613 | |
---|
614 | awm->at_x(x); |
---|
615 | awm->label("Dist max:"); |
---|
616 | awm->create_input_field(AWAR_DIST_MAX_DIST, 7); |
---|
617 | x += FIELD_XSIZE; |
---|
618 | |
---|
619 | awm->at_x(x); |
---|
620 | awm->callback(di_change_dist, 2); |
---|
621 | awm->create_button("PLUS_MAX", "+"); |
---|
622 | x += BUTTON_XSIZE; |
---|
623 | |
---|
624 | awm->at_x(x); |
---|
625 | awm->callback(di_change_dist, 3); |
---|
626 | awm->create_button("MINUS_MAX", "-"); |
---|
627 | x += BUTTON_XSIZE; |
---|
628 | |
---|
629 | awm->set_info_area_height(40); |
---|
630 | |
---|
631 | dmatrix->init(dmatrix->di_matrix); |
---|
632 | |
---|
633 | di_view_set_distances(awm->get_root(), 2, AW_CL(dmatrix)); |
---|
634 | |
---|
635 | return (AW_window *)awm; |
---|
636 | } |
---|