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"
50 switch (whatChanged) {
63 void MatrixDisplay::setup() {
70 sprintf(format_string,
"%%%i.%if", digits+2, digits);
78 memset(max_chars, 0,
sizeof(*max_chars)*(
DI_G_LAST+1));
103 if (cell_paddx<0 && -cell_paddx >= cell_width) {
104 cell_paddx = -cell_width+1;
107 if (cell_paddy<0 && -cell_paddy >= cell_height) {
108 cell_paddy = -cell_height+1;
113 cell_width += cell_paddx;
114 cell_height += cell_paddy;
128 set_scrollbar_steps(cell_width, cell_height, 50, 50);
133 void MatrixDisplay::adapt_to_canvas_size() {
142 screen_width = squ.
r-squ.
l;
143 screen_height = squ.
b-squ.
t;
147 long horiz_paint_size = (squ.
r-lim.
width-off_dx)/cell_width;
148 long vert_paint_size = (squ.
b-off_dy)/cell_height;
150 horiz_page_size = (n > horiz_paint_size) ? horiz_paint_size : n;
151 vert_page_size = (n > vert_paint_size) ? vert_paint_size : n;
155 rect.
r = (
int)((n-horiz_page_size)*cell_width+squ.
r);
156 rect.
b = (
int)((n-vert_page_size)*cell_height+squ.
b);
163 horiz_page_start = 0;
164 horiz_last_view_start = 0;
166 vert_last_view_start = 0;
185 #define MINMAX_GRANULARITY 10000L
187 void MatrixDisplay::scroll_to(
int sxpos,
int sypos) {
204 static int clickx, clicky;
205 static int startx, starty;
215 int x_screen_diff = clickx -
event.x;
216 int y_screen_diff = clicky -
event.y;
218 scroll_to(startx + x_screen_diff, starty + y_screen_diff);
238 int direction =
event.button ==
AW_WHEEL_UP ? -1 : 1;
239 disp->
scroll_cells(horizontal*direction, !horizontal*direction);
249 click_device->reset();
254 disp->
device = click_device;
256 disp->
device = oldMatrixDevice;
269 if (idx >= matrix->nentries) {
273 DI_ENTRY *entry = matrix->entries[idx];
274 const char *species_name = entry->
name;
299 void MatrixDisplay::draw() {
304 long x,
y, xpos, ypos;
307 if (!autopop(m))
return;
315 char *selSpecies =
NULp;
318 int name_display_width_top;
319 int name_display_width_left;
323 name_display_width_top = (cell_width-1)/lim.
width;
324 name_display_width_left = (off_dx-1)/lim.
width;
327 int BUFLEN =
std::max(200,
std::max(name_display_width_left, name_display_width_top));
334 for (x = horiz_page_start;
335 x < (horiz_page_start + horiz_page_size) && (x < total_cells_horiz);
339 for (y = vert_page_start;
340 y < (vert_page_start + vert_page_size) && (y < total_cells_vert);
343 bool is_identity = (x ==
y);
346 AW_pos cellx = xpos*cell_width;
347 AW_pos celly = ypos*cell_height;
356 if (val2>=min_view_dist && val2<=max_view_dist) {
357 int maxw = cell_width-cell_paddx;
359 int h = cell_height - cell_paddy-1;
362 if (cell_paddy >= 0) {
373 int y3 = y2+hruler/2;
377 double len = ((val2-min_view_dist)/(max_view_dist-min_view_dist)) * maxw;
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);
402 else if (val2 == 1.0) {
403 strcpy(buf, leadZero ?
"1.0" :
" 1");
407 sprintf(buf, format_string, val2);
410 device->
text(gc, leadZero ? buf : buf+1, cellx, celly);
418 if (selSpecies && strcmp(buf, selSpecies) == 0) sel_x_pos = xpos;
419 buf[name_display_width_top] = 0;
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();
445 for (y = vert_page_start; y < vert_page_start + vert_page_size; y++) {
447 if (selSpecies && strcmp(buf, selSpecies) == 0) sel_y_pos = ypos;
448 buf[name_display_width_left] = 0;
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();
469 void MatrixDisplay::set_scrollbar_steps(
long width_h,
long width_v,
long page_h,
long page_v) {
481 int old_vert_page_start = vert_page_start;
486 int diff = vert_page_start-old_vert_page_start;
488 int diff_pix =
abs(diff)*cell_height;
489 int top_y = off_dy-cell_height;
490 int keep_cells = vert_page_size-
abs(diff);
491 int keep_pix = keep_cells*cell_height;
493 if (diff>0 && diff<vert_page_size) {
499 else if (diff>-vert_page_size && diff<0) {
518 int old_horiz_page_start = horiz_page_start;
523 int diff = horiz_page_start-old_horiz_page_start;
526 int diff_pix =
abs(diff)*cell_width;
527 int keep_cells = horiz_page_size-
abs(diff);
528 int keep_pix = keep_cells*cell_width;
530 if (diff>0 && diff<horiz_page_size) {
536 else if (diff>-horiz_page_size && diff<0) {
589 if (update_display_on_dist_change) {
601 RootCallback reinit_needed_cb = makeRootCallback(
reinit_needed, disp);
623 {
"*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'" },
628 AW_window_simple *aws =
new AW_window_simple;
629 aws->init(awr,
"MATRIX_SETTINGS",
"Matrix settings");
631 const int FIELDWIDTH = 3;
632 const int SCALERWIDTH = 200;
637 aws->create_button(
"CLOSE",
"CLOSE",
"C");
640 aws->create_button(
"HELP",
"HELP");
644 aws->label_length(21);
647 aws->label(
"X-padding (pixels)");
651 aws->label(
"Y-padding (pixels)");
655 aws->label(
"Show leading zero");
659 aws->label(
"Precision (digits)");
663 aws->label(
"Min. namechars (top)");
667 aws->label(
"Min. namechars (left)");
683 awm->
init(awr,
"SHOW_MATRIX",
"ARB distance matrix", 800, 600);
706 "+-Ruler$#555",
"-Display$#00AA55",
707 "#BelowDist$#008732",
708 "#AboveDist$#DB008D",
730 #define SCALER_SIZE 200
void monitor_vertical_scroll_cb(AW_window *)
virtual void clear(AW_bitset filteri)
void set_resize_callback(AW_area area, const WindowCallback &wcb)
void handle_move(AW_event &event)
const AW_bitset AW_SCREEN
AW_pos get_scrolled_picture_height() const
AW_device * get_device(AW_area area)
const AW_screen_area & get_area_size() const
static void vertical_change_cb(AW_window *aww, MatrixDisplay *disp)
void insert_menu_topic(const char *id, const char *name, const char *mnemonic, const char *help_text_, AW_active mask, const WindowCallback &wcb)
void set_left_clip_border(int left, bool allow_oversize=false)
const char * get_window_id() const
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)
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)
void set_top_clip_border(int top, bool allow_oversize=false)
AW_awar * set_minmax(float min, float max)
AW_window * DI_create_save_matrix_window(AW_root *aw_root, save_matrix_params *save_params)
const char * GBS_global_string(const char *templat,...)
void AW_POPDOWN(AW_window *window)
const AW_clicked_element * best_click(AW_device_click::ClickPreference prefer=AW_device_click::PREFER_NEARER)
AW_pos get_scrolled_picture_width() const
void set_offset(const AW::Vector &off)
int slider_pos_horizontal
current position of the vertical slider
#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,...)
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)
AW_awar * add_callback(const RootCallback &cb)
struct Unfixed_cb_parameter * UNFIXED
void create_input_field_with_scaler(const char *awar_name, int textcolumns=4, int scaler_length=250, AW_ScalerType scalerType=AW_SCALER_LINEAR)
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
static int diff(int v1, int v2, int v3, int v4, int st, int en)
WindowCallback makeHelpCallback(const char *helpfile)
#define AWAR_MATRIX_DIGITS
#define AWAR_MATRIX_PADDINGX
AW_awar * awar_float(const char *var_name, float default_value=0.0, AW_default default_file=AW_ROOT_DEFAULT)
void get_event(AW_event *eventi) const
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)
void AW_save_properties(AW_window *aw)
void calculate_scrollbars()
AW_device_click * get_click_device(AW_area area, int mousex, int mousey, int max_distance)
static void horizontal_change_cb(AW_window *aww, MatrixDisplay *disp)
#define AWAR_DIST_MIN_DIST
void set_expose_callback(AW_area area, const WindowCallback &wcb)
void create_menu(const char *name, const char *mnemonic, AW_active mask=AWM_ALL)
bool line(int gc, const AW::LineVector &Line, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
AW_window * AW_create_gc_window(AW_root *aw_root, AW_gc_manager *gcman)
static void create_matrix_awars(AW_root *awr, MatrixDisplay *disp)
void label(const char *label)
#define AWAR_SPECIES_NAME
char * read_string() const
static AWT_config_mapping_def matrixConfigMapping[]
AW_awar * awar(const char *awar)
static AW_window_menu_modes_opengl * awm
#define AWAR_DIST_MAX_DIST
AW_window * DI_create_view_matrix_window(AW_root *awr, MatrixDisplay *disp, save_matrix_params *sparam)
class AW_awar * window_local_awar(const char *localname, bool tmp=true)
#define AWAR_MATRIX_PADDINGY
#define AWAR_MATRIX_NAMECHARS_LEFT
void tell_scrolled_picture_size(AW_screen_area rectangle)
void set_right_clip_border(int right, bool allow_oversize=false)
void set_info_area_height(int height)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
void auto_space(int xspace, int yspace)
void set_horizontal_scrollbar_position(int position)
#define MINMAX_GRANULARITY
void aw_message(const char *msg)
static void input_cb(AW_window *aww, MatrixDisplay *disp)
GB_ERROR write_string(const char *aw_string)
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)
void set_vertical_scrollbar_position(int position)
T get(size_t i, size_t j) const
static void motion_cb(AW_window *aww, MatrixDisplay *disp)
GB_transaction ta(gb_var)
void set_horizontal_change_callback(const WindowCallback &wcb)
bool box(int gc, AW::FillStyle filled, const AW::Rectangle &rect, AW_bitset filteri=AW_ALL_DEVICES_SCALED)
void set_vertical_change_callback(const WindowCallback &wcb)
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)
int slider_pos_vertical
window id
void set_input_callback(AW_area area, const WindowCallback &wcb)
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)
#define AWAR_MATRIX_SHOWZERO