mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 14:43:33 +02:00
Base classes for InputContexts
This commit is contained in:
5
src/schule/ngb/zm/game/InputContext.java
Normal file
5
src/schule/ngb/zm/game/InputContext.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package schule.ngb.zm.game;
|
||||
|
||||
public class InputContext {
|
||||
|
||||
}
|
||||
71
src/schule/ngb/zm/game/InputType.java
Normal file
71
src/schule/ngb/zm/game/InputType.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package schule.ngb.zm.game;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
public class InputType {
|
||||
|
||||
static final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1);
|
||||
|
||||
public class ActionInput extends InputType {
|
||||
|
||||
private int inputCode;
|
||||
|
||||
private String action;
|
||||
|
||||
private ActionListener al;
|
||||
|
||||
private double delay = 0.0;
|
||||
|
||||
private long lastTriggered = 0L;
|
||||
|
||||
private boolean repeats = false;
|
||||
|
||||
private boolean onPress = true;
|
||||
|
||||
private boolean pressed = false;
|
||||
|
||||
|
||||
public void press( int inputCode, long time ) {
|
||||
pressed = true;
|
||||
if( onPress ) {
|
||||
trigger(inputCode, time);
|
||||
}
|
||||
}
|
||||
|
||||
public void release( int inputCode, long time ) {
|
||||
pressed = false;
|
||||
if( !onPress ) {
|
||||
trigger(inputCode, time);
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger( int inputCode, long time ) {
|
||||
if( shouldTrigger(inputCode, time) ) {
|
||||
//al.actionTriggered(action);
|
||||
lastTriggered = time;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldTrigger( int inputCode, long time ) {
|
||||
return this.inputCode == inputCode && time - lastTriggered > delay;
|
||||
}
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
return inputCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TriggerInput extends InputType {
|
||||
|
||||
}
|
||||
|
||||
public class RangeInput extends InputType {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user