cc-haxe/src/kernel/ui/WindowContext.hx

136 lines
3.7 KiB
Haxe
Raw Normal View History

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;
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;
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>;
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;
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<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
public function getCursorPos():Vec2<Int> {
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();
}
public function setTextColor(colour:Color) {
2022-02-21 14:35:37 +00:00
writer.setTextColor(colour);
}
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
}