t_max_err paramui_notify(t_paramui *x, t_symbol *s, t_symbol *msg, void *sender, void *data) { if(msg == _sym_modified) jbox_redraw(&x->box); else if((msg == _sym_attr_modified) && (sender == x)){ t_object *textfield; t_symbol *attrname; attrname = (t_symbol *)object_method((t_object *)data, gensym("getname")); if(attrname == _sym_name){ if(!x->attr_label || x->attr_label == _sym_nothing){ textfield = jbox_get_textfield((t_object*) x); object_method(textfield, gensym("settext"), x->attr_name->s_name); } } else if(attrname == gensym("label")){ if(x->attr_label && x->attr_label != _sym_nothing){ textfield = jbox_get_textfield((t_object*) x); object_method(textfield, gensym("settext"), x->attr_label->s_name); } } else paramui_menu_build(x); // we don't really want this everytime -- make this conditional... jbox_redraw(&x->box); } return MAX_ERR_NONE; }
void* paramui_oksize(t_paramui *x, t_rect *rect) { t_object *textfield = NULL; // We do textfield configuration here because the margins are dependent upon the dimensions // textfield is used for displaying the parameter name textfield = jbox_get_textfield((t_object*) x); textfield_set_noactivate(textfield, 1); textfield_set_readonly(textfield, 1); textfield_set_editonclick(textfield, 0); textfield_set_wordwrap(textfield, 0); textfield_set_useellipsis(textfield, 1); textfield_set_textcolor(textfield, &s_light_gray); textfield_set_textmargins(textfield, 18.0, 2.0, rect->width - 80.0, 2.0); return (void *)1; }
void odisplay_bundle2text(t_odisplay *x) { critical_enter(x->lock); if(x->newbndl && x->bndl_s){ long len = osc_bundle_s_getLen(x->bndl_s); char ptr[len]; memcpy(ptr, osc_bundle_s_getPtr(x->bndl_s), len); critical_exit(x->lock); long bufpos = osc_bundle_s_nformat(NULL, 0, len, (char *)ptr, 0); char *buf = osc_mem_alloc(bufpos + 1); osc_bundle_s_nformat(buf, bufpos + 1, len, (char *)ptr, 0); if (bufpos != 0) { /* if(buf[bufpos - 2] == '\n'){ buf[bufpos - 2] = '\0'; } */ } else { *buf = '\0'; } #ifndef OMAX_PD_VERSION critical_enter(x->lock); if(x->text){ osc_mem_free(x->text); } x->textlen = bufpos; x->text = buf; critical_exit(x->lock); object_method(jbox_get_textfield((t_object *)x), gensym("settext"), buf); #else opd_textbox_resetText(x->textbox, buf); #endif if(buf){ //osc_mem_free(buf); } x->newbndl = 0; } critical_exit(x->lock); }
void *odisplay_new(t_symbol *msg, short argc, t_atom *argv){ t_odisplay *x; t_dictionary *d = NULL; long boxflags; // box setup if(!(d = object_dictionaryarg(argc, argv))){ return NULL; } boxflags = 0 | JBOX_DRAWFIRSTIN | JBOX_NODRAWBOX | JBOX_DRAWINLAST | JBOX_TRANSPARENT //| JBOX_NOGROW //| JBOX_GROWY //| JBOX_GROWBOTH //| JBOX_HILITE //| JBOX_BACKGROUND //| JBOX_DRAWBACKGROUND //| JBOX_NOFLOATINSPECTOR //| JBOX_MOUSEDRAGDELTA | JBOX_TEXTFIELD ; if((x = (t_odisplay *)object_alloc(odisplay_class))){ jbox_new((t_jbox *)x, boxflags, argc, argv); x->ob.b_firstin = (void *)x; x->outlet = outlet_new(x, NULL); //x->proxy = proxy_new(x, 1, &(x->inlet)); x->bndl_u = NULL; x->bndl_s = NULL; x->newbndl = 0; x->textlen = 0; x->text = NULL; //x->bndl_has_been_checked_for_subs = 0; //x->bndl_has_subs = 0; critical_new(&(x->lock)); x->qelem = qelem_new((t_object *)x, (method)odisplay_refresh); x->new_data_indicator_clock = clock_new((t_object *)x, (method)odisplay_refresh); x->have_new_data = 1; x->draw_new_data_indicator = 0; attr_dictionary_process(x, d); t_object *textfield = jbox_get_textfield((t_object *)x); if(textfield){ object_attr_setchar(textfield, gensym("editwhenunlocked"), 0); textfield_set_readonly(textfield, '1'); textfield_set_selectallonedit(textfield, '1'); textfield_set_textmargins(textfield, 5, 5, 5, 15); textfield_set_textcolor(textfield, &(x->text_color)); } jbox_ready((t_jbox *)x); //odisplay_gettext(x); odisplay_clear(x); return x; } return NULL; }
// we get the text, convert it to an OSC bundle, and then call the paint // function via qelem_set which converts the OSC bundle back to text. // We do this so that it's formatted nicely with no unnecessary whitespace // and tabbed subbundles, etc. void odisplay_gettext(t_odisplay *x) { long size = 0; char *text = NULL; #ifdef OMAX_PD_VERSION text = x->textbox->text; #else t_object *textfield = jbox_get_textfield((t_object *)x); object_method(textfield, gensym("gettextptr"), &text, &size); #endif odisplay_clearBundles(x); size = strlen(text); // the value returned in text doesn't make sense if(size == 0){ return; } char *buf = text; if(text[size - 1] != '\n'){ buf = alloca(size + 2); memcpy(buf, text, size); buf[size] = '\n'; buf[size + 1] = '\0'; size += 2; } t_osc_bndl_u *bndl_u = NULL; t_osc_err e = osc_parser_parseString(size, buf, &bndl_u); if(e){ #ifdef OMAX_PD_VERSION // x->parse_error = 1; #endif object_error((t_object *)x, "error parsing bundle\n"); return; } t_osc_bndl_s *bs = osc_bundle_u_serialize(bndl_u); t_osc_bndl_s *bndl_s = NULL; osc_bundle_s_deepCopy(&bndl_s, bs); odisplay_newBundle(x, bndl_u, bndl_s); #ifdef OMAX_PD_VERSION x->have_new_data = 1; jbox_redraw((t_jbox *)x); #else x->have_new_data = 1; qelem_set(x->qelem); #endif /* if(size > 2){ int i; char *r = text + 1; char *w = text + 1; char *rm1 = text; for(i = 0; i <= size; i++){ if(*rm1 == ' ' && *r == ' '){ r++; }else{ *w++ = *r++; } rm1++; } } */ }
void odisplay_mouseup(t_odisplay *x, t_object *patcherview, t_pt pt, long modifiers){ textfield_set_textmargins(jbox_get_textfield((t_object *)x), 5, 5, 5, 15); jbox_redraw((t_jbox *)x); odisplay_output_bundle(x); }
void odisplay_mousedown(t_odisplay *x, t_object *patcherview, t_pt pt, long modifiers){ textfield_set_textmargins(jbox_get_textfield((t_object *)x), 6, 6, 5, 15); jbox_redraw((t_jbox *)x); }