JUCE
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
MouseEvent Class Referencefinal

Contains position and status information about a mouse event. More...

Public Member Functions

 MouseEvent (MouseInputSource source, Point< float > position, ModifierKeys modifiers, float pressure, float orientation, float rotation, float tiltX, float tiltY, Component *eventComponent, Component *originator, Time eventTime, Point< float > mouseDownPos, Time mouseDownTime, int numberOfClicks, bool mouseWasDragged) noexcept
 Creates a MouseEvent. More...
 
 ~MouseEvent () noexcept
 Destructor. More...
 
int getMouseDownX () const noexcept
 Returns the x coordinate of the last place that a mouse was pressed. More...
 
int getMouseDownY () const noexcept
 Returns the y coordinate of the last place that a mouse was pressed. More...
 
Point< intgetMouseDownPosition () const noexcept
 Returns the coordinates of the last place that a mouse was pressed. More...
 
int getDistanceFromDragStart () const noexcept
 Returns the straight-line distance between where the mouse is now and where it was the last time the button was pressed. More...
 
int getDistanceFromDragStartX () const noexcept
 Returns the difference between the mouse's current x position and where it was when the button was last pressed. More...
 
int getDistanceFromDragStartY () const noexcept
 Returns the difference between the mouse's current y position and where it was when the button was last pressed. More...
 
Point< intgetOffsetFromDragStart () const noexcept
 Returns the difference between the mouse's current position and where it was when the button was last pressed. More...
 
bool mouseWasDraggedSinceMouseDown () const noexcept
 Returns true if the user seems to be performing a drag gesture. More...
 
bool mouseWasClicked () const noexcept
 Returns true if the mouse event is part of a click gesture rather than a drag. More...
 
int getNumberOfClicks () const noexcept
 For a click event, the number of times the mouse was clicked in succession. More...
 
int getLengthOfMousePress () const noexcept
 Returns the time that the mouse button has been held down for. More...
 
bool isPressureValid () const noexcept
 Returns true if the pressure value for this event is meaningful. More...
 
bool isOrientationValid () const noexcept
 Returns true if the orientation value for this event is meaningful. More...
 
bool isRotationValid () const noexcept
 Returns true if the rotation value for this event is meaningful. More...
 
bool isTiltValid (bool tiltX) const noexcept
 Returns true if the current tilt value (either x- or y-axis) is meaningful. More...
 
Point< intgetPosition () const noexcept
 The position of the mouse when the event occurred. More...
 
int getScreenX () const
 Returns the mouse x position of this event, in global screen coordinates. More...
 
int getScreenY () const
 Returns the mouse y position of this event, in global screen coordinates. More...
 
Point< intgetScreenPosition () const
 Returns the mouse position of this event, in global screen coordinates. More...
 
int getMouseDownScreenX () const
 Returns the x coordinate at which the mouse button was last pressed. More...
 
int getMouseDownScreenY () const
 Returns the y coordinate at which the mouse button was last pressed. More...
 
Point< intgetMouseDownScreenPosition () const
 Returns the coordinates at which the mouse button was last pressed. More...
 
MouseEvent getEventRelativeTo (Component *newComponent) const noexcept
 Creates a version of this event that is relative to a different component. More...
 
MouseEvent withNewPosition (Point< float > newPosition) const noexcept
 Creates a copy of this event with a different position. More...
 
MouseEvent withNewPosition (Point< int > newPosition) const noexcept
 Creates a copy of this event with a different position. More...
 

Static Public Member Functions

static void setDoubleClickTimeout (int timeOutMilliseconds) noexcept
 Changes the application-wide setting for the double-click time limit. More...
 
static int getDoubleClickTimeout () noexcept
 Returns the application-wide setting for the double-click time limit. More...
 

Public Attributes

const Point< float > position
 The position of the mouse when the event occurred. More...
 
const int x
 The x-position of the mouse when the event occurred. More...
 
const int y
 The y-position of the mouse when the event occurred. More...
 
const ModifierKeys mods
 The key modifiers associated with the event. More...
 
const float pressure
 The pressure of the touch or stylus for this event. More...
 
const float orientation
 The orientation of the touch input for this event in radians where 0 indicates a touch aligned with the x-axis and pointing from left to right; increasing values indicate rotation in the clockwise direction. More...
 
const float rotation
 The rotation of the pen device for this event in radians. More...
 
const float tiltX
 The tilt of the pen device along the x-axis between -1.0 and 1.0. More...
 
const float tiltY
 The tilt of the pen device along the y-axis between -1.0 and 1.0. More...
 
const Point< float > mouseDownPosition
 The coordinates of the last place that a mouse button was pressed. More...
 
Component *const eventComponent
 The component that this event applies to. More...
 
Component *const originalComponent
 The component that the event first occurred on. More...
 
const Time eventTime
 The time that this mouse-event occurred. More...
 
const Time mouseDownTime
 The time that the corresponding mouse-down event occurred. More...
 
MouseInputSource source
 The source device that generated this event. More...
 

Detailed Description

Contains position and status information about a mouse event.

See also
MouseListener, Component::mouseMove, Component::mouseEnter, Component::mouseExit, Component::mouseDown, Component::mouseUp, Component::mouseDrag

Constructor & Destructor Documentation

◆ MouseEvent()

MouseEvent::MouseEvent ( MouseInputSource  source,
Point< float >  position,
ModifierKeys  modifiers,
float  pressure,
float  orientation,
float  rotation,
float  tiltX,
float  tiltY,
Component eventComponent,
Component originator,
Time  eventTime,
Point< float >  mouseDownPos,
Time  mouseDownTime,
int  numberOfClicks,
bool  mouseWasDragged 
)
noexcept

Creates a MouseEvent.

Normally an application will never need to use this.

Parameters
sourcethe source that's invoking the event
positionthe position of the mouse, relative to the component that is passed-in
modifiersthe key modifiers at the time of the event
pressurethe pressure of the touch or stylus, in the range 0 to 1. Devices that do not support force information may return 0.0, 1.0, or a negative value, depending on the platform
orientationthe orientation of the touch input for this event in radians. The default is 0
rotationthe rotation of the pen device for this event in radians. The default is 0
tiltXthe tilt of the pen device along the x-axis between -1.0 and 1.0. The default is 0
tiltYthe tilt of the pen device along the y-axis between -1.0 and 1.0. The default is 0
eventComponentthe component that the mouse event applies to
originatorthe component that originally received the event
eventTimethe time the event happened
mouseDownPosthe position of the corresponding mouse-down event (relative to the component that is passed-in). If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be the same as the current mouse-x position.
mouseDownTimethe time at which the corresponding mouse-down event happened If there isn't a corresponding mouse-down (e.g. for a mouse-move), this will just be the same as the current mouse-event time.
numberOfClickshow many clicks, e.g. a double-click event will be 2, a triple-click will be 3, etc
mouseWasDraggedwhether the mouse has been dragged significantly since the previous mouse-down

◆ ~MouseEvent()

MouseEvent::~MouseEvent ( )
noexcept

Destructor.

Member Function Documentation

◆ getMouseDownX()

int MouseEvent::getMouseDownX ( ) const
noexcept

Returns the x coordinate of the last place that a mouse was pressed.

The coordinate is relative to the component specified in MouseEvent::component.

See also
getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown

◆ getMouseDownY()

int MouseEvent::getMouseDownY ( ) const
noexcept

Returns the y coordinate of the last place that a mouse was pressed.

The coordinate is relative to the component specified in MouseEvent::component.

See also
getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown

◆ getMouseDownPosition()

Point<int> MouseEvent::getMouseDownPosition ( ) const
noexcept

Returns the coordinates of the last place that a mouse was pressed.

The coordinates are relative to the component specified in MouseEvent::component. For a floating point version of this value, see mouseDownPosition.

See also
mouseDownPosition, getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown

Referenced by LassoComponent< SelectableItemType >::beginLasso().

◆ getDistanceFromDragStart()

int MouseEvent::getDistanceFromDragStart ( ) const
noexcept

Returns the straight-line distance between where the mouse is now and where it was the last time the button was pressed.

This is quite handy for things like deciding whether the user has moved far enough for it to be considered a drag operation.

See also
getDistanceFromDragStartX

◆ getDistanceFromDragStartX()

int MouseEvent::getDistanceFromDragStartX ( ) const
noexcept

Returns the difference between the mouse's current x position and where it was when the button was last pressed.

See also
getDistanceFromDragStart

◆ getDistanceFromDragStartY()

int MouseEvent::getDistanceFromDragStartY ( ) const
noexcept

Returns the difference between the mouse's current y position and where it was when the button was last pressed.

See also
getDistanceFromDragStart

◆ getOffsetFromDragStart()

Point<int> MouseEvent::getOffsetFromDragStart ( ) const
noexcept

