import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.gui.Avatar;
-import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
* </pre>
*/
private final Map<Integer, Long> pressedKeysToPressedTimeMap = new HashMap<>();
- private final List<MouseClick> detectedMouseClicks = new ArrayList<>();
+ private final List<MouseEvent> detectedMouseEvents = new ArrayList<>();
private final List<KeyEvent> detectedKeyEvents = new ArrayList<>();
private int wheelMovedDirection = 0;
private Point2D mouseDraggedDirection = new Point2D();
* @return <code>true</code> if view needs to be repainted.
*/
private synchronized boolean handleMouseClicksAndHover(final ViewPanel viewPanel) {
- MouseClick unprocessedMouseClick = findUnprocessedMouseClick();
+ boolean rerenderNeeded = false;
+ MouseEvent event = findClickLocationToTrace();
+ if (event != null){
+ // process mouse clicks as a first priority
+ rerenderNeeded = true;
+ } else {
+ // when there are no mouse clicks, process mouse hovering
+
+ if (mouseMoved) {
+ mouseMoved = false;
+ // we would like to re-render frame when user moved mouse, to see what objects mouse is hovering over
+ rerenderNeeded = true;
+ }
+
+ if (currentMouseLocation != null) {
+ // mouse click with button 0 amounts to mouse hovering event
+ event = new MouseEvent(currentMouseLocation, 0);
+ }
+ }
+
+ if (viewPanel.getRenderingContext() != null)
+ viewPanel.getRenderingContext().setMouseEvent(event);
- if (unprocessedMouseClick != null) {
- viewPanel.getRenderingContext().mouseClick = unprocessedMouseClick;
- return false;
- } else
- return handleMouseHovering(viewPanel);
+ return rerenderNeeded;
}
- private MouseClick findUnprocessedMouseClick() {
- synchronized (detectedMouseClicks) {
- if (detectedMouseClicks.isEmpty())
+ private MouseEvent findClickLocationToTrace() {
+ synchronized (detectedMouseEvents) {
+ if (detectedMouseEvents.isEmpty())
return null;
- return detectedMouseClicks.remove(0);
- }
- }
-
- private boolean handleMouseHovering(ViewPanel viewPanel) {
- if (currentMouseLocation != null) {
- RenderingContext renderingContext = viewPanel.getRenderingContext();
- if (renderingContext != null)
- renderingContext.mouseClick = new MouseClick(currentMouseLocation, 0);
- // mouse click with button 0 amounts to mouse hovering event
+ return detectedMouseEvents.remove(0);
}
-
- if (mouseMoved) {
- mouseMoved = false;
- return true;
- } else
- return false;
}
boolean isKeyPressed(final int keyCode) {
}
@Override
- public void mouseClicked(final MouseEvent e) {
- synchronized (detectedMouseClicks) {
- detectedMouseClicks.add(new MouseClick(e.getX(), e.getY(), e.getButton()));
+ public void mouseClicked(final java.awt.event.MouseEvent e) {
+ synchronized (detectedMouseEvents) {
+ detectedMouseEvents.add(new MouseEvent(e.getX(), e.getY(), e.getButton()));
}
}
}
@Override
- public void mouseEntered(final MouseEvent e) {
+ public void mouseEntered(final java.awt.event.MouseEvent e) {
mouseWithinWindow = true;
}
@Override
- public synchronized void mouseExited(final MouseEvent e) {
+ public synchronized void mouseExited(final java.awt.event.MouseEvent e) {
mouseWithinWindow = false;
currentMouseLocation = null;
}
@Override
- public synchronized void mouseMoved(final MouseEvent e) {
+ public synchronized void mouseMoved(final java.awt.event.MouseEvent e) {
currentMouseLocation = new Point2D(e.getX(), e.getY());
mouseMoved = true;
}
@Override
- public void mousePressed(final MouseEvent e) {
+ public void mousePressed(final java.awt.event.MouseEvent e) {
}
@Override