Убрано масштабирование от системы

This commit is contained in:
2025-12-20 19:07:59 +03:00
parent b5d60d67dd
commit b49ee3e46c
2 changed files with 47 additions and 25 deletions

View File

@@ -39,9 +39,9 @@ pub fn deinit(self: *Canvas) void {
/// Заполнить canvas градиентом
pub fn redrawGradient(self: *Canvas) !void {
const size = self.getScaledSize();
const width: u32 = @intFromFloat(size.w);
const height: u32 = @intFromFloat(size.h);
const size = self.getScaledImageSize();
const width: u32 = size.w;
const height: u32 = size.h;
// Выделить буфер пиксельных данных
const pixels = try self.allocator.alloc(Color.PMA, @as(usize, width) * height);
@@ -84,37 +84,38 @@ pub fn addZoom(self: *Canvas, value: f32) void {
self.zoom = @max(self.zoom, 0.01);
}
pub fn getScaledSize(self: Canvas) Size {
pub fn getScaledImageSize(self: Canvas) ImageRect {
return .{
.w = self.size.w * self.zoom,
.h = self.size.h * self.zoom,
.x = @intFromFloat(self.pos.x),
.y = @intFromFloat(self.pos.y),
.w = @intFromFloat(self.size.w * self.zoom),
.h = @intFromFloat(self.size.h * self.zoom),
};
}
/// Видимая часть изображения, которую реально видит пользователь.
///
/// Возвращает прямоугольник в координатах самой картинки (пиксели текстуры):
/// - (0,0) — левый верхний пиксель изображения
/// - размеры ограничены размером текстуры
/// Возвращает прямоугольник в координатах изображения (пиксели).
///
/// Важно: функция НЕ зависит от `texture` и может вызываться до её создания.
/// Параметры:
/// - `viewport`: размер видимой области scroll-area (x/y игнорируются)
/// - `scroll_offset`: текущий scroll (виртуальные координаты контента)
pub fn getVisibleImageRect(self: Canvas, viewport: dvui.Rect, scroll_offset: dvui.Point) ImageRect {
const tex = self.texture orelse return .{ .x = 0, .y = 0, .w = 0, .h = 0 };
const image_rect = self.getScaledImageSize();
const img_w_f: f32 = @floatFromInt(tex.width);
const img_h_f: f32 = @floatFromInt(tex.height);
const img_w_f: f32 = @floatFromInt(image_rect.w);
const img_h_f: f32 = @floatFromInt(image_rect.h);
const view_left: f32 = scroll_offset.x;
const view_top: f32 = scroll_offset.y;
const view_right: f32 = scroll_offset.x + viewport.w;
const view_bottom: f32 = scroll_offset.y + viewport.h;
const img_left: f32 = self.pos.x;
const img_top: f32 = self.pos.y;
const img_right: f32 = self.pos.x + img_w_f;
const img_bottom: f32 = self.pos.y + img_h_f;
const img_left: f32 = @floatFromInt(image_rect.x);
const img_top: f32 = @floatFromInt(image_rect.y);
const img_right: f32 = img_left + img_w_f;
const img_bottom: f32 = img_top + img_h_f;
const inter_left: f32 = @max(view_left, img_left);
const inter_top: f32 = @max(view_top, img_top);
@@ -135,10 +136,10 @@ pub fn getVisibleImageRect(self: Canvas, viewport: dvui.Rect, scroll_offset: dvu
const local_y1: f32 = inter_bottom - img_top;
// Консервативно округляем до пикселей: начало вниз (floor), конец вверх (ceil)
const x0_u32: u32 = floatToClampedU32(@floor(local_x0), tex.width);
const y0_u32: u32 = floatToClampedU32(@floor(local_y0), tex.height);
const x1_u32: u32 = floatToClampedU32(@ceil(local_x1), tex.width);
const y1_u32: u32 = floatToClampedU32(@ceil(local_y1), tex.height);
const x0_u32: u32 = floatToClampedU32(@floor(local_x0), image_rect.w);
const y0_u32: u32 = floatToClampedU32(@floor(local_y0), image_rect.h);
const x1_u32: u32 = floatToClampedU32(@ceil(local_x1), image_rect.w);
const y1_u32: u32 = floatToClampedU32(@ceil(local_y1), image_rect.h);
const out: ImageRect = .{
.x = x0_u32,