Дополнительные базовые модели
This commit is contained in:
@@ -10,7 +10,7 @@ canvas: Canvas,
|
|||||||
cpu_render: *CpuRenderEngine,
|
cpu_render: *CpuRenderEngine,
|
||||||
frame_index: u64,
|
frame_index: u64,
|
||||||
/// Открытые документы в текущем окне
|
/// Открытые документы в текущем окне
|
||||||
documents: std.array_list.Managed(Document),
|
documents: std.ArrayList(Document),
|
||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator) !WindowContext {
|
pub fn init(allocator: std.mem.Allocator) !WindowContext {
|
||||||
var self: WindowContext = undefined;
|
var self: WindowContext = undefined;
|
||||||
@@ -23,13 +23,14 @@ pub fn init(allocator: std.mem.Allocator) !WindowContext {
|
|||||||
self.canvas = Canvas.init(allocator, self.cpu_render.renderEngine());
|
self.canvas = Canvas.init(allocator, self.cpu_render.renderEngine());
|
||||||
|
|
||||||
self.frame_index = 0;
|
self.frame_index = 0;
|
||||||
self.documents = std.array_list.Managed(Document).init(allocator);
|
self.documents = std.ArrayList(Document).empty;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *WindowContext) void {
|
pub fn deinit(self: *WindowContext) void {
|
||||||
self.documents.deinit();
|
for (self.documents.items) |*doc| doc.deinit();
|
||||||
|
self.documents.deinit(self.allocator);
|
||||||
self.canvas.deinit();
|
self.canvas.deinit();
|
||||||
self.allocator.destroy(self.cpu_render);
|
self.allocator.destroy(self.cpu_render);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,67 @@
|
|||||||
|
const std = @import("std");
|
||||||
const basic_models = @import("basic_models.zig");
|
const basic_models = @import("basic_models.zig");
|
||||||
const Size = basic_models.Size;
|
const Size = basic_models.Size;
|
||||||
|
const ObjectCommon = basic_models.ObjectCommon;
|
||||||
|
const Point2 = basic_models.Point2;
|
||||||
|
|
||||||
const Document = @This();
|
const Document = @This();
|
||||||
|
|
||||||
size: Size,
|
size: Size,
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
layers: std.ArrayList(Layer),
|
||||||
|
|
||||||
|
pub fn init(allocator: std.mem.Allocator, size: Size) Document {
|
||||||
|
return .{
|
||||||
|
.size = size,
|
||||||
|
.allocator = allocator,
|
||||||
|
.layers = std.ArrayList(Layer).empty,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: *Document) void {
|
||||||
|
for (self.layers.items) |*layer| layer.deinit();
|
||||||
|
self.layers.deinit(self.allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const Layer = struct {
|
||||||
|
name: [64:0]u8 = .{0} ** 64,
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
objects: std.ArrayList(Object),
|
||||||
|
|
||||||
|
pub fn init(allocator: std.mem.Allocator) Layer {
|
||||||
|
return .{
|
||||||
|
.allocator = allocator,
|
||||||
|
.objects = std.ArrayList(Object).empty,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: *Layer) void {
|
||||||
|
self.objects.deinit(self.allocator);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Объект на слое: общие свойства + полиморфные данные по тегу (path, rect, ellipse, ...).
|
||||||
|
/// Полиморфизм через tagged union — без наследования и vtable, диспетчеризация через switch (obj.data).
|
||||||
|
pub const Object = struct {
|
||||||
|
common: ObjectCommon,
|
||||||
|
data: Data,
|
||||||
|
|
||||||
|
pub const Data = union(enum) {
|
||||||
|
path: PathData,
|
||||||
|
rect: RectData,
|
||||||
|
ellipse: EllipseData,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Точки контура (заглушка; позже — владение через Layer/Document allocator)
|
||||||
|
pub const PathData = struct {};
|
||||||
|
|
||||||
|
pub const RectData = struct {
|
||||||
|
width: f32,
|
||||||
|
height: f32,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const EllipseData = struct {
|
||||||
|
radius_x: f32,
|
||||||
|
radius_y: f32,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -14,3 +14,25 @@ pub const Size = struct {
|
|||||||
width: f32,
|
width: f32,
|
||||||
height: f32,
|
height: f32,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Точка в 2D (документные единицы)
|
||||||
|
pub const Point2 = struct {
|
||||||
|
x: f32,
|
||||||
|
y: f32,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Трансформ объекта: позиция и масштаб (поворот при необходимости добавить отдельно)
|
||||||
|
pub const Transform2 = struct {
|
||||||
|
x: f32 = 0,
|
||||||
|
y: f32 = 0,
|
||||||
|
scale_x: f32 = 1,
|
||||||
|
scale_y: f32 = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Общие свойства любого объекта на слое (видимость, блокировка, непрозрачность, трансформ)
|
||||||
|
pub const ObjectCommon = struct {
|
||||||
|
transform: Transform2 = .{},
|
||||||
|
visible: bool = true,
|
||||||
|
locked: bool = false,
|
||||||
|
opacity: f32 = 1.0,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user