Public Member Functions | Static Public Member Functions | Public Attributes

MouseEvent Class Reference

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

List of all members.

Public Member Functions

 MouseEvent (MouseInputSource &source, const Point< int > &position, const ModifierKeys &modifiers, Component *eventComponent, Component *originator, const Time &eventTime, const Point< int > mouseDownPos, const Time &mouseDownTime, int numberOfClicks, bool mouseWasDragged) noexcept
 Creates a MouseEvent.
 ~MouseEvent () noexcept
 Destructor.
int getMouseDownX () const noexcept
 Returns the x co-ordinate of the last place that a mouse was pressed.
int getMouseDownY () const noexcept
 Returns the y co-ordinate of the last place that a mouse was pressed.
const Point< int > getMouseDownPosition () const noexcept
 Returns the co-ordinates of the last place that a mouse was pressed.
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.
int getDistanceFromDragStartX () const noexcept
 Returns the difference between the mouse's current x postion and where it was when the button was last pressed.
int getDistanceFromDragStartY () const noexcept
 Returns the difference between the mouse's current y postion and where it was when the button was last pressed.
const Point< int > getOffsetFromDragStart () const noexcept
 Returns the difference between the mouse's current postion and where it was when the button was last pressed.
bool mouseWasClicked () const noexcept
 Returns true if the mouse has just been clicked.
int getNumberOfClicks () const noexcept
 For a click event, the number of times the mouse was clicked in succession.
int getLengthOfMousePress () const noexcept
 Returns the time that the mouse button has been held down for.
const Point< int > getPosition () const noexcept
 The position of the mouse when the event occurred.
int getScreenX () const
 Returns the mouse x position of this event, in global screen co-ordinates.
int getScreenY () const
 Returns the mouse y position of this event, in global screen co-ordinates.
const Point< int > getScreenPosition () const
 Returns the mouse position of this event, in global screen co-ordinates.
int getMouseDownScreenX () const
 Returns the x co-ordinate at which the mouse button was last pressed.
int getMouseDownScreenY () const
 Returns the y co-ordinate at which the mouse button was last pressed.
const Point< int > getMouseDownScreenPosition () const
 Returns the co-ordinates at which the mouse button was last pressed.
MouseEvent getEventRelativeTo (Component *otherComponent) const noexcept
 Creates a version of this event that is relative to a different component.
MouseEvent withNewPosition (const Point< int > &newPosition) const noexcept
 Creates a copy of this event with a different position.

Static Public Member Functions

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

Public Attributes

const int x
 The x-position of the mouse when the event occurred.
const int y
 The y-position of the mouse when the event occurred.
const ModifierKeys mods
 The key modifiers associated with the event.
Component *const eventComponent
 The component that this event applies to.
Component *const originalComponent
 The component that the event first occurred on.
const Time eventTime
 The time that this mouse-event occurred.
MouseInputSourcesource
 The source device that generated this event.

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 ( MouseInputSource source,
const Point< int > &  position,
const ModifierKeys modifiers,
Component eventComponent,
Component originator,
const Time eventTime,
const Point< int >  mouseDownPos,
const Time mouseDownTime,
int  numberOfClicks,
bool  mouseWasDragged 
)

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
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 (  )

Destructor.


Member Function Documentation

int MouseEvent::getMouseDownX (  ) const

Returns the x co-ordinate of the last place that a mouse was pressed.

The co-ordinate is relative to the component specified in MouseEvent::component.

See also:
getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
int MouseEvent::getMouseDownY (  ) const

Returns the y co-ordinate of the last place that a mouse was pressed.

The co-ordinate is relative to the component specified in MouseEvent::component.

See also:
getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked
const Point<int> MouseEvent::getMouseDownPosition (  ) const

Returns the co-ordinates of the last place that a mouse was pressed.

The co-ordinates are relative to the component specified in MouseEvent::component.

See also:
getDistanceFromDragStart, getDistanceFromDragStartX, mouseWasClicked

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

int MouseEvent::getDistanceFromDragStart (  ) const

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
int MouseEvent::getDistanceFromDragStartX (  ) const

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

See also:
getDistanceFromDragStart
int MouseEvent::getDistanceFromDragStartY (  ) const

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

See also:
getDistanceFromDragStart
const Point<int> MouseEvent::getOffsetFromDragStart (  ) const

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

See also:
getDistanceFromDragStart
bool MouseEvent::mouseWasClicked (  ) const

Returns true if the mouse has just been clicked.

Used in either your mouseUp() or mouseDrag() methods, this will tell you whether the user has dragged the mouse more than a few pixels from the place where the mouse-down occurred.

Once they have dragged it far enough for this method to return false, it will continue to return false until the mouse-up, even if they move the mouse back to the same position where they originally pressed it. 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 any small movements they might make while clicking.

Returns:
true if the mouse wasn't dragged by more than a few pixels between the last time the button was pressed and released.
int MouseEvent::getNumberOfClicks (  ) const

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.

int MouseEvent::getLengthOfMousePress (  ) const

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.

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

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).

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

int MouseEvent::getScreenX (  ) const

Returns the mouse x position of this event, in global screen co-ordinates.

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

See also:
getScreenPosition
int MouseEvent::getScreenY (  ) const

Returns the mouse y position of this event, in global screen co-ordinates.

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

See also:
getScreenPosition
const Point<int> MouseEvent::getScreenPosition (  ) const

Returns the mouse position of this event, in global screen co-ordinates.

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

See also:
getMouseDownScreenPosition
int MouseEvent::getMouseDownScreenX (  ) const

Returns the x co-ordinate at which the mouse button was last pressed.

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

See also:
getMouseDownScreenPosition
int MouseEvent::getMouseDownScreenY (  ) const

Returns the y co-ordinate at which the mouse button was last pressed.

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

See also:
getMouseDownScreenPosition
const Point<int> MouseEvent::getMouseDownScreenPosition (  ) const

Returns the co-ordinates at which the mouse button was last pressed.

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

See also:
getScreenPosition
MouseEvent MouseEvent::getEventRelativeTo ( Component otherComponent ) const

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.

MouseEvent MouseEvent::withNewPosition ( const Point< int > &  newPosition ) const

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.

static void MouseEvent::setDoubleClickTimeout ( int  timeOutMilliseconds ) [static]

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
static int MouseEvent::getDoubleClickTimeout (  ) [static]

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

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).

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).

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().

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

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

The time that this mouse-event occurred.

The source device that generated this event.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines