We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This is needed to adapt the graphics to the different sizes of my android devices.
import controlP5.*;
int buttonSize = ... ;
ControlP5 MyController;
Button but_Play;
MyController = new ControlP5(this);
// make button Play
PImage[] play_Img = {loadImage("play.png"), loadImage("play.png"), loadImage("play.png")};
//**play_Img.resize(0,60); = not allowed**
but_Play = MyController.addButton("but_Play")
.setValue(0)
.setPosition(tab, dotWidth)
.setSize(buttonSize, buttonSize)
.setImages(play_Img)
.updateSize()
;
Answers
playImg
is an array, you need to call resize in aPImage
. Loop trough array and call in each Image returned, I guess should work.note naming collections with plural names help sporting this things, perhaps
playImages
...Just use a for loop to loop through each
PImage
in the array.As already mentioned, playImg is an array.
Apart from clone() and other Object's methods, arrays got no more methods!
And why reload the same file? We can simply make cloned copies of it w/ get() or copy():
https://processing.org/reference/PImage_get_.html
https://processing.org/reference/PImage_copy_.html
You're gonna need an extra array for your Button objects too: :P
comment to _vk and KevinWorkman:
you r not incrementing
i
here... never ending loop...Comment to GoToLoop As I have several buttons, for the moment using 3 times the same imgs, but also have several toggles, using 2 imgs for the different state, the resizing should be repeated. And there I run into trouble. I also don't understand why the import controlP5.Button ( import controlP5.Toggle) is needed as I thought that this is included in the import controlP5.ControlP5 statement. In the console the following type of warning is repeated WARNING: Controller with name "/but_Play" already exists. overwriting reference of existing controller. thanks
My new attempt below: :-\"
I was just being explicit about which classes from controlP5 library were being imported.
Feel free to delete them and stick w/ generalized
import controlP5.*;
only. O:-)Sorry for waiting but I first tried to understand and implement your solutions in my program. My program actually works fine in Java mode therefore I am a bit reluctant to change too much. To get it running on android devices there are still some problems to solve. One is a very practical one, getting the graphics for the buttons/toggles resizing to the screens of the devices. For most of the GUI I rely on the controlP5 library which I am happy with. The Button controller of the library requires three images to cover the different states of the buttons. The Toggle controller only two. In my program I have 15 buttons and 3 toggles. For the moment I generate each button / toggle separately. I understand that this could be programmed more compact but for the moment I do not care to write (cut and paste) a bit more lines as it helps me to understand what’s going on. Below you can find a working extract from my program in which I implemented you solutions. As you can see, the button solution works fine but when applying this to the toggle it also seems to work, but not quit as intended. First the toggle img is not resized to the same size as that of the buttons. This is of course clear as the resizing is dependent of the number of imgs ( 2 for the toggle, 3 for the buttons). I tried to fix this but did not find a solution. Second you can see (in the console) that the toggle value actually changes on clicking. But the corresponding img is not shown. This makes me wonder If the controller really works. ( in my original program, where the definition of the controller is similar to that of the buttons, it works fine). Last I tried to implement you second solution but could not get it running. So I had to comment out these lines. I don’t know how to upload the 4 required png’s. But they are just squares of 180x180 px. Maybe this makes things clearer. Anyway thanks for your help. Take your time as I cannot read the forum until Saturday afternoon. Regards, marc.