From 85a3bac0959ab4ad96082362b153370df508383a Mon Sep 17 00:00:00 2001 From: Roman Pytkov Date: Sun, 22 Feb 2026 22:09:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=20=D0=B2=20=D0=BA=D0=B0=D0=BD=D0=B2=D0=B0=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Canvas.zig | 16 ++++++++-------- src/WindowContext.zig | 2 +- src/main.zig | 6 ------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Canvas.zig b/src/Canvas.zig index b678b0e..fbf88a4 100644 --- a/src/Canvas.zig +++ b/src/Canvas.zig @@ -4,28 +4,27 @@ const dvui = @import("dvui"); const Document = @import("models/Document.zig"); const RenderEngine = @import("render/RenderEngine.zig").RenderEngine; const ImageRect = @import("models/basic_models.zig").ImageRect; -const Size = dvui.Size; const Color = dvui.Color; const Canvas = @This(); allocator: std.mem.Allocator, +document: *Document, +render_engine: RenderEngine, texture: ?dvui.Texture = null, -size: Size = .{ .w = 800, .h = 600 }, -pos: dvui.Point = dvui.Point{ .x = 0, .y = 0 }, +pos: dvui.Point = dvui.Point{ .x = 400, .y = 400 }, scroll: dvui.ScrollInfo = .{ .vertical = .auto, .horizontal = .auto, }, native_scaling: bool = true, -document: ?*Document = null, -render_engine: RenderEngine, _visible_rect: ?ImageRect = null, _zoom: f32 = 1, -pub fn init(allocator: std.mem.Allocator, engine: RenderEngine) Canvas { +pub fn init(allocator: std.mem.Allocator, document: *Document, engine: RenderEngine) Canvas { return .{ .allocator = allocator, + .document = document, .render_engine = engine, }; } @@ -79,11 +78,12 @@ pub fn addZoom(self: *Canvas, value: f32) void { } pub fn getScaledImageSize(self: Canvas) ImageRect { + const doc = self.document; return .{ .x = @intFromFloat(self.pos.x), .y = @intFromFloat(self.pos.y), - .w = @intFromFloat(self.size.w * self._zoom), - .h = @intFromFloat(self.size.h * self._zoom), + .w = @intFromFloat(doc.size.width * self._zoom), + .h = @intFromFloat(doc.size.height * self._zoom), }; } diff --git a/src/WindowContext.zig b/src/WindowContext.zig index 205286d..56bf7b8 100644 --- a/src/WindowContext.zig +++ b/src/WindowContext.zig @@ -18,7 +18,7 @@ pub const OpenDocument = struct { const default_size = basic_models.Size{ .width = 800, .height = 600 }; self.document = Document.init(allocator, default_size); self.cpu_render = CpuRenderEngine.init(allocator, .Squares); - self.canvas = Canvas.init(allocator, (&self.cpu_render).renderEngine()); + self.canvas = Canvas.init(allocator, &self.document, (&self.cpu_render).renderEngine()); } pub fn deinit(self: *OpenDocument) void { diff --git a/src/main.zig b/src/main.zig index 3689d64..a449eb1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -112,12 +112,6 @@ fn gui_frame(ctx: *WindowContext) bool { dvui.label(@src(), "Tools", .{}, .{}); if (active_doc) |doc| { const canvas = &doc.canvas; - if (dvui.button(@src(), "Fill Random Color", .{}, .{}) or ctx.frame_index == 0) { - canvas.exampleReset() catch |err| { - std.debug.print("Error reset example: {}\n", .{err}); - }; - canvas.pos = .{ .x = 400, .y = 400 }; - } if (dvui.checkbox(@src(), &canvas.native_scaling, "Scaling", .{})) {} if (dvui.button(@src(), if (doc.cpu_render.type == .Gradient) "Gradient" else "Squares", .{}, .{})) { if (doc.cpu_render.type == .Gradient) {