GripDispatcher
import compose.grips.*; GripDispatcher dispatch; CircleGrip c1, c2, c3; void setup() { dispatch = new GripDispatcher(this); c1 = new CircleGrip(25, 50, 40); c2 = new CircleGrip(50, 50, 40); c3 = new CircleGrip(75, 50, 40); } void draw() { background(200); dispatch.update(); dispatch.draw(); } class CircleGrip extends Grip { float x, y, diameter; CircleGrip(float x, float y, float diameter) { this.x = x; this.y = y; this.diameter = diameter; } boolean isHovering() { return dist(mouseX, mouseY, x, y) < diameter/2; } void draw() { if (this.isTheHover()) { fill(255, 0, 0, 230); // We are the BEST match (top most) } else if (this.isHovering()) { fill(255, 255, 0, 230); // Our hover conditions are satisfied } else { fill(255, 230); // We're not hovering } ellipse(x, y, diameter, diameter); } }- Description
GripDispatcher objects are responsible for collecting, updating and drawing Grip objects. A GripDispatcher must be created before any Grips can be instantiated.
- Methods
- update()
- Calls update on every Grip and selects a new hover.
- draw()
- Calls the draw method of every Grip.
- clear()
- Removes every Grip from the GripDispatcher.
- getActiveGrip()
- Returns the active Grip.
- getHoverGrip()
- Returns the currently hovering Grip.
- Constructors
new GripDispatcher(PApplet)- Related
No Comments
You must be logged in to post a comment.