cc-haxe/src/kernel/ui/WindowManager.hx

106 lines
2.9 KiB
Haxe
Raw Normal View History

2021-12-20 00:55:30 +00:00
package kernel.ui;
import lib.TermWriteable;
import kernel.peripherals.Peripherals.Peripheral;
class WindowManager {
2022-02-21 00:50:19 +00:00
public static var instance:WindowManager;
2021-12-20 00:55:30 +00:00
2022-02-21 00:50:19 +00:00
@:allow(kernel.Init)
private function new() {
2022-02-21 14:17:38 +00:00
KernelEvents.instance.onKey.handle(params ->{
2021-12-20 00:55:30 +00:00
if (currentMainContext != null){
2022-02-21 14:17:38 +00:00
currentMainContext.keyTrigger.trigger(params);
2021-12-20 00:55:30 +00:00
}
});
2022-02-21 14:17:38 +00:00
KernelEvents.instance.onKeyUp.handle(keyCode -> {
2021-12-20 00:55:30 +00:00
if (currentMainContext != null){
2022-02-21 00:50:19 +00:00
currentMainContext.keyUpTrigger.trigger(keyCode);
2021-12-20 00:55:30 +00:00
}
});
2022-02-21 14:17:38 +00:00
KernelEvents.instance.onMouseClick.handle(params ->{
2021-12-20 00:55:30 +00:00
if (currentMainContext != null){
2022-02-21 14:17:38 +00:00
currentMainContext.clickTrigger.trigger(params);
2021-12-20 00:55:30 +00:00
}
});
2022-02-21 14:17:38 +00:00
KernelEvents.instance.onMouseDrag.handle(params ->{
2021-12-20 00:55:30 +00:00
if (currentMainContext != null){
2022-02-21 14:17:38 +00:00
currentMainContext.mouseDragTrigger.trigger(params);
2021-12-20 00:55:30 +00:00
}
});
2022-02-21 14:17:38 +00:00
KernelEvents.instance.onMouseScroll.handle(params ->{
2021-12-20 00:55:30 +00:00
if (currentMainContext != null){
2022-02-21 14:17:38 +00:00
currentMainContext.mouseScrollTrigger.trigger(params);
2021-12-20 00:55:30 +00:00
}
});
2022-02-21 14:17:38 +00:00
KernelEvents.instance.onMouseUp.handle(params ->{
2021-12-20 00:55:30 +00:00
if (currentMainContext != null){
2022-02-21 14:17:38 +00:00
currentMainContext.mouseUpTrigger.trigger(params);
2021-12-20 00:55:30 +00:00
}
});
2022-02-21 14:17:38 +00:00
KernelEvents.instance.onPaste.handle(text->{
2021-12-20 00:55:30 +00:00
if (currentMainContext != null){
2022-02-21 00:50:19 +00:00
currentMainContext.pasteTrigger.trigger(text);
2021-12-20 00:55:30 +00:00
}
});
2022-02-21 14:17:38 +00:00
KernelEvents.instance.onMonitorTouch.handle(params ->{
2021-12-20 00:55:30 +00:00
// TODO
});
}
2022-02-21 00:50:19 +00:00
private var currentMainContext:WindowContext;
private final allContexts:Array<WindowContext> = new Array();
private final outputMap:Map<String,WindowContext> = new Map();
2021-12-20 00:55:30 +00:00
public function createNewContext(): WindowContext {
var newContext = new WindowContext(new VirtualTermWriter());
allContexts.push(newContext);
2022-02-21 00:50:19 +00:00
// newContext.setTarget(MainTerm.instance);
2021-12-20 00:55:30 +00:00
newContext.enable();
currentMainContext = newContext;
return newContext;
}
public function getOutputs(): Array<String> {
var arr = Peripheral.instance.getScreens().map(screen -> return screen.getAddr());
arr.push("main");
return arr;
}
public function focusContextToOutput(context: WindowContext,output: String) {
var target: TermWriteable;
if (output == "main"){
target = MainTerm.instance;
}else{
target = Peripheral.instance.getScreen(output);
if (target == null){
// output target not found
return;
}
}
if (outputMap.exists(output)){
outputMap[output].disable();
}
outputMap[output] = context;
context.setTarget(target);
context.enable();
}
2022-02-21 14:17:38 +00:00
}