moved kernel events to new lib
This commit is contained in:
@@ -3,7 +3,7 @@ package kernel.ui;
|
||||
using tink.CoreApi;
|
||||
|
||||
import util.Color;
|
||||
import kernel.ui.WindowManager.ButtonType;
|
||||
import kernel.ButtonType;
|
||||
import util.Vec.Vec2;
|
||||
import lib.TermWriteable;
|
||||
|
||||
|
||||
@@ -2,91 +2,56 @@ package kernel.ui;
|
||||
|
||||
import lib.TermWriteable;
|
||||
import kernel.peripherals.Peripherals.Peripheral;
|
||||
import haxe.Exception;
|
||||
import util.Vec.Vec2;
|
||||
|
||||
enum ButtonType {
|
||||
Left;
|
||||
Middle;
|
||||
Right;
|
||||
}
|
||||
|
||||
class WindowManager {
|
||||
public static var instance:WindowManager;
|
||||
|
||||
@:allow(kernel.Init)
|
||||
private function new() {
|
||||
KernelEvents.instance.on("key",params -> {
|
||||
var keyCode: Int = params[1];
|
||||
var isHeld: Bool = params[2];
|
||||
|
||||
KernelEvents.instance.onKey.handle(params ->{
|
||||
if (currentMainContext != null){
|
||||
currentMainContext.keyTrigger.trigger({keyCode: keyCode,isHeld: isHeld});
|
||||
currentMainContext.keyTrigger.trigger(params);
|
||||
}
|
||||
});
|
||||
|
||||
KernelEvents.instance.on("key_up",params -> {
|
||||
var keyCode: Int = params[1];
|
||||
|
||||
KernelEvents.instance.onKeyUp.handle(keyCode -> {
|
||||
if (currentMainContext != null){
|
||||
currentMainContext.keyUpTrigger.trigger(keyCode);
|
||||
}
|
||||
});
|
||||
|
||||
KernelEvents.instance.on("mouse_click",params -> {
|
||||
var button: ButtonType = ccButtonToEnum(params[1]);
|
||||
var clickPos: Vec2<Int> = {
|
||||
x: (params[2]:Int) - 1,
|
||||
y: (params[3]:Int) - 1
|
||||
};
|
||||
|
||||
KernelEvents.instance.onMouseClick.handle(params ->{
|
||||
if (currentMainContext != null){
|
||||
currentMainContext.clickTrigger.trigger({button: button,pos: clickPos});
|
||||
currentMainContext.clickTrigger.trigger(params);
|
||||
}
|
||||
});
|
||||
|
||||
KernelEvents.instance.onMouseDrag.handle(params ->{
|
||||
if (currentMainContext != null){
|
||||
currentMainContext.mouseDragTrigger.trigger(params);
|
||||
}
|
||||
});
|
||||
|
||||
KernelEvents.instance.on("mouse_drag",params -> {
|
||||
var button: ButtonType = ccButtonToEnum(params[1]);
|
||||
var pos: Vec2<Int> = {
|
||||
x: (params[2]:Int) - 1,
|
||||
y: (params[3]:Int) - 1,
|
||||
}
|
||||
KernelEvents.instance.onMouseScroll.handle(params ->{
|
||||
if (currentMainContext != null){
|
||||
currentMainContext.mouseDragTrigger.trigger({button: button,pos: pos});
|
||||
currentMainContext.mouseScrollTrigger.trigger(params);
|
||||
}
|
||||
});
|
||||
|
||||
KernelEvents.instance.on("mouse_scroll",params -> {
|
||||
var dir: Int = params[1];
|
||||
var pos: Vec2<Int> = {
|
||||
x: (params[2]:Int) - 1,
|
||||
y: (params[3]:Int) - 1,
|
||||
}
|
||||
|
||||
KernelEvents.instance.onMouseUp.handle(params ->{
|
||||
if (currentMainContext != null){
|
||||
currentMainContext.mouseScrollTrigger.trigger({dir: dir,pos: pos});
|
||||
currentMainContext.mouseUpTrigger.trigger(params);
|
||||
}
|
||||
});
|
||||
|
||||
KernelEvents.instance.on("mouse_up",params -> {
|
||||
var button: ButtonType = ccButtonToEnum(params[1]);
|
||||
var pos: Vec2<Int> = {
|
||||
x: (params[2]:Int) - 1,
|
||||
y: (params[2]:Int) - 1,
|
||||
}
|
||||
|
||||
if (currentMainContext != null){
|
||||
currentMainContext.mouseUpTrigger.trigger({button: button,pos: pos});
|
||||
}
|
||||
});
|
||||
|
||||
KernelEvents.instance.on("paste",params -> {
|
||||
var text: String = params[1];
|
||||
|
||||
KernelEvents.instance.onPaste.handle(text->{
|
||||
if (currentMainContext != null){
|
||||
currentMainContext.pasteTrigger.trigger(text);
|
||||
}
|
||||
});
|
||||
|
||||
KernelEvents.instance.on("monitor_touch",array -> {
|
||||
KernelEvents.instance.onMonitorTouch.handle(params ->{
|
||||
// TODO
|
||||
});
|
||||
}
|
||||
@@ -137,18 +102,4 @@ class WindowManager {
|
||||
context.setTarget(target);
|
||||
context.enable();
|
||||
}
|
||||
|
||||
private static function ccButtonToEnum(button: Int): ButtonType {
|
||||
switch button {
|
||||
case 1:
|
||||
return Left;
|
||||
case 2:
|
||||
return Middle;
|
||||
case 3:
|
||||
return Right;
|
||||
case _:
|
||||
throw new Exception("Invalid input");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user