Set custom sprite on toolbox button at runtime (riscos cloverleaf)
Sergey Lentsov (8268) 63 posts |
Hello, I need to set custom sprite on the button (I need to show member’s profile picture downloaded from net), i have decoded single Sprite with the SpriteArea as my source image. 1. As I understand I can’t assign my private SpriteArea to toolbox button, toolbox always get SpriteArea from parent window, which in turn get it at Toolbox initialization, so windows can’t have own private sprite areas only single area per application? Is this correct? 2. If p.1 is right then I think to create some custom sprite named “profilespr” in app SpriteArea and then replace it by my loaded sprite. But I not found any SWI for copy/merge the sprite from other SpriteArea from memory (only from file). I see only way to solve my task is to delete sprite in Toolbox SpriteArea, then create new one instead (because dimensions my be different) and then copy image data from my original sprite. This way is not efficient as needs to copy data around but I see no other simple way to do it. I’m right or there is a better way? Right now I use custom subwindows with own Redraw function to show custom images but it is lot of code for such simple task and I needs to do position of subwindow in the code instead in the ResEdit.. |
Rick Murray (539) 13840 posts |
I can’t help with toolbox, however, if the source and destination sprites are the same size and bit depth, you could get a pointer to the source, and the destination, and just copy the appropriate number of words. But yeah, it sounds a bit clumsy if toolbox can’t cope with different custom sprite areas… |
Chris Johnson (125) 825 posts |
If you are using the button gadget, then in its configuration window is an option ‘Use client’s sprite area’. This should be ticked. Then in the Validation field enter Sspritename. I have used this method in a couple of my apps to use local sprites in buttons. |
Chris Johnson (125) 825 posts |
I should have added: the validation string can be rewritten at any time to change the sprite. |
Sergey Lentsov (8268) 63 posts |
@Chris Johnson Yes, I know that I can set sprite NAME but this sprite will looked up in the app’s SpriteArea and I need to copy/replace my source sprite to app’s SpriteArea first. Currently I get JPG or PNG from net then decode it to Sprite (with SpriteArea header) and would be good if I can assign this SpriteArea to the button directly without using app’s SpriteArea and deleting existing sprite→then create new sprite→then copy data from my source sprite. Delete and recreate is required if old and new sprites have different dimensions. |
David J. Ruck (33) 1635 posts |
Deleting the old sprite and creating a new one with the same name, is the correct way of doing it. Then a redraw of the button using Wimp_SetIconState. |