Hi!
I have this problem which I hope you guys could help me out with. I am using eclipse just so you know.
I have a "main" class that is called ProcessingSketch, which looks like this:
import processing.core.*;
import processing.opengl.PGraphicsOpenGL;
public class ProcessingSketch extends PApplet {
public static void main(String args[]) {
PApplet.main(new String[] { "--present", "ProcessingSketch" });
}
Button button1;
Scrollbar bar;
PImage img;
int color1 = 204;
int color2 = 255;
int color3 = color(20,20,180);
public void setup()
{
frameRate(120);
size(1022, 488,PGraphicsOpenGL.OPENGL);
smooth();
fill(0);
strokeWeight(1);
background(120);
bar = new Scrollbar(this, 10, height-10, 1000, 7, -511.0f, 511.0f);
button1 = new Button(this, true, width/2, height-40, 20, color1, color2, color3);
img = loadImage("faith-love-peace.jpg");
}
public void draw()
{
background(204);
int x = (int)(bar.getPos());
image(img, x, 0);
bar.update(mouseX, mouseY);
bar.display();
button1.update(mouseX, mouseY);
button1.display();
}
public void changeImage()
{
println("CIAO");
}
public void mousePressed()
{
bar.press(mouseX, mouseY);
button1.press();
}
public void mouseReleased()
{
bar.release();
button1.release();
}
}
I have two classes that I work with Button and Scrollbar. But my problem is general. From the Button class I want to be able to call the ornage marked method above. How do I do this? Do I have to use a static method? I will attach the button class aswell below so you can see it:
import processing.core.PApplet;
public class Button
{
int x, y; // The x- and y-coordinates
int size; // Dimension (width and height)
int baseGray; // Default gray value
int overGray; // Value when mouse is over the button
int pressGray; // Value when mouse is over and pressed
boolean over = false; // True when the mouse is over
boolean pressed = false; // True when the mouse is over and pressed
boolean circleRect = false; //True when circle, False when rectangle
PApplet parent;
Button(PApplet q, boolean cR, int xp, int yp, int s, int b, int o, int p)
{
x = xp;
y = yp;
size = s;
baseGray = b;
overGray = o;
pressGray = p;
parent = q;
circleRect = cR;
}
// Updates the over field every frame
void update(int mx, int my)
{
//CHECK RECTANGLE
if(circleRect == false)
{
if ((mx >= x-(size/2)) && (mx <= x-(size/2)+size) && (my >= y-(size/2)) && (my <= y-(size/2)+size))
{
over = true;
}
else
{
over = false;
}
}
//CHECK CIRCLE
else if(circleRect == true)
{
if (PApplet.dist(mx, my, x, y) < size/2)
{
over = true;
}
else
{
over = false;
}
}
}
boolean press()
{
if (over == true)
{
pressed = true;
xxxxx.changeimage();
return true;
}
else
{
return false;
}
}
void release()
{
pressed = false; // Set to false when the mouse is released
}
void display()
{
if (pressed == true)
{
parent.fill(pressGray);
}
else if (over == true)
{
parent.fill(overGray);
}
else
{
parent.fill(baseGray);
}
if(circleRect == false)
{
parent.stroke(255);
parent.rect(x-(size/2), y-(size/2), size, size);
}
else if(circleRect == true)
{
parent.stroke(255);
parent.ellipse(x, y, size, size);
}
}
}
If anyone has any ideas on how to best do this, please let me know! Thank you!
Best regards
Lukas
1