Dear all,
I developed a very simple sketch in which I use the selectOutput function.
It works but, as soon as the select output file window is open, the sketch graphic disappear and the desktop is shown.
Did you have any similar problem ? How did you fix it ?
Thank you very much for your help and cooperation
regards
This is the source code of TestFile.pde
PImage myImage;
cButton myButton;
void setup()
{
fullScreen(P2D, 2);
myImage=loadImage("img.jpg");
myButton=new cButton("","button",(displayWidth-myImage.width)/2,(displayHeight-myImage.height)/2,100);
}
void draw()
{
image(myImage,(displayWidth-myImage.width)/2,(displayHeight-myImage.height)/2);
myButton.drawBottone();
int x = myButton.testMouse();
if(x>=0) {
selectOutput("Select a file to write to:", "fileSelected");
}
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
}
}
This is the source code of cButton class buttonClass.pde file:
final static String RELEASED
= "Released";
final static String OVER
= "Over";
final static String PRESSED
= "Pressed";
class cButton {
PImage released;
PImage over;
PImage pressed;
int status;
int left;
int right;
int top;
int bottom;
int x;
int y;
int mouseStatus;
float res;
int sx;
int sy;
cButton(String path, String name, int lx, int ly, int resize) {
released = loadImage(path + name + RELEASED + ".png");
over = loadImage(path + name + OVER + ".png");
pressed = loadImage(path + name + PRESSED + ".png");
status = 0;
x = lx;
y = ly;
res = (float) resize;
sx = (int) ((float) released.width * (res / 100));
sy = (int) ((float) released.height * (res / 100));
right = x + sx;
bottom = y + sy;
top = y;
left = x;
mouseStatus = 0;
}
int mouse() {
int x = testMouse();
drawBottone();
return x;
}
public void drawBottone() {
switch (status) {
case 0: // released
image(released, x, y, sx, sy);
break;
case 1: // over
image(over, x, y, sx, sy);
break;
case 2: // pressed
image(pressed, x, y, sx, sy);
break;
}
}
public void drawBottone(int x, int y) {
switch (status) {
case 0: // released
image(released, x, y, sx, sy);
break;
case 1: // over
image(over, x, y, sx, sy);
break;
case 2: // pressed
image(pressed, x, y, sx, sy);
break;
}
}
public int testMouse() {
int flg;
int ret;
flg = 0;
ret = -1;
// println("X: "+mouseX+" Y: "+mouseY);
if (mouseX >= left && mouseX <= right) {
if (mouseY >= top && mouseY <= bottom) {
if (mousePressed == true && mouseButton == LEFT) {
flg = 2;
ret = 1;
} else {
flg = 1;
}
}
}
status = flg;
if(ret==1) {
if( mouseStatus<0) {
mouseStatus=ret;
} else
ret=-1;
}else
mouseStatus=ret;
// println(ret);
return ret;
}
}