Styles provide a means by which to inherit attribute values from a patcher that are consistently used across many objects. More...

+ Collaboration diagram for Styles:

Macros

#define FILL_ATTR_SAVE
 Flag indicating we want this fill attribute saved (creates attrs). More...
 
#define CLASS_ATTR_STYLE_RGBA_NOSAVE(c, attrname, flags, structname, structmember, label)
 Define an RGBA style attribute with standard settings. More...
 
#define CLASS_ATTR_STYLE_RGBA(c, attrname, flags, structname, structmember, label)
 Define an RGBA style attribute with standard settings. More...
 
#define CLASS_ATTR_STYLE_RGBA_PREVIEW(c, attrname, flags, structname, structmember, label, previewtype)
 Define an RGBA style attribute with standard settings. More...
 
#define CLASS_ATTR_STYLE_ALIAS_NOSAVE(c, attrname, aliasname)
 Define an unsaved alias. More...
 
#define CLASS_ATTR_STYLE_ALIAS_COMPATIBILITY(c, attrname, aliasname)
 Define a Max 5/6 saved compatibility alias. More...
 
#define CLASS_ATTR_STYLE_ALIAS_RGBA_LEGACY(c, attrname, aliasname)
 Define a Max 4 legacy RGB attribute alias. More...
 

Functions

BEGIN_USING_C_LINKAGE void class_attr_setstyle (t_class *c, const char *s)
 Add an attribute to the current style. More...
 
void class_attr_style_alias (t_class *c, const char *name, const char *aliasname, long legacy)
 Add an alias to the current style. More...
 
void class_attr_setfill (t_class *c, const char *name, long flags)
 Specify that an attr requires a fill. More...
 
void jgraphics_attr_fillrect (t_object *b, t_jgraphics *g, t_symbol *attrname, t_rect *area)
 Fill using the current value of a named style color that exists either in the object or the defined style. More...
 
t_jpatternjgraphics_attr_setfill (t_object *b, t_jgraphics *g, t_symbol *attrname, t_rect *area)
 Fill using the current value of a named style color that exists either in the object or the defined style. More...
 
void object_attr_getfillcolor_atposition (t_object *b, const char *attrname, double pos, t_jrgba *c)
 Determine the color at a given position in a fill. More...
 
long object_attr_getfill (t_object *obj, t_symbol *attrname)
 Determine if an attribute is a fill. More...
 
void class_attr_stylemap (t_class *c, char *attrname, char *mapname)
 Associate the name of an attribute of your class with the name of an attribute of a style. More...
 

Detailed Description

Styles provide a means by which to inherit attribute values from a patcher that are consistently used across many objects.

Macro Definition Documentation

#define CLASS_ATTR_STYLE_ALIAS_COMPATIBILITY (   c,
  attrname,
  aliasname 
)

Define a Max 5/6 saved compatibility alias.

Parameters
cThe class whose attribute will be added to the style.
attrnameThe name of the attribute of your class.
aliasnameThe name of the alias.
#define CLASS_ATTR_STYLE_ALIAS_NOSAVE (   c,
  attrname,
  aliasname 
)

Define an unsaved alias.

Parameters
cThe class whose attribute will be added to the style.
attrnameThe name of the attribute of your class.
aliasnameThe name of the alias.
See also
'jslider' example project in the SDK.
#define CLASS_ATTR_STYLE_ALIAS_RGBA_LEGACY (   c,
  attrname,
  aliasname 
)

Define a Max 4 legacy RGB attribute alias.

Parameters
cThe class whose attribute will be added to the style.
attrnameThe name of the attribute of your class.
aliasnameThe name of the alias.
See also
'jslider' example project in the SDK.
#define CLASS_ATTR_STYLE_RGBA (   c,
  attrname,
  flags,
  structname,
  structmember,
  label 
)

Define an RGBA style attribute with standard settings.

Parameters
cThe class whose attribute will be added to the style.
attrnameThe name of the attribute of your class.
flagsAny flags you wish to declare for this attribute, as defined in e_max_attrflags.
structnameThe C identifier for the struct (containing a valid t_object header) representing an instance of this class.
structmemberThe C identifier of the member in the struct that holds the value of this attribute.
labelA human-friendly label for the Max inspector.
See also
CLASS_ATTR_STYLE_RGBA_NOSAVE is a variant that does not save the state with the Patcher.
CLASS_ATTR_STYLE_RGBA_PREVIEW is a variant that provides a style preview.
class_attr_setstyle() is the lower level function used to provide the style part of the attribute definition.
#define CLASS_ATTR_STYLE_RGBA_NOSAVE (   c,
  attrname,
  flags,
  structname,
  structmember,
  label 
)

Define an RGBA style attribute with standard settings.

Parameters
cThe class whose attribute will be added to the style.
attrnameThe name of the attribute of your class.
flagsAny flags you wish to declare for this attribute, as defined in e_max_attrflags.
structnameThe C identifier for the struct (containing a valid t_object header) representing an instance of this class.
structmemberThe C identifier of the member in the struct that holds the value of this attribute.
labelA human-friendly label for the Max inspector.
See also
CLASS_ATTR_STYLE_RGBA is a variant that saves the state with the Patcher.
CLASS_ATTR_STYLE_RGBA_PREVIEW is a variant that provides a style preview.
class_attr_setstyle() is the lower level function used to provide the style part of the attribute definition.
#define CLASS_ATTR_STYLE_RGBA_PREVIEW (   c,
  attrname,
  flags,
  structname,
  structmember,
  label,
  previewtype 
)

