Skip to content

Commit

Permalink
Add API to check for left/right mouse events
Browse files Browse the repository at this point in the history
convenience API to check for left/right mouse buttons on MouseEvents
  • Loading branch information
steffen-wilke committed Jan 2, 2021
1 parent f4a2233 commit bf8087f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/de/gurkenlabs/litiengine/input/IMouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,26 @@ public interface IMouse {
*/
public boolean isRightButtonPressed();

/**
* Returns true if the mouse event specifies the left mouse button.
*
* @param event
* The MouseEvent object
*
* @return true if the left mouse button was active.
*/
public boolean isLeftButton(MouseEvent event);

/**
* Returns true if the mouse event specifies the right mouse button.
*
* @param event
* The MouseEvent object
*
* @return true if the right mouse button was active.
*/
public boolean isRightButton(MouseEvent event);

/**
* If set to true, the mouse will be locked to the render component of the game.
*
Expand Down
10 changes: 10 additions & 0 deletions src/de/gurkenlabs/litiengine/input/Mouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public boolean isRightButtonPressed() {
return this.isRightMouseButtonDown;
}

@Override
public boolean isLeftButton(MouseEvent event) {
return SwingUtilities.isLeftMouseButton(event);
}

@Override
public boolean isRightButton(MouseEvent event) {
return SwingUtilities.isRightMouseButton(event);
}

@Override
public void mouseClicked(final MouseEvent e) {
this.updateLocation(e);
Expand Down

0 comments on commit bf8087f

Please sign in to comment.