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

137 lines
3.6 KiB
Haxe

package kernel.ui;
import util.Pos;
using tink.CoreApi;
import util.Color;
import kernel.ButtonType;
import util.Vec.Vec2;
import kernel.ui.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:Pos}>;
public var onKey(default, null):Signal<{keyCode:Int, isHeld:Bool}>;
public var onKeyUp(default, null):Signal<Int>;
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}>;
public var onPaste(default, null):Signal<String>;
@:allow(kernel.ui.WindowManager) private final onClickTrigger:SignalTrigger<{button:ButtonType, pos:Pos}>;
@:allow(kernel.ui.WindowManager) private final onKeyTrigger:SignalTrigger<{keyCode:Int, isHeld:Bool}>;
@:allow(kernel.ui.WindowManager) private final onKeyUpTrigger:SignalTrigger<Int>;
@: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}>;
@:allow(kernel.ui.WindowManager) private final onPasteTrigger:SignalTrigger<String>;
@: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<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();
}
public function write(text:String) {
writer.write(text);
}
public function scroll(y:Int) {
writer.scroll(y);
}
public function getCursorPos():Pos {
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<Int> {
return writer.getSize();
}
public function clear() {
writer.clear();
}
public function clearLine() {
writer.clearLine();
}
public function getTextColor():Color {
return writer.getTextColor();
}
public function setTextColor(color:Color) {
writer.setTextColor(color);
}
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();
}
}