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