package kernel.ui; using tink.CoreApi; import util.Color; import kernel.ui.WindowManager.ButtonType; import util.Vec.Vec2; import lib.TermWriteable; class WindowContext implements TermWriteable { private final writer:VirtualTermWriter; public var clickSignal(default,null):Signal<{button: ButtonType, pos: Vec2}>; public var keySignal(default,null):Signal<{keyCode: Int, isHeld: Bool}>; public var keyUpSignal(default,null):Signal; public var mouseDragSignal(default,null):Signal<{button: ButtonType, pos: Vec2}>; public var mouseScrollSignal(default,null):Signal<{dir: Int,pos: Vec2}>; public var mouseUpSignal(default,null):Signal<{button: ButtonType,pos: Vec2}>; public var pasteSignal(default,null):Signal ; @:allow(kernel.ui.WindowManager) private final clickTrigger:SignalTrigger<{button: ButtonType, pos: Vec2}>; @:allow(kernel.ui.WindowManager) private final keyTrigger:SignalTrigger<{keyCode: Int, isHeld: Bool}>; @:allow(kernel.ui.WindowManager) private final keyUpTrigger:SignalTrigger; @:allow(kernel.ui.WindowManager) private final mouseDragTrigger:SignalTrigger<{button: ButtonType, pos: Vec2}>; @:allow(kernel.ui.WindowManager) private final mouseScrollTrigger:SignalTrigger<{dir: Int,pos: Vec2}>; @:allow(kernel.ui.WindowManager) private final mouseUpTrigger:SignalTrigger<{button: ButtonType,pos: Vec2}>; @:allow(kernel.ui.WindowManager) private final pasteTrigger:SignalTrigger; public function new(writer: VirtualTermWriter) { this.writer = writer; this.onResize = writer.onResize; 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(); 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>; @: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 { 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 { 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(); } }