2021-12-20 00:55:30 +00:00
|
|
|
package kernel.ui;
|
|
|
|
|
2022-03-08 12:33:40 +00:00
|
|
|
import util.Pos;
|
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;
|
2022-03-05 01:41:30 +00:00
|
|
|
import kernel.ui.TermWriteable;
|
2021-12-20 00:55:30 +00:00
|
|
|
|
2022-03-03 23:59:32 +00:00
|
|
|
/**
|
|
|
|
The main object you interact with when writing anything to the screen.
|
|
|
|
**/
|
2021-12-20 00:55:30 +00:00
|
|
|
class WindowContext implements TermWriteable {
|
2022-02-21 14:35:37 +00:00
|
|
|
private final writer:VirtualTermWriter;
|
|
|
|
|
2022-03-08 12:33:40 +00:00
|
|
|
public var onClick(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
2022-03-04 12:28:52 +00:00
|
|
|
public var onKey(default, null):Signal<{keyCode:Int, isHeld:Bool}>;
|
|
|
|
public var onKeyUp(default, null):Signal<Int>;
|
2022-03-08 12:33:40 +00:00
|
|
|
public var onMouseDrag(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
|
|
|
public var onMouseScroll(default, null):Signal<{dir:Int, pos:Pos}>;
|
|
|
|
public var onMouseUp(default, null):Signal<{button:ButtonType, pos:Pos}>;
|
2022-03-04 12:28:52 +00:00
|
|
|
public var onPaste(default, null):Signal<String>;
|
2022-02-21 14:35:37 +00:00
|
|
|
|
2022-03-08 12:33:40 +00:00
|
|
|
@:allow(kernel.ui.WindowManager) private final onClickTrigger:SignalTrigger<{button:ButtonType, pos:Pos}>;
|
2022-03-04 12:28:52 +00:00
|
|
|
@:allow(kernel.ui.WindowManager) private final onKeyTrigger:SignalTrigger<{keyCode:Int, isHeld:Bool}>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final onKeyUpTrigger:SignalTrigger<Int>;
|
2022-03-08 12:33:40 +00:00
|
|
|
@:allow(kernel.ui.WindowManager) private final onMouseDragTrigger:SignalTrigger<{button:ButtonType, pos:Pos}>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final onMouseScrollTrigger:SignalTrigger<{dir:Int, pos:Pos}>;
|
|
|
|
@:allow(kernel.ui.WindowManager) private final onMouseUpTrigger:SignalTrigger<{button:ButtonType, pos:Pos}>;
|
2022-03-04 12:28:52 +00:00
|
|
|
@:allow(kernel.ui.WindowManager) private final onPasteTrigger:SignalTrigger<String>;
|
2022-02-21 14:35:37 +00:00
|
|
|
|
2022-03-03 23:59:32 +00:00
|
|
|
@:allow(kernel.ui.WindowManager)
|
|
|
|
private function new(writer:VirtualTermWriter) {
|
2022-02-21 14:35:37 +00:00
|
|
|
this.writer = writer;
|
|
|
|
this.onResize = writer.onResize;
|
|
|
|
|
2022-03-04 12:28:52 +00:00
|
|
|
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();
|
2022-02-21 14:35:37 +00:00
|
|
|
|
2022-03-04 12:28:52 +00:00
|
|
|
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();
|
2022-02-21 14:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public var onResize(default, null):Signal<Vec2<Int>>;
|
|
|
|
|
|
|
|
@: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();
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function write(text:String) {
|
2022-02-21 14:35:37 +00:00
|
|
|
writer.write(text);
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function scroll(y:Int) {
|
2022-02-21 14:35:37 +00:00
|
|
|
writer.scroll(y);
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
2022-03-08 12:33:40 +00:00
|
|
|
public function getCursorPos():Pos {
|
2021-12-20 00:55:30 +00:00
|
|
|
return writer.getCursorPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCursorPos(x:Int, y:Int) {
|
2022-02-21 14:35:37 +00:00
|
|
|
writer.setCursorPos(x, y);
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function getCursorBlink():Bool {
|
|
|
|
return writer.getCursorBlink();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCursorBlink(blink:Bool) {
|
2022-02-21 14:35:37 +00:00
|
|
|
writer.setCursorBlink(blink);
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function getSize():Vec2<Int> {
|
|
|
|
return writer.getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clear() {
|
2022-02-21 14:35:37 +00:00
|
|
|
writer.clear();
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function clearLine() {
|
2022-02-21 14:35:37 +00:00
|
|
|
writer.clearLine();
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function getTextColor():Color {
|
|
|
|
return writer.getTextColor();
|
|
|
|
}
|
|
|
|
|
2022-03-12 20:48:09 +00:00
|
|
|
public function setTextColor(color:Color) {
|
|
|
|
writer.setTextColor(color);
|
2022-02-21 14:35:37 +00:00
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function getBackgroundColor():Color {
|
|
|
|
return writer.getBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBackgroundColor(color:Color) {
|
2022-02-21 14:35:37 +00:00
|
|
|
writer.setBackgroundColor(color);
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
|
|
|
|
public function isColor():Bool {
|
|
|
|
return writer.isColor();
|
|
|
|
}
|
2022-03-03 14:44:32 +00:00
|
|
|
|
|
|
|
public function reset() {
|
|
|
|
writer.reset();
|
|
|
|
}
|
2021-12-20 00:55:30 +00:00
|
|
|
}
|