X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgui%2Fhumaninput%2FHIDInputTracker.java;h=af0ae3104fa42dfe325ea2e4e0bb5a533ea52cf4;hb=f4f24fac9a22e6f05f6e1115d3a578513fbbd03c;hp=5bf7927d145f2c08828858cafdf1211ddb9ee7bb;hpb=9dcd9d8a7d3bc16eb6fde3681cd32e02dc0707e9;p=sixth-3d.git 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 5bf7927..af0ae31 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,12 +1,7 @@ /* - * Sixth 3D engine. Copyright ©2012-2018, 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 - * or later as published by the Free Software Foundation. - * + * Sixth 3D engine. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. */ - package eu.svjatoslav.sixth.e3d.gui.humaninput; import eu.svjatoslav.sixth.e3d.geometry.Point2D; @@ -21,6 +16,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +/** + * Human input device input tracker. + *
+ * Idea is to capture all keyboard and mouse inputs from underlying operating system in this class
+ * and forward those as needed to subsequent virtual components.
+ */
public class HIDInputTracker implements
MouseMotionListener, KeyListener, MouseListener, MouseWheelListener, ViewRenderListener {
@@ -74,7 +75,7 @@ public class HIDInputTracker implements
* @return true
if view needs to be repainted.
*/
private boolean handleKeyboardEvents() {
- final UserInputHandler currentFocusOwner = viewPanel.getKeyboardFocusStack().getCurrentFocusOwner();
+ final KeyboardInputHandler currentFocusOwner = viewPanel.getKeyboardFocusStack().getCurrentFocusOwner();
ArrayListtrue
if view update is needed.
*/
private boolean forwardKeyboardEventsToFocusOwner(
- UserInputHandler currentFocusOwner, ArrayListtrue
if view needs to be repainted.
*/
private synchronized boolean handleMouseClicksAndHover(final ViewPanel viewPanel) {
- MouseEvent mouseEventAndLocationToTrace = getMouseEventAndLocationToTrace(viewPanel);
- if (mouseEventAndLocationToTrace != null)
- {
- viewPanel.getRenderingContext().mouseEvent = mouseEventAndLocationToTrace;
- return true;
+ 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);
+ }
}
- return false;
- }
- private MouseEvent getMouseEventAndLocationToTrace(ViewPanel viewPanel) {
- MouseEvent unprocessedMouseEvent = findClickLocationToTrace();
- if (unprocessedMouseEvent != null) {
- return unprocessedMouseEvent;
- } else
- return getHoverLocationToTrace(viewPanel);
+ if (viewPanel.getRenderingContext() != null)
+ viewPanel.getRenderingContext().setMouseEvent(event);
+
+ return rerenderNeeded;
}
private MouseEvent findClickLocationToTrace() {
@@ -143,17 +153,6 @@ public class HIDInputTracker implements
}
}
- private MouseEvent getHoverLocationToTrace(ViewPanel viewPanel) {
- if (mouseMoved) {
- mouseMoved = 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) {
return pressedKeysToPressedTimeMap.containsKey(keyCode);
}
@@ -247,7 +246,8 @@ public class HIDInputTracker implements
* @return true
if view needs to be repainted.
*/
private boolean handleMouseDragging() {
- // TODO: need to detect whether user moved mouse or touch screen
+ // TODO: It would be nice here to detect somehow whether user moved mouse or touch screen.
+ // in case of touch screen, we would like to reverse movement along X and Y axis.
final Avatar avatar = viewPanel.getAvatar();
// for mouse