2021-12-20 00:55:30 +00:00
|
|
|
package kernel.ui;
|
|
|
|
|
2022-02-21 00:50:19 +00:00
|
|
|
using tink.CoreApi;
|
|
|
|
|
2021-12-20 00:55:30 +00:00
|
|
|
import util.Color;
|
2022-02-21 14:17:38 +00:00
|
|
|
import kernel.ButtonType;
|
2021-12-20 00:55:30 +00:00
|
|
|
import util.Vec.Vec2;
|
|
|
|
import lib.TermWriteable;
|
|
|
|
|
|
|
|
class WindowContext implements TermWriteable {
|
|
|
|
private final writer:VirtualTermWriter;
|
|
|
|
|
2022-02-21 00:50:19 +00:00
|
|
|
public var clickSignal(default,null):Signal<{button: ButtonType, pos: Vec2<Int>}>;
|
|
|
|
public var keySignal(default,null):Signal<{keyCode: Int, isHeld: Bool}>;
|
|
|
|
public var keyUpSignal(default,null):Signal<Int>;
|
|
|
|
public var mouseDragSignal(default,null):Signal<{button: ButtonType, pos: Vec2<Int>}>;
|
|
|
|
public var mouseScrollSignal(default,null):Signal<{dir: Int,pos: Vec2<Int>}>;
|
|
|
|
public var mouseUpSignal(default,null):Signal<{button: ButtonType,pos: Vec2<Int>}>;
|
|
|
|
public var pasteSignal(default,null):Signal<String> ;
|
|
|
|
|
|
|
|
@:allow(kernel.ui.WindowManager) private final clickTrigger:SignalTrigger<{button: ButtonType, pos: Vec2<Int>}>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final keyTrigger:SignalTrigger<{keyCode: Int, isHeld: Bool}>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final keyUpTrigger:SignalTrigger<Int>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final mouseDragTrigger:SignalTrigger<{button: ButtonType, pos: Vec2<Int>}>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final mouseScrollTrigger:SignalTrigger<{dir: Int,pos: Vec2<Int>}>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final mouseUpTrigger:SignalTrigger<{button: ButtonType,pos: Vec2<Int>}>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final pasteTrigger:SignalTrigger<String>;
|
|
|
|
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function new(writer: VirtualTermWriter) {
|
|
|
|
this.writer = writer;
|
2022-02-21 00:50:19 +00:00
|
|
|
this.onResize = writer.onResize;
|
2021-12-20 00:55:30 +00:00
|
|
|
|
2022-02-21 00:50:19 +00:00
|
|
|
this.clickTrigger = Signal.trigger();
|
|
|
|
this.keyTrigger = Signal.trigger();
|
|
|
|
this.keyUpTrigger = Signal.trigger();
|
|
|
|
this.mouseDragTrigger = Signal.trigger();
|
|
|
|
this.mouseScrollTrigger = Signal.trigger();
|
|
|
|
this.mouseUpTrigger = Signal.trigger();
|
|
|
|
this.pasteTrigger = Signal.trigger();
|
2021-12-20 00:55:30 +00:00
|
|
|
|
2022-02-21 00:50:19 +00:00
|
|
|
this.clickSignal = clickTrigger.asSignal();
|
|
|
|
this.keySignal = keyTrigger.asSignal();
|
|
|
|
this.keyUpSignal = keyUpTrigger.asSignal();
|
|
|
|
this.mouseDragSignal = mouseDragTrigger.asSignal();
|
|
|
|
this.mouseScrollSignal = mouseScrollTrigger.asSignal();
|
|
|
|
this.mouseUpSignal = mouseUpTrigger.asSignal();
|
|
|
|
this.pasteSignal = pasteTrigger.asSignal();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public var onResize(default, null):Signal<Vec2<Int>>;
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
@:allow(kernel.ui)
|
|
|
|
private function setTarget(target: TermWriteable) {
|
|
|
|
writer.setTarget(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
@:allow(kernel.ui)
|
|
|
|
private function enable() {
|
|
|
|
writer.enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
@:allow(kernel.ui)
|
|
|
|
private function disable() {
|
|
|
|
writer.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
@:allow(kernel.ui)
|
|
|
|
private function isEnabled() {
|
|
|
|
return writer.isEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function write(text:String) {
|
|
|
|
writer.write(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scroll(y:Int) {
|
|
|
|
writer.scroll(y);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCursorPos():Vec2<Int> {
|
|
|
|
return writer.getCursorPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCursorPos(x:Int, y:Int) {
|
|
|
|
writer.setCursorPos(x,y);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCursorBlink():Bool {
|
|
|
|
return writer.getCursorBlink();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCursorBlink(blink:Bool) {
|
|
|
|
writer.setCursorBlink(blink);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSize():Vec2<Int> {
|
|
|
|
return writer.getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clear() {
|
|
|
|
writer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clearLine() {
|
|
|
|
writer.clearLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTextColor():Color {
|
|
|
|
return writer.getTextColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTextColor(colour:Color) {
|
|
|
|
writer.setTextColor(colour);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBackgroundColor():Color {
|
|
|
|
return writer.getBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBackgroundColor(color:Color) {
|
|
|
|
writer.setBackgroundColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isColor():Bool {
|
|
|
|
return writer.isColor();
|
|
|
|
}
|
|
|
|
}
|