Returns the difference between the mouse's current position and where it was when the button was last pressed.

See also
getDistanceFromDragStart

◆ mouseWasDraggedSinceMouseDown()

bool MouseEvent::mouseWasDraggedSinceMouseDown ( ) const
noexcept

Returns true if the user seems to be performing a drag gesture.

This is only meaningful if called in either a mouseUp() or mouseDrag() method.

It will return true if the user has dragged the mouse more than a few pixels from the place where the mouse-down occurred or the mouse has been held down for a significant amount of time.

Once they have dragged it far enough for this method to return true, it will continue to return true until the mouse-up, even if they move the mouse back to the same location at which the mouse-down happened. This means that it's very handy for objects that can either be clicked on or dragged, as you can use it in the mouseDrag() callback to ignore small movements they might make while trying to click.

◆ mouseWasClicked()

bool MouseEvent::mouseWasClicked ( ) const
noexcept

Returns true if the mouse event is part of a click gesture rather than a drag.

This is effectively the opposite of mouseWasDraggedSinceMouseDown()

◆ getNumberOfClicks()

int MouseEvent::getNumberOfClicks ( ) const
noexcept

For a click event, the number of times the mouse was clicked in succession.

So for example a double-click event will return 2, a triple-click 3, etc.

◆ getLengthOfMousePress()

int MouseEvent::getLengthOfMousePress ( ) const
noexcept

Returns the time that the mouse button has been held down for.

If called from a mouseDrag or mouseUp callback, this will return the number of milliseconds since the corresponding mouseDown event occurred. If called in other contexts, e.g. a mouseMove, then the returned value may be 0 or an undefined value.

◆ isPressureValid()

bool MouseEvent::isPressureValid ( ) const
noexcept

Returns true if the pressure value for this event is meaningful.

◆ isOrientationValid()

bool MouseEvent::isOrientationValid ( ) const
noexcept

Returns true if the orientation value for this event is meaningful.

◆ isRotationValid()

bool MouseEvent::isRotationValid ( ) const
noexcept

Returns true if the rotation value for this event is meaningful.

◆ isTiltValid()

bool MouseEvent::isTiltValid ( bool  tiltX) const
noexcept

Returns true if the current tilt value (either x- or y-axis) is meaningful.

◆ getPosition()

Point<int> MouseEvent::getPosition ( ) const
noexcept

The position of the mouse when the event occurred.

This position is relative to the top-left of the component to which the event applies (as indicated by the MouseEvent::eventComponent field).

For a floating-point position, see MouseEvent::position

Referenced by LassoComponent< SelectableItemType >::dragLasso().

◆ getScreenX()

int MouseEvent::getScreenX ( ) const

Returns the mouse x position of this event, in global screen coordinates.

The coordinates are relative to the top-left of the main monitor.

See also
getScreenPosition

◆ getScreenY()

int MouseEvent::getScreenY ( ) const

Returns the mouse y position of this event, in global screen coordinates.

The coordinates are relative to the top-left of the main monitor.

See also
getScreenPosition

◆ getScreenPosition()

Point<int> MouseEvent::getScreenPosition ( ) const

Returns the mouse position of this event, in global screen coordinates.

The coordinates are relative to the top-left of the main monitor.

See also
getMouseDownScreenPosition

◆ getMouseDownScreenX()

int MouseEvent::getMouseDownScreenX ( ) const

Returns the x coordinate at which the mouse button was last pressed.

The coordinates are relative to the top-left of the main monitor.

See also
getMouseDownScreenPosition

◆ getMouseDownScreenY()

int MouseEvent::getMouseDownScreenY ( ) const

Returns the y coordinate at which the mouse button was last pressed.

The coordinates are relative to the top-left of the main monitor.

See also
getMouseDownScreenPosition

◆ getMouseDownScreenPosition()

Point<int> MouseEvent::getMouseDownScreenPosition ( ) const

Returns the coordinates at which the mouse button was last pressed.

The coordinates are relative to the top-left of the main monitor.

See also
getScreenPosition

◆ getEventRelativeTo()

MouseEvent MouseEvent::getEventRelativeTo ( Component newComponent) const
noexcept

Creates a version of this event that is relative to a different component.

The x and y positions of the event that is returned will have been adjusted to be relative to the new component. The component pointer that is passed-in must not be null.

◆ withNewPosition() [1/2]

MouseEvent MouseEvent::withNewPosition ( Point< float >  newPosition) const
noexcept

