177 lines
4.7 KiB
Haxe
177 lines
4.7 KiB
Haxe
|
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<Int>}> = new Signal();
|
||
|
private final _keySignal:Signal<{keyCode: Int, isHeld: Bool}> = new Signal();
|
||
|
private final _keyUpSignal:Signal<Int> = new Signal();
|
||
|
private final _mouseDragSignal:Signal<{button: ButtonType, pos: Vec2<Int>}> = new Signal();
|
||
|
private final _mouseScrollSignal:Signal<{dir: Int,pos: Vec2<Int>}> = new Signal();
|
||
|
private final _mouseUpSignal:Signal<{button: ButtonType,pos: Vec2<Int>}> = new Signal();
|
||
|
private final _pasteSignal:Signal<String> = new Signal();
|
||
|
|
||
|
public var clickSignal(get,null):SignalReadonly<{button: ButtonType, pos: Vec2<Int>}>;
|
||
|
public var keySignal(get,null):SignalReadonly<{keyCode: Int, isHeld: Bool}>;
|
||
|
public var keyUpSignal(get,null):SignalReadonly<Int>;
|
||
|
public var mouseDragSignal(get,null):SignalReadonly<{button: ButtonType, pos: Vec2<Int>}>;
|
||
|
public var mouseScrollSignal(get,null):SignalReadonly<{dir: Int,pos: Vec2<Int>}>;
|
||
|
public var mouseUpSignal(get,null):SignalReadonly<{button: ButtonType,pos: Vec2<Int>}>;
|
||
|
public var pasteSignal(get,null):SignalReadonly<String> ;
|
||
|
|
||
|
public function new(writer: VirtualTermWriter) {
|
||
|
this.writer = writer;
|
||
|
}
|
||
|
|
||
|
public var onResize(get, null):SignalReadonly<Vec2<Int>>;
|
||
|
|
||
|
function get_onResize():SignalReadonly<Vec2<Int>> {
|
||
|
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<Int>) {
|
||
|
_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<Int>) {
|
||
|
_mouseDragSignal.emit({button: button,pos: pos});
|
||
|
}
|
||
|
|
||
|
@:allow(kernel.ui.WindowManager) // Package private
|
||
|
private function mouseScroll(dir: Int,pos: Vec2<Int>) {
|
||
|
_mouseScrollSignal.emit({dir: dir,pos: pos});
|
||
|
}
|
||
|
|
||
|
@:allow(kernel.ui.WindowManager) // Package private
|
||
|
private function mouseUp(button: ButtonType,pos: Vec2<Int>) {
|
||
|
_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<Int> {
|
||
|
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(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();
|
||
|
}
|
||
|
}
|