131 lines
2.4 KiB
Java
131 lines
2.4 KiB
Java
package electrosphere.controls;
|
|
|
|
import electrosphere.renderer.ui.events.MouseEvent;
|
|
|
|
public class Control {
|
|
|
|
public static enum ControlType {
|
|
KEY,
|
|
MOUSE_BUTTON,
|
|
MOUSE_MOVEMENT,
|
|
}
|
|
|
|
ControlType type;
|
|
boolean state;
|
|
int keyValue;
|
|
ControlMethod onPress;
|
|
ControlMethod onRelease;
|
|
ControlMethod onRepeat;
|
|
ControlMethod onClick;
|
|
MouseCallback onMove;
|
|
|
|
float pressFrame = 0;
|
|
float repeatTimeout = 0;
|
|
|
|
public boolean isIsKey() {
|
|
return type == ControlType.KEY;
|
|
}
|
|
|
|
public boolean isIsMouse() {
|
|
return type == ControlType.MOUSE_BUTTON;
|
|
}
|
|
|
|
public boolean isState() {
|
|
return state;
|
|
}
|
|
|
|
public ControlType getType(){
|
|
return type;
|
|
}
|
|
|
|
public int getKeyValue() {
|
|
return keyValue;
|
|
}
|
|
|
|
public void setState(boolean state) {
|
|
this.state = state;
|
|
}
|
|
|
|
public Control(ControlType type, int keyValue) {
|
|
this.type = type;
|
|
this.keyValue = keyValue;
|
|
this.state = false;
|
|
}
|
|
|
|
public void setOnPress(ControlMethod method){
|
|
onPress = method;
|
|
}
|
|
|
|
public void setOnRelease(ControlMethod method){
|
|
onRelease = method;
|
|
}
|
|
|
|
public void setOnRepeat(ControlMethod method){
|
|
onRepeat = method;
|
|
}
|
|
|
|
public void setOnMove(MouseCallback method){
|
|
onMove = method;
|
|
}
|
|
|
|
public void setOnClick(ControlMethod method){
|
|
onClick = method;
|
|
}
|
|
|
|
public void onPress(){
|
|
if(onPress != null){
|
|
onPress.execute();
|
|
}
|
|
}
|
|
|
|
public void onRelease(){
|
|
if(onRelease != null){
|
|
onRelease.execute();
|
|
}
|
|
}
|
|
|
|
public void onRepeat(){
|
|
if(onRepeat != null){
|
|
onRepeat.execute();
|
|
}
|
|
}
|
|
|
|
public void onMove(MouseEvent event){
|
|
if(onMove != null){
|
|
onMove.execute(event);
|
|
}
|
|
}
|
|
|
|
public void onClick(){
|
|
if(onClick != null){
|
|
onClick.execute();
|
|
}
|
|
}
|
|
|
|
public float getPressFrame(){
|
|
return this.pressFrame;
|
|
}
|
|
|
|
public void setPressFrame(float frame){
|
|
pressFrame = frame;
|
|
}
|
|
|
|
public float getRepeatTimeout(){
|
|
return this.repeatTimeout;
|
|
}
|
|
|
|
public void setRepeatTimeout(float timeout){
|
|
repeatTimeout = timeout;
|
|
}
|
|
|
|
|
|
public interface ControlMethod {
|
|
public void execute();
|
|
}
|
|
|
|
public interface MouseCallback {
|
|
public void execute(MouseEvent event);
|
|
}
|
|
|
|
}
|