ARB
DI_view_matrix.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : DI_view_matrix.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include "di_view_matrix.hxx"
12 
13 #include <aw_awars.hxx>
14 #include <aw_preset.hxx>
15 #include <aw_msg.hxx>
16 #include <aw_root.hxx>
17 
18 #include <awt_canvas.hxx>
19 
20 #include <arb_algo.h>
21 #include <awt_config_manager.hxx>
22 
23 #define AWAR_MATRIX "matrix/"
24 #define AWAR_MATRIX_PADDINGX AWAR_MATRIX "paddingx"
25 #define AWAR_MATRIX_PADDINGY AWAR_MATRIX "paddingy"
26 #define AWAR_MATRIX_SHOWZERO AWAR_MATRIX "show_zero"
27 #define AWAR_MATRIX_DIGITS AWAR_MATRIX "show_digits"
28 #define AWAR_MATRIX_NAMECHARS_TOP AWAR_MATRIX "namechars_top"
29 #define AWAR_MATRIX_NAMECHARS_LEFT AWAR_MATRIX "namechars_left"
30 
31 static void vertical_change_cb (AW_window *aww, MatrixDisplay *disp) { disp->monitor_vertical_scroll_cb(aww); }
33 
34 static void redisplay_needed(UNFIXED, MatrixDisplay *disp) {
36  disp->update_display();
37 }
38 
39 static void reinit_needed(UNFIXED, MatrixDisplay *disp) {
41  disp->update_display();
42 }
43 
44 static void resize_needed(UNFIXED, MatrixDisplay *disp) {
45  disp->mark(MatrixDisplay::NEED_SETUP); // @@@ why not NEED_RESIZE?
46  disp->update_display();
47 }
48 
49 static void gc_changed_cb(GcChange whatChanged, MatrixDisplay *disp) {
50  switch (whatChanged) {
52  di_assert(0); // not used atm
53  FALLTHROUGH; // in NDEBUG
54  case GC_COLOR_CHANGED:
55  redisplay_needed(NULp, disp);
56  break;
57  case GC_FONT_CHANGED:
58  resize_needed(NULp, disp);
59  break;
60  }
61 }
62 
63 void MatrixDisplay::setup() {
64  DI_MATRIX *m = get_matrix();
65  AW_root *awr = awm->get_root();
66 
67  leadZero = awr->awar(AWAR_MATRIX_SHOWZERO)->read_int();
68  digits = awr->awar(AWAR_MATRIX_DIGITS)->read_int();
69 
70  sprintf(format_string, "%%%i.%if", digits+2, digits);
71 
72  // calculate cell width and height
73  {
74  cell_width = 0;
75  cell_height = 0;
76 
77  int max_chars[DI_G_LAST+1];
78  memset(max_chars, 0, sizeof(*max_chars)*(DI_G_LAST+1));
79 
80  max_chars[DI_G_STANDARD] = leadZero+2; // standard cell contains "0.0", "1.0" or "---"
81  max_chars[DI_G_BELOW_DIST] = leadZero+1+digits; // size of numeric distance
82  max_chars[DI_G_ABOVE_DIST] = max_chars[DI_G_BELOW_DIST];
83  max_chars[DI_G_NAMES] = awr->awar(AWAR_MATRIX_NAMECHARS_TOP)->read_int();
84 
85  for (int igc=DI_G_STANDARD; igc<=DI_G_LAST; ++igc) {
86  DI_gc gc = DI_gc(igc);
87  if (max_chars[gc]) {
88  const AW_font_limits& lim = device->get_font_limits(gc, 0);
89 
90  cell_width = std::max(cell_width, lim.width*max_chars[gc]);
91  cell_height = std::max(cell_height, int(lim.get_height()));
92  }
93  }
94 
95  {
96  // ensure cell-dimensions are > 0
97  AW_awar *pad_awarx = awr->awar(AWAR_MATRIX_PADDINGX);
98  AW_awar *pad_awary = awr->awar(AWAR_MATRIX_PADDINGY);
99 
100  cell_paddx = pad_awarx->read_int();
101  cell_paddy = pad_awary->read_int();
102 
103  if (cell_paddx<0 && -cell_paddx >= cell_width) {
104  cell_paddx = -cell_width+1;
105  pad_awarx->write_int(cell_paddx);
106  }
107  if (cell_paddy<0 && -cell_paddy >= cell_height) {
108  cell_paddy = -cell_height+1;
109  pad_awary->write_int(cell_paddy);
110  }
111  }
112 
113  cell_width += cell_paddx;
114  cell_height += cell_paddy;
115  }
116 
117  {
119 
120  off_dx = awr->awar(AWAR_MATRIX_NAMECHARS_LEFT)->read_int() * lim.width + 1 + cell_paddx;
121  off_dy = lim.get_height() + cell_height; // off_dy corresponds to "lower" y of cell
122  }
123 
124  if (m) {
125  total_cells_horiz=m->nentries;
126  total_cells_vert=m->nentries;
127  }
128  set_scrollbar_steps(cell_width, cell_height, 50, 50);
129 
130  mark(NEED_RESIZE);
131 }
132 
133 void MatrixDisplay::adapt_to_canvas_size() {
135 
136  DI_MATRIX *m = get_matrix();
137  long n = 0;
138 
139  if (m) n = m->nentries;
140 
141  const AW_screen_area& squ = device->get_area_size();
142  screen_width = squ.r-squ.l;
143  screen_height = squ.b-squ.t;
144 
145  AW_screen_area rect; // @@@ used uninitialized if !m
146  if (m) {
147  long horiz_paint_size = (squ.r-lim.width-off_dx)/cell_width;
148  long vert_paint_size = (squ.b-off_dy)/cell_height;
149 
150  horiz_page_size = (n > horiz_paint_size) ? horiz_paint_size : n;
151  vert_page_size = (n > vert_paint_size) ? vert_paint_size : n;
152 
153  rect.l = 0;
154  rect.t = 0;
155  rect.r = (int)((n-horiz_page_size)*cell_width+squ.r);
156  rect.b = (int)((n-vert_page_size)*cell_height+squ.b);
157  }
158  else {
159  horiz_page_size = 0;
160  vert_page_size = 0;
161  }
162 
163  horiz_page_start = 0;
164  horiz_last_view_start = 0;
165  vert_page_start = 0;
166  vert_last_view_start = 0;
167 
168  device->reset(); // clip_size == device_size
169  device->clear(-1);
170  device->set_right_clip_border((int)(off_dx+cell_width*horiz_page_size));
171  device->reset(); // reset shift_x and shift_y
176 
177  mark(NEED_CLEAR);
178 }
179 
183 };
184 
185 #define MINMAX_GRANULARITY 10000L
186 
187 void MatrixDisplay::scroll_to(int sxpos, int sypos) {
188  sxpos = force_in_range(0, sxpos, int(awm->get_scrolled_picture_width())-screen_width);
189  sypos = force_in_range(0, sypos, int(awm->get_scrolled_picture_height())-screen_height);
190 
193 
196 }
197 
198 void MatrixDisplay::scroll_cells(int cells_x, int cells_y) {
199  scroll_to(awm->slider_pos_horizontal + cells_x*cell_width,
200  awm->slider_pos_vertical + cells_y*cell_height);
201 }
202 
204  static int clickx, clicky; // original click pos
205  static int startx, starty; // original slider position
206 
207  if (event.type == AW_Mouse_Press) {
208  clickx = event.x;
209  clicky = event.y;
210 
211  startx = awm->slider_pos_horizontal;
212  starty = awm->slider_pos_vertical;
213  }
214  else if (event.type == AW_Mouse_Drag || event.type == AW_Mouse_Release) {
215  int x_screen_diff = clickx - event.x;
216  int y_screen_diff = clicky - event.y;
217 
218  scroll_to(startx + x_screen_diff, starty + y_screen_diff);
219  }
220 }
221 
222 static void motion_cb(AW_window *aww, MatrixDisplay *disp) {
223  AW_event event;
224  aww->get_event(&event);
225 
226  if (event.button == AW_BUTTON_MIDDLE) {
227  disp->handle_move(event);
228  }
229 }
230 
231 static void input_cb(AW_window *aww, MatrixDisplay *disp) {
232  AW_event event;
233  aww->get_event(&event);
234 
235  if (event.button == AW_WHEEL_UP || event.button == AW_WHEEL_DOWN) {
236  if (event.type == AW_Mouse_Press) {
237  bool horizontal = event.keymodifier & AW_KEYMODE_ALT;
238  int direction = event.button == AW_WHEEL_UP ? -1 : 1;
239  disp->scroll_cells(horizontal*direction, !horizontal*direction);
240  }
241  }
242  else if (event.button == AW_BUTTON_MIDDLE) {
243  disp->handle_move(event);
244  }
245  else {
246  AW_device_click *click_device = aww->get_click_device(AW_MIDDLE_AREA, event.x, event.y, AWT_CATCH);
247 
248  click_device->set_filter(AW_CLICK);
249  click_device->reset();
250 
251  {
252  AW_device *oldMatrixDevice = disp->device;
253 
254  disp->device = click_device;
255  disp->update_display(); // detect clicked element
256  disp->device = oldMatrixDevice;
257  }
258 
259  if (event.type == AW_Mouse_Press) {
260  AWT_graphic_event gevent(AWT_MODE_NONE, event, false, click_device);
261  const AW_clicked_element *clicked = gevent.best_click();
262 
263  if (clicked) {
264  ClickAction action = static_cast<ClickAction>(clicked->cd1());
265 
266  if (action == CLICK_SELECT_SPECIES) {
267  size_t idx = size_t(clicked->cd2());
268  DI_MATRIX *matrix = disp->get_matrix();
269  if (idx >= matrix->nentries) {
270  aw_message(GBS_global_string("Illegal idx %zi [allowed: 0-%zi]", idx, matrix->nentries));
271  }
272  else {
273  DI_ENTRY *entry = matrix->entries[idx];
274  const char *species_name = entry->name;
275 
276  aww->get_root()->awar(AWAR_SPECIES_NAME)->write_string(species_name);
277  }
278  }
279  else if (action == CLICK_SET_MINMAX) {
280  AW_root *aw_root = aww->get_root();
281  AW_awar *awar_bound = NULp;
282 
283  switch (event.button) {
284  case AW_BUTTON_LEFT: awar_bound = aw_root->awar(AWAR_DIST_MIN_DIST); break;
285  case AW_BUTTON_RIGHT: awar_bound = aw_root->awar(AWAR_DIST_MAX_DIST); break;
286  default: break;
287  }
288 
289  if (awar_bound) {
290  float val = float(clicked->cd2())/MINMAX_GRANULARITY;
291  awar_bound->write_float(val);
292  }
293  }
294  }
295  }
296  }
297 }
298 
299 void MatrixDisplay::draw() {
300  // draw matrix
301 
302  if (!device) return;
303 
304  long x, y, xpos, ypos;
305 
306  DI_MATRIX *m = get_matrix();
307  if (!autopop(m)) return;
308 
309  GB_transaction ta(gb_main);
310 
311  if (beforeUpdate&NEED_CLEAR) device->clear(-1);
312  device->set_offset(AW::Vector(off_dx, off_dy));
313  xpos = 0;
314 
315  char *selSpecies = NULp;
316  if (awm) selSpecies = awm->get_root()->awar(AWAR_SPECIES_NAME)->read_string();
317 
318  int name_display_width_top;
319  int name_display_width_left;
320  {
322 
323  name_display_width_top = (cell_width-1)/lim.width;
324  name_display_width_left = (off_dx-1)/lim.width;
325  }
326 
327  int BUFLEN = std::max(200, std::max(name_display_width_left, name_display_width_top));
328  char buf[BUFLEN];
329 
330  int sel_x_pos = -1;
331 
332  // device->set_line_attributes(DI_G_RULER, 1, AW_SOLID); // @@@ try AW_DOTTED here (need merges from dev!)
333 
334  for (x = horiz_page_start;
335  x < (horiz_page_start + horiz_page_size) && (x < total_cells_horiz);
336  x++)
337  {
338  ypos = 0;
339  for (y = vert_page_start;
340  y < (vert_page_start + vert_page_size) && (y < total_cells_vert);
341  y++)
342  {
343  bool is_identity = (x == y);
344 
345  // lower(!) left corner of cell:
346  AW_pos cellx = xpos*cell_width;
347  AW_pos celly = ypos*cell_height;
348 
349  if (is_identity) {
350  device->text(DI_G_STANDARD, "---"+(1-leadZero), cellx, celly);
351  }
352  else {
353  double val2 = m->matrix->get(x, y);
355 
356  if (val2>=min_view_dist && val2<=max_view_dist) { // display ruler
357  int maxw = cell_width-cell_paddx;
358 
359  int h = cell_height - cell_paddy-1;
360 
361  int hbox, hruler;
362  if (cell_paddy >= 0) {
363  hbox = h*2/3;
364  hruler = h-hbox;
365  }
366  else {
367  hbox = h;
368  hruler = 0;
369  }
370 
371  int y1 = celly - h;
372  int y2 = y1+hbox;
373  int y3 = y2+hruler/2;
374  int y4 = y2+hruler;
375  int x2 = cellx;
376 
377  double len = ((val2-min_view_dist)/(max_view_dist-min_view_dist)) * maxw;
378  if (len >= 0) {
379  device->box(DI_G_RULER_DISPLAY, AW::FillStyle::SOLID, x2, y1, int(len+0.5), hbox);
380  }
381  else {
382  device->text(DI_G_STANDARD, "???", cellx, celly);
383  }
384 
385  if (hruler) { // do not paint ruler if cell_paddy is negative
386  double v;
387  int cnt;
388  int maxx = x2+maxw-1;
389  for (v = x2, cnt = 0; v < x2 + maxw; v += maxw * .24999, ++cnt) {
390  int xr = std::min(int(v+0.5), maxx);
391  device->line(DI_G_RULER, xr, (cnt&1) ? y3 : y2, xr, y4);
392  }
393  device->line(DI_G_RULER, x2, y4, maxx, y4);
394  }
395  }
396  else {
397  DI_gc gc;
398  if (val2 == 0.0) {
399  strcpy(buf, "0.0");
400  gc = DI_G_STANDARD;
401  }
402  else if (val2 == 1.0) {
403  strcpy(buf, leadZero ? "1.0" : " 1");
404  gc = DI_G_STANDARD;
405  }
406  else {
407  sprintf(buf, format_string, val2);
408  gc = val2<min_view_dist ? DI_G_BELOW_DIST : DI_G_ABOVE_DIST;
409  }
410  device->text(gc, leadZero ? buf : buf+1, cellx, celly);
411  }
412  }
413  ypos++;
414  }
415 
416  // display horizontal (top) speciesnames:
417  strcpy(buf, m->entries[x]->name);
418  if (selSpecies && strcmp(buf, selSpecies) == 0) sel_x_pos = xpos; // remember x-position for selected species
419  buf[name_display_width_top] = 0; // cut group-names if too long
420 
422  device->text(DI_G_NAMES, buf, xpos * cell_width, cell_height - off_dy);
423 
424  xpos++;
425  }
426 
427  device->set_offset(AW::Vector(off_dx, 0));
428 
430 
431  // highlight selected species (vertically)
432  if (sel_x_pos != -1) {
433  AW_pos linex1 = sel_x_pos*cell_width - cell_paddx/2-1;
434  AW_pos linex2 = linex1+cell_width;
435  AW_pos height = area.height();
436  device->line(DI_G_STANDARD, linex1, 0, linex1, height);
437  device->line(DI_G_STANDARD, linex2, 0, linex2, height);
438  }
439 
440  device->set_offset(AW::Vector(0, off_dy));
441 
442  // display vertical (left) speciesnames
443  ypos = 0;
444  int sel_y_pos = -1;
445  for (y = vert_page_start; y < vert_page_start + vert_page_size; y++) {
446  strcpy(buf, m->entries[y]->name);
447  if (selSpecies && strcmp(buf, selSpecies) == 0) sel_y_pos = ypos; // remember x-position for selected species
448  buf[name_display_width_left] = 0; // cut group-names if too long
450  device->text(DI_G_NAMES, buf, 0, ypos * cell_height);
451  ypos++;
452  }
453 
454  // highlight selected species (horizontally)
455  if (sel_y_pos != -1) {
456  AW_pos liney2 = sel_y_pos*cell_height + cell_paddy/2+1;
457  AW_pos liney1 = liney2-cell_height;
458  AW_pos width = area.width();
459  device->line(DI_G_STANDARD, 0, liney1, width, liney1);
460  device->line(DI_G_STANDARD, 0, liney2, width, liney2);
461  }
462 
463  free(selSpecies);
464 
465  device->set_offset(AW::Vector(0, 0));
466 #undef BUFLEN
467 }
468 
469 void MatrixDisplay::set_scrollbar_steps(long width_h, long width_v, long page_h, long page_v) {
470  awm->window_local_awar("scroll_width_horizontal")->write_int(width_h);
471  awm->window_local_awar("scroll_width_vertical")->write_int(width_v);
472  awm->window_local_awar("horizontal_page_increment")->write_int(page_h);
473  awm->window_local_awar("vertical_page_increment")->write_int(page_v);
474 }
475 
476 #if defined(WARN_TODO)
477 #warning test scrolling again with fixed box_impl()
478 #endif
479 
481  if (!device) return;
482 
483  int old_vert_page_start = vert_page_start;
484 
485  vert_last_view_start = aww->slider_pos_vertical;
486  vert_page_start = aww->slider_pos_vertical/cell_height;
487 
488  int diff = vert_page_start-old_vert_page_start; // amount of rows to scroll
489  if (diff) {
490  int diff_pix = abs(diff)*cell_height;
491  int top_y = off_dy-cell_height;
492  int keep_cells = vert_page_size-abs(diff);
493  int keep_pix = keep_cells*cell_height;
494 
495  if (diff>0 && diff<vert_page_size) { // scroll some positions up
496  device->move_region(0, top_y+diff_pix, screen_width, keep_pix, 0, top_y);
497  device->clear_part (0, top_y+keep_pix, screen_width, diff_pix, AW_SCREEN);
499  device->set_top_clip_border(top_y+keep_pix, true);
500  }
501  else if (diff>-vert_page_size && diff<0) { // scroll some positions down
502  device->move_region(0, top_y, screen_width, keep_pix, 0, top_y+diff_pix);
503  device->clear_part (0, top_y, screen_width, diff_pix, AW_SCREEN);
505  device->set_bottom_clip_border(top_y+diff_pix, true);
506  }
507  else { // repaint
509  mark(NEED_CLEAR);
510  }
511 
512  update_display();
514  }
515 }
516 
518  if (!device) return;
519 
520  int old_horiz_page_start = horiz_page_start;
521 
522  horiz_last_view_start = aww->slider_pos_horizontal;
523  horiz_page_start = aww->slider_pos_horizontal/cell_width;
524 
525  int diff = horiz_page_start-old_horiz_page_start; // amount of columns to scroll
526 
527  if (diff) {
528  int diff_pix = abs(diff)*cell_width;
529  int keep_cells = horiz_page_size-abs(diff);
530  int keep_pix = keep_cells*cell_width;
531 
532  if (diff>0 && diff<horiz_page_size) { // scroll some positions left
533  device->move_region(off_dx+diff_pix, 0, keep_pix, screen_height, off_dx, 0);
534  device->clear_part (off_dx+keep_pix, 0, diff_pix, screen_height, AW_SCREEN);
536  device->set_left_clip_border(keep_pix, true);
537  }
538  else if (diff>-horiz_page_size && diff<0) { // scroll some positions right
539  device->move_region(off_dx, 0, keep_pix, screen_height, off_dx+diff_pix, 0);
540  device->clear_part (off_dx, 0, diff_pix, screen_height, AW_SCREEN);
542  device->set_right_clip_border(off_dx+diff_pix, true);
543  }
544  else { // repaint
546  mark(NEED_CLEAR);
547  }
548 
549  update_display();
551  }
552 }
553 
554 static bool update_display_on_dist_change = true;
555 
556 static void di_view_set_max_dist(AW_window *aww, int max_dist) {
557  AW_root *aw_root = aww->get_root();
558  {
559  LocallyModify<bool> flag(update_display_on_dist_change, false);
560  aw_root->awar(AWAR_DIST_MIN_DIST)->write_float(0.0);
561  }
562  aw_root->awar(AWAR_DIST_MAX_DIST)->write_float(max_dist*0.01);
563 }
564 
565 static void di_view_set_distances(AW_root *awr, int setmax, MatrixDisplay *disp) {
566  // cl_dmatrix: 0 -> set min and fix max, 1 -> set max and fix min, 2 -> set both
567  float max_dist = awr->awar(AWAR_DIST_MAX_DIST)->read_float();
568  float min_dist = awr->awar(AWAR_DIST_MIN_DIST)->read_float();
569 
570  {
571  LocallyModify<bool> flag(update_display_on_dist_change, false);
572 
573  switch (setmax) {
574  case 2: // both
575  disp->set_slider_max(max_dist);
576  // fall-through
577  case 0: // set min and fix max
578  disp->set_slider_min(min_dist);
579  if (min_dist>max_dist) awr->awar(AWAR_DIST_MAX_DIST)->write_float(min_dist);
580  break;
581  case 1: // set max and fix min
582  disp->set_slider_max(max_dist);
583  if (min_dist>max_dist) awr->awar(AWAR_DIST_MIN_DIST)->write_float(max_dist);
584  break;
585 
586  default:
587  di_assert(0);
588  break;
589  }
590  }
591  if (update_display_on_dist_change) {
593  disp->update_display();
594  }
595 }
596 
597 static void di_bind_dist_awars(AW_root *aw_root, MatrixDisplay *disp) {
598  aw_root->awar_float(AWAR_DIST_MIN_DIST)->add_callback(makeRootCallback(di_view_set_distances, 0, disp));
599  aw_root->awar_float(AWAR_DIST_MAX_DIST)->add_callback(makeRootCallback(di_view_set_distances, 1, disp));
600 }
601 
602 static void create_matrix_awars(AW_root *awr, MatrixDisplay *disp) {
603  RootCallback reinit_needed_cb = makeRootCallback(reinit_needed, disp);
604 
605  awr->awar_int(AWAR_MATRIX_SHOWZERO, 1) ->add_callback(reinit_needed_cb);
606  awr->awar_int(AWAR_MATRIX_PADDINGX, 4) ->set_minmax(-10, 10)->add_callback(reinit_needed_cb);
607  awr->awar_int(AWAR_MATRIX_PADDINGY, 4) ->set_minmax(-10, 10)->add_callback(reinit_needed_cb);
608  awr->awar_int(AWAR_MATRIX_DIGITS, 4) ->set_minmax(0, 10) ->add_callback(reinit_needed_cb);
609  awr->awar_int(AWAR_MATRIX_NAMECHARS_TOP, 8) ->set_minmax(0, 10) ->add_callback(reinit_needed_cb);
610  awr->awar_int(AWAR_MATRIX_NAMECHARS_LEFT, 10)->set_minmax(0, 10) ->add_callback(reinit_needed_cb);
611 }
612 
614  { AWAR_MATRIX_PADDINGX, "paddingx" },
615  { AWAR_MATRIX_PADDINGY, "paddingy" },
616  { AWAR_MATRIX_SHOWZERO, "showzero" },
617  { AWAR_MATRIX_DIGITS, "precision" },
618  { AWAR_MATRIX_NAMECHARS_TOP, "namechars_top" },
619  { AWAR_MATRIX_NAMECHARS_LEFT, "namechars_left" },
620 
621  { NULp, NULp }
622 };
623 
625  { "*compact", "Compact matrix view\n- use with fontsize=8\n- use without correction only (hides leading digits)", "namechars_left='10';namechars_top='3';paddingx='-3';paddingy='-2';precision='2';showzero='0'" },
626  { NULp, NULp, NULp }
627 };
628 
630  AW_window_simple *aws = new AW_window_simple;
631  aws->init(awr, "MATRIX_SETTINGS", "Matrix settings");
632 
633  const int FIELDWIDTH = 3;
634  const int SCALERWIDTH = 200;
635 
636  aws->auto_space(10, 10);
637 
638  aws->callback(AW_POPDOWN);
639  aws->create_button("CLOSE", "CLOSE", "C");
640 
641  aws->callback(makeHelpCallback("matrix_settings.hlp"));
642  aws->create_button("HELP", "HELP");
643 
644  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "matrix_settings", matrixConfigMapping, NULp, predefinedMatrixConfig);
645 
646  aws->label_length(21);
647 
648  aws->at_newline();
649  aws->label("X-padding (pixels)");
650  aws->create_input_field_with_scaler(AWAR_MATRIX_PADDINGX, FIELDWIDTH, SCALERWIDTH);
651 
652  aws->at_newline();
653  aws->label("Y-padding (pixels)");
654  aws->create_input_field_with_scaler(AWAR_MATRIX_PADDINGY, FIELDWIDTH, SCALERWIDTH);
655 
656  aws->at_newline();
657  aws->label("Show leading zero");
658  aws->create_toggle(AWAR_MATRIX_SHOWZERO);
659 
660  aws->at_newline();
661  aws->label("Precision (digits)");
662  aws->create_input_field_with_scaler(AWAR_MATRIX_DIGITS, FIELDWIDTH, SCALERWIDTH);
663 
664  aws->at_newline();
665  aws->label("Min. namechars (top)");
666  aws->create_input_field_with_scaler(AWAR_MATRIX_NAMECHARS_TOP, FIELDWIDTH, SCALERWIDTH);
667 
668  aws->at_newline();
669  aws->label("Min. namechars (left)");
670  aws->create_input_field_with_scaler(AWAR_MATRIX_NAMECHARS_LEFT, FIELDWIDTH, SCALERWIDTH);
671 
672  aws->window_fit();
673  return aws;
674 }
675 
677  if (disp) redisplay_needed(NULp, disp);
678 }
679 
681  di_bind_dist_awars(awr, disp);
682  create_matrix_awars(awr, disp);
683 
685  awm->init(awr, "SHOW_MATRIX", "ARB distance matrix", 800, 600);
686 
687  disp->device = awm->get_device(AW_MIDDLE_AREA);
688  disp->awm = awm;
689 
690  awr->awar(AWAR_SPECIES_NAME)->add_callback(makeRootCallback(selected_species_changed_cb, disp));
691 
692  awm->set_vertical_change_callback (makeWindowCallback(vertical_change_cb, disp));
693  awm->set_horizontal_change_callback(makeWindowCallback(horizontal_change_cb, disp));
694 
695  awm->set_resize_callback(AW_MIDDLE_AREA, makeWindowCallback(resize_needed, disp));
696  awm->set_expose_callback(AW_MIDDLE_AREA, makeWindowCallback(redisplay_needed, disp));
697  awm->set_input_callback (AW_MIDDLE_AREA, makeWindowCallback(input_cb, disp));
698  awm->set_motion_callback(AW_MIDDLE_AREA, makeWindowCallback(motion_cb, disp));
699 
700  AW_gc_manager *gc_manager =
701  AW_manage_GC(awm,
702  awm->get_window_id(),
704  makeGcChangedCallback(gc_changed_cb, disp),
705  "#D0D0D0",
706  "#Standard$#000000",
707  "#Names$#000000",
708  "+-Ruler$#555", "-Display$#00AA55",
709  "#BelowDist$#008732",
710  "#AboveDist$#DB008D",
711  NULp);
712 
713  awm->create_menu("File", "F");
714  awm->insert_menu_topic("save_matrix", "Save Matrix to File", "S", "save_matrix.hlp", AWM_ALL, makeCreateWindowCallback(DI_create_save_matrix_window, sparam));
715  awm->insert_menu_topic("close", "Close", "C", NULp, AWM_ALL, AW_POPDOWN);
716 
717  awm->create_menu("Range", "R");
718  awm->insert_menu_topic("deselect_range", "Deselect range", "D", NULp, AWM_ALL, makeWindowCallback(di_view_set_max_dist, 0));
719  awm->insert_menu_topic("show_dist_species", "Species range [ <= 2% ]", "S", NULp, AWM_ALL, makeWindowCallback(di_view_set_max_dist, 2));
720  awm->insert_menu_topic("show_dist_genus", "Genus range [ <= 5% ]", "G", NULp, AWM_ALL, makeWindowCallback(di_view_set_max_dist, 5));
721  awm->insert_menu_topic("show_dist_010", "Range [ <= 10% ]", "1", NULp, AWM_ALL, makeWindowCallback(di_view_set_max_dist, 10));
722  awm->insert_menu_topic("show_dist_025", "Range [ <= 25% ]", "2", NULp, AWM_ALL, makeWindowCallback(di_view_set_max_dist, 25));
723  awm->insert_menu_topic("show_dist_050", "Range [ <= 50% ]", "5", NULp, AWM_ALL, makeWindowCallback(di_view_set_max_dist, 50));
724  awm->insert_menu_topic("show_dist_100", "Whole range [ 0-100% ]", "0", NULp, AWM_ALL, makeWindowCallback(di_view_set_max_dist, 100));
725 
726  awm->create_menu("Properties", "P");
727  awm->insert_menu_topic("matrix_settings", "Settings ...", "S", "matrix_settings.hlp", AWM_ALL, create_matrix_settings_window);
728  awm->insert_menu_topic("matrix_colors", "Colors and Fonts ...", "C", "color_props.hlp", AWM_ALL, makeCreateWindowCallback(AW_create_gc_window, gc_manager));
729  awm->insert_menu_topic("save_props", "Save Properties (dist.arb)", "P", "savedef.hlp", AWM_ALL, AW_save_properties);
730 
731 #define FIELD_SIZE 7
732 #define SCALER_SIZE 200
733 
734  awm->auto_space(5, 5);
735 
738 
739  awm->set_info_area_height(35);
740 
741  di_view_set_distances(awm->get_root(), 2, disp);
742 
743  return awm;
744 }
void monitor_vertical_scroll_cb(AW_window *)
virtual void clear(AW_bitset filteri)
Definition: AW_device.cxx:313
void set_resize_callback(AW_area area, const WindowCallback &wcb)
Definition: AW_window.cxx:813
void handle_move(AW_event &event)
const AW_bitset AW_SCREEN
Definition: aw_device.hxx:34
AW_pos get_scrolled_picture_height() const
Definition: AW_window.cxx:838
AW_device * get_device(AW_area area)
Definition: AW_window.cxx:534
short get_height() const
const AW_screen_area & get_area_size() const
Definition: AW_device.cxx:57
static void vertical_change_cb(AW_window *aww, MatrixDisplay *disp)
static char * y[maxsp+1]
void insert_menu_topic(const char *id, const char *name, const char *mnemonic, const char *help_text_, AW_active mask, const WindowCallback &wcb)
Definition: AW_window.cxx:592
void set_left_clip_border(int left, bool allow_oversize=false)
const char * get_window_id() const
Definition: aw_window.hxx:364
static bool update_display_on_dist_change
void set_slider_min(double d)
static void selected_species_changed_cb(AW_root *, MatrixDisplay *disp)
virtual void clear_part(const AW::Rectangle &rect, AW_bitset filteri)
Definition: AW_device.cxx:317
static void redisplay_needed(UNFIXED, MatrixDisplay *disp)
void monitor_horizontal_scroll_cb(AW_window *)
static void di_view_set_max_dist(AW_window *aww, int max_dist)
static AWT_predefined_config predefinedMatrixConfig[]
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
long read_int() const
Definition: AW_awar.cxx:187
void set_top_clip_border(int top, bool allow_oversize=false)
AW_awar * set_minmax(float min, float max)
Definition: AW_awar.cxx:532
AW_window * DI_create_save_matrix_window(AW_root *aw_root, save_matrix_params *save_params)
Definition: DI_matr.cxx:1107
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
const AW_clicked_element * best_click(AW_device_click::ClickPreference prefer=AW_device_click::PREFER_NEARER)
Definition: awt_canvas.hxx:233
AW_pos get_scrolled_picture_width() const
Definition: AW_window.cxx:834
void set_offset(const AW::Vector &off)
Definition: aw_device.hxx:130
int slider_pos_horizontal
current position of the vertical slider
Definition: aw_window.hxx:339
#define AWAR_MATRIX_NAMECHARS_TOP
void mark(UpdateFlag needed)
AW_gc_manager * AW_manage_GC(AW_window *aww, const char *gc_base_name, AW_device *device, int base_drag, AW_GCM_AREA area, const GcChangedCallback &changecb, const char *default_background_color,...)
Definition: AW_preset.cxx:969
static void di_view_set_distances(AW_root *awr, int setmax, MatrixDisplay *disp)
static void resize_needed(UNFIXED, MatrixDisplay *disp)
void set_motion_callback(AW_area area, const WindowCallback &wcb)
Definition: AW_window.cxx:808
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
struct Unfixed_cb_parameter * UNFIXED
Definition: cb_base.h:15
void create_input_field_with_scaler(const char *awar_name, int textcolumns=4, int scaler_length=250, AW_ScalerType scalerType=AW_SCALER_LINEAR)
Definition: AW_button.cxx:1140
void scroll_cells(int cells_x, int cells_y)
static void reinit_needed(UNFIXED, MatrixDisplay *disp)
const AW_font_limits & get_font_limits(int gc, char c) const
Definition: AW_device.cxx:399
GcChange
Definition: aw_base.hxx:94
static int diff(int v1, int v2, int v3, int v4, int st, int en)
Definition: ClustalV.cxx:534
double AW_pos
Definition: aw_base.hxx:29
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
#define AWAR_MATRIX_DIGITS
void push_clip_scale()
Definition: AW_device.cxx:91
#define AWT_CATCH
#define AWAR_MATRIX_PADDINGX
AW_awar * awar_float(const char *var_name, float default_value=0.0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:560
void get_event(AW_event *eventi) const
Definition: AW_window.cxx:540
void set_bottom_clip_border(int bottom, bool allow_oversize=false)
CONSTEXPR_INLINE const T & force_in_range(const T &lower_bound, const T &value, const T &upper_bound)
Definition: arb_algo.h:20
void AW_save_properties(AW_window *aw)
Definition: AW_preset.cxx:1452
void calculate_scrollbars()
Definition: AW_window.cxx:870
AW_device_click * get_click_device(AW_area area, int mousex, int mousey, int max_distance)
Definition: AW_window.cxx:523
AW_CL cd1() const
static void horizontal_change_cb(AW_window *aww, MatrixDisplay *disp)
#define AWAR_DIST_MIN_DIST
Definition: di_matr.hxx:40
void set_expose_callback(AW_area area, const WindowCallback &wcb)
Definition: AW_window.cxx:762
void create_menu(const char *name, const char *mnemonic, AW_active mask=AWM_ALL)
Definition: AW_window.cxx:469
bool line(int gc, const AW::LineVector &Line, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
Definition: aw_device.hxx:430
void pop_clip_scale()
Definition: AW_device.cxx:62
AW_window * AW_create_gc_window(AW_root *aw_root, AW_gc_manager *gcman)
Definition: AW_preset.cxx:1373
AW_device * device
Definition: di_matr.hxx:75
static void create_matrix_awars(AW_root *awr, MatrixDisplay *disp)
void label(const char *label)
Definition: AW_window.cxx:102
AP_FLOAT get(size_t i, size_t j) const
Definition: AP_matrix.hxx:46
#define AWAR_SPECIES_NAME
char * name
Definition: di_matr.hxx:89
char * read_string() const
Definition: AW_awar.cxx:201
static AWT_config_mapping_def matrixConfigMapping[]
const AW_bitset AW_CLICK
Definition: aw_device.hxx:35
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
static AW_window_menu_modes_opengl * awm
#define AWAR_DIST_MAX_DIST
Definition: di_matr.hxx:41
float read_float() const
Definition: AW_awar.cxx:180
AW_window * DI_create_view_matrix_window(AW_root *awr, MatrixDisplay *disp, save_matrix_params *sparam)
long int flag
Definition: f2c.h:39
class AW_awar * window_local_awar(const char *localname, bool tmp=true)
Definition: AW_window.cxx:970
#define AWAR_MATRIX_PADDINGY
#define AWAR_MATRIX_NAMECHARS_LEFT
void tell_scrolled_picture_size(AW_screen_area rectangle)
Definition: AW_window.cxx:820
AP_smatrix * matrix
Definition: di_matr.hxx:153
void set_right_clip_border(int right, bool allow_oversize=false)
void set_info_area_height(int height)
Definition: AW_window.cxx:793
AW_event_type type
Definition: aw_window.hxx:81
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
DI_ENTRY ** entries
Definition: di_matr.hxx:151
#define FIELD_SIZE
void auto_space(int xspace, int yspace)
Definition: AW_at.cxx:259
AW_CL cd2() const
AW_window * awm
AW_MouseButton button
Definition: aw_window.hxx:86
size_t nentries
Definition: di_matr.hxx:152
void set_horizontal_scrollbar_position(int position)
Definition: AW_window.cxx:995
void reset()
Definition: AW_device.cxx:280
#define abs(x)
Definition: f2c.h:151
#define di_assert(cond)
Definition: DI_clusters.cxx:31
#define MINMAX_GRANULARITY
void aw_message(const char *msg)
Definition: AW_status.cxx:932
ClickAction
AW_root * get_root()
Definition: aw_window.hxx:348
#define NULp
Definition: cxxforward.h:97
void init(AW_root *root, const char *wid, const char *windowname, int width, int height)
Definition: AW_window.cxx:2584
static void input_cb(AW_window *aww, MatrixDisplay *disp)
GB_ERROR write_string(const char *aw_string)
DI_MATRIX * get_matrix()
virtual void move_region(AW_pos src_x, AW_pos src_y, AW_pos width, AW_pos height, AW_pos dest_x, AW_pos dest_y)
Definition: AW_device.cxx:263
void set_vertical_scrollbar_position(int position)
Definition: AW_window.cxx:986
#define FALLTHROUGH
Definition: cxxforward.h:110
static void motion_cb(AW_window *aww, MatrixDisplay *disp)
GB_transaction ta(gb_var)
void set_horizontal_change_callback(const WindowCallback &wcb)
Definition: AW_window.cxx:1046
bool box(int gc, AW::FillStyle filled, const AW::Rectangle &rect, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
Definition: aw_device.hxx:471
void set_vertical_change_callback(const WindowCallback &wcb)
Definition: AW_window.cxx:1030
static void gc_changed_cb(GcChange whatChanged, MatrixDisplay *disp)
GB_ERROR write_float(float aw_float)
static AW_window * create_matrix_settings_window(AW_root *awr)
static void di_bind_dist_awars(AW_root *aw_root, MatrixDisplay *disp)
void set_slider_max(double d)
#define min(a, b)
Definition: f2c.h:153
int slider_pos_vertical
window id
Definition: aw_window.hxx:338
#define SCALER_SIZE
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
void set_input_callback(AW_area area, const WindowCallback &wcb)
Definition: AW_window.cxx:803
GB_ERROR write_int(long aw_int)
bool text(int gc, const SizedCstr &cstr, const AW::Position &pos, AW_pos alignment=0.0, AW_bitset filteri=AW_ALL_DEVICES_UNSCALED)
Definition: aw_device.hxx:440
#define AWAR_MATRIX_SHOWZERO
#define max(a, b)
Definition: f2c.h:154