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); } }