Replace graphics file with canvas API
This commit is contained in:
parent
38dadb6d05
commit
d034c526e4
|
@ -0,0 +1,23 @@
|
|||
const coral = @import("coral");
|
||||
|
||||
pub const Item = struct {
|
||||
transform: Transform,
|
||||
|
||||
options: union (enum) {
|
||||
sprite: struct {
|
||||
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
pub const Transform = extern struct {
|
||||
x: coral.math.Vector2,
|
||||
y: coral.math.Vector2,
|
||||
origin: coral.math.Vector2,
|
||||
|
||||
pub const identity = Transform{
|
||||
.x = .{1, 0},
|
||||
.y = .{0, 1},
|
||||
.origin = .{0, 0},
|
||||
};
|
||||
};
|
|
@ -1,68 +0,0 @@
|
|||
const coral = @import("coral");
|
||||
|
||||
const ext = @import("./ext.zig");
|
||||
|
||||
pub const Canvas = struct {
|
||||
allocator: coral.io.Allocator,
|
||||
items: coral.slots.Dense(coral.slots.addressable_key, Item),
|
||||
|
||||
const Item = union (enum) {
|
||||
sprite: struct {
|
||||
transform: Transform2D,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn create_sprite(self: *Canvas, transform: Transform2D) coral.io.AllocationError!Sprite {
|
||||
const slot = try self.items.insert(self.allocator, .{.sprite = .{
|
||||
.transform = transform,
|
||||
}});
|
||||
|
||||
errdefer coral.debug.assert(self.items.remove(slot));
|
||||
|
||||
return Sprite{
|
||||
.slot = slot,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Canvas) void {
|
||||
self.items.free(self.allocator);
|
||||
}
|
||||
|
||||
pub fn destroy_sprite(self: *Canvas, sprite: Sprite) void {
|
||||
self.items.remove(sprite) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn init(allocator: coral.io.Allocator) Canvas {
|
||||
return .{
|
||||
.allocator = allocator,
|
||||
.items = .{},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const Label = struct {
|
||||
index: u32,
|
||||
version: u32,
|
||||
};
|
||||
|
||||
pub const Sprite = struct {
|
||||
slot: coral.slots.Slot(coral.slots.addressable_key),
|
||||
};
|
||||
|
||||
pub const Transform2D = extern struct {
|
||||
x: coral.math.Vector2,
|
||||
y: coral.math.Vector2,
|
||||
origin: coral.math.Vector2,
|
||||
|
||||
pub fn from_trs(translation_x: f32, translation_y: f32, rotation: f32, scale_x: f32, scale_y: f32) Transform2D {
|
||||
return identity.scaled(scale_x, scale_y).multiply(
|
||||
identity.rotated(rotation).multiply(
|
||||
identity.translated(translation_x, translation_y)));
|
||||
}
|
||||
|
||||
pub const identity = Transform2D{
|
||||
.x = coral.math.Vector2{1, 0},
|
||||
.y = coral.math.Vector2{0, 1},
|
||||
.origin = coral.math.Vector2{0, 0},
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue