feat: Добавил толщину линий, унифицировал геометрию
Переименовал основные геометрические модели (Point, Size, Rect, Scale, Radii), явно разделив их на типы с плавающей точкой (_f) и целочисленные (_i). Обновил использование этих типов во всем проекте для улучшения типобезопасности и ясности. Ввел новое свойство thickness для объектов и реализовал его применение при отрисовке линий и ломаных. Добавил Point2_i для целочисленных координат буфера в конвейере отрисовки.
This commit is contained in:
@@ -4,9 +4,9 @@ const dvui = @import("dvui");
|
||||
const Document = @import("models/Document.zig");
|
||||
const RenderEngine = @import("render/RenderEngine.zig").RenderEngine;
|
||||
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 Rect_i = basic_models.Rect_i;
|
||||
const Size_i = basic_models.Size_i;
|
||||
const Point2_f = @import("models/basic_models.zig").Point2_f;
|
||||
const Color = dvui.Color;
|
||||
|
||||
const Canvas = @This();
|
||||
@@ -22,11 +22,11 @@ scroll: dvui.ScrollInfo = .{
|
||||
},
|
||||
native_scaling: bool = true,
|
||||
redraw_throttle_ms: u32 = 50,
|
||||
_visible_rect: ?ImageRect = null,
|
||||
_visible_rect: ?Rect_i = null,
|
||||
_zoom: f32 = 1,
|
||||
_redraw_pending: bool = false,
|
||||
_last_redraw_time_ms: i64 = 0,
|
||||
cursor_document_point: ?Point2 = null,
|
||||
cursor_document_point: ?Point2_f = null,
|
||||
/// true — рисовать документ (render), false — пример (gradient/squares).
|
||||
draw_document: bool = true,
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn deinit(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 };
|
||||
const vis: Rect_i = self._visible_rect orelse Rect_i{ .x = 0, .y = 0, .w = 0, .h = 0 };
|
||||
|
||||
if (vis.w == 0 or vis.h == 0) {
|
||||
if (self.texture) |tex| {
|
||||
@@ -58,7 +58,7 @@ fn redraw(self: *Canvas) !void {
|
||||
return;
|
||||
}
|
||||
|
||||
const canvas_size: ImageSize = .{ .w = full.w, .h = full.h };
|
||||
const canvas_size: Size_i = .{ .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
|
||||
@@ -106,17 +106,17 @@ pub fn processPendingRedraw(self: *Canvas) !void {
|
||||
try self.redraw();
|
||||
}
|
||||
|
||||
pub fn getZoomedImageSize(self: Canvas) ImageRect {
|
||||
pub fn getZoomedImageSize(self: Canvas) Rect_i {
|
||||
const doc = self.document;
|
||||
return .{
|
||||
.x = @intFromFloat(self.pos.x),
|
||||
.y = @intFromFloat(self.pos.y),
|
||||
.w = @intFromFloat(doc.size.width * self._zoom),
|
||||
.h = @intFromFloat(doc.size.height * self._zoom),
|
||||
.w = @intFromFloat(doc.size.w * self._zoom),
|
||||
.h = @intFromFloat(doc.size.h * self._zoom),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn contentPointToDocument(self: Canvas, content_point: dvui.Point, natural_scale: f32) ?Point2 {
|
||||
pub fn contentPointToDocument(self: Canvas, content_point: dvui.Point, natural_scale: f32) ?Point2_f {
|
||||
const img = self.getZoomedImageSize();
|
||||
const left_n = @as(f32, @floatFromInt(img.x)) / natural_scale;
|
||||
const top_n = @as(f32, @floatFromInt(img.y)) / natural_scale;
|
||||
@@ -129,7 +129,7 @@ pub fn contentPointToDocument(self: Canvas, content_point: dvui.Point, natural_s
|
||||
|
||||
const px_x = content_point.x * natural_scale - @as(f32, @floatFromInt(img.x));
|
||||
const px_y = content_point.y * natural_scale - @as(f32, @floatFromInt(img.y));
|
||||
return Point2{
|
||||
return Point2_f{
|
||||
.x = px_x / self._zoom,
|
||||
.y = px_y / self._zoom,
|
||||
};
|
||||
@@ -148,7 +148,7 @@ pub fn updateVisibleImageRect(self: *Canvas, viewport: dvui.Rect, scroll_offset:
|
||||
return false;
|
||||
}
|
||||
|
||||
fn computeVisibleImageRect(self: Canvas, viewport: dvui.Rect, scroll_offset: dvui.Point) ImageRect {
|
||||
fn computeVisibleImageRect(self: Canvas, viewport: dvui.Rect, scroll_offset: dvui.Point) Rect_i {
|
||||
const image_rect = self.getZoomedImageSize();
|
||||
|
||||
const img_w: u32 = image_rect.w;
|
||||
@@ -163,7 +163,7 @@ fn computeVisibleImageRect(self: Canvas, viewport: dvui.Rect, scroll_offset: dvu
|
||||
const vis_x: u32 = @intCast(std.math.clamp(raw_x, 0, @as(i64, img_w) - @as(i64, vis_w)));
|
||||
const vis_y: u32 = @intCast(std.math.clamp(raw_y, 0, @as(i64, img_h) - @as(i64, vis_h)));
|
||||
|
||||
return ImageRect{
|
||||
return Rect_i{
|
||||
.x = vis_x,
|
||||
.y = vis_y,
|
||||
.w = vis_w,
|
||||
|
||||
Reference in New Issue
Block a user