Hello, I am in the process of organizing, cleaning, and simplifying my code. I repeat myself a lot in my application, breaking one of the finest rules in programming, therefore I figured the best way to start cleaning up is with a button class. I have the buttons working outside of the class but got lost while trying to create and implement a new button class so I could use some help getting back on track. For now I am working towards simply drawing the buttons and changing the color when the mouse is over it.
` //using processing video and movie
import processing.video.*;
import controlP5.*;
import java.awt.geom.*;
ControlP5 cp5;
Movie movie;
static String nomeLink;
//size of buttons and the integers that load a view to the big square
int toolSize = 20;
//positions for each buttom
int playX, playY;
int pauseX, pauseY;
int fastX, fastY;
int reverseX, reverseY;
int plusX, plusY;
int minusX, minusY;
String current = "";
String view = "One";
boolean constrain = false;
//booleans to help decide which button the mouse is over
boolean playOver = false;
boolean pauseOver = false;
boolean fastOver = false;
boolean reverseOver = false;
boolean plusOver = false;
boolean minusOver = false;
boolean play = true;
int mode = 1;
//naming our buttons
PImage play1;
PImage pause;
PImage rewind;
PImage fast;
PImage plus;
PImage minus;
//Using to implement the class
Button playButton, pauseButton, rewindButton, forwardButton, zoomIn, zoomOut;
void setup() {
size(1280, 360);
background (51);
//set our button images
play1 = loadImage("Play.png");
pause = loadImage("Pause.png");
rewind = loadImage("Rewind.png");
fast = loadImage("Fast-Forward.png");
plus = loadImage("Plus.png");
minus = loadImage("Minus.png");
//setting the position of our buttons
playX = width/ 4-30;
playY = height/2 + 130;
pauseX = width/ 4 - 60;
pauseY = height/2 + 130;
fastX = width/ 4 + 30 - 30;
fastY = height/2 + 130;
reverseX = width/ 4 - 90;
reverseY = height/2 + 130;
plusX = width/4 + 60 - 30;
plusY = height/2 + 130;
minusX = width/4 + 90 - 30;
minusY = height/2 + 130;
//setting the position and size for each button
image(play1, playX, playY, toolSize, toolSize);
image(pause, pauseX, pauseY, toolSize, toolSize);
image(fast, fastX, fastY, toolSize, toolSize);
image(rewind, reverseX, reverseY, toolSize, toolSize);
image(plus, plusX, plusY, toolSize, toolSize);
image(minus, minusX, minusY, toolSize, toolSize);
}
//Button Class - Not Implemented yet
class Buttons
{
final int COLORSTATE0 = color (255, 0, 0);
final int COLORSTATE1 = color (0, 255, 0);
int buttonX, buttonY, buttonWidth, buttonHeight;
boolean over = false , buttonPressed = false;
boolean pressed = false;
PImage play;
PImage forward;
PImage rewind;
PImage pause;
PImage zoomIn;
PImage zoomOut;
color buttonColor, hoverColor;
color currentColor;
//Assigning values for the button class
Buttons(int tempbuttonX, int tempbuttonY, int tempbuttonWidth, int tempbuttonHeight)
{
buttonX = tempbuttonX;
buttonY = tempbuttonY;
buttonWidth = tempbuttonWidth;
buttonHeight = tempbuttonHeight;
// mouseposX = tempmouseposX;
// mouseposY = tempmouseposY;
}
}
//Checking if the mouse is over the button
boolean overButton(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
//Changing the button filter if your mouse is over it --Buggy and repetitive
void redraw(int toolSize) {
if ((overButton(playX, playY, toolSize, toolSize)))
{
current = "Play";
play1.filter(THRESHOLD);
pause.filter(GRAY);
fast.filter(GRAY);
rewind.filter(GRAY);
plus.filter(GRAY);
minus.filter(GRAY);
}
else if ((overButton(pauseX, pauseY, toolSize, toolSize)))
{
current = "Pause";
play1.filter(GRAY);
pause.filter(THRESHOLD);
fast.filter(GRAY);
rewind.filter(GRAY);
plus.filter(GRAY);
minus.filter(GRAY);
}
else if ((overButton(fastX, fastY, toolSize, toolSize)))
{
current = "Forward";
play1.filter(GRAY);
pause.filter(GRAY);
fast.filter(THRESHOLD);
rewind.filter(GRAY);
plus.filter(GRAY);
minus.filter(GRAY);
}
else if ((overButton(reverseX, reverseY, toolSize, toolSize)))
{
current = "Rewind";
play1.filter(GRAY);
pause.filter(GRAY);
fast.filter(GRAY);
rewind.filter(THRESHOLD);
plus.filter(GRAY);
minus.filter(GRAY);
}
else if ((overButton(plusX, plusY, toolSize, toolSize)))
{
current = "Plus";
play1.filter(GRAY);
pause.filter(GRAY);
fast.filter(GRAY);
rewind.filter(GRAY);
plus.filter(THRESHOLD);
minus.filter(GRAY);
}
else if ((overButton(minusX, minusY, toolSize, toolSize)))
{
current = "Minus";
play1.filter(GRAY);
pause.filter(GRAY);
fast.filter(GRAY);
rewind.filter(GRAY);
plus.filter(GRAY);
minus.filter(THRESHOLD);
}
}
`