package kernel.ui; import util.Color; import util.Signal; import kernel.ui.WindowManager.ButtonType; import util.Vec.Vec2; import lib.TermWriteable; class WindowContext implements TermWriteable { private final writer:VirtualTermWriter; private final _clickSignal:Signal<{button: ButtonType, pos: Vec2}> = new Signal(); private final _keySignal:Signal<{keyCode: Int, isHeld: Bool}> = new Signal(); private final _keyUpSignal:Signal = new Signal(); private final _mouseDragSignal:Signal<{button: ButtonType, pos: Vec2}> = new Signal(); private final _mouseScrollSignal:Signal<{dir: Int,pos: Vec2}> = new Signal(); private final _mouseUpSignal:Signal<{button: ButtonType,pos: Vec2}> = new Signal(); private final _pasteSignal:Signal = new Signal(); public var clickSignal(get,null):SignalReadonly<{button: ButtonType, pos: Vec2}>; public var keySignal(get,null):SignalReadonly<{keyCode: Int, isHeld: Bool}>; public var keyUpSignal(get,null):SignalReadonly; public var mouseDragSignal(get,null):SignalReadonly<{button: ButtonType, pos: Vec2}>; public var mouseScrollSignal(get,null):SignalReadonly<{dir: Int,pos: Vec2}>; public var mouseUpSignal(get,null):SignalReadonly<{button: ButtonType,pos: Vec2}>; public var pasteSignal(get,null):SignalReadonly ; public function new(writer: VirtualTermWriter) { this.writer = writer; } public var onResize(get, null):SignalReadonly>; function get_onResize():SignalReadonly> { return writer.onResize; } @: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 get_clickSignal(){ return _clickSignal; } public function get_keySignal(){ return _keySignal; } public function get_keyUpSignal(){ return _keyUpSignal; } public function get_mouseDragSignal(){ return _mouseDragSignal; } public function get_mouseScrollSignal(){ return _mouseScrollSignal; } public function get_mouseUpSignal(){ return _mouseUpSignal; } public function get_pasteSignal(){ return _pasteSignal; } @:allow(kernel.ui.WindowManager) // Package private private function click(button:ButtonType ,pos: Vec2) { _clickSignal.emit({button: button,pos: pos}); } @:allow(kernel.ui.WindowManager) // Package private private function key(keyCode: Int, isHeld: Bool) { _keySignal.emit({keyCode: keyCode,isHeld: isHeld}); } @:allow(kernel.ui.WindowManager) // Package private private function keyUp(keyCode: Int) { _keyUpSignal.emit(keyCode); } @:allow(kernel.ui.WindowManager) // Package private private function mouseDrag(button: ButtonType, pos: Vec2) { _mouseDragSignal.emit({button: button,pos: pos}); } @:allow(kernel.ui.WindowManager) // Package private private function mouseScroll(dir: Int,pos: Vec2) { _mouseScrollSignal.emit({dir: dir,pos: pos}); } @:allow(kernel.ui.WindowManager) // Package private private function mouseUp(button: ButtonType,pos: Vec2) { _mouseUpSignal.emit({button: button,pos: pos}); } @:allow(kernel.ui.WindowManager) // Package private private function paste(text: String) { _pasteSignal.emit(text); } 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(); } }