You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.4 KiB
69 lines
1.4 KiB
package com.jotuntech.sketcher.common;
|
|
|
|
import java.awt.Point;
|
|
import java.awt.geom.Point2D;
|
|
import java.nio.ByteBuffer;
|
|
|
|
/**
|
|
* Class for containing tablet input data.
|
|
*
|
|
* @author Thor Harald Johansen
|
|
*/
|
|
public class Input extends Point2D.Float implements Streamable {
|
|
/** Pressure axis */
|
|
public int pressure = 0;
|
|
|
|
/** Creates a new input. */
|
|
public Input() {
|
|
|
|
}
|
|
|
|
public Input(float x, float y) {
|
|
super(x, y);
|
|
}
|
|
|
|
public Input(float x, float y, int pressure) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.pressure = pressure;
|
|
}
|
|
|
|
public Input(Point p) {
|
|
x = p.x;
|
|
y = p.y;
|
|
}
|
|
|
|
public Input(Point p, int pressure) {
|
|
x = p.x;
|
|
y = p.y;
|
|
this.pressure = pressure;
|
|
}
|
|
|
|
/**
|
|
* Calculates the difference between the input and the argument such that if
|
|
* one axis of the input is greater than one axis of the argument, the
|
|
* resultant axis will be negative.
|
|
*
|
|
* @param d Input to calculate difference against.
|
|
* @return Difference of inputs.
|
|
*/
|
|
public Input difference(Input d) {
|
|
return new Input(d.x - x, d.y - y, (d.pressure + pressure) >> 1);
|
|
}
|
|
|
|
public Input clone() {
|
|
return new Input(x, y, pressure);
|
|
}
|
|
|
|
public void decode(ByteBuffer in) {
|
|
x = in.getFloat();
|
|
y = in.getFloat();
|
|
pressure = in.getInt();
|
|
}
|
|
|
|
public void encode(ByteBuffer out) {
|
|
out.putFloat(x);
|
|
out.putFloat(y);
|
|
out.putInt(pressure);
|
|
}
|
|
}
|
|
|