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=5f0ef248ea43b7050d2959bc1ab8fbbba013b337;hp=6015ee75957fcbae7baa113be9f5cce852a5dd73;hb=59baa428fb2d9e7f0fe5423f4cea47f2d6245914;hpb=70ee733b25c56bed539b89ff5507ae0af842d68a 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 6015ee7..5f0ef24 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 @@ -1,5 +1,5 @@ /* - * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * Sixth 3D engine. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License @@ -33,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(); @@ -117,36 +117,41 @@ public class HIDInputTracker implements * @return true 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); + return detectedMouseEvents.remove(0); } } - private boolean handleMouseHovering(ViewPanel viewPanel) { - if (currentMouseLocation != null) - // mouse click with button 0 amounts to mouse hovering event - viewPanel.getRenderingContext().mouseClick = new MouseClick(currentMouseLocation, 0); - - if (mouseMoved) { - mouseMoved = false; - return true; - } else - return false; - } - boolean isKeyPressed(final int keyCode) { return pressedKeysToPressedTimeMap.containsKey(keyCode); } @@ -172,9 +177,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())); } } @@ -193,24 +198,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