void draw_value(t_number_tilde *x, t_object *view, t_rect *rect) { t_elayer *g = ebox_start_layer((t_ebox *)x, gensym("value_layer"), rect->width, rect->height); t_etext *jtl = etext_layout_create(); if (g && jtl) { int size, inc = 0; float peak; char number[256]; sprintf(number, "%i", (int)x->f_peak_value); size = strlen(number); // TRONQUER LE NOMBRE ENTIER if(size > x->f_max_decimal+1) { sprintf(number, "%i...", (int)(x->f_peak_value / powf(10, size - (x->f_max_decimal+1)))); } // TRONQUER LES DECIMALS else { // ENLEVER LES ZERO peak = x->f_peak_value; while(peak - (int)peak != 0) { peak *= 10; inc++; } // TRONQUER SELON LE NOMBRE MAXIMUM DE DECIMAL if(inc > x->f_max_decimal - size) inc = x->f_max_decimal - size; if(inc > x->f_ndecimal) inc = x->f_ndecimal; if(inc == 0) sprintf(number, "%i", (int)x->f_peak_value); else if(inc == 1) sprintf(number, "%.1f", x->f_peak_value); else if(inc == 2) sprintf(number, "%.2f", x->f_peak_value); else if(inc == 3) sprintf(number, "%.3f", x->f_peak_value); else if(inc == 4) sprintf(number, "%.4f", x->f_peak_value); else if(inc == 5) sprintf(number, "%.5f", x->f_peak_value); else sprintf(number, "%.6f", x->f_peak_value); } etext_layout_settextcolor(jtl, &x->f_color_text); etext_layout_set(jtl, number, &x->j_box.b_font, sys_fontwidth(x->j_box.b_font.c_size) + 8, rect->height / 2., rect->width - 3, 0, ETEXT_LEFT, ETEXT_JLEFT, ETEXT_NOWRAP); etext_layout_draw(jtl, g); ebox_end_layer((t_ebox*)x, gensym("value_layer")); } ebox_paint_layer((t_ebox *)x, gensym("value_layer"), 0., 0.); etext_layout_destroy(jtl); }
static void draw_text(t_tab *x, t_object *view, t_rect *rect) { int i; t_elayer *g = ebox_start_layer((t_ebox *)x, cream_sym_text_layer, rect->width, rect->height); if(g) { t_etext *jtl = etext_layout_create(); if(jtl) { if(x->f_orientation) { const float ratio = rect->height / (float)x->f_nitems; for(i = 0; i < x->f_nitems; i++) { if(x->f_items[i]) { etext_layout_set(jtl, x->f_items[i]->s_name, &x->f_font, 0.f, ratio * (i + 0.5f) + (i ? 2.f : 0.f), rect->width, 0.f, ETEXT_CENTRED, ETEXT_NOWRAP); etext_layout_draw(jtl, g); } } } else { const float ratio = rect->width / (float)x->f_nitems; for(i = 0; i < x->f_nitems; i++) { if(x->f_items[i]) { etext_layout_settextcolor(jtl, &x->f_color_text); etext_layout_set(jtl, x->f_items[i]->s_name, &x->f_font, ratio * i, rect->height * 0.5f, ratio - 2.f, 0.f, ETEXT_CENTRED, ETEXT_WRAP); etext_layout_draw(jtl, g); } } } etext_layout_destroy(jtl); } ebox_end_layer((t_ebox*)x, cream_sym_text_layer); } ebox_paint_layer((t_ebox *)x, cream_sym_text_layer, 0., 0.); }
void draw_background(t_number_tilde *x, t_object *view, t_rect *rect) { t_elayer *g = ebox_start_layer((t_ebox *)x, cream_sym_background_layer, rect->width, rect->height); t_etext *jtl = etext_layout_create(); if (g && jtl) { etext_layout_set(jtl, "~", &x->j_box.b_font, 1, rect->height / 2., rect->width, 0, ETEXT_LEFT, ETEXT_JLEFT, ETEXT_NOWRAP); etext_layout_settextcolor(jtl, &x->f_color_text); etext_layout_draw(jtl, g); egraphics_set_line_width(g, 2); egraphics_set_color_rgba(g, &x->f_color_border); egraphics_move_to(g, 0, 0); egraphics_line_to(g, sys_fontwidth(x->j_box.b_font.c_size) + 6, rect->height / 2.); egraphics_line_to(g, 0, rect->height); egraphics_stroke(g); ebox_end_layer((t_ebox*)x, cream_sym_background_layer); } ebox_paint_layer((t_ebox *)x, cream_sym_background_layer, 0., 0.); etext_layout_destroy(jtl); }
void draw_text(t_breakpoints *x, t_object *view, t_rect *rect) { char number[512]; t_elayer *g = ebox_start_layer((t_ebox *)x, cream_sym_text_layer, rect->width, rect->height); t_etext *jtl = etext_layout_create(); if(g && jtl) { float height = sys_fontheight(ebox_getfontsize((t_ebox *)x)) + 1; if (x->f_point_selected != -1) { sprintf(number, "x : %.2f y : %.2f", x->f_point_abscissa[x->f_point_selected], x->f_point_ordinate[x->f_point_selected]); } else if(x->f_mouse.x != -666666 && x->f_mouse.y != -666666) { x->f_mouse.x = pd_clip_minmax(x->f_mouse.x, x->f_range_abscissa[0], x->f_range_abscissa[1]); x->f_mouse.y = pd_clip_minmax(x->f_mouse.y, x->f_range_ordinate[0], x->f_range_ordinate[1]); sprintf(number, "x : %.2f y : %.2f", x->f_mouse.x, x->f_mouse.y); } else { ebox_end_layer((t_ebox*)x, cream_sym_text_layer); ebox_paint_layer((t_ebox *)x, cream_sym_text_layer, 0., 0.); return; } etext_layout_set(jtl, number, &x->j_box.b_font, 5, height * 0.5, rect->width, 0, ETEXT_LEFT, ETEXT_JLEFT, ETEXT_NOWRAP); etext_layout_settextcolor(jtl, &x->f_color_text); etext_layout_draw(jtl, g); ebox_end_layer((t_ebox*)x, cream_sym_text_layer); } if(jtl) { etext_layout_destroy(jtl); } ebox_paint_layer((t_ebox *)x, cream_sym_text_layer, 0., 0.); }