[draw] event for array element only gets a pointer to the containing scalar
A super difficult, obscure, but potentially useful improvement lies ahead:
Imagine this struct:
[struct foo float x float y array a elem] [plot a 0 0 0 0]
Now imagine the elem struct:
[struct elem float x float y float state] [loadbang] | [fill black, stroke black, stroke-width 1, mousedown 1, fill-opacity state( | [draw rect 20 20] | [route mousedown] | [unpack p 0 0] | [get elem state] | [print]
The problem? When you click one of the array elements with the mouse, the [draw rect] outlet sends a message that contains a pointer to the scalar that contains the array element, not the array element itself. Thus there is no way to figure out exactly which array element was clicked, nor mutate its state.
What is needed is a pointer to the array element itself. That would allow the user to quite easily create their own scalar version of a toggle matrix. What is more, scalars can cache their bbox info in a way that a bunch of iemgui tgls cannot. So when mousing over a scalar matrix of 256 of these tgls, Pd would only traverse over a single scalar.
The difficulty in solving this is that I'm currently using pd_bind to store a reference to the relevant scalar in t_symbol->s_thing. This scalar is then fetched and used to set a gpointer in draw_notifyforscalar. But to generate a gpointer to an array element I need both a reference to a t_array and one to a t_word, neither of which can be the referent of s_thing. So while I can store string formats of the pointers to those fields in the GUI, when the callback comes back into Pd I have no way of going from the t_symbol to those fields.
Anyhow, if I could figure out how to do this it would make the [draw] object very powerful. Any of the mouseevents could be set across array elements declaratively, greatly improving the expressivity of the [draw] interface.