Attributes with gradient color pickers (t_jpattern & attributes)


    Mar 04 2018 | 3:30 pm
    Hey, I am having a hard time wrapping my head around this issue, so maybe someone could be so kind as to point me into a right direction to understand this. So far, I have done CLASS_ATTR_RGBA in the standard way, yielding a the normal, solid color picker. Many native UI objects though are able to show a switch button, for the user to pick either a solid color or 2 color gradient for their objects. Now, I believe this has to be done using the t_jpattern struct, but I have no idea how to create an attribute that takes a jpattern as a structmember argument. From the uitextfield example, I can figure out that adding class_attr_setstyle() and class_attr_setfill() somehow suddenly yields this option to switch between solid and gradient colors (also adding automatically the usual _type, _color1, _color2, _angle etc... suffixes to my structname), but I'm not sure how to properly save these values in a pattern to use for my jgraphics. I assume this somehow has to do with the fact, that I am applying a pre-defined style and somehow transforming my attribute into one that can handle gradients... So, this is how I used to do things: /*mystruct... */ t_jrgba j_bgcolor; CLASS_ATTR_RGBA(c, "bgcolor", 0, t_myobject, j_bgcolor); CLASS_ATTR_DEFAULT_SAVE_PAINT(c, "bgcolor", 0, "1. 1. 1. 1."); CLASS_ATTR_STYLE_LABEL(c, "bgcolor", 0, "rgba", "Background Color");
    And this is as far as I seem to have gotten :/ /*mystruct... */ t_jrgba j_bgcolor; CLASS_ATTR_RGBA(c, "bgcolor", 0, t_myobject, j_bgcolor); CLASS_ATTR_DEFAULT_SAVE_PAINT(c, "bgcolor", 0, "1. 1. 1. 1."); CLASS_ATTR_STYLE_LABEL(c, "bgcolor", 0, "rgba", "Background Color"); class_attr_setstyle(c, "bgcolor"); class_attr_setfill(c, "bgcolor", FILL_ATTR_SAVE);
    Do note however, that doing this destroys my functionality and I end up with no color saved in j_bgcolor. Converting j_bgcolor in a t_jpattern does not give any results either... So, would anyone know what to do? Would really appreciate this! Thanks!

    • Mar 12 2018 | 4:52 pm
      Hi,
      Sorry to report that a gradient single-attribute `bgcolor` is a special case for e.g. the [message] object. We don't support that for other objects at this time. For now, I recommend making 2 attributes for the 2 colors in your gradient.
      Cheers!
    • Aug 10 2018 | 10:32 am
      Hi everyone,
      I bumped into this topic trying to implement a similar thing. Is this situation gonna change when Max 8 is officially released or not yet? Best,
    • Aug 13 2018 | 3:55 pm
      This is an API issue rather than something internal to the Max application itself. So Max 8 won't have a bearing on this per se, but the new C++ API that is in development could potentially address it. I've created a ticket for this request @ https://github.com/Cycling74/min-api/issues/120
      Cheers! Tim