/* Copyright (c) 2002-2003 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ /* FIXME creation lag (X-specific) */ /* LATER think about pushing text to the text editor (ctrl-t) -- not easy, because we are not 'textedfor' */ #include #include #include #include #include "m_pd.h" #include "g_canvas.h" #include "common/loud.h" /* our proxy of the text_class (not in the API), LATER do not cheat */ static t_class *makeshift_class; //#define COMMENT_DEBUG #define COMMENT_LMARGIN 1 #define COMMENT_RMARGIN 1 #define COMMENT_TMARGIN 2 #define COMMENT_BMARGIN 2 #define COMMENT_MINWIDTH 8 #define COMMENT_HANDLEWIDTH 8 #define COMMENT_OUTBUFSIZE 1000 typedef struct _comment { t_object x_ob; t_glist *x_glist; t_canvas *x_canvas; /* also an 'isvised' flag */ t_symbol *x_bindsym; char x_tag[32]; char x_texttag[32]; char x_outlinetag[32]; t_clock *x_transclock; t_binbuf *x_binbuf; char *x_textbuf; int x_textbufsize; int x_pixwidth; int x_bbset; int x_bbpending; int x_x1; int x_y1; int x_x2; int x_y2; int x_newx2; int x_dragon; int x_fontsize; /* requested size */ t_symbol *x_fontfamily; /* requested family */ int x_fontprops; /* LATER pack weight and slant */ t_symbol *x_encoding; /* requested encoding */ unsigned char x_red; unsigned char x_green; unsigned char x_blue; char x_color[8]; int x_selstart; int x_selend; int x_active; int x_ready; } t_comment; static t_class *comment_class; static t_class *commentsink_class; static t_pd *commentsink = 0; static void comment_draw(t_comment *x) { char buf[COMMENT_OUTBUFSIZE], *outbuf, *outp; int cvid = (int)x->x_canvas; int reqsize = x->x_textbufsize + 350; /* FIXME estimation */ if (reqsize > COMMENT_OUTBUFSIZE) { #ifdef COMMENT_DEBUG post("allocating %d outbuf bytes", reqsize); #endif if (!(outbuf = getbytes(reqsize))) return; } else outbuf = buf; outp = outbuf; if (x->x_encoding) sprintf(outp, "set tt [comment_entext %s {%.*s}]\n", x->x_encoding->s_name, x->x_textbufsize, x->x_textbuf); else sprintf(outp, "set tt {%.*s}\n", x->x_textbufsize, x->x_textbuf); outp += strlen(outp); sprintf(outp, ".x%x.c create text %f %f -text $tt \ -tags {%s %s} -font {%s %d} -fill %s", cvid, (float)(text_xpix((t_text *)x, x->x_glist) + COMMENT_LMARGIN), (float)(text_ypix((t_text *)x, x->x_glist) + COMMENT_TMARGIN), x->x_texttag, x->x_tag, x->x_fontfamily->s_name, x->x_fontsize, (glist_isselected(x->x_glist, &x->x_glist->gl_gobj) ? "blue" : x->x_color)); outp += strlen(outp); if (x->x_pixwidth) sprintf(outp, " -width %d -anchor nw\n", x->x_pixwidth); else strcpy(outp, " -anchor nw\n"); outp += strlen(outp); sprintf(outp, "comment_bbox %s .x%x.c %s\n", x->x_bindsym->s_name, cvid, x->x_texttag); outp += strlen(outp); sprintf(outp, ".x%x.c bind %s