Exemplo n.º 1
0
t_canvas *riddle_nextgraph(t_riddle *rd)
{
    while (rd->rd_private->pr_oc)
    {
        t_object *dst;
        t_inlet *ip;
        int inno;
        rd->rd_private->pr_oc =
            obj_nexttraverseoutlet(rd->rd_private->pr_oc, &dst, &ip, &inno);
        if (dst)
        {
            int siginno = obj_siginletindex(dst, inno);
            if (siginno < 0)
            {
                /* should not happen, LATER rethink */
                break;
            }
            else if (pd_class((t_pd *)dst) != canvas_class)
            {
                loud_error((t_pd *)rd, "invalid connection (not to a canvas)");
                break;
            }
            else return ((t_canvas *)dst);
        }
    }
    return (0);
}
Exemplo n.º 2
0
    /* just forward any messages to the garray */
static void array_define_anything(t_glist *x,
    t_symbol *s, int argc, t_atom *argv)
{
    t_glist *gl = (x->gl_list ? pd_checkglist(&x->gl_list->g_pd) : 0);
    if (gl && gl->gl_list && pd_class(&gl->gl_list->g_pd) == garray_class)
        typedmess(&gl->gl_list->g_pd, s, argc, argv);
    else bug("array_define_anything");
}
Exemplo n.º 3
0
static t_float gobj_getxforsort(t_gobj *g)
{
    if (pd_class(&g->g_pd) == scalar_class)
    {
        t_float x1, y1;
        scalar_getbasexy((t_scalar *)g, &x1, &y1);
        return(x1);
    }
    else return (0);
}
Exemplo n.º 4
0
void canvas_undo_cleardirty(t_canvas *x)
{
        /* clear dirty flags of this canvas
         * and all sub-canvases (but not abstractions/
         */
    t_gobj*y;
    canvas_undo_docleardirty(x);
    for(y=x->gl_list; y; y=y->g_next)
        if (pd_class(&y->g_pd) == canvas_class && !canvas_isabstraction((t_canvas*)y))
            canvas_undo_cleardirty((t_canvas*)y);
}
Exemplo n.º 5
0
void max_default(t_pd *x, t_symbol *s, int argc, t_atom *argv)
{
    int i;
    char str[80];
    startpost("%s: unknown message %s", class_getname(pd_class(x)),
        s->s_name);
    for (i = 0; i < argc; i++)
    {
        atom_string(argv+i, str, 80);
        poststring(str);
    }
    endpost();
}
Exemplo n.º 6
0
static int canvas_undo_doisdirty(t_canvas*x)
{
    t_undo *udo = x?canvas_undo_get(x):0;
    t_gobj*y;
    if (!udo) return 0;
    if (udo->u_last != udo->u_cleanstate) return 1;

    for(y=x->gl_list; y; y=y->g_next)
        if (pd_class(&y->g_pd) == canvas_class && !canvas_isabstraction((t_canvas*)y))
            if (canvas_undo_doisdirty((t_canvas*)y))
                return 1;
    return 0;
}
Exemplo n.º 7
0
void canvas_resortoutlets(t_canvas *x)
{
    int noutlets = 0, i, j, xmax;
    t_gobj *y, **vec, **vp, **maxp;

    for (noutlets = 0, y = x->gl_list; y; y = y->g_next)
        if (pd_class(&y->g_pd) == voutlet_class) noutlets++;

    if (noutlets < 2) return;

    vec = (t_gobj **)getbytes(noutlets * sizeof(*vec));

    for (y = x->gl_list, vp = vec; y; y = y->g_next)
        if (pd_class(&y->g_pd) == voutlet_class) *vp++ = y;

    for (i = noutlets; i--;)
    {
        t_outlet *ip;
        for (vp = vec, xmax = -0x7fffffff, maxp = 0, j = noutlets;
                j--; vp++)
        {
            int x1, y1, x2, y2;
            t_gobj *g = *vp;
            if (!g) continue;
            gobj_getrect(g, x, &x1, &y1, &x2, &y2);
            if (x1 > xmax) xmax = x1, maxp = vp;
        }
        if (!maxp) break;
        y = *maxp;
        *maxp = 0;
        ip = voutlet_getit(&y->g_pd);

        obj_moveoutletfirst(&x->gl_obj, ip);
    }
    freebytes(vec, noutlets * sizeof(*vec));
    if (x->gl_owner && glist_isvisible(x->gl_owner))
        canvas_fixlinesfor(x->gl_owner, &x->gl_obj);
}
Exemplo n.º 8
0
static void plustot_env_takeover(t_glist *glist, t_plusbob *defparent,
				 t_plusbob *newparent)
{
    t_gobj *g;
    for (g = glist->gl_list; g; g = g->g_next)
    {
	if (pd_class(&g->g_pd) == canvas_class)
	{
	    if (!plustin_glistfind((t_glist *)g, PLUSTIN_GLIST_THIS))
		plustot_env_takeover((t_glist *)g, defparent, newparent);
	}
	else plusbob_detachownedchildren(defparent, newparent, (t_pd *)g);
    }
}
Exemplo n.º 9
0
static void array_define_bang(t_glist *x)
{
    t_glist *gl = (x->gl_list ? pd_checkglist(&x->gl_list->g_pd) : 0);
    if (gl && gl->gl_list && pd_class(&gl->gl_list->g_pd) == garray_class)
    {
        t_gpointer gp;
        gpointer_init(&gp);
        gpointer_setglist(&gp, gl,
            garray_getscalar((t_garray *)gl->gl_list));
        outlet_pointer(x->gl_obj.ob_outlet, &gp);
        gpointer_unset(&gp);
    }
    else bug("array_define_bang");
}
Exemplo n.º 10
0
    /* send a pointer to the scalar that owns this array to
    whomever is bound to the given symbol */
