I was hoping to use this library, but I must be doing something wrong. Can someone let me know what I am not doing right?
The idea is that clicking on the slider bar changes its color, but it only works when clicking on the rectangle’s pre-pushMatrix() position. (it starts out horizontal and is simply rotated 90 degrees.)
// mouseOnPathPositionAsPercent
import mouse.transformed2D.*;
MouseTransformed mouse = new MouseTransformed(this);
Slider slider;
PVector m;
void setup() {
size(800, 480);
slider = new Slider();
}
void draw() {
background(0, 0, 255);
m = new PVector(mouseX, mouseY);
slider.display();
}
void mousePressed() {
if (slider.isOver() == true) {
slider.fillColor = 50;
}
}
void mouseReleased() {
slider.fillColor = 255;
}
class Slider {
PVector loc, dims, xyMin, xyMax;
float angle;
int fillColor;
Slider() {
loc = new PVector(width/2, height/2);
dims = new PVector(300, 75);
xyMin = new PVector(loc.x - dims.x/2, loc.y - dims.y/2);
xyMax = new PVector(loc.x + dims.x/2, loc.y + dims.y/2);
angle = 90;
fillColor = 255;
}
boolean isOver() {
if (mouse.mouseX() > xyMin.x && mouse.mouseY() > xyMin.y &&
mouse.mouseX() < xyMax.x && mouse.mouseY() < xyMax.y) {
return true;
} else {
return false;
}
}
void display() {
mouse.pushMatrix();
mouse.translate(loc.x, loc.y);
mouse.rotate(radians(angle));
fill(fillColor);
rectMode(CENTER);
rect(0, 0, dims.x, dims.y);
mouse.popMatrix();
}
}