use Pos instead of Vec2<Int>

This commit is contained in:
2022-03-08 13:33:40 +01:00
parent edc3195192
commit de35f34173
13 changed files with 59 additions and 45 deletions

View File

@@ -1,5 +1,6 @@
package lib.ui;
import util.Pos;
import util.Rect;
import util.Vec.Vec2;
import kernel.ui.Pixel;
@@ -9,7 +10,7 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
this = [[]];
}
public inline function set(i:Vec2<Int>, pixel:Pixel) {
public inline function set(i:Pos, pixel:Pixel) {
if (this[i.y] == null) {
this[i.y] = [];
}
@@ -17,15 +18,15 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
this[i.y][i.x] = pixel;
}
public inline function get(i:Vec2<Int>):Pixel {
public inline function get(i:Pos):Pixel {
return this[i.y][i.x];
}
public function keyValueIterator():KeyValueIterator<Vec2<Int>, Pixel> {
public function keyValueIterator():KeyValueIterator<Pos, Pixel> {
return new CanvasKeyValueIterator(this);
}
public function combine(other:Canvas, offset:Vec2<Int>) {
public function combine(other:Canvas, offset:Pos) {
for (key => value in other) {
if (value == null) {
continue;
@@ -67,7 +68,7 @@ abstract Canvas(Array<Array<Pixel>>) to Array<Array<Pixel>> {
class CanvasKeyValueIterator {
private final canvas:Array<Array<Pixel>>;
private var index:Vec2<Int> = {x: 0, y: 0};
private var index:Pos = {x: 0, y: 0};
@:allow(lib.ui.Canvas)
private function new(canvas:Array<Array<Pixel>>) {
@@ -78,8 +79,8 @@ class CanvasKeyValueIterator {
return index.y < canvas.length && index.x <= canvas[index.y].length;
}
public function next():{key:Vec2<Int>, value:Pixel} {
var oldIndex:Vec2<Int> = this.index;
public function next():{key:Pos, value:Pixel} {
var oldIndex:Pos = this.index;
if (index.x >= canvas[index.y].length) {
// Goto next line