set background, border color

Nov 24, 2012 at 2:13pm

set background, border color

Hey,

does anyone know how to set the background, border color of a external from within?

#65344
Nov 24, 2012 at 2:38pm

Hi,

An UI external ?

class_addmethod(c, (method)tralala_params, "getdrawparams", A_CANT, 0);

...

void tralala_params(t_tll *x, t_object *pv, t_jboxdrawparams *params)
{
    jrgba_copy(&params->d_bordercolor, &x->border);
    jrgba_copy(&params->d_boxfillcolor, &x->background);
}
void tralala_params(t_tll *x, t_object *pv, t_jboxdrawparams *params)
{
    if (TLL_FLAG_TRUE(TLL_FLAG_FOCUS)) {
        jrgba_copy(&params->d_bordercolor, &x->border);
        jrgba_copy(&params->d_boxfillcolor, &x->background);
    } else {
        jrgba_copy(&params->d_bordercolor, &x->uBorder);
        jrgba_copy(&params->d_boxfillcolor, &x->uBackground);
    }
}
#235495
Nov 24, 2012 at 2:52pm

Hi Nicolas,
wow, that was fast. I meant for a non ui object. Does your code work for those?

#235496
Nov 24, 2012 at 3:13pm

Hello,

No, that is only for UI object.

#235497
Nov 24, 2012 at 3:22pm

hmm, does anyone know for a non-ui object?

#235498
Nov 24, 2012 at 3:45pm

Hi,

You can do something like that :

void flop_bang(t_flop *x)
{
    t_jrgba color;
    t_object *mybox = NULL;

    if (!(object_obex_lookup(x, gensym("#B"), &mybox))) {
        jrgba_set(&color, 1., 1., 0., 1.);
        object_attr_setcolor(mybox, gensym("color"), &color);
    }
}
#235499
Nov 24, 2012 at 4:09pm

Hi,

that’s exactly what I needed, thanks Nicolas!

#235500
Nov 24, 2012 at 4:25pm

Hi one more question about this,

should t_jrgba color be freed at the end of the function with sysmem_freeptr(color)?

#235501
Nov 24, 2012 at 4:36pm

Hi,

No (as t_jrgba is just a structure allocated on the stack).

typedef struct _jrgba {
    double red;      ///< Red component in the range [0.0, 1.0]
    double green;    ///< Green component in the range [0.0, 1.0]
    double blue;
    double alpha;    ///< Alpha (transparency) component in the range [0.0, 1.0]
} t_jrgba;
#235502
Nov 24, 2012 at 4:49pm

Hey,

good to know. Thanks again!

#235503

You must be logged in to reply to this topic.