Grip

import compose.grips.*;

GripDispatcher dispatch;

void setup() {
  dispatch = new GripDispatcher(this);
  new CircleGrip(50, 50, 40);
}

void draw() {
  dispatch.update(); // Checks for hover
  dispatch.draw(); // Calls all the draw methods
}

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);
    } else {
      fill(255);
    }
    ellipse(x, y, diameter, diameter);
  }

}

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

Description

Grip is useful for (1) drawing things every frame (2) updating those things every frame (3) making those things respond to the mouse, and sometimes the keyboard. By default, Grips are automatically added to the last GripDispatcher defined upon creation and cannot be created before a GripDispatcher is. However, for this reason we need not necessarily assign Grips to variables.

Fields
selectable
Remains active on release if true
Methods
update()
Arbitrary code running every frame
draw()
Contains directions for drawing
isHovering()
True if the mouse is contained by this Grip's geometry
isTheHover()
True if the best candidate for hover as determined by GripDispatcher
isTheActive()
True if selected by the user
focus()
Called when this Grip becomes active
blur()
Called when this Grip is no longer active
mousePressed()
Called when the mouse is pressed
mouseReleased()
Called when the mouse is released
mouseEntered()
Called when this grip becomes the hover.
mouseExited()
Called when this grip is no longer the hover.
mouseClicked()
Called when the mouse is clicked
mouseDoubleClicked()
Called when the mouse is clicked twice
mouseDragged()
Called when the mouse is dragged
mouseMoved()
Called when the mouse is moved
mouseFirstDragged()
Called the first frame the mouse is dragged
Constructors
None
Related
Last Modified: January 18, 2010

2 Comments

You must be logged in to post a comment.