github.com/256dpi/max-go@v0.7.0/lib/max/ext_boxstyle.h (about) 1 #ifndef _EXT_BOXSTYLE_H_ 2 #define _EXT_BOXSTYLE_H_ 3 4 #include "ext_prefix.h" 5 #include "ext_mess.h" 6 7 #include "jgraphics.h" 8 9 BEGIN_USING_C_LINKAGE 10 11 12 /** Add an attribute to the current style. 13 @ingroup styles 14 15 @param c The class whose attribute will be added to the style. 16 @param s The name of the attribute to be added to the style. 17 @see The 'uitextfield' example project in the SDK. 18 */ 19 void class_attr_setstyle(t_class *c, const char *s); 20 21 22 /** Add an alias to the current style. 23 This is used for backward compatibility where an attribute using an old name will want a style applied to it from a different name. 24 Typically you will use one of the macros such as #CLASS_ATTR_STYLE_ALIAS_NOSAVE rather than using this function directly. 25 @ingroup styles 26 27 @param c The class for whom the alias will be created. 28 @param name The name of the attribute of the style. 29 @param aliasname The name of the alias. 30 @param legacy Always pass 0 for this argument. 31 @see #CLASS_ATTR_STYLE_ALIAS_NOSAVE 32 @see The 'jslider' project in the SDK. 33 */ 34 void class_attr_style_alias(t_class *c, const char *name, const char *aliasname, long legacy); 35 36 37 /** Flag indicating we want this fill attribute saved (creates attrs). 38 @ingroup styles 39 @see class_attr_setfill() 40 @see The 'uitextfield' example project in the SDK. 41 */ 42 #define FILL_ATTR_SAVE 1 43 44 45 /** Specify that an attr requires a fill. 46 @ingroup styles 47 48 @param c The class whose attribute is a fill. 49 @param name The name of the attribute. 50 @param flags 0 for none, or #FILL_ATTR_SAVE. 51 @see The 'uitextfield' example project in the SDK. 52 */ 53 void class_attr_setfill(t_class *c, const char *name, long flags); 54 55 56 /** Fill using the current value of a named style color that exists either in the object or the defined style. 57 Abdridged example from the 'attrui' object: 58 @code 59 long is_fill = object_attr_getfill(destination, x->j_attr); 60 61 if (is_fill) { 62 jgraphics_attr_fillrect((t_object *)destination, g, x->j_attr, rect); 63 jgraphics_rectangle(g, rect->x, rect->y, rect->width, rect->height); // ready to be stroked 64 } 65 else { 66 object_attr_getjrgba(destination, x->j_attr, &color); 67 jgraphics_set_source_jrgba(g, &color); 68 jgraphics_rectangle(g, rect->x, rect->y, rect->width, rect->height); 69 jgraphics_fill_preserve(g); 70 } 71 72 jgraphics_set_source_jrgba(g, &bordercolor); 73 jgraphics_stroke(g); 74 @endcode 75 76 @ingroup styles 77 78 @param b The instance of your object. 79 @param g The jgraphics context. 80 @param attrname The name of the attribute whose fill style you want. 81 @param area The rect area to be filled. 82 */ 83 void jgraphics_attr_fillrect(t_object *b, t_jgraphics *g, t_symbol *attrname, t_rect *area); 84 85 86 /** Fill using the current value of a named style color that exists either in the object or the defined style. 87 Example from the 'panel' object: 88 @code 89 t_rect r; 90 91 r.x = r.y = thick * 0.5; 92 r.width = rect->width - thick; 93 r.height = rect->height - thick; 94 95 pat = jgraphics_attr_setfill((t_object *)x, g, ps_bgfillcolor, &r); 96 jgraphics_rectangle_rounded(g, r.x, r.y, r.width, r.height, round, round); 97 jgraphics_fill_preserve(g); 98 jgraphics_pattern_destroy(pat); 99 100 object_attr_getjrgba(x, ps_bordercolor, &color); 101 jgraphics_set_source_jrgba(g, &color); 102 jgraphics_set_line_width(g, thick); 103 jgraphics_stroke(g); 104 @endcode 105 106 @ingroup styles 107 108 @param b The instance of your object. 109 @param g The jgraphics context. 110 @param attrname The name of the attribute whose fill style you want. 111 @param area The rect area to be filled. 112 @return The pattern. 113 */ 114 t_jpattern *jgraphics_attr_setfill(t_object *b, t_jgraphics *g, t_symbol *attrname, t_rect *area); 115 116 117 /** Determine the color at a given position in a fill. 118 @ingroup styles 119 @param b The instance of your object. 120 @param attrname The name of the attribute to query. 121 @param pos The position in a range of [0.0, 1.0]. 122 @param c A valid #t_jrgba whose members will be filled-in upon return. 123 @return true if the object is a fill, otherwise false. 124 */ 125 void object_attr_getfillcolor_atposition(t_object *b, const char *attrname, double pos, t_jrgba *c); 126 127 128 /** Determine if an attribute is a fill. 129 @ingroup styles 130 @param obj The instance of your object. 131 @param attrname The name of the attribute to query. 132 @return true if the object is a fill, otherwise false. 133 */ 134 long object_attr_getfill(t_object *obj, t_symbol *attrname); 135 136 void object_style_setfillattribute(t_object *x, t_symbol *fillattr, t_symbol *entry, long argc, t_atom *argv); 137 138 139 /** Associate the name of an attribute of your class with the name of an attribute of a style. 140 @ingroup styles 141 @param c The class whose attribute will be added to the style. 142 @param attrname The name of the attribute of your class. 143 @param mapname The name of the attribute from the style. 144 @see 'jslider' example project in the SDK. 145 */ 146 void class_attr_stylemap(t_class *c, const char *attrname, const char *mapname); 147 148 t_symbol *object_attr_attrname_forstylemap(t_object *x, t_symbol *mapname); // internal use only 149 t_symbol *object_attr_stylemapname(t_object *x, t_symbol *attrname); // internal use only 150 151 152 // menus of named styles 153 154 t_jpopupmenu *style_getmenu(t_object *context, t_symbol *current, long mask, long *selecteditem, long *headercount); // internal use only 155 void style_handlemenu(t_object *context, long itemindex, t_symbol **current); // internal use only 156 157 // Attribute Macros for simple and maintainable style attribute definitions 158 159 // CLASS_ATTR_STYLE_RGBA defines an RGBA style attribute with standard settings 160 // and replaces RGBA style definitions of the following pattern, with and without "preview" and saving: 161 /* 162 CLASS_ATTR_RGBA(c,"accentcolor",0, t_jnumber, j_tricolor); 163 CLASS_ATTR_SAVE(c, "accentcolor", 0); 164 CLASS_ATTR_PAINT(c, "accentcolor", 0); 165 CLASS_ATTR_STYLE_LABEL(c, "accentcolor", 0 , "rgba", "Triangle Color"); 166 class_attr_setstyle(c, "accentcolor"); 167 CLASS_ATTR_ATTR_PARSE(c, "accentcolor", "preview", USESYM(symbol), 0, "triangle_fill"); 168 */ 169 170 /** Define an RGBA style attribute with standard settings. 171 @ingroup styles 172 @param c The class whose attribute will be added to the style. 173 @param attrname The name of the attribute of your class. 174 @param flags Any flags you wish to declare for this attribute, as defined in #e_max_attrflags. 175 @param structname The C identifier for the struct (containing a valid #t_object header) representing an instance of this class. 176 @param structmember The C identifier of the member in the struct that holds the value of this attribute. 177 @param label A human-friendly label for the Max inspector. 178 @see #CLASS_ATTR_STYLE_RGBA is a variant that saves the state with the patcher. 179 @see #CLASS_ATTR_STYLE_RGBA_PREVIEW is a variant that provides a style preview. 180 @see class_attr_setstyle() is the lower level function used to provide the style part of the attribute definition. 181 */ 182 #define CLASS_ATTR_STYLE_RGBA_NOSAVE(c,attrname,flags,structname,structmember,label) \ 183 { CLASS_ATTR_DOUBLE_ARRAY(c,attrname,flags,structname,structmember,4); \ 184 CLASS_ATTR_ACCESSORS(c,attrname,NULL,jgraphics_attr_setrgba); \ 185 CLASS_ATTR_PAINT(c,attrname,0); \ 186 CLASS_ATTR_STYLE_LABEL(c,attrname,0,"rgba",label); \ 187 class_attr_setstyle(c,attrname); } 188 189 190 /** Define an RGBA style attribute with standard settings. 191 @ingroup styles 192 @param c The class whose attribute will be added to the style. 193 @param attrname The name of the attribute of your class. 194 @param flags Any flags you wish to declare for this attribute, as defined in #e_max_attrflags. 195 @param structname The C identifier for the struct (containing a valid #t_object header) representing an instance of this class. 196 @param structmember The C identifier of the member in the struct that holds the value of this attribute. 197 @param label A human-friendly label for the Max inspector. 198 @see #CLASS_ATTR_STYLE_RGBA_NOSAVE is a variant that does not save the state with the patcher. 199 @see #CLASS_ATTR_STYLE_RGBA_PREVIEW is a variant that provides a style preview. 200 @see class_attr_setstyle() is the lower level function used to provide the style part of the attribute definition. 201 */ 202 #define CLASS_ATTR_STYLE_RGBA(c,attrname,flags,structname,structmember,label) \ 203 { CLASS_ATTR_STYLE_RGBA_NOSAVE(c,attrname,flags,structname,structmember,label) \ 204 CLASS_ATTR_SAVE(c,attrname,0); } 205 206 207 /** Define an RGBA style attribute with standard settings. 208 @ingroup styles 209 @param c The class whose attribute will be added to the style. 210 @param attrname The name of the attribute of your class. 211 @param flags Any flags you wish to declare for this attribute, as defined in #e_max_attrflags. 212 @param structname The C identifier for the struct (containing a valid #t_object header) representing an instance of this class. 213 @param structmember The C identifier of the member in the struct that holds the value of this attribute. 214 @param label A human-friendly label for the Max inspector. 215 @param previewtype Type of preview to use in the style bar, e.g. "triangle_fill" 216 @see #CLASS_ATTR_STYLE_RGBA_NOSAVE is a variant that does not save the state with the patcher. 217 @see #CLASS_ATTR_STYLE_RGBA is a variant that saves the state with the patcher but does not provide the preview. 218 @see class_attr_setstyle() is the lower level function used to provide the style part of the attribute definition. 219 */ 220 #define CLASS_ATTR_STYLE_RGBA_PREVIEW(c,attrname,flags,structname,structmember,label,previewtype) \ 221 { CLASS_ATTR_STYLE_RGBA(c,attrname,flags,structname,structmember,label); \ 222 CLASS_ATTR_ATTR_PARSE(c,attrname,"preview",USESYM(symbol),0,previewtype); } 223 224 225 /** Define an unsaved alias. 226 @ingroup styles 227 @param c The class whose attribute will be added to the style. 228 @param attrname The name of the attribute of your class. 229 @param aliasname The name of the alias. 230 @see 'jslider' example project in the SDK. 231 */ 232 #define CLASS_ATTR_STYLE_ALIAS_NOSAVE(c,attrname,aliasname) \ 233 { class_attr_style_alias(c,attrname,aliasname,false); \ 234 CLASS_ATTR_INVISIBLE(c,aliasname,0); \ 235 CLASS_ATTR_PAINT(c,aliasname,0); } 236 237 238 /** Define a Max 5/6 saved compatibility alias 239 @ingroup styles 240 @param c The class whose attribute will be added to the style. 241 @param attrname The name of the attribute of your class. 242 @param aliasname The name of the alias. 243 */ 244 #define CLASS_ATTR_STYLE_ALIAS_COMPATIBILITY(c,attrname,aliasname) \ 245 { class_attr_style_alias(c,attrname,aliasname,false); \ 246 CLASS_ATTR_INVISIBLE(c,aliasname,0); \ 247 CLASS_ATTR_SAVE(c,aliasname,0); \ 248 CLASS_ATTR_PAINT(c,aliasname,0); } 249 250 251 /** Define a Max 4 legacy RGB attribute alias 252 @ingroup styles 253 @param c The class whose attribute will be added to the style. 254 @param attrname The name of the attribute of your class. 255 @param aliasname The name of the alias. 256 @see 'jslider' example project in the SDK. 257 */ 258 #define CLASS_ATTR_STYLE_ALIAS_RGBA_LEGACY(c,attrname,aliasname) \ 259 { class_attr_style_alias(c,attrname,aliasname,false); \ 260 CLASS_ATTR_INVISIBLE(c,aliasname,0); \ 261 CLASS_ATTR_PAINT(c,aliasname,0); \ 262 CLASS_ATTR_ACCESSORS(c,aliasname,NULL,jgraphics_attr_setrgb_alias); } 263 264 265 END_USING_C_LINKAGE 266 267 #endif // _EXT_BOXSTYLE_H