static void array_define_send(t_glist *x, t_symbol *s)
{
    t_glist *gl = (x->gl_list ? pd_checkglist(&x->gl_list->g_pd) : 0);
    if (!s->s_thing)
        pd_error(x, "array_define_send: %s: no such object", s->s_name);
    else if (gl && gl->gl_list && pd_class(&gl->gl_list->g_pd) == garray_class)
    {
        t_gpointer gp;
        gpointer_init(&gp);
        gpointer_setglist(&gp, gl,
            garray_getscalar((t_garray *)gl->gl_list));
        pd_pointer(s->s_thing, &gp);
        gpointer_unset(&gp);
    }
    else bug("array_define_send");
}
Exemplo n.º 11
0
static void array_define_yrange(t_glist *x, t_floatarg ylo, t_floatarg yhi)
{
    t_glist *gl = (x->gl_list ? pd_checkglist(&x->gl_list->g_pd) : 0);
    if (gl && gl->gl_list && pd_class(&gl->gl_list->g_pd) == garray_class)
    {
        int n = garray_getarray((t_garray *)gl->gl_list)->a_n;
        vmess(&x->gl_list->g_pd, gensym("bounds"),
            "ffff", 0., yhi, (double)(n == 1 ? n : n-1), ylo);
        vmess(&x->gl_list->g_pd, gensym("xlabel"),
            "fff", ylo + glist_pixelstoy(gl, 2) - glist_pixelstoy(gl, 0),
                0., (float)(n-1));
        vmess(&x->gl_list->g_pd, gensym("ylabel"),
            "fff", glist_pixelstox(gl, 0) - glist_pixelstox(gl, 5), ylo, yhi);
    }
    else bug("array_define_yrange");
}
Exemplo n.º 12
0
/* delete an object from a glist and free it */
void glist_delete(t_glist *x, t_gobj *y)
{
    t_gobj *g;
    t_object *ob;
    t_gotfn chkdsp = zgetfn(&y->g_pd, gensym("dsp"));
    t_canvas *canvas = glist_getcanvas(x);
    int drawcommand = class_isdrawcommand(y->g_pd);
    int wasdeleting;

    wasdeleting = canvas_setdeleting(canvas, 1);
    if (x->gl_editor)
    {
        if (x->gl_editor->e_grab == y) x->gl_editor->e_grab = 0;
        if (glist_isselected(x, y)) glist_deselect(x, y);

        /* HACK -- we had phantom outlets not getting erased on the
        screen because the canvas_setdeleting() mechanism is too
        crude.  LATER carefully set up rules for when the rtexts
        should exist, so that they stay around until all the
        steps of becoming invisible are done.  In the meantime, just
        zap the inlets and outlets here... */
        if (pd_class(&y->g_pd) == canvas_class)
        {
            t_glist *gl = (t_glist *)y;
            if (gl->gl_isgraph && glist_isvisible(x))
            {
                char tag[80];
                sprintf(tag, "graph%lx", (t_int)gl);
                glist_eraseiofor(x, &gl->gl_obj, tag);
            }
            else
            {
                if (glist_isvisible(x))
                    text_eraseborder(&gl->gl_obj, x,
                                     rtext_gettag(glist_findrtext(x, &gl->gl_obj)));
            }
        }
    }
    /* if we're a drawing command, erase all scalars now, before deleting
    it; we'll redraw them once it's deleted below. */
    if (drawcommand)
        canvas_redrawallfortemplate(template_findbyname(canvas_makebindsym(
                                        glist_getcanvas(x)->gl_name)), 2);
    gobj_delete(y, x);
    if (glist_isvisible(canvas))
    {
        gobj_vis(y, x, 0);
    }
    if (x->gl_editor && (ob = pd_checkobject(&y->g_pd)))
        rtext_new(x, ob);
    if (x->gl_list == y) x->gl_list = y->g_next;
    else for (g = x->gl_list; g; g = g->g_next)
            if (g->g_next == y)
            {
                g->g_next = y->g_next;
                break;
            }
    pd_free(&y->g_pd);
    if (chkdsp) canvas_update_dsp();
    if (drawcommand)
        canvas_redrawallfortemplate(template_findbyname(canvas_makebindsym(
                                        glist_getcanvas(x)->gl_name)), 1);
    canvas_setdeleting(canvas, wasdeleting);
    x->gl_valid = ++glist_valid;
}
Exemplo n.º 13
0
static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
    int *indexp)
{
    //fprintf(stderr,"rtext_senditup <%s>\n", x->x_buf);
    if (x)
    {
        t_float dispx, dispy;
        char smallbuf[200], *tempbuf;
        int outchars_b = 0, nlines = 0, ncolumns = 0,
            pixwide, pixhigh, font, fontwidth, fontheight, findx, findy;
        int reportedindex = 0;
        t_canvas *canvas = glist_getcanvas(x->x_glist);
        int widthspec_c = x->x_text->te_width; // width if any specified
        // width limit in chars
        int widthlimit_c = (widthspec_c ? widthspec_c : BOXWIDTH);
        //fprintf(stderr,"senditup widthlimit_c %d %d\n",
        //    widthspec_c, widthlimit_c);
        int inindex_b = 0; // index location in the buffer
        int inindex_c = 0; // index location in the u8 chars
        int selstart_b = 0, selend_b = 0; // selection start and end
        // buffer size in u8 chars
        int x_bufsize_c = u8_charnum(x->x_buf, x->x_bufsize);
            /* if we're a GOP (the new, "goprect" style) borrow the font size
            from the inside to preserve the spacing */
        if (pd_class(&x->x_text->te_pd) == canvas_class &&
            ((t_glist *)(x->x_text))->gl_isgraph &&
            ((t_glist *)(x->x_text))->gl_goprect)
                font =  glist_getfont((t_glist *)(x->x_text));
        else font = glist_getfont(x->x_glist);
        fontwidth = sys_fontwidth(font);
        fontheight = sys_fontheight(font);
        // calculating x and y in pixels
        findx = (*widthp + (fontwidth/2)) / fontwidth;
        findy = *heightp / fontheight;
        if (x->x_bufsize >= 100)
             tempbuf = (char *)t_getbytes(2 * x->x_bufsize + 1);
        else tempbuf = smallbuf;
        while (x_bufsize_c - inindex_c > 0)
        {
            int inchars_b  = x->x_bufsize - inindex_b;
            int inchars_c  = x_bufsize_c  - inindex_c;
            int maxindex_c =
                (inchars_c > widthlimit_c ? widthlimit_c : inchars_c);
            int maxindex_b = u8_offset(x->x_buf + inindex_b, maxindex_c);
            int eatchar = 1;
            int foundit_b  = firstone(x->x_buf + inindex_b, '\n', maxindex_b);
            int foundit_c;
            //following deals with \v replacement for \n in multiline comments
            int foundit_bv  = firstone(x->x_buf + inindex_b, '\v', maxindex_b);
            //fprintf(stderr,"%d %d <%s>\n", foundit_b, foundit_bv, x->x_buf);
            if ((foundit_bv < foundit_b && foundit_bv != -1) ||
                (foundit_b == -1 && foundit_bv != -1))
                foundit_b = foundit_bv;
            if (foundit_b < 0) //if we did not find an \n
            { 
                /* too much text to fit in one line? */
                if (inchars_c > widthlimit_c)
                {
                    /* is there a space to break the line at?  OK if it's even
                    one byte past the end since in this context we know there's
                    more text */
                    foundit_b =
                        lastone(x->x_buf + inindex_b, ' ', maxindex_b + 1);
                    if (foundit_b < 0)
                    {
                        foundit_b = maxindex_b;
                        foundit_c = maxindex_c;
                        eatchar = 0;
                    }
                    else
                        foundit_c = u8_charnum(x->x_buf + inindex_b, foundit_b);
                }
                else
                {
                    foundit_b = inchars_b;
                    foundit_c = inchars_c;
                    eatchar = 0;
                }
            }
            else
                foundit_c = u8_charnum(x->x_buf + inindex_b, foundit_b);

            if (nlines == findy)
            {
                int actualx = (findx < 0 ? 0 :
                    (findx > foundit_c ? foundit_c : findx));
                *indexp = inindex_b + u8_offset(x->x_buf + inindex_b, actualx);
                reportedindex = 1;
            }
            //fprintf(stderr,"eatchar %d <%s>\n", eatchar, tempbuf);
            strncpy(tempbuf+outchars_b, x->x_buf + inindex_b, foundit_b);
            if (x->x_selstart >= inindex_b &&
                x->x_selstart <= inindex_b + foundit_b + eatchar)
                    selstart_b = x->x_selstart + outchars_b - inindex_b;
            if (x->x_selend >= inindex_b &&
                x->x_selend <= inindex_b + foundit_b + eatchar)
                    selend_b = x->x_selend + outchars_b - inindex_b;
            outchars_b += foundit_b;
            inindex_b += (foundit_b + eatchar);
            inindex_c += (foundit_c + eatchar);
            if (inindex_b < x->x_bufsize)
                tempbuf[outchars_b++] = '\n';
            // if we found a row that is longer than previous (total width)
            if (foundit_c > ncolumns)
                ncolumns = foundit_c;
            nlines++;
        }
        // append new line in case we end our input with an \n
        if (x->x_buf[x_bufsize_c - 1] == '\n')
        {
            nlines++;
        }
        if (!reportedindex)
            *indexp = outchars_b;
        dispx = text_xpix(x->x_text, x->x_glist);
        dispy = text_ypix(x->x_text, x->x_glist);
        if (nlines < 1) nlines = 1;
        if (!widthspec_c)
        {
            while (ncolumns < (x->x_text->te_type == T_TEXT ? 1 : 3))
            {
                tempbuf[outchars_b++] = ' ';
                ncolumns++;
            }
        }
        else ncolumns = widthspec_c;
        pixwide = ncolumns * fontwidth + (LMARGIN + RMARGIN);
        pixhigh = nlines * fontheight + (TMARGIN + BMARGIN);

        if (action && x->x_text->te_width && x->x_text->te_type != T_ATOM)
        {
                /* if our width is specified but the "natural" width is the
                same as the specified width, set specified width to zero
                so future text editing will automatically change width.
                Except atoms whose content changes at runtime. */
            int widthwas = x->x_text->te_width, newwidth = 0, newheight = 0,
                newindex = 0;
            x->x_text->te_width = 0;
            rtext_senditup(x, 0, &newwidth, &newheight, &newindex);
            if (newwidth/fontwidth != widthwas)
                x->x_text->te_width = widthwas;
            else x->x_text->te_width = 0;
            //fprintf(stderr,"senditup width %d %d %d\n",
            //    newwidth/fontwidth, widthwas, x->x_text->te_width);
        }
        if (action == SEND_FIRST)
        {
            //fprintf(stderr,"canvas=.x%lx %s\n", (t_int)canvas, tempbuf);
            sys_vgui("pdtk_text_new .x%lx.c {%s %s text} %f %f {%.*s} %d %s\n",
                canvas, x->x_tag, rtext_gettype(x)->s_name,
                dispx + LMARGIN, dispy + TMARGIN,
                outchars_b, tempbuf, sys_hostfontsize(font),
                (glist_isselected(x->x_glist,
                    &x->x_glist->gl_gobj)? "$pd_colors(selection)" :
                        "$pd_colors(text)"));
        }
        else if (action == SEND_UPDATE)
        {
            /*fprintf(stderr,
                "SEND_UPDATE canvas_class=%d isgraph=%d goprect=%d\n",
                (pd_class(&x->x_text->te_pd) == canvas_class ? 1 : 0),
                ((t_glist *)(x->x_text))->gl_isgraph,
                ((t_glist *)(x->x_text))->gl_goprect );*/

            sys_vgui("pdtk_text_set .x%lx.c %s {%.*s}\n",
                canvas, x->x_tag, outchars_b, tempbuf);

            /*if ( pd_class(&x->x_text->te_pd) == canvas_class &&
                ((t_glist *)(x->x_text))->gl_isgraph &&
                (((t_glist *)(x->x_text))->gl_goprect) )
            {
                fprintf(stderr, "do not update outlets\n");
            }
            else */

            if (pixwide != x->x_drawnwidth || pixhigh != x->x_drawnheight) 
                text_drawborder(x->x_text, x->x_glist, x->x_tag,
                    pixwide, pixhigh, 0);
            if (x->x_active)
            {
                if (selend_b > selstart_b)
                {
                    sys_vgui(".x%lx.c select from %s %d\n", canvas, 
                        x->x_tag, u8_charnum(tempbuf, selstart_b));
                    sys_vgui(".x%lx.c select to %s %d\n", canvas, 
                        x->x_tag, u8_charnum(tempbuf, selend_b)
                          + (sys_oldtclversion ? 0 : -1));
                    sys_vgui(".x%lx.c focus \"\"\n", canvas);        
                }
                else
                {
                    sys_vgui(".x%lx.c select clear\n", canvas);
                    sys_vgui(".x%lx.c icursor %s %d\n", canvas, x->x_tag,
                        u8_charnum(tempbuf, selstart_b));
                    sys_vgui(".x%lx.c focus %s\n", canvas, x->x_tag);        
                }
            }
        }
        x->x_drawnwidth = pixwide;
        x->x_drawnheight = pixhigh;
        
        *widthp = pixwide;
        *heightp = pixhigh;
        if (tempbuf != smallbuf)
            t_freebytes(tempbuf, 2 * x->x_bufsize + 1);
    }
}
Exemplo n.º 14
0
Arquivo: g_rtext.c Projeto: cviejo/mPD
void rtext_activate(t_rtext *x, int state)
{
    //fprintf(stderr,"rtext_activate state=%d\n", state);
    int w = 0, h = 0, widthspec, heightspec, indx, isgop;
    t_glist *glist = x->x_glist;
    t_canvas *canvas = glist_getcanvas(glist);
    //if (state && x->x_active) printf("duplicate rtext_activate\n");
    // the following prevents from selecting all when inside an
    // object that is already being texted for... please *test*
    // "fixes" before committing them
    //if (state == x->x_active) return; // avoid excess calls
    if (state)
    {
        //sys_vgui(".x%lx.c focus %s\n", canvas, x->x_tag);
        glist->gl_editor->e_textedfor = x;
        glist->gl_editor->e_textdirty = 0;
        x->x_dragfrom = x->x_selstart = 0;
        x->x_selend = x->x_bufsize;
        x->x_active = 1;
    }
    else
    {
        //sys_vgui("selection clear .x%lx.c\n", canvas);
        //sys_vgui(".x%lx.c focus \"\"\n", canvas);
        if (glist->gl_editor->e_textedfor == x)
            glist->gl_editor->e_textedfor = 0;
        x->x_active = 0;
    }
    rtext_senditup(x, SEND_UPDATE, &w, &h, &indx);
    /* hack...
       state = 0 no editing
       state = 1 editing
       state = 2 editing a new object
       State 2 isn't necessary, except that Pd has
       traditionally had this "floating" state for
       new objects where the box text is editable and
       the box position follows the mouse
    */

    /* If we're a gop canvas... */
    if (pd_class((t_pd*)x->x_text) == canvas_class &&
        ((t_canvas *)x->x_text)->gl_isgraph)
    {
        widthspec = ((t_canvas *)x->x_text)->gl_pixwidth;
        heightspec = ((t_canvas *)x->x_text)->gl_pixheight;
        isgop = 1;
    }
    else
    {
        widthspec = x->x_text->te_width; // width if any specified
        heightspec = -1; // signal that we don't have a heightspec
        isgop = 0;
    }

    /* we need to get scroll to make sure we've got the
       correct bbox for the svg */
    canvas_getscroll(glist_getcanvas(canvas));
    gui_vmess("gui_textarea", "xssiiiisiii",
        canvas,
        x->x_tag,
        (pd_class((t_pd *)x->x_text) == message_class ? "msg" : "obj"),
        x->x_text->te_xpix,
        x->x_text->te_ypix,
        widthspec,
        heightspec,
        x->x_buf,
        sys_hostfontsize(glist_getfont(glist)),
        isgop,
        state);
}
Exemplo n.º 15
0
static int rdsink_push(t_rdsink *si, t_object *x, int outno)
{
    int result = 1;
    t_outlet *op;
    t_outconnect *oc = obj_starttraverseoutlet(x, &op, outno);
    while (oc)
    {
        t_object *dst;
        t_inlet *ip;
        int inno;
        oc = obj_nexttraverseoutlet(oc, &dst, &ip, &inno);
        if (dst)
        {
            int siginno = obj_siginletindex(dst, inno);
            if (siginno < 0)
            {
                /* should not happen, LATER rethink */
            }
            else if (zgetfn((t_pd *)dst, rdps__reblock))
            {
                si->si_outbuf->a_w.w_float = (t_float)siginno;
                typedmess((t_pd *)dst, rdps__reblock, 4, si->si_outbuf);
            }
            else if (pd_class((t_pd *)dst) == canvas_class)
            {
                t_gobj *ob;
                int i;
                for (i = 0, ob = ((t_canvas *)dst)->gl_list;
                        ob; ob = ob->g_next)
                {
                    if (pd_class((t_pd *)ob) == vinlet_class)
                    {
                        if (i == inno)
                            break;
                        else
                            i++;
                    }
                }
                if (ob)
                {
#ifdef RIDDLE_DEBUG
                    riddlebug_post(si->si_riddle, "PUSH-SUBCANVAS",
                                   "vinlet %d (\"%s\")",
                                   inno, class_getname(*(t_pd *)ob));
#endif
                    rdsink_push(si, (t_object *)ob, 0);
                }
                else loudbug_bug("rdsink_push 1");
            }
            else if (pd_class((t_pd *)dst) == voutlet_class)
            {
                t_rdvoutlet *vout = (t_rdvoutlet *)dst;
                if (vout->x_canvas)
                {
                    int n;
                    t_outlet *o;
                    for (o = ((t_object *)vout->x_canvas)->ob_outlet, n = 0;
                            o; o = (t_outlet *)(((t_rdoutlet *)o)->o_next), n++)
                        if (o == vout->x_parentoutlet)
                            break;
                    if (o)
                    {
#ifdef RIDDLE_DEBUG
                        riddlebug_post(si->si_riddle, "PUSH-OUTLET",
                                       "outno %d, graph %x",
                                       n, (int)vout->x_canvas);
#endif
                        rdsink_push(si, (t_object *)vout->x_canvas, n);
                    }
                    else loudbug_bug("rdsink_push 2");
                }
#ifdef RIDDLE_DEBUG
                else riddlebug_post(si->si_riddle, "PUSH-OUTLET",
                                        "void canvas...");
#endif
            }
            else
            {
                char *dstname = class_getname(*(t_pd *)dst);
#ifdef RIDDLE_DEBUG
                riddlebug_post(si->si_riddle, "PUSH-RIDDLESS",
                               "inlet %d (\"%s\")", inno, dstname);
#endif
                if (si->si_flags & RIDDLE_STRICTNESSMASK)
                {
                    if (strcmp(dstname, "print~"))
                    {
                        loud_error((t_pd *)x, "not a riddle: \"%s\"", dstname);
                        result = 0;
                    }
                }
                else if (!strcmp(dstname, "send~") ||
                         !strcmp(dstname, "throw~"))
                {
                    loud_error((t_pd *)x, "bad destination: \"%s\"", dstname);
                    result = 0;
                }
            }
        }
    }
    return (result);
}
Exemplo n.º 16
0
t_outlet *voutlet_getit(t_pd *x)
{
    if (pd_class(x) != voutlet_class) bug("voutlet_getit");
    return (((t_voutlet *)x)->x_parentoutlet);
}
Exemplo n.º 17
0
t_inlet *vinlet_getit(t_pd *x)
{
    if (pd_class(x) != vinlet_class) bug("vinlet_getit");
    return (((t_vinlet *)x)->x_inlet);
}
Exemplo n.º 18
0
Arquivo: g_rtext.c Projeto: cviejo/mPD
static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
    int *indexp)
{
    //fprintf(stderr,"rtext_senditup <%s>\n", x->x_buf);
    if (x)
    {
        t_float dispx, dispy;
        char smallbuf[200] = { '\0' }, *tempbuf;
        int outchars_b = 0, nlines = 0, ncolumns = 0,
            pixwide, pixhigh, font, fontwidth, fontheight, findx, findy;
        int reportedindex = 0;
        t_canvas *canvas = glist_getcanvas(x->x_glist);
        int widthspec_c = x->x_text->te_width; // width if any specified
        // width limit in chars
        int widthlimit_c = (widthspec_c ? widthspec_c : BOXWIDTH);
        int inindex_b = 0; // index location in the buffer
        int inindex_c = 0; // index location in the u8 chars
        int selstart_b = 0, selend_b = 0; // selection start and end
        // buffer size in u8 chars
        //fprintf(stderr,"buf = <%s> | last 2 chars = %d %d\n", x->x_buf, x->x_buf[x->x_bufsize-1], x->x_buf[x->x_bufsize]);
        int x_bufsize_c = u8_charnum(x->x_buf, x->x_bufsize);
            /* if we're a GOP (the new, "goprect" style) borrow the font size
            from the inside to preserve the spacing */
        if (pd_class(&x->x_text->te_pd) == canvas_class &&
            ((t_glist *)(x->x_text))->gl_isgraph &&
            ((t_glist *)(x->x_text))->gl_goprect)
                font =  glist_getfont((t_glist *)(x->x_text));
        else font = glist_getfont(x->x_glist);
        fontwidth = sys_fontwidth(font);
        fontheight = sys_fontheight(font);
        // calculating x and y in pixels
        findx = (*widthp + (fontwidth/2)) / fontwidth;
        findy = *heightp / fontheight;
        if (x->x_bufsize >= 100)
             tempbuf = (char *)t_getbytes(2 * x->x_bufsize + 1);
        else tempbuf = smallbuf;
        while (x_bufsize_c - inindex_c > 0)
        {
            int inchars_b  = x->x_bufsize - inindex_b;
            int inchars_c  = x_bufsize_c  - inindex_c;
            int maxindex_c =
                (inchars_c > widthlimit_c ? widthlimit_c : inchars_c);
            int maxindex_b = u8_offset(x->x_buf + inindex_b, maxindex_c);
            int eatchar = 1;
            //fprintf(stderr, "firstone <%s> inindex_b=%d maxindex_b=%d\n", x->x_buf + inindex_b, inindex_b, maxindex_b);
            int foundit_b  = firstone(x->x_buf + inindex_b, '\n', maxindex_b);
            int foundit_c;
            //following deals with \v replacement for \n in multiline comments
            int foundit_bv  = firstone(x->x_buf + inindex_b, '\v', maxindex_b);
            if ((foundit_bv < foundit_b && foundit_bv != -1) ||
                (foundit_b == -1 && foundit_bv != -1))
                foundit_b = foundit_bv;
            if (foundit_b < 0) //if we did not find an \n
            { 
                /* too much text to fit in one line? */
                if (inchars_c > widthlimit_c)
                {
                    /* is there a space to break the line at?  OK if it's even
                    one byte past the end since in this context we know there's
                    more text */
                    foundit_b =
                        lastone(x->x_buf + inindex_b, ' ', maxindex_b + 1);
                    if (foundit_b < 0)
                    {
                        foundit_b = maxindex_b;
                        foundit_c = maxindex_c;
                        eatchar = 0;
                    }
                    else
                        foundit_c = u8_charnum(x->x_buf + inindex_b, foundit_b);
                }
                else
                {
                    foundit_b = inchars_b;
                    foundit_c = inchars_c;
                    eatchar = 0;
                }
            }
            else
                foundit_c = u8_charnum(x->x_buf + inindex_b, foundit_b);

            if (nlines == findy)
            {
                int actualx = (findx < 0 ? 0 :
                    (findx > foundit_c ? foundit_c : findx));
                *indexp = inindex_b + u8_offset(x->x_buf + inindex_b, actualx);
                reportedindex = 1;
            }
            strncpy(tempbuf+outchars_b, x->x_buf + inindex_b, foundit_b);
            if (x->x_selstart >= inindex_b &&
                x->x_selstart <= inindex_b + foundit_b + eatchar)
                    selstart_b = x->x_selstart + outchars_b - inindex_b;
            if (x->x_selend >= inindex_b &&
                x->x_selend <= inindex_b + foundit_b + eatchar)
                    selend_b = x->x_selend + outchars_b - inindex_b;
            outchars_b += foundit_b;
            inindex_b += (foundit_b + eatchar);
            inindex_c += (foundit_c + eatchar);
            if (inindex_b < x->x_bufsize)
                tempbuf[outchars_b++] = '\n';
            // if we found a row that is longer than previous (total width)
            if (foundit_c > ncolumns)
                ncolumns = foundit_c;
            nlines++;
        }
        // append new line in case we end our input with an \n
        if (x_bufsize_c > 0 && (x->x_buf[x_bufsize_c - 1] == '\n' || x->x_buf[x_bufsize_c - 1] == '\v'))
        {
            nlines++;
            tempbuf[outchars_b++] = '\n';
            //tempbuf[outchars_b] = '\0';
            //outchars_b++;
        }
        if (!reportedindex)
            *indexp = outchars_b;
        dispx = text_xpix(x->x_text, x->x_glist);
        dispy = text_ypix(x->x_text, x->x_glist);
        if (nlines < 1) nlines = 1;
        if (!widthspec_c)
        {
            while (ncolumns < (x->x_text->te_type == T_TEXT ? 1 : 3))
            {
                tempbuf[outchars_b++] = ' ';
                ncolumns++;
            }
        }
        else ncolumns = widthspec_c;

        // add a null character at the end of the string --for u8_charnum
        // _and_ for the new gui_vmess calls which don't use the %.*s syntax.
        // Because of the way binbuf_gettext works, we should always have
        // a space before this null character. But I'm not 100% sure this
        // space is guaranteed to be there, so we'll just filter it out on
        // the GUI side for now.
        tempbuf[outchars_b++] = '\0';

        pixwide = ncolumns * fontwidth + (LMARGIN + RMARGIN);
        pixhigh = nlines * fontheight + (TMARGIN + BMARGIN);
        //printf("outchars_b=%d bufsize=%d %d\n", outchars_b, x->x_bufsize, x->x_buf[outchars_b]);

        if (action && x->x_text->te_width && x->x_text->te_type != T_ATOM)
        {
            /* if our width is specified but the "natural" width is the
               same as the specified width, set specified width to zero
               so future text editing will automatically change width.
               Except atoms whose content changes at runtime. */
            int widthwas = x->x_text->te_width, newwidth = 0, newheight = 0,
                newindex = 0;
            x->x_text->te_width = 0;
            rtext_senditup(x, 0, &newwidth, &newheight, &newindex);
            if (newwidth/fontwidth != widthwas)
                x->x_text->te_width = widthwas;
            else x->x_text->te_width = 0;
        }
        if (action == SEND_FIRST)
        {
            //fprintf(stderr,"send_first rtext=%lx t_text=%lx\n", x, x->x_text);
            gui_vmess("gui_text_new", "xssiiisi",
                canvas, x->x_tag, rtext_gettype(x)->s_name,
                glist_isselected(x->x_glist, ((t_gobj*)x->x_text)),
                LMARGIN,
                fontheight,
                tempbuf,
                sys_hostfontsize(font));
               
        }
        else if (action == SEND_UPDATE)
        {
            gui_vmess("gui_text_set", "xss", canvas, x->x_tag, tempbuf);

            // We add the check for T_MESSAGE below so that the box border
            // gets resized correctly using our interim event handling in
            // pd_canvas.html.  I could remove the conditional, but
            // this part of Pd is convoluted enough that I'm not sure
            // if there'd be any side effects.
            if (glist_isvisible(x->x_glist) && (pixwide != x->x_drawnwidth ||
                pixhigh != x->x_drawnheight ||
                x->x_text->te_type == T_MESSAGE)) 
                text_drawborder(x->x_text, x->x_glist, x->x_tag,
                    pixwide, pixhigh, 0);
            if (x->x_active)
            {
                if (selend_b > selstart_b)
                {
                    //sys_vgui(".x%lx.c select from %s %d\n", canvas, 
                    //    x->x_tag, u8_charnum(tempbuf, selstart_b));
                    //sys_vgui(".x%lx.c select to %s %d\n", canvas, 
                    //    x->x_tag, u8_charnum(tempbuf, selend_b)
                    //      + (sys_oldtclversion ? 0 : -1));
                    //sys_vgui(".x%lx.c focus \"\"\n", canvas);        
                }
                else
                {
                    //sys_vgui(".x%lx.c select clear\n", canvas);
                    //sys_vgui(".x%lx.c icursor %s %d\n", canvas, x->x_tag,
                    //    u8_charnum(tempbuf, selstart_b));
                    //sys_vgui(".x%lx.c focus %s\n", canvas, x->x_tag);        
                }
            }
        }
        x->x_drawnwidth = pixwide;
        x->x_drawnheight = pixhigh;
        
        *widthp = pixwide;
        *heightp = pixhigh;
        if (tempbuf != smallbuf)
            t_freebytes(tempbuf, 2 * x->x_bufsize + 1);
    }
    //printf("END\n");
}