From: <bor...@us...> - 2018-12-04 10:41:37
|
Revision: 3735 http://sourceforge.net/p/ftm/code/3735 Author: borghesi Date: 2018-12-04 10:41:34 +0000 (Tue, 04 Dec 2018) Log Message: ----------- ftm.object: fixed resize editing description or name Modified Paths: -------------- trunk/ftm/externals/max5/ftm.object.c Modified: trunk/ftm/externals/max5/ftm.object.c =================================================================== --- trunk/ftm/externals/max5/ftm.object.c 2018-11-28 14:14:28 UTC (rev 3734) +++ trunk/ftm/externals/max5/ftm.object.c 2018-12-04 10:41:34 UTC (rev 3735) @@ -1,4 +1,3 @@ -asdf /* * FTM externals * Copyright (C) 2004 by IRCAM-Centre Georges Pompidou, Paris, France. @@ -40,15 +39,15 @@ /* debug scope console printouts */ #define DEBUG_FTM_OBJECT 0 -#ifndef WIN32 -# if DEBUG_FTM_OBJECT && defined(DEBUG) -# define debug_post(args...) post(args) -# else -# define debug_post(args...) -# endif +#ifdef WIN32 +static void debug_post(const char *format, ...){} #else -static void debug_post(const char *format, ...){} +#if DEBUG_FTM_OBJECT && defined(DEBUG) +#define debug_post(args...) post(args) +#else +#define debug_post(args...) #endif +#endif #define MAX_CHARS 2048 @@ -248,36 +247,44 @@ char *name = ftmobj_str_name(self); char *sep = ftmobj_str_separator(self); t_size new_size; - double width, height; + double width, height, empty_width, empty_height; t_jfont *jf = jfont_create(jbox_get_fontname((t_object *)self)->s_name, (t_jgraphics_font_slant)jbox_get_font_slant((t_object *)self), (t_jgraphics_font_weight)jbox_get_font_weight((t_object *)self), jbox_get_fontsize((t_object *)self)); char text[512]; snprintf(text, 512, "%s %s %s ", description, sep, name); - jfont_text_measure(jf, text, &width, &height); + jfont_text_measure(jf, text, &width, &height); + jfont_text_measure(jf, fts_symbol_name(sym_empty_object_text), &empty_width, &empty_height); jfont_destroy(jf); + + if(width < empty_width) width = empty_width; + new_size.height = height + 6; new_size.width = width + 8; if (self->activeview && patcherview_get_presentation(self->activeview) != 0) { - t_size old_size; - jbox_get_presentation_size((t_object *) self, &old_size); + t_rect bounds; + jbox_get_presentation_rect((t_object *) self, &bounds); - if (old_size.width != new_size.width || old_size.height != new_size.height) + if (bounds.width != new_size.width || bounds.height != new_size.height) { - jbox_set_presentation_size((t_object *) self, &new_size); + bounds.width = new_size.width; + bounds.height = new_size.height; + jbox_set_presentation_rect((t_object *) self, &bounds); jbox_redraw((t_jbox *)self); } } else { - t_size old_size; - jbox_get_patching_size((t_object *) self, &old_size); - - if (old_size.width != new_size.width || old_size.height != new_size.height) + t_rect bounds; + jbox_get_patching_rect((t_object *) self, &bounds); + + if (bounds.width != new_size.width || bounds.height != new_size.height) { - jbox_set_patching_size((t_object *) self, &new_size); + bounds.width = new_size.width; + bounds.height = new_size.height; + jbox_set_patching_rect((t_object *) self, &bounds); jbox_redraw((t_jbox *)self); } } @@ -286,12 +293,14 @@ static void ftmobj_resize_to_current_text(ftmobj_t *self) { - t_size current_size, new_size; + t_rect current_bounds; + t_size new_size; long textsize = 0; char *currenttext = NULL; int text_len; double curr_text_width, curr_text_height; double ot_width, ot_height; + double empty_width, empty_height; int width; double incr_w, incr_h; char txt[512]; @@ -300,16 +309,17 @@ bool presentation = self->activeview ? patcherview_get_presentation(self->activeview) != 0 : 0; if (presentation) - jbox_get_presentation_size((t_object *) self, ¤t_size); + jbox_get_presentation_rect((t_object *) self, ¤t_bounds); else - jbox_get_patching_size((t_object *) self, ¤t_size); + jbox_get_patching_rect((t_object *) self, ¤t_bounds); object_method(textfield, gensym("gettextptr"), ¤ttext, &textsize); text_len = (int)strlen(currenttext); jfont_text_measure(jf, currenttext, &curr_text_width, &curr_text_height); jfont_text_measure(jf, "w", &incr_w, &incr_h); + jfont_text_measure(jf, fts_symbol_name(sym_empty_object_text), &empty_width, &empty_height); - new_size.height = curr_text_height + 4; + new_size.height = curr_text_height + 6; if(self->edit_name == 1) { @@ -317,7 +327,7 @@ char *sep = ftmobj_str_separator(self); snprintf(txt, 512, "%s %s ", description, sep); - jfont_text_measure(jf, txt, &ot_width, &ot_height); + jfont_text_measure(jf, txt, &ot_width, &ot_height); } else { @@ -325,17 +335,20 @@ char *sep = ftmobj_str_separator(self); snprintf(txt, 512, " %s %s", sep, name); - jfont_text_measure(jf, txt, &ot_width, &ot_height); + jfont_text_measure(jf, txt, &ot_width, &ot_height); } width = (ot_width + 5) + (curr_text_width + 2); - new_size.width = (width + incr_w < current_size.width) ? current_size.width : width + incr_w; + new_size.width = (width + incr_w < /*current_size.width*/empty_width) ? /*current_size.width*/empty_width : width + incr_w; - if (new_size.width > current_size.width) + if (new_size.width > current_bounds.width) { + current_bounds.width = new_size.width; + current_bounds.height = new_size.height; + if (presentation) - jbox_set_presentation_size((t_object *) self, &new_size); + jbox_set_presentation_rect((t_object *) self, ¤t_bounds); else - jbox_set_patching_size((t_object *) self, &new_size); + jbox_set_patching_rect((t_object *) self, ¤t_bounds); jbox_redraw((t_jbox *)self); } @@ -751,7 +764,11 @@ } debug_post("textfield_deactivate edit_name %d text '%s'", self->edit_name, text); - fts_symbol_t sym = fts_new_symbol(text); + fts_symbol_t sym; + if(text[0] != '\0') + sym = fts_new_symbol(text); + else + sym = sym_empty_description; //MRO: end edit: copy edited (unreplaced) text into _init, parse and set replaced text internally if(self->edit_name == 1) @@ -979,7 +996,8 @@ char *sep = ftmobj_str_separator(self); t_jfont *jf = jfont_create(jbox_get_fontname((t_object *)self)->s_name, (t_jgraphics_font_slant)jbox_get_font_slant((t_object *)self), (t_jgraphics_font_weight)jbox_get_font_weight((t_object *)self), jbox_get_fontsize((t_object *)self)); double width, height, min_width; - t_size current_size, new_size; + t_rect current_bounds; + t_size new_size; char text[512]; snprintf(text, 512, "%s %s %s ", description, sep, name); @@ -990,17 +1008,20 @@ bool presentation = self->activeview ? patcherview_get_presentation(self->activeview) != 0 : 0; if (presentation) - jbox_get_presentation_size((t_object *) self, ¤t_size); + jbox_get_presentation_rect((t_object *) self, ¤t_bounds); else - jbox_get_patching_size((t_object *) self, ¤t_size); + jbox_get_patching_rect((t_object *) self, ¤t_bounds); - new_size.width = current_size.width > min_width ? current_size.width : min_width; + new_size.width = current_bounds.width > min_width ? current_bounds.width : min_width; new_size.height = height + 6; + current_bounds.width = new_size.width; + current_bounds.height = new_size.height; + if (presentation) - jbox_set_presentation_size((t_object *) self, &new_size); + jbox_set_presentation_rect((t_object *) self, ¤t_bounds); else - jbox_set_patching_size((t_object *) self, &new_size); + jbox_set_patching_rect((t_object *) self, ¤t_bounds); } static t_max_err @@ -1009,23 +1030,18 @@ ftmobj_t *self = (ftmobj_t *)b; t_symbol *attrname; - if (msg == gensym("attr_modified")) - { + if (msg == gensym("attr_modified")) + { t_atom *av = NULL; long ac = 0; attrname = (t_symbol *)object_method((t_object *)data, gensym("getname")); - + if(attrname == gensym("fontname") || attrname == gensym("fontsize")) ftmobj_fit_to_text(self); - else if(attrname == gensym("patching_rect")) + else if(attrname == gensym("patching_rect") || attrname == gensym("patching_size")) { if(self->activated == 1 && sender == self && self->changing_size == 0) - { - t_atom a; - self->changing_size = 1; - atom_setobj(&a, (t_object *)self); - defer_low(self,(method)ftmobj_resize_to_current_text, 0, 1, &a); - } + ftmobj_resize_to_current_text(self); if(self->activated == 0 && self->changing_size == 0) { self->changing_size = 1; @@ -1032,7 +1048,7 @@ fix_height_and_width(self); self->changing_size = 0; } - } + } if(attrname == gensym("rect")) { if(sender == self->editor_view) @@ -1046,15 +1062,15 @@ } else if(attrname == gensym("editbox")) { - object_attr_getvalueof(sender, gensym("editbox"), &ac, &av); + object_attr_getvalueof(sender, gensym("editbox"), &ac, &av); debug_post("ftmobj_notify msg %s attr %s", msg->s_name, attrname->s_name); - + if(ac == 1 && atom_gettype(av) == A_OBJ && atom_getobj(av) == (t_object *)self) { int locked = patcherview_get_locked((t_object *)sender); if(self->activated == 0 && !locked) - textfield_activate_byclick(self, (t_object *)sender); - else + textfield_activate_byclick(self, (t_object *)sender); + else if(locked)//fix to avoid edition when object is double-clicked in runmode { t_atom arv; @@ -1061,7 +1077,7 @@ object_method_typed( (t_object *)sender, gensym("endeditbox"), 0, NULL, &arv); } } - else + else { if(self->activated == 1) textfield_deactivate(self); @@ -1075,26 +1091,26 @@ if (ac == 1 && atom_gettype(av) == A_LONG) { - int locked = (int)atom_getlong(av); - debug_post(" locked %d description '%s' name '%s'", locked, ftmobj_str_description(self), ftmobj_str_name(self)); - - if (locked == 0) // MRO unlocked - { // reinstall original text in textfield with #1 for display and editing, (but keep replaced text in parsed description) - - textfield_init_bounds_and_text(self, self->edit_name, 1); // repaint textfield from description/name_init - } - else if (locked == 1) // avoid load lock == 255 - { // display replaced text with #1 transcoded to abstraction args - textfield_init_bounds_and_text(self, self->edit_name, 0); // from description/name_init - } - debug_post("--> locked %d description '%s' name '%s'", locked, ftmobj_str_description(self), ftmobj_str_name(self)); + int locked = (int)atom_getlong(av); + debug_post(" locked %d description '%s' name '%s'", locked, ftmobj_str_description(self), ftmobj_str_name(self)); + + if (locked == 0) // MRO unlocked + { // reinstall original text in textfield with #1 for display and editing, (but keep replaced text in parsed description) + + textfield_init_bounds_and_text(self, self->edit_name, 1); // repaint textfield from description/name_init + } + else if (locked == 1) // avoid load lock == 255 + { // display replaced text with #1 transcoded to abstraction args + textfield_init_bounds_and_text(self, self->edit_name, 0); // from description/name_init + } + debug_post("--> locked %d description '%s' name '%s'", locked, ftmobj_str_description(self), ftmobj_str_name(self)); } - } + } } else if(msg == gensym("interface")) { if(data != NULL) - self->editor_interface = (fts_symbol_t )data; + self->editor_interface = (fts_symbol_t )data; } else if(msg == gensym("free")) { @@ -2336,7 +2352,7 @@ } else { - self->description_init = fts_s_empty_string; + self->description_init = /*fts_s_empty_string*/sym_empty_description; self->persistence_init = ftm_context_is_persistent(&self->context); } @@ -2444,7 +2460,7 @@ CLASS_ATTR_DEFAULTNAME_SAVE_PAINT(_mc,"textcolor", 0, "0. 0. 0. 1."); CLASS_ATTR_DEFAULT(_mc, "patching_rect", 0, "0. 0. 64. 18."); - CLASS_ATTR_ACCESSORS(_mc, "patching_size", NULL, ftmobj_set_attribute_patching_size); + CLASS_ATTR_ACCESSORS(_mc, "patching_size", NULL, /*ftmobj_set_attribute_patching_size*/NULL); CLASS_ATTR_SYM(_mc, "editor_interface", 0, ftmobj_t, editor_interface); CLASS_ATTR_SAVE(_mc,"editor_interface", 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |