a LOT of minor stuff

This commit is contained in:
2022-03-05 02:41:30 +01:00
parent ce45bf2726
commit df77704d1c
12 changed files with 90 additions and 56 deletions

View File

@@ -1,11 +1,17 @@
package kernel.ui;
using tink.CoreApi;
import util.Vec.Vec2;
import util.Color;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
using tink.CoreApi;
/**
A virtual terminal. With this a GUI program can still write to its "screen"
even if its not displayed right now. When the GUI gets displayed again
this buffer will be written to the screen.
**/
class TermBuffer implements TermWriteable {
/**
format [y][x]. First index is the line. Second index the char in the line.
@@ -15,14 +21,14 @@ class TermBuffer implements TermWriteable {
private var cursorPos:Vec2<Int> = {x: 0, y: 0};
private var currentTextColor:Color = White;
private var currentBgColor:Color = Black;
private var cursorBlink: Bool = false;
private var size:Vec2<Int> = {x: 51, y: 19}; // Default size set to default size of the main terminal
public var onResize(default, null):Signal<Vec2<Int>>;
public final onResize:Signal<Vec2<Int>>;
private final onResizeTrigger:SignalTrigger<Vec2<Int>>;
private final onResizeTrigger:SignalTrigger<Vec2<Int>> = Signal.trigger();
public function new() {
this.onResizeTrigger = Signal.trigger();
private function new() {
this.onResize = onResizeTrigger.asSignal();
initScreenBuffer(size);
}
@@ -126,11 +132,11 @@ class TermBuffer implements TermWriteable {
}
public function getCursorBlink():Bool {
throw new haxe.exceptions.NotImplementedException();
return this.cursorBlink;
}
public function setCursorBlink(blink:Bool) {
// TODO
this.cursorBlink = blink;
}
public function getSize():Vec2<Int> {
@@ -164,7 +170,7 @@ class TermBuffer implements TermWriteable {
}
public function isColor():Bool {
throw new haxe.exceptions.NotImplementedException();
return true; // Lets return true for now.
}
public function reset() {

View File

@@ -0,0 +1,44 @@
package kernel.ui;
using tink.CoreApi;
import util.Color;
import util.Vec.Vec2;
/**
Interface describing a terminal. E.g. the main computer screen or a external screen.
**/
interface TermWriteable {
public var onResize(default, null):Signal<Vec2<Int>>;
public function write(text:String):Void;
public function scroll(y:Int):Void;
/**
Even though CC is 1 based we use a 0 based index.
**/
public function getCursorPos():Vec2<Int>;
/**
Even though CC is 1 based we use a 0 based index.
**/
public function setCursorPos(x:Int, y:Int):Void;
public function getCursorBlink():Bool;
public function setCursorBlink(blink:Bool):Void;
public function getSize():Vec2<Int>;
public function clear():Void;
public function clearLine():Void;
public function getTextColor():Color;
public function setTextColor(colour:Color):Void;
public function getBackgroundColor():Color;
public function setBackgroundColor(color:Color):Void;
public function isColor():Bool;
// public function setPaletteColor(...);
// public function getPaletteColor(colour);
/**
Clears the screen, resetes the courser to (0,0) and resetes the color to Black and White.
**/
public function reset():Void;
}

View File

@@ -4,8 +4,12 @@ using tink.CoreApi;
import util.Vec.Vec2;
import util.Color;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
/**
A term writer that can switch beetween its internal buffer and another termwriter.
The other target is most of the time a real screen
**/
class VirtualTermWriter implements TermWriteable extends TermBuffer {
private static final defaultSize:Vec2<Int> = {x: 50, y: 50};
@@ -13,7 +17,8 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
private var enabled:Bool = false;
private var onResizeLink:CallbackLink;
public function new(?target:TermWriteable) {
@:allow(kernel.ui)
private function new(?target:TermWriteable) {
setTarget(target);
if (enabled) {
@@ -52,6 +57,8 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
setSuperSize(newSize);
});
newTarget.reset();
target = newTarget;
}
}
@@ -95,11 +102,18 @@ class VirtualTermWriter implements TermWriteable extends TermBuffer {
}
public override function getCursorBlink():Bool {
throw new haxe.exceptions.NotImplementedException();
if (isEnabled()){
return target.getCursorBlink();
}else{
return super.getCursorBlink();
}
}
public override function setCursorBlink(blink:Bool) {
// TODO
if (isEnabled()){
target.setCursorBlink(blink);
}
super.setCursorBlink(blink);
}
public override function getSize():Vec2<Int> {

View File

@@ -5,7 +5,7 @@ using tink.CoreApi;
import util.Color;
import kernel.ButtonType;
import util.Vec.Vec2;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
/**
The main object you interact with when writing anything to the screen.

View File

@@ -1,8 +1,12 @@
package kernel.ui;
import lib.TermWriteable;
import kernel.ui.TermWriteable;
import kernel.peripherals.Peripherals.Peripheral;
/**
Responsable for creating window context, forwarding UI events to the context
and switching context to real screens.
**/
class WindowManager {
/**
Depends on: KernelEvents, Peripheral
@@ -45,9 +49,9 @@ class WindowManager {
});
KernelEvents.instance.onMouseUp.handle(params -> {
// if (currentMainContext != null) {
if (currentMainContext != null) {
currentMainContext.onMouseUpTrigger.trigger(params);
// }
}
});
KernelEvents.instance.onPaste.handle(text -> {