package kernel.ui; using tink.CoreApi; import util.Color; import kernel.ButtonType; import util.Vec.Vec2; import lib.TermWriteable; /** The main object you interact with when writing anything to the screen. **/ class WindowContext implements TermWriteable { private final writer:VirtualTermWriter; public var onClick(default, null):Signal<{button:ButtonType, pos:Vec2}>; public var onKey(default, null):Signal<{keyCode:Int, isHeld:Bool}>; public var onKeyUp(default, null):Signal; public var onMouseDrag(default, null):Signal<{button:ButtonType, pos:Vec2}>; public var onMouseScroll(default, null):Signal<{dir:Int, pos:Vec2}>; public var onMouseUp(default, null):Signal<{button:ButtonType, pos:Vec2}>; public var onPaste(default, null):Signal; @:allow(kernel.ui.WindowManager) private final onClickTrigger:SignalTrigger<{button:ButtonType, pos:Vec2}>; @:allow(kernel.ui.WindowManager) private final onKeyTrigger:SignalTrigger<{keyCode:Int, isHeld:Bool}>; @:allow(kernel.ui.WindowManager) private final onKeyUpTrigger:SignalTrigger; @:allow(kernel.ui.WindowManager) private final onMouseDragTrigger:SignalTrigger<{button:ButtonType, pos:Vec2}>; @:allow(kernel.ui.WindowManager) private final onMouseScrollTrigger:SignalTrigger<{dir:Int, pos:Vec2}>; @:allow(kernel.ui.WindowManager) private final onMouseUpTrigger:SignalTrigger<{button:ButtonType, pos:Vec2}>; @:allow(kernel.ui.WindowManager) private final onPasteTrigger:SignalTrigger; @:allow(kernel.ui.WindowManager) private function new(writer:VirtualTermWriter) { this.writer = writer; this.onResize = writer.onResize; this.onClickTrigger = Signal.trigger(); this.onKeyTrigger = Signal.trigger(); this.onKeyUpTrigger = Signal.trigger(); this.onMouseDragTrigger = Signal.trigger(); this.onMouseScrollTrigger = Signal.trigger(); this.onMouseUpTrigger = Signal.trigger(); this.onPasteTrigger = Signal.trigger(); this.onClick = onClickTrigger.asSignal(); this.onKey = onKeyTrigger.asSignal(); this.onKeyUp = onKeyUpTrigger.asSignal(); this.onMouseDrag = onMouseDragTrigger.asSignal(); this.onMouseScroll = onMouseScrollTrigger.asSignal(); this.onMouseUp = onMouseUpTrigger.asSignal(); this.onPaste = onPasteTrigger.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(); } public function reset() { writer.reset(); } }