2021-12-20 00:55:30 +00:00
|
|
|
package kernel.ui;
|
|
|
|
|
2022-03-05 01:41:30 +00:00
|
|
|
import kernel.ui.TermWriteable;
|
2021-12-20 00:55:30 +00:00
|
|
|
import kernel.peripherals.Peripherals.Peripheral;
|
|
|
|
|
2022-03-05 01:41:30 +00:00
|
|
|
/**
|
|
|
|
Responsable for creating window context, forwarding UI events to the context
|
|
|
|
and switching context to real screens.
|
|
|
|
**/
|
2021-12-20 00:55:30 +00:00
|
|
|
class WindowManager {
|
2022-02-24 18:47:27 +00:00
|
|
|
/**
|
|
|
|
Depends on: KernelEvents, Peripheral
|
|
|
|
**/
|
2022-02-21 14:35:37 +00:00
|
|
|
public static var instance:WindowManager;
|
2022-03-04 12:28:52 +00:00
|
|
|
private var currentMainContext:WindowContext;
|
|
|
|
private final allContexts:Array<WindowContext> = new Array();
|
|
|
|
private final outputMap:Map<String, WindowContext> = new Map();
|
2022-02-21 14:35:37 +00:00
|
|
|
|
|
|
|
@:allow(kernel.Init)
|
|
|
|
private function new() {
|
|
|
|
KernelEvents.instance.onKey.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
2022-03-04 12:28:52 +00:00
|
|
|
currentMainContext.onKeyTrigger.trigger(params);
|
2022-02-21 14:35:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onKeyUp.handle(keyCode -> {
|
|
|
|
if (currentMainContext != null) {
|
2022-03-04 12:28:52 +00:00
|
|
|
currentMainContext.onKeyUpTrigger.trigger(keyCode);
|
2022-02-21 14:35:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMouseClick.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
2022-03-04 12:28:52 +00:00
|
|
|
currentMainContext.onClickTrigger.trigger(params);
|
2022-02-21 14:35:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMouseDrag.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
2022-03-04 12:28:52 +00:00
|
|
|
currentMainContext.onMouseDragTrigger.trigger(params);
|
2022-02-21 14:35:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMouseScroll.handle(params -> {
|
|
|
|
if (currentMainContext != null) {
|
2022-03-04 12:28:52 +00:00
|
|
|
currentMainContext.onMouseScrollTrigger.trigger(params);
|
2022-02-21 14:35:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMouseUp.handle(params -> {
|
2022-03-05 01:41:30 +00:00
|
|
|
if (currentMainContext != null) {
|
2022-03-04 12:28:52 +00:00
|
|
|
currentMainContext.onMouseUpTrigger.trigger(params);
|
2022-03-05 01:41:30 +00:00
|
|
|
}
|
2022-02-21 14:35:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onPaste.handle(text -> {
|
|
|
|
if (currentMainContext != null) {
|
2022-03-04 12:28:52 +00:00
|
|
|
currentMainContext.onPasteTrigger.trigger(text);
|
2022-02-21 14:35:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
KernelEvents.instance.onMonitorTouch.handle(params -> {
|
|
|
|
// TODO
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createNewContext():WindowContext {
|
|
|
|
var newContext = new WindowContext(new VirtualTermWriter());
|
|
|
|
|
|
|
|
allContexts.push(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;
|
2022-03-03 23:59:32 +00:00
|
|
|
currentMainContext = context;
|
2022-02-21 14:35:37 +00:00
|
|
|
} 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
|
|
|
}
|