Первые попытки рисовать
This commit is contained in:
@@ -3,7 +3,9 @@ const builtin = @import("builtin");
|
||||
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 basic_models = @import("models/basic_models.zig");
|
||||
const ImageRect = basic_models.ImageRect;
|
||||
const ImageSize = basic_models.ImageSize;
|
||||
const Point2 = @import("models/basic_models.zig").Point2;
|
||||
const Color = dvui.Color;
|
||||
|
||||
@@ -25,6 +27,8 @@ _zoom: f32 = 1,
|
||||
_redraw_pending: bool = false,
|
||||
_last_redraw_time_ms: i64 = 0,
|
||||
cursor_document_point: ?Point2 = null,
|
||||
/// true — рисовать документ (render), false — пример (gradient/squares).
|
||||
draw_document: bool = true,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, document: *Document, engine: RenderEngine) Canvas {
|
||||
return .{
|
||||
@@ -41,7 +45,7 @@ pub fn deinit(self: *Canvas) void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn redrawExample(self: *Canvas) !void {
|
||||
fn redraw(self: *Canvas) !void {
|
||||
const full = self.getZoomedImageSize();
|
||||
|
||||
const vis: ImageRect = self._visible_rect orelse ImageRect{ .x = 0, .y = 0, .w = 0, .h = 0 };
|
||||
@@ -54,7 +58,11 @@ pub fn redrawExample(self: *Canvas) !void {
|
||||
return;
|
||||
}
|
||||
|
||||
const new_texture = self.render_engine.example(.{ .w = full.w, .h = full.h }, vis) catch null;
|
||||
const canvas_size: ImageSize = .{ .w = full.w, .h = full.h };
|
||||
const new_texture = if (self.draw_document)
|
||||
self.render_engine.render(self.document, canvas_size, vis) catch null
|
||||
else
|
||||
self.render_engine.example(canvas_size, vis) catch null;
|
||||
|
||||
if (new_texture) |tex| {
|
||||
if (self.texture) |old_tex| {
|
||||
@@ -68,7 +76,7 @@ pub fn redrawExample(self: *Canvas) !void {
|
||||
|
||||
pub fn exampleReset(self: *Canvas) !void {
|
||||
self.render_engine.exampleReset();
|
||||
try self.redrawExample();
|
||||
try self.redraw();
|
||||
}
|
||||
|
||||
pub fn setZoom(self: *Canvas, value: f32) void {
|
||||
@@ -88,14 +96,14 @@ pub fn processPendingRedraw(self: *Canvas) !void {
|
||||
if (!self._redraw_pending) return;
|
||||
if (self.redraw_throttle_ms == 0) {
|
||||
self._redraw_pending = false;
|
||||
try self.redrawExample();
|
||||
try self.redraw();
|
||||
return;
|
||||
}
|
||||
const now_ms = std.time.milliTimestamp();
|
||||
const elapsed: i64 = if (self._last_redraw_time_ms == 0) self.redraw_throttle_ms else now_ms - self._last_redraw_time_ms;
|
||||
if (elapsed < @as(i64, @intCast(self.redraw_throttle_ms))) return;
|
||||
self._redraw_pending = false;
|
||||
try self.redrawExample();
|
||||
try self.redraw();
|
||||
}
|
||||
|
||||
pub fn getZoomedImageSize(self: Canvas) ImageRect {
|
||||
|
||||
Reference in New Issue
Block a user