WarpPI/core/src/main/java/it/cavallium/warppi/device/input/TouchInputDevice.java

44 lines
1.2 KiB
Java
Raw Normal View History

2019-02-27 23:29:03 +01:00
package it.cavallium.warppi.device.input;
import java.util.concurrent.Flow.Subscriber;
import java.util.function.Consumer;
import it.cavallium.warppi.event.TouchEvent;
import it.cavallium.warppi.event.TouchEventListener;
import it.cavallium.warppi.event.TouchPoint;
2018-07-28 23:26:07 +02:00
public interface TouchInputDevice {
boolean getSwappedAxes();
2018-08-28 02:39:41 +02:00
2018-09-22 11:17:30 +02:00
boolean getInvertedX();
2018-08-28 02:39:41 +02:00
2018-09-22 11:17:30 +02:00
boolean getInvertedY();
2018-08-28 02:39:41 +02:00
2018-09-22 11:17:30 +02:00
default void setInvertedXY() {}
2018-08-28 02:39:41 +02:00
2018-09-22 11:17:30 +02:00
default void setInvertedX() {}
2018-08-28 02:39:41 +02:00
2018-09-22 11:17:30 +02:00
default void setInvertedY() {}
2018-08-28 02:39:41 +02:00
void listenTouchEvents(Consumer<TouchEvent> touchEventListener);
default TouchPoint makePoint(final long id, float x, float y, final int screenWidth, final int screenHeight,
final float radiusX, final float radiusY, final float force, final float rotationAngle) {
if (getSwappedAxes()) {
final double oldX = x;
final double oldY = y;
x = (float) (oldY * screenWidth / screenHeight);
y = (float) (oldX * screenHeight / screenWidth);
}
if (getInvertedX()) {
x = screenWidth - x;
}
if (getInvertedY()) {
y = screenHeight - y;
}
return new TouchPoint(id, x, y, radiusX, radiusY, force, rotationAngle);
}
void initialize();
}