query width and height of UI object box
after a longer break, i’m working on a UI external again, and my brain still seems to be a little rusty…
while initializing the object variables in the new-routine, i need to query the width and height of the current objects box. therefore i guess i need a patcherview (in order to be able to call jbox_get_rect_for_view()).
is it possible to get a patcherview at this stage of object instantiation (in the new-routine), or would i have to somehow get hold of the patcher_rect attribute from the inspector?
you do not need a patcherview. You need a dictionary.
You need to query the values you need from the dictionary that you create in the myobject_new routine. They are all there.
Look at the jslider example in the SDK and specifically at the jslider_stdargs() method to get a clue on where the values you need might be.
Hope this helps.
Let me know if that solves your problem.
thanks for the hint. dictionary looks interesting, but somewhat complicated…
from the api get the impression, i need something like dictionary_copyatoms, to get hold of the patcher_rect attributes.
so i tried:
t_atom **r = NULL;
long num = 4;
dictionary_copyatoms(d, gensym("patching_rect"), &num, r);
for(k=0; k<4; k++)
post("k: %ld — %f", k, atom_getfloat((t_atom *)r+k));
the atom_getfloat() call causes me trouble.
is that going into the right direction at all?
it’s not urgent, as i found a workaround for what i was trying to do, but comments on how to get values from the dictionary would still be welcome.
The only reason why you get a crash is because of some dereference confusion.
Do the same but replace atom_getfloat((t_atom *)r+k) with atom_getfloat((*r)+k)
Other than that, you are definitely in the right direction…
You might also want to consider using dictionary_getatoms().
This way you don’t need to allocate any memory.
You just get a pointer to the patching rect which, in most cases, it’s all you need.
> Do the same but replace atom_getfloat((t_atom *)r+k) with atom_getfloat((*r)+k)
hm, i’ve tried that before, and it crashes here just the same.
any more clues anyone?
Do you know which line it crashes on? The crash report probably tells you.
However, I can see a couple of suspicious things about your call to dictionary_copyatoms().
t_atom *r = NULL; long num = 0; long k; dictionary_copyatoms(d, gensym("patching_rect"), &num, &r); for (k=0; k<4; k++) post("k: %ld -- %f", k, atom_getfloat((*r)+k)); if (r) sysmem_freeptr(r);
This is email-client coding, but notice that I pass a size (num) initialized to zero and also that for 'r' I am passing the address of a valid pointer (which is pointing to NULL).
Hope this helps
thanks, tim. your version won’t compile here, but it got me on the right track.
i got a little confused by the pointer to point to t_atom thing from the dictionary_copyatoms() call, and wasn’t sure how to properly dereference it. but this, too, of course is only an address.
so this works for me:
t_atom *r = NULL;
long num = 0;
dictionary_copyatoms(d, gensym("patching_rect"), &num, &r);
for (k=0; k<4; k++)
post("k: %ld -- %f", k, atom_getfloat(r+k));
dictionary seems to be quite powerful. i think a future version of the sdk would benefit from some more examples on how it can be used.