Creates a copy of this event with a different position.

All other members of the event object are the same, but the x and y are replaced with these new values.

◆ withNewPosition() [2/2]

MouseEvent MouseEvent::withNewPosition ( Point< int newPosition) const
noexcept

Creates a copy of this event with a different position.

All other members of the event object are the same, but the x and y are replaced with these new values.

◆ setDoubleClickTimeout()

static void MouseEvent::setDoubleClickTimeout ( int  timeOutMilliseconds)
staticnoexcept

Changes the application-wide setting for the double-click time limit.

This is the maximum length of time between mouse-clicks for it to be considered a double-click. It's used by the Component class.

See also
getDoubleClickTimeout, MouseListener::mouseDoubleClick

◆ getDoubleClickTimeout()

static int MouseEvent::getDoubleClickTimeout ( )
staticnoexcept

Returns the application-wide setting for the double-click time limit.

This is the maximum length of time between mouse-clicks for it to be considered a double-click. It's used by the Component class.

See also
setDoubleClickTimeout, MouseListener::mouseDoubleClick

Member Data Documentation

◆ position

const Point<float> MouseEvent::position

The position of the mouse when the event occurred.

This value is relative to the top-left of the component to which the event applies (as indicated by the MouseEvent::eventComponent field).

This is a more accurate floating-point version of the position returned by getPosition() and the integer x and y member variables.

◆ x

const int MouseEvent::x

The x-position of the mouse when the event occurred.

This value is relative to the top-left of the component to which the event applies (as indicated by the MouseEvent::eventComponent field).

For a floating-point coordinate, see MouseEvent::position

◆ y

const int MouseEvent::y

The y-position of the mouse when the event occurred.

This value is relative to the top-left of the component to which the event applies (as indicated by the MouseEvent::eventComponent field).

For a floating-point coordinate, see MouseEvent::position

◆ mods

const ModifierKeys MouseEvent::mods

The key modifiers associated with the event.

This will let you find out which mouse buttons were down, as well as which modifier keys were held down.

When used for mouse-up events, this will indicate the state of the mouse buttons just before they were released, so that you can tell which button they let go of.

Referenced by LassoComponent< SelectableItemType >::dragLasso().

◆ pressure

const float MouseEvent::pressure

The pressure of the touch or stylus for this event.

The range is 0 (soft) to 1 (hard). If the input device doesn't provide any pressure data, it may return a negative value here, or 0.0 or 1.0, depending on the platform.

◆ orientation

const float MouseEvent::orientation

The orientation of the touch input for this event in radians where 0 indicates a touch aligned with the x-axis and pointing from left to right; increasing values indicate rotation in the clockwise direction.

The default is 0.

◆ rotation

const float MouseEvent::rotation

The rotation of the pen device for this event in radians.

Indicates the clockwise rotation, or twist, of the pen. The default is 0.

◆ tiltX

const float MouseEvent::tiltX

The tilt of the pen device along the x-axis between -1.0 and 1.0.

A positive value indicates a tilt to the right. The default is 0.

◆ tiltY

const float MouseEvent::tiltY

The tilt of the pen device along the y-axis between -1.0 and 1.0.

A positive value indicates a tilt toward the user. The default is 0.

◆ mouseDownPosition

const Point<float> MouseEvent::mouseDownPosition

The coordinates of the last place that a mouse button was pressed.

The coordinates are relative to the component specified in MouseEvent::component.

See also
getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasDraggedSinceMouseDown

◆ eventComponent

Component* const MouseEvent::eventComponent

The component that this event applies to.

This is usually the component that the mouse was over at the time, but for mouse-drag events the mouse could actually be over a different component and the events are still sent to the component that the button was originally pressed on.

The x and y member variables are relative to this component's position.

If you use getEventRelativeTo() to retarget this object to be relative to a different component, this pointer will be updated, but originalComponent remains unchanged.

See also
originalComponent

◆ originalComponent

Component* const MouseEvent::originalComponent

The component that the event first occurred on.

If you use getEventRelativeTo() to retarget this object to be relative to a different component, this value remains unchanged to indicate the first component that received it.

See also
eventComponent

◆ eventTime

const Time MouseEvent::eventTime

The time that this mouse-event occurred.

◆ mouseDownTime

const Time MouseEvent::mouseDownTime

The time that the corresponding mouse-down event occurred.

◆ source

MouseInputSource MouseEvent::source

The source device that generated this event.


The documentation for this class was generated from the following file: