GViewListener API

Although the control is created from the GView class the only method you are likely to use is the addListener, all the functionality you need is in the GViewListener class. You would not access the functionality directly rather you would create a user-defined listener class that extends the GViewListener class and access the functionality through that class.

This guide details the most common functionality you are likely to use.

Event Handlers

Whenever Processing fires a mouse event it will be passed to the GView class to see if it needs to process it. Provided the control is visible, enabled and the mouse is over the control it forwards the event to the GViewListener class.

IMPORTANT: The event handlers are only called when the mouse is over the control

Event handlers Description
public void onMouseEntered()
public void onMouseExited()
Event handlers for when the mouse enters or leaves the view. The equivalent methods used in the main sketch code are executed when the mouse enters or leaves the application (sketch).
public void onMouseClicked()
public void onMouseDragged()
public void onMouseMoved()
public void onMousePressed()
public void onMouseReleased()
public void onMouseWheel()
These behave in the same way as the equivalent Processing methods so look at the Processing documents for more information.
public void mouseEvent(MouseEvent e)
This method would be used instead of the onMouse??? methods shown above. It allows the user to process the event in a single method.

Key modifiers

A mouse event also includes information about which modifier keys were pressed when the event was generated. These methods allow you to find out which keys were down.

Key modifier methods Description
boolean isShiftDown()
boolean isControlDown()
boolean isMetaDown()
boolean isAltDown()
These behave in the same way as the equivalent Processing methods so look at the Processing documents for more information.
int getModifiers()
This method return an integer whose state indicates which if any of the above keys are down.

Mouse information

Method Description
int mouseX()
int mouseY()
int pmouseX()
int pmouseY()
Equivalent to mouseX, mouseY, pmouseX and pmouseY but the mouse positions are relative to the top-left corner of the view.
int button()
Which button if any is pressed
int count()
How much the mouse wheel was rotated
boolean isMouseOver()
Returns true if the mouse is over the control
boolean isMousePressed()
Returns true if a mouse button is pressed

View information

int width()
int height()
Similar to Processing's width and height but they return the width and height of the view.
boolean is3D()
Returns true if using the P3D renderer else returns false.
PGraphics getGraphics()
Returns the graphics object associated with this view.
PApplet getPApplet()
Returns the PApplet object used to create this view.

Event information

These methods are included for the sake of completeness and will rarely if ever be needed.

MouseEvent getEvent()
Returns the last event processed by the listener. Useful if you need the event to do something not covered in this API.
int getFlavor()
Always returns Event.MOUSE
Object getNativeEvent()
Returns the platform native event object of the last event processed by the listener.