X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgui%2Fhumaninput%2FHIDInputTracker.java;h=5bf7927d145f2c08828858cafdf1211ddb9ee7bb;hp=ee625d5079f4216ee10a3bd3a2b97826b46395db;hb=9dcd9d8a7d3bc16eb6fde3681cd32e02dc0707e9;hpb=4bb8945294848559aab76e248207781c6e097714 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/HIDInputTracker.java b/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/HIDInputTracker.java index ee625d5..5bf7927 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/HIDInputTracker.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/gui/humaninput/HIDInputTracker.java @@ -11,7 +11,6 @@ package eu.svjatoslav.sixth.e3d.gui.humaninput; 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; @@ -34,7 +33,7 @@ public class HIDInputTracker implements * */ private final Map pressedKeysToPressedTimeMap = new HashMap<>(); - private final List detectedMouseClicks = new ArrayList<>(); + private final List detectedMouseEvents = new ArrayList<>(); private final List detectedKeyEvents = new ArrayList<>(); private int wheelMovedDirection = 0; private Point2D mouseDraggedDirection = new Point2D(); @@ -118,37 +117,41 @@ public class HIDInputTracker implements * @return true if view needs to be repainted. */ private synchronized boolean handleMouseClicksAndHover(final ViewPanel viewPanel) { - MouseClick unprocessedMouseClick = findUnprocessedMouseClick(); + MouseEvent mouseEventAndLocationToTrace = getMouseEventAndLocationToTrace(viewPanel); + if (mouseEventAndLocationToTrace != null) + { + viewPanel.getRenderingContext().mouseEvent = mouseEventAndLocationToTrace; + return true; + } + return false; + } - if (unprocessedMouseClick != null) { - viewPanel.getRenderingContext().mouseClick = unprocessedMouseClick; - return false; + private MouseEvent getMouseEventAndLocationToTrace(ViewPanel viewPanel) { + MouseEvent unprocessedMouseEvent = findClickLocationToTrace(); + if (unprocessedMouseEvent != null) { + return unprocessedMouseEvent; } else - return handleMouseHovering(viewPanel); + return getHoverLocationToTrace(viewPanel); } - private MouseClick findUnprocessedMouseClick() { - synchronized (detectedMouseClicks) { - if (detectedMouseClicks.isEmpty()) + private MouseEvent findClickLocationToTrace() { + synchronized (detectedMouseEvents) { + if (detectedMouseEvents.isEmpty()) return null; - return detectedMouseClicks.remove(0); + return detectedMouseEvents.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 - } - + private MouseEvent getHoverLocationToTrace(ViewPanel viewPanel) { if (mouseMoved) { mouseMoved = false; - return true; - } else - return false; + if (currentMouseLocation != null) { + return new MouseEvent(currentMouseLocation, 0); + // mouse click with button 0 amounts to mouse hovering event + } + } + return null; } boolean isKeyPressed(final int keyCode) { @@ -176,9 +179,9 @@ public class HIDInputTracker implements } @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())); } } @@ -197,24 +200,24 @@ public class HIDInputTracker implements } @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