Define an RGBA style attribute with standard settings.

Parameters
cThe class whose attribute will be added to the style.
attrnameThe name of the attribute of your class.
flagsAny flags you wish to declare for this attribute, as defined in e_max_attrflags.
structnameThe C identifier for the struct (containing a valid t_object header) representing an instance of this class.
structmemberThe C identifier of the member in the struct that holds the value of this attribute.
labelA human-friendly label for the Max inspector.
previewtypeType of preview to use in the style bar, e.g. "triangle_fill"
See also
CLASS_ATTR_STYLE_RGBA_NOSAVE is a variant that does not save the state with the Patcher.
CLASS_ATTR_STYLE_RGBA is a variant that saves the state with the Patcher but does not provide the preview.
class_attr_setstyle() is the lower level function used to provide the style part of the attribute definition.
#define FILL_ATTR_SAVE

Flag indicating we want this fill attribute saved (creates attrs).

See also
class_attr_setfill()
The 'uitextfield' example project in the SDK.

Function Documentation

void class_attr_setfill ( t_class c,
const char *  name,
long  flags 
)

Specify that an attr requires a fill.

Parameters
cThe class whose attribute is a fill.
nameThe name of the attribute.
flags0 for none, or FILL_ATTR_SAVE.
See also
The 'uitextfield' example project in the SDK.
BEGIN_USING_C_LINKAGE void class_attr_setstyle ( t_class c,
const char *  s 
)

Add an attribute to the current style.

Parameters
cThe class whose attribute will be added to the style.
sThe name of the attribute to be added to the style.
See also
The 'uitextfield' example project in the SDK.
void class_attr_style_alias ( t_class c,
const char *  name,
const char *  aliasname,
long  legacy 
)

Add an alias to the current style.

This is used for backward compatibility where an attribute using an old name will want a style applied to it from a different name. Typically you will use one of the macros such as CLASS_ATTR_STYLE_ALIAS_NOSAVE rather than using this function directly.

Parameters
cThe class for whom the alias will be created.
nameThe name of the attribute of the style.
aliasnameThe name of the alias.
legacyAlways pass 0 for this argument.
See also
CLASS_ATTR_STYLE_ALIAS_NOSAVE
The 'jslider' project in the SDK.
void class_attr_stylemap ( t_class c,
char *  attrname,
char *  mapname 
)

Associate the name of an attribute of your class with the name of an attribute of a style.

Parameters
cThe class whose attribute will be added to the style.
attrnameThe name of the attribute of your class.
mapnameThe name of the attribute from the style.
See also
'jslider' example project in the SDK.
void jgraphics_attr_fillrect ( t_object b,
t_jgraphics g,
t_symbol attrname,
t_rect area 
)

Fill using the current value of a named style color that exists either in the object or the defined style.

Abdridged example from the 'attrui' object:

1 long is_fill = object_attr_getfill(destination, x->j_attr);
2 
3 if (is_fill) {
4  jgraphics_attr_fillrect((t_object *)destination, g, x->j_attr, rect);
5  jgraphics_rectangle(g, rect->x, rect->y, rect->width, rect->height); // ready to be stroked
6 }
7 else {
8  object_attr_getjrgba(destination, x->j_attr, &color);
9  jgraphics_set_source_jrgba(g, &color);
10  jgraphics_rectangle(g, rect->x, rect->y, rect->width, rect->height);
11  jgraphics_fill_preserve(g);
12 }
13 
14 jgraphics_set_source_jrgba(g, &bordercolor);
15 jgraphics_stroke(g);
Parameters
bThe instance of your object.
gThe jgraphics context.
attrnameThe name of the attribute whose fill style you want.
areaThe rect area to be filled.
t_jpattern* jgraphics_attr_setfill ( t_object b,
t_jgraphics g,
t_symbol attrname,
t_rect area 
)

Fill using the current value of a named style color that exists either in the object or the defined style.

Example from the 'panel' object:

1 t_rect r;
2 
3 r.x = r.y = thick * 0.5;
4 r.width = rect->width - thick;
5 r.height = rect->height - thick;
6 
7 pat = jgraphics_attr_setfill((t_object *)x, g, ps_bgfillcolor, &r);
8 jgraphics_rectangle_rounded(g, r.x, r.y, r.width, r.height, round, round);
9 jgraphics_fill_preserve(g);
10 jgraphics_pattern_destroy(pat);
11 
12 object_attr_getjrgba(x, ps_bordercolor, &color);
13 jgraphics_set_source_jrgba(g, &color);
14 jgraphics_set_line_width(g, thick);
15 jgraphics_stroke(g);
Parameters
bThe instance of your object.
gThe jgraphics context.
attrnameThe name of the attribute whose fill style you want.
areaThe rect area to be filled.
Returns
The pattern.
long object_attr_getfill ( t_object obj,
t_symbol attrname 
)

Determine if an attribute is a fill.

Parameters
objThe instance of your object.
attrnameThe name of the attribute to query.
Returns
true if the object is a fill, otherwise false.
void object_attr_getfillcolor_atposition ( t_object b,
const char *  attrname,
double  pos,
t_jrgba c 
)

Determine the color at a given position in a fill.

Parameters
bThe instance of your object.
attrnameThe name of the attribute to query.
posThe position in a range of [0.0, 1.0].
cA valid t_jrgba whose members will be filled-in upon return.
Returns
true if the object is a fill, otherwise false.
  Copyright © 2015, Cycling '74