diff --git a/pd/nw/dialog_iemgui.html b/pd/nw/dialog_iemgui.html index d40dbfa8f790b93c0f968af67d89367ccda1b76e..4a8e2861f357e61a4a284b7322f11857e372bd6f 100644 --- a/pd/nw/dialog_iemgui.html +++ b/pd/nw/dialog_iemgui.html @@ -291,6 +291,27 @@ <fieldset> <legend data-i18n="iem.prop.heading.colors"></legend> + <table class="draw_style prop hidden" style="margin-bottom: 7px;"> + <tr> + <td> + <label data-i18n="[title]iem.prop.drawstyle_tt"> + <span data-i18n="iem.prop.drawstyle" + style="margin-right: 6px;"></span> + </label> + </td> + <td data-i18n="[title]iem.prop.drawstyle_tt"> + <select name="draw_style" + onchange="update_attr(this, true);" + style="width: 14em;"> + <option value="0">draw everything (default)</option> + <option value="1">draw frame only</option> + <option value="2">draw triangle only</option> + <option value="3">draw number only</option> + </select> + </td> + <td> + </table> + <div class="background_color prop hidden"> <label data-i18n="[title]iem.prop.bgcolor_tt"> <input type="color" name="background_color" @@ -512,6 +533,8 @@ function send_params(attrs, create_undo_point) { var slot18 = attrs.steady_on_click ? +attrs.steady_on_click : 0; + var draw_style = attrs.draw_style ? +attrs.draw_style : 0; + pdgui.pdsend(pd_object_callback, "dialog", width, height, slot3, // bng: flash_interrupt @@ -532,7 +555,7 @@ function send_params(attrs, create_undo_point) { background_color, foreground_color, label_color, slot18, // steady on click - 0, // not sure what this is doing here + draw_style, // numbox draw style create_undo_point ? 1 : 0 // whether we set an undo point ); } diff --git a/pd/nw/locales/de/translation.json b/pd/nw/locales/de/translation.json index 6a43d138c9d81288f3996f6ae8460fa0df4de399..771b7727414d157de9e587e90fc8461022b63403 100644 --- a/pd/nw/locales/de/translation.json +++ b/pd/nw/locales/de/translation.json @@ -5,7 +5,7 @@ "size": "Größe und Verhalten", "messages": "Nachrichten", "label": "Etikett", - "colors": "Farben" + "colors": "Erscheinungsbild" }, "size_tt": "Größe des iemgui-Elements", "size": "Größe", @@ -41,6 +41,8 @@ "log_height_tt": "the framus intersects with the ramistan approximately at the podernoster", "steady": "stabil beim Klicken", "steady_tt": "verschiebe den Schieberegler nicht beim Klicken. Verschiebe ihn nur beim Ziehen der Maus", + "drawstyle": "Rahmen-Stil", + "drawstyle_tt": "Rahmen-Stil durch Auswahl der Elemente anpassen", "send": "Sende-Symbol", "send_tt": "Symbol zum Senden drahtloser Nachrichten an andere iemgui-Elemente oder Objekte", "receive": "Empfangs-Symbol", diff --git a/pd/nw/locales/en/translation.json b/pd/nw/locales/en/translation.json index b54d90c993b803af05c4e412ae7f566a661a9a12..9883efa2ad6b5c00c31197fe706471397d2b987b 100644 --- a/pd/nw/locales/en/translation.json +++ b/pd/nw/locales/en/translation.json @@ -5,7 +5,7 @@ "size": "size and behavior", "messages": "messaging", "label": "label", - "colors": "colors" + "colors": "appearance" }, "size_tt": "size of the iemgui", "size": "size", @@ -41,6 +41,8 @@ "log_height_tt": "the framus intersects with the ramistan approximately at the podernoster", "steady": "steady on click", "steady_tt": "don't move the slider when clicked. Only move it when dragging the mouse", + "drawstyle": "frame style", + "drawstyle_tt": "adjust number frame style by toggling its elements", "send": "send symbol", "send_tt": "symbol to send wireless messages to other iemguis or objects", "receive": "receive symbol", diff --git a/pd/nw/locales/fr/translation.json b/pd/nw/locales/fr/translation.json index 59099097fa6e7b616d36514515c99bd0efc622d5..8783b6b71d0c58f93416c5f5d5e1b8a0b69aa7b7 100644 --- a/pd/nw/locales/fr/translation.json +++ b/pd/nw/locales/fr/translation.json @@ -5,7 +5,7 @@ "size": "Taille et comportement", "messages": "Messages", "label": "Label", - "colors": "Couleurs" + "colors": "Apparence" }, "size": "Taille", "size_tt": "Taille de l'objet IemGui", @@ -41,6 +41,8 @@ "log_height_tt": "Le framus se croise avec le ramistan approximativement au paternoster !", "steady": "Fixe au clic", "steady_tt": "Ne bouge pas le curseur quand cliqué. Bouge seulement quand on le fait glisser avec la souris", + "drawstyle": "Style du cadre", + "drawstyle_tt": "Ajuster le style du cadre en choisissant ses éléments", "send": "Envoyer au symbole", "send_tt": "Messages sans-fil à envoyer à travers le Symbole vers d'autres IemGui ou Objets", "receive": "Recevoir du symbole", diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index 96682242efe36282d5672f7d93ec40f9cba8d334..23bcf364fd2070f5110774ae059db13f22c6f696 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -2964,7 +2964,7 @@ function gui_text_set (cid, tag, text) { function gui_text_set_mynumbox (cid, tag, text, active) { gui(cid).get_elem(tag + "text", function(e) { - //post("guit_text_set_activate " + tag + " " + text + " " + active); + //post("gui_text_set_mynumbox " + tag + " " + text + " " + active); text = text.trim(); e.textContent = ""; text_to_tspans(cid, e, text); @@ -3272,13 +3272,18 @@ function gui_toggle_update(cid, tag, state, color) { }) } -function numbox_data_string(w, h) { +function numbox_data_string_frame(w, h) { return ["M", 0, 0, "L", w - 4, 0, w, 4, w, h, 0, h, - "z", + "z"] + .join(" "); +} + +function numbox_data_string_triangle(w, h) { + return ["M", 0, 0, "L", 0, 0, (h / 2)|0, (h / 2)|0, // |0 to force int 0, h] @@ -3286,27 +3291,38 @@ function numbox_data_string(w, h) { } // Todo: send fewer parameters from c -function gui_numbox_new(cid, tag, color, x, y, w, h, is_toplevel) { +function gui_numbox_new(cid, tag, color, x, y, w, h, drawstyle, is_toplevel) { // numbox doesn't have a standard iemgui border, // so we must create its gobj manually gui(cid).get_elem("patchsvg", function() { var g = gui_gobj_new(cid, tag, "iemgui", x, y, is_toplevel); - var data = numbox_data_string(w, h); var border = create_item(cid, "path", { - d: data, + d: numbox_data_string_frame(w, h), fill: color, stroke: "black", - "stroke-width": 1, + "stroke-width": (drawstyle < 2 ? 1 : 0), id: (tag + "border"), "class": "border" }); g.appendChild(border); + var triangle = create_item(cid, "path", { + d: numbox_data_string_triangle(w, h), + fill: color, + stroke: "black", + "stroke-width": (drawstyle == 0 || drawstyle == 2 ? 1 : 0), + id: (tag + "triangle"), + "class": "border" + }); + g.appendChild(triangle); }); } function gui_numbox_coords(cid, tag, w, h) { gui(cid).get_elem(tag + "border", { - d: numbox_data_string(w, h) + d: numbox_data_string_frame(w, h) + }); + gui(cid).get_elem(tag + "triangle", { + d: numbox_data_string_triangle(w, h) }); } @@ -3332,14 +3348,14 @@ function gui_numbox_draw_text(cid,tag,text,font_size,color,xpos,ypos,basex,basey }); } -function gui_numbox_update(cid, tag, fcolor, bgcolor, font_name, font_size, font_weight) { +function gui_numbox_update(cid, tag, fcolor, bgcolor, num_font_size, font_name, font_size, font_weight) { gui(cid) .get_elem(tag + "border", { fill: bgcolor }) .get_elem(tag + "text", { fill: fcolor, - "font-size": font_size + "font-size": num_font_size }) // label may or may not exist, but that's covered by the API .get_elem(tag + "label", function() { @@ -5847,12 +5863,7 @@ function gui_iemgui_dialog(did, attr_array) { // We are subtracting 25 for the menu // ico@vt.edu: since adding frameless window, we use top 20px for draggable titlebar, // so now we subtract only 5 (25-20) - //post("attr_array=" + attr_array); - var height = 409; - if (attr_array[1] === "vu") { - height = 360; - } - create_window(did, "iemgui", 298, height, + create_window(did, "iemgui", 298, 414-5, popup_coords[2] + 10, popup_coords[3] + 60, attr_array_to_object(attr_array)); } diff --git a/pd/src/g_all_guis.c b/pd/src/g_all_guis.c index 66c575bb62d5c0c70e1e463ce524014c8dc6bca7..0c5a6284e747ce7ecaac09c23050917812bf4097 100644 --- a/pd/src/g_all_guis.c +++ b/pd/src/g_all_guis.c @@ -1268,7 +1268,7 @@ void iemgui_draw_io(t_iemgui *x, int old_sr_flags) t_canvas *canvas=glist_getcanvas(x->x_glist); if (x->x_glist != canvas) return; // is gop t_class *c = pd_class((t_pd *)x); - if (c == my_numbox_class && ((t_my_numbox *)x)->x_hide_frame > 1) + if (c == my_numbox_class && ((t_my_numbox *)x)->x_drawstyle > 1) return; //sigh if (!(old_sr_flags&4) && !glist_isvisible(canvas)) { diff --git a/pd/src/g_all_guis.h b/pd/src/g_all_guis.h index d7dec83594539e657c83d8ce3079022d9ea03588..e978b67e974e925d8efea7dda327d9b6cddda74a 100644 --- a/pd/src/g_all_guis.h +++ b/pd/src/g_all_guis.h @@ -190,9 +190,14 @@ typedef struct _my_numbox int x_numwidth; // unsigned (width in pixels) int x_scalewidth; /* temporary value for scalehandle */ int x_scaleheight; /* temporary value for scalehandle */ + int x_yresize_x; /* value of x when y resize started */ int x_tmpfontsize; /* temporary value for scalehandle */ + int x_num_fontsize;/* font size for the number only that should + automatically adjust to the box size */ + int x_focused; /* helps us determine when and how we are editing value + 0 no focus, 1 keyboard focus, 2 mouse focus */ int x_log_height; - int x_hide_frame; /* 0 default, 1 just arrow, 2, just frame, 3 both */ + int x_drawstyle; /* 0 default, 1 just frame, 2, just arrow, 3 number only */ } t_my_numbox; extern int sys_noloadbang; diff --git a/pd/src/g_numbox.c b/pd/src/g_numbox.c index b72c46bc9c86d6d6a8a1e35ea1721ea91f16ed64..4cee7c6eccfe9b60821f574e83f658554fe42b82 100644 --- a/pd/src/g_numbox.c +++ b/pd/src/g_numbox.c @@ -26,8 +26,9 @@ static void my_numbox_draw_update(t_gobj *client, t_glist *glist); t_widgetbehavior my_numbox_widgetbehavior; /*static*/ t_class *my_numbox_class; -// forward declaration +// forward declarations static void my_numbox_set_change(t_my_numbox *x, t_floatarg f); +static void my_numbox_ftoa(t_my_numbox *x , int append); static t_symbol *numbox_keyname_sym_a; @@ -38,8 +39,11 @@ static void my_numbox_tick_reset(t_my_numbox *x) { //post(" success\n"); my_numbox_set_change(x, 0); + my_numbox_ftoa(x, 0); sys_queuegui(x, x->x_gui.x_glist, my_numbox_draw_update); } + glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0); + x->x_focused = 0; } static void my_numbox_tick_wait(t_my_numbox *x) @@ -73,19 +77,21 @@ void my_numbox_clip(t_my_numbox *x) int my_numbox_calc_fontwidth2(t_my_numbox *x, int w, int h, int fontsize) { - int f=31; - if (x->x_gui.x_font_style == 1) f = 27; - else if(x->x_gui.x_font_style == 2) f = 25; + int f=25; + // ico@vt.edu 20200917: below options are disabled for the value + // inside the numbox since we ignore those in 2.x + //if (x->x_gui.x_font_style == 1) f = 27; + //else if(x->x_gui.x_font_style == 2) f = 25; return (fontsize * f * w) / 36 + (h / 2) + 4; } int my_numbox_calc_fontwidth(t_my_numbox *x) { return my_numbox_calc_fontwidth2(x,x->x_gui.x_w,x->x_gui.x_h, - x->x_gui.x_fontsize); + x->x_num_fontsize); } -void my_numbox_ftoa(t_my_numbox *x) +static void my_numbox_ftoa(t_my_numbox *x, int append) { double f=x->x_val; int bufsize, is_exp=0, i, idecimal; @@ -102,7 +108,7 @@ void my_numbox_ftoa(t_my_numbox *x) { if(is_exp) { - if(x->x_gui.x_w <= 5) + if(!append && x->x_gui.x_w <= 5) { x->x_buf[0] = (f < 0.0 ? '-' : '+'); x->x_buf[1] = 0; @@ -111,7 +117,7 @@ void my_numbox_ftoa(t_my_numbox *x) for(idecimal=0; idecimal < i; idecimal++) if(x->x_buf[idecimal] == '.') break; - if(idecimal > (x->x_gui.x_w - 4)) + if(!append && idecimal > (x->x_gui.x_w - 4)) { x->x_buf[0] = (f < 0.0 ? '-' : '+'); x->x_buf[1] = 0; @@ -131,12 +137,12 @@ void my_numbox_ftoa(t_my_numbox *x) for(idecimal=0; idecimal < bufsize; idecimal++) if(x->x_buf[idecimal] == '.') break; - if(idecimal > x->x_gui.x_w) + if(!append && idecimal > x->x_gui.x_w) { x->x_buf[0] = (f < 0.0 ? '-' : '+'); x->x_buf[1] = 0; } - else + else if (!append) x->x_buf[x->x_gui.x_w] = 0; } } @@ -156,11 +162,20 @@ static void my_numbox_draw_update(t_gobj *client, t_glist *glist) if (!glist_isvisible(glist)) return; if(x->x_gui.x_change && x->x_buf[0]) { - //printf("draw_update 1\n"); + //post("draw_update 1 : focused=%d", x->x_focused); char *cp=x->x_buf; int sl = strlen(x->x_buf); - x->x_buf[sl] = '>'; - x->x_buf[sl+1] = 0; + if (x->x_focused == 1) + { + x->x_buf[sl] = '>'; + x->x_buf[sl+1] = 0; + } else if (x->x_focused == 2) { + // this is triggered when one presses return while retaining the focus of the number + // so, we make sure to subtract the '>' that has disappeared and adjust visible digits + // accordingly below + x->x_buf[sl] = 0; + sl--; + } if(sl >= x->x_gui.x_w) cp += sl - x->x_gui.x_w + 1; gui_vmess("gui_text_set_mynumbox", "xxsi", @@ -168,11 +183,23 @@ static void my_numbox_draw_update(t_gobj *client, t_glist *glist) x, cp, 1); - x->x_buf[sl] = 0; + // here we check that we are not in the focused mode 2 that has this already taken care of above + if (x->x_focused != 2) + x->x_buf[sl] = 0; } else { - my_numbox_ftoa(x); /* mmm... side-effects */ + //if (!x->x_focused || x->x_focused == 2) + //post("draw_update 2: x->x_buf=<%s> focused=%d change=%d", x->x_buf, x->x_focused, x->x_gui.x_change); + if (!x->x_buf[0] && x->x_focused == 1 && x->x_gui.x_change == 1) + { + x->x_buf[0] = '>'; + x->x_buf[1] = 0; + } + else + { + my_numbox_ftoa(x, 0); /* mmm... side-effects */ + } gui_vmess("gui_text_set_mynumbox", "xxsi", glist_getcanvas(glist), x, @@ -191,14 +218,11 @@ static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist) char cbuf[8]; sprintf(cbuf, "#%6.6x", x->x_gui.x_bcol); int half=x->x_gui.x_h/2; - // ico@vt.edu 2020-08-24: this offset is better as float to ensure - // that the vertical positioning of the number is as close to the center - // as nw.js allows - t_float d=0.5+x->x_gui.x_h/34.0; + t_float d=1+x->x_gui.x_h/34.0; int x1=text_xpix(&x->x_gui.x_obj, glist), x2=x1+x->x_numwidth; int y1=text_ypix(&x->x_gui.x_obj, glist), y2=y1+x->x_gui.x_h; - gui_vmess("gui_numbox_new", "xxsiiiii", + gui_vmess("gui_numbox_new", "xxsiiiiii", canvas, x, cbuf, @@ -206,23 +230,16 @@ static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist) y1, x2 - x1, y2 - y1, + x->x_drawstyle, glist_istoplevel(glist)); - /* Not sure when it is necessary to hide the frame... perhaps for - k12? */ - if (!x->x_hide_frame || x->x_hide_frame == 2) - { - //sys_vgui(".x%zx.c create polyline %d %d %d %d %d %d -stroke #%6.6x " - // "-tags {%zxBASE2 x%zx text iemgui}\n", - // canvas, x1, y1, x1 + half, y1 + half, x1, y2, - // x->x_gui.x_fcol, x, x); - } - my_numbox_ftoa(x); + + my_numbox_ftoa(x, 0); sprintf(cbuf, "#%6.6x", x->x_gui.x_fcol); gui_vmess("gui_numbox_draw_text", "xxsisifii", canvas, x, x->x_buf, - x->x_gui.x_fontsize, + x->x_num_fontsize, cbuf, x1+half+2, y1+half+d, x1, y1); } @@ -238,9 +255,9 @@ static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist) iemgui_base_draw_move(&x->x_gui); - if (x->x_hide_frame <= 1) + if (x->x_drawstyle <= 1) iemgui_io_draw_move(&x->x_gui); - if (!x->x_hide_frame || x->x_hide_frame == 2) + if (!x->x_drawstyle || x->x_drawstyle == 2) { //sys_vgui(".x%zx.c coords %zxBASE2 %d %d %d %d %d %d\n", // canvas, x, x1, y1, x1 + half, y1 + half, x1, y2); @@ -265,11 +282,12 @@ static void my_numbox_draw_config(t_my_numbox* x,t_glist* glist) char fg[8], bg[8]; sprintf(fg, "#%6.6x", x->x_gui.x_fcol); sprintf(bg, "#%6.6x", x->x_gui.x_bcol); - gui_vmess("gui_numbox_update", "xxsssii", + gui_vmess("gui_numbox_update", "xxssisii", canvas, x, fg, bg, + x->x_num_fontsize, iemgui_typeface((t_iemgui *)x), x->x_gui.x_fontsize, sys_fontweight); @@ -310,6 +328,7 @@ static void my_numbox__clickhook(t_scalehandle *sh, int newstate) canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x); if (!sh->h_scale) scalehandle_click_label(sh); + x->x_yresize_x = 0; } /* not sure if we need this */ sh->h_dragon = newstate; @@ -321,24 +340,34 @@ static void my_numbox__motionhook(t_scalehandle *sh, if (sh->h_scale) { t_my_numbox *x = (t_my_numbox *)(sh->h_master); + x->x_focused = 2; //int dx = (int)mouse_x - sh->h_offset_x; - int dy = (int)mouse_y - sh->h_offset_y; + int dy = (sh->h_constrain == CURSOR_EDITMODE_RESIZE_X) ? 0 : + (int)mouse_y - sh->h_offset_y; + + if (sh->h_constrain == CURSOR_EDITMODE_RESIZE_Y && x->x_yresize_x == 0) + { + x->x_yresize_x = mouse_x; + } /* first calculate y */ int newy = maxi(x->x_gui.x_obj.te_ypix + x->x_gui.x_h + dy, x->x_gui.x_obj.te_ypix + SCALE_NUM_MINHEIGHT); /* then readjust fontsize */ - x->x_tmpfontsize = maxi((newy - x->x_gui.x_obj.te_ypix) * 0.8, + x->x_tmpfontsize = maxi((newy - x->x_gui.x_obj.te_ypix) * 0.9, IEM_FONT_MINSIZE); - int f = 31; - if (x->x_gui.x_font_style == 1) f = 27; - else if(x->x_gui.x_font_style == 2) f = 25; + int f = 25; + // ico@vt.edu 20200917: below options are disabled for the value + // inside the numbox since we ignore those in 2.x + //if (x->x_gui.x_font_style == 1) f = 27; + //else if(x->x_gui.x_font_style == 2) f = 25; int char_w = (x->x_tmpfontsize * f) / 36; /* get the new total width */ - int new_total_width = x->x_numwidth + (int)mouse_x - + int new_total_width = x->x_numwidth + + (sh->h_constrain == CURSOR_EDITMODE_RESIZE_Y ? x->x_yresize_x : (int)mouse_x) - (text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist) + x->x_numwidth); /* now figure out what does this translate into in terms of @@ -359,7 +388,7 @@ static void my_numbox__motionhook(t_scalehandle *sh, // dx,dy,x->x_scalewidth,x->x_scaleheight,numwidth,sh->h_dragx); scalehandle_drag_scale(sh); - x->x_gui.x_fontsize = x->x_tmpfontsize; + x->x_num_fontsize = x->x_tmpfontsize; x->x_gui.x_w = new_char_len; x->x_gui.x_h = x->x_scaleheight; x->x_numwidth = my_numbox_calc_fontwidth(x); @@ -382,7 +411,7 @@ static void my_numbox__motionhook(t_scalehandle *sh, { properties_set_field_int(properties,"width",x->x_scalewidth); properties_set_field_int(properties,"height",x->x_scaleheight); - properties_set_field_int(properties,"font_size",x->x_tmpfontsize); + //properties_set_field_int(properties,"font_size",x->x_tmpfontsize); } } scalehandle_dragon_label(sh,mouse_x, mouse_y); @@ -434,7 +463,7 @@ static void my_numbox_save(t_gobj *z, t_binbuf *b) srl[0], srl[1], srl[2], x->x_gui.x_ldx, x->x_gui.x_ldy, iem_fstyletoint(&x->x_gui), x->x_gui.x_fontsize, bflcol[0], bflcol[1], bflcol[2], - x->x_val, x->x_log_height, x->x_hide_frame); + x->x_val, x->x_log_height, x->x_drawstyle); } int my_numbox_check_minmax(t_my_numbox *x, double min, double max) @@ -495,7 +524,7 @@ static void my_numbox_properties(t_gobj *z, t_glist *owner) -----------output-range:----------- %g min: %g max: %d \ %d lin log %d %d log-height: %d {%s} {%s} {%s} %d %d %d %d %d %d %d\n", x->x_gui.x_w, 1, x->x_gui.x_h, 8, x->x_min, x->x_max, - x->x_hide_frame, /*EXCEPTION: x_hide_frame instead of schedule*/ + x->x_drawstyle, /*EXCEPTION: x_drawstyle instead of schedule*/ x->x_lin0_log1, x->x_gui.x_loadinit, -1, x->x_log_height, /*no multi, but iem-characteristic*/ srl[0]->s_name, srl[1]->s_name, srl[2]->s_name, @@ -526,7 +555,7 @@ static void my_numbox_properties(t_gobj *z, t_glist *owner) gui_s("background_color"); gui_i(0xffffff & x->x_gui.x_bcol); gui_s("foreground_color"); gui_i(0xffffff & x->x_gui.x_fcol); gui_s("label_color"); gui_i(0xffffff & x->x_gui.x_lcol); - gui_s("hide_frame"); gui_i(x->x_hide_frame); + gui_s("draw_style"); gui_i(x->x_drawstyle); gui_end_array(); gui_end_vmess(); } @@ -547,14 +576,15 @@ static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc, double max = atom_getfloatarg(3, argc, argv); x->x_lin0_log1 = !!atom_getintarg(4, argc, argv); x->x_log_height = maxi(atom_getintarg(6, argc, argv),10); - if (argc > 17) - x->x_hide_frame = (int)atom_getintarg(18, argc, argv); + x->x_drawstyle = (int)atom_getintarg(18, argc, argv); iemgui_dialog(&x->x_gui, argc, argv); x->x_numwidth = my_numbox_calc_fontwidth(x); my_numbox_check_minmax(x, min, max); + // automatically adjust the number font size + x->x_num_fontsize = maxi(x->x_gui.x_h * 0.9, IEM_FONT_MINSIZE); // normally, you'd do move+config, but here you have to do erase+new - // because iemgui_draw_io does not support changes to x_hide_frame. + // because iemgui_draw_io does not support changes to x_drawstyle. iemgui_draw_erase(&x->x_gui); iemgui_draw_new(&x->x_gui); //iemgui_draw_move(&x->x_gui); @@ -568,6 +598,7 @@ static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc, static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy) { + x->x_focused = 2; double k2=1.0; int old = x->x_val; @@ -581,6 +612,7 @@ static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy) if (old != x->x_val) { x->x_gui.x_changed = 1; + my_numbox_ftoa(x, 0); sys_queuegui(x, x->x_gui.x_glist, my_numbox_draw_update); my_numbox_bang(x); } @@ -591,7 +623,6 @@ static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy) static void my_numbox_click(t_my_numbox *x, t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl, t_floatarg alt) { - //post("my_numbox_click"); glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, (t_glistmotionfn)my_numbox_motion, my_numbox_key, xpos, ypos); } @@ -600,29 +631,32 @@ static int my_numbox_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit) { t_my_numbox* x = (t_my_numbox *)z; - //post("my_numbox_newclick %d", doit); if(doit) { //printf("newclick doit\n"); my_numbox_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt); if(shift) + { x->x_gui.x_finemoved = 1; + } else x->x_gui.x_finemoved = 0; if(!x->x_gui.x_change) { - //printf(" change=0\n"); clock_delay(x->x_clock_wait, 50); my_numbox_set_change(x, 1); clock_delay(x->x_clock_reset, 3000); - x->x_buf[0] = 0; + if (shift) + my_numbox_ftoa(x, 1); + else + x->x_buf[0] = 0; + x->x_focused = 2; sys_queuegui(x, x->x_gui.x_glist, my_numbox_draw_update); } else { - //printf(" change=1\n"); my_numbox_set_change(x, 0); clock_unset(x->x_clock_reset); x->x_buf[0] = 0; @@ -630,6 +664,10 @@ static int my_numbox_newclick(t_gobj *z, struct _glist *glist, sys_queuegui(x, x->x_gui.x_glist, my_numbox_draw_update); } } + else + { + //x->x_focused = 1; + } return (1); } @@ -655,13 +693,13 @@ static void my_numbox_log_height(t_my_numbox *x, t_floatarg lh) x->x_k = 1.0; } -static void my_numbox_hide_frame(t_my_numbox *x, t_floatarg lh) +static void my_numbox_drawstyle(t_my_numbox *x, t_floatarg lh) { if(lh < 0.0) lh = 0.0; if (lh > 3.0) lh = 3.0; - x->x_hide_frame = (int)lh; + x->x_drawstyle = (int)lh; my_numbox_draw(x, x->x_gui.x_glist, 4); my_numbox_draw(x, x->x_gui.x_glist, 2); } @@ -731,6 +769,8 @@ static void my_numbox_loadbang(t_my_numbox *x, t_floatarg action) static void my_numbox_key(void *z, t_floatarg fkey) { t_my_numbox *x = z; + if (fkey != 0) + x->x_focused = 1; // this is used for arrow up and down if (fkey == -1) @@ -746,11 +786,14 @@ static void my_numbox_key(void *z, t_floatarg fkey) char buf[3]; buf[1] = 0; + // this is what is triggered when one clicks outside the numbox + // and therefore loses focus if (c == 0) { my_numbox_set_change(x, 0); clock_unset(x->x_clock_reset); x->x_gui.x_changed = 1; + clock_delay(x->x_clock_reset, 0); sys_queuegui(x, x->x_gui.x_glist, my_numbox_draw_update); return; } @@ -767,7 +810,11 @@ static void my_numbox_key(void *z, t_floatarg fkey) } else if((c=='\b')||(c==127)) { - int sl=strlen(x->x_buf)-1; + int sl; + if (x->x_gui.x_finemoved) + sl = 0; + else + sl=strlen(x->x_buf)-1; if(sl < 0) sl = 0; @@ -778,15 +825,23 @@ static void my_numbox_key(void *z, t_floatarg fkey) else if((c=='\n')||(c==13)) { x->x_val = atof(x->x_buf); - x->x_buf[0] = 0; + //x->x_buf[0] = 0; my_numbox_set_change(x, 1); clock_unset(x->x_clock_reset); my_numbox_clip(x); my_numbox_bang(x); x->x_gui.x_changed = 1; + x->x_focused = 2; sys_queuegui(x, x->x_gui.x_glist, my_numbox_draw_update); } - clock_delay(x->x_clock_reset, 3000); + + if(c==27) + { + clock_unset(x->x_clock_reset); + my_numbox_tick_reset(x); + } + else + clock_delay(x->x_clock_reset, 3000); } static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) @@ -821,7 +876,7 @@ static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) if (!strcmp("Up", av[1].a_w.w_symbol->s_name)) { //fprintf(stderr,"...Up\n"); - if(x->x_buf[0] == 0 && x->x_val != 0) + if((x->x_buf[0] == 0 || x->x_buf == '>') && x->x_val != 0) sprintf(x->x_buf, "%g", x->x_val+1); else sprintf(x->x_buf, "%g", atof(x->x_buf) + 1); @@ -830,7 +885,7 @@ static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) else if (!strcmp("ShiftUp", av[1].a_w.w_symbol->s_name)) { //fprintf(stderr,"...ShiftUp\n"); - if(x->x_buf[0] == 0 && x->x_val != 0) + if((x->x_buf[0] == 0 || x->x_buf == '>') && x->x_val != 0) sprintf(x->x_buf, "%g", x->x_val+0.01); else sprintf(x->x_buf, "%g", atof(x->x_buf) + 0.01); @@ -839,7 +894,7 @@ static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) else if (!strcmp("Down", av[1].a_w.w_symbol->s_name)) { //fprintf(stderr,"...Down\n"); - if(x->x_buf[0] == 0 && x->x_val != 0) + if((x->x_buf[0] == 0 || x->x_buf == '>') && x->x_val != 0) sprintf(x->x_buf, "%g", x->x_val-1); else sprintf(x->x_buf, "%g", atof(x->x_buf) - 1); @@ -848,7 +903,7 @@ static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av) else if (!strcmp("ShiftDown", av[1].a_w.w_symbol->s_name)) { //fprintf(stderr,"...ShiftDown\n"); - if(x->x_buf[0] == 0 && x->x_val != 0) + if((x->x_buf[0] == 0 || x->x_buf == '>') && x->x_val != 0) sprintf(x->x_buf, "%g", x->x_val-0.01); else sprintf(x->x_buf, "%g", atof(x->x_buf) - 0.01); @@ -897,9 +952,9 @@ static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv) else iemgui_new_getnames(&x->x_gui, 6, 0); if((argc == 18)&&IS_A_FLOAT(argv,17)) log_height = maxi(atom_getintarg(17, argc, argv),10); - x->x_hide_frame = 0; // default behavior + x->x_drawstyle = 0; // default behavior if((argc == 19)&&IS_A_FLOAT(argv,18)) - x->x_hide_frame = (int)atom_getintarg(18, argc, argv); + x->x_drawstyle = (int)atom_getintarg(18, argc, argv); x->x_gui.x_draw = (t_iemfunptr)my_numbox_draw; x->x_gui.x_glist = (t_glist *)canvas_getcurrent(); x->x_val = x->x_gui.x_loadinit ? v : 0.0; @@ -914,6 +969,9 @@ static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv) x->x_gui.x_w = w; x->x_gui.x_h = h; x->x_buf[0] = 0; + // default font size that will then automatically adjust + // based on width and height + x->x_num_fontsize = maxi(x->x_gui.x_h * 0.9, IEM_FONT_MINSIZE); x->x_numwidth = my_numbox_calc_fontwidth(x); my_numbox_check_minmax(x, min, max); iemgui_verify_snd_ne_rcv(&x->x_gui); @@ -927,12 +985,16 @@ static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv) x->x_scalewidth = 0; x->x_scaleheight = 0; x->x_tmpfontsize = 0; + x->x_gui.x_obj.te_iemgui = 1; x->x_gui.x_changed = 0; x->x_gui.legacy_x = 0; x->x_gui.legacy_y = 1; + x->x_focused = 0; + x->x_yresize_x = 0; + return (x); } @@ -981,8 +1043,8 @@ void g_numbox_setup(void) gensym("init"), A_FLOAT, 0); class_addmethod(my_numbox_class, (t_method)my_numbox_log_height, gensym("log_height"), A_FLOAT, 0); - class_addmethod(my_numbox_class, (t_method)my_numbox_hide_frame, - gensym("hide_frame"), A_FLOAT, 0); + class_addmethod(my_numbox_class, (t_method)my_numbox_drawstyle, + gensym("drawstyle"), A_FLOAT, 0); numbox_keyname_sym_a = gensym("#keyname_a");