Зум к курсору
This commit is contained in:
@@ -88,6 +88,10 @@ pub fn addZoom(self: *Canvas, value: f32) void {
|
||||
self._zoom = @max(self._zoom, 0.01);
|
||||
}
|
||||
|
||||
pub fn getZoom(self: Canvas) f32 {
|
||||
return self._zoom;
|
||||
}
|
||||
|
||||
pub fn requestRedraw(self: *Canvas) void {
|
||||
self._redraw_pending = true;
|
||||
}
|
||||
@@ -116,23 +120,27 @@ pub fn getZoomedImageSize(self: Canvas) Rect_i {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn contentPointToDocument(self: Canvas, content_point: dvui.Point, natural_scale: f32) ?Point2_f {
|
||||
/// Возвращает координаты точки контента в координатах документа. Всегда возвращает точку,
|
||||
/// даже если она за пределами документа
|
||||
pub fn contentPointToDocument(self: Canvas, content_point: dvui.Point, natural_scale: f32) Point2_f {
|
||||
const img = self.getZoomedImageSize();
|
||||
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 .{
|
||||
.x = px_x / self._zoom,
|
||||
.y = px_y / self._zoom,
|
||||
};
|
||||
}
|
||||
|
||||
/// Возвращает true, если точка контента лежит внутри холста (документа).
|
||||
pub fn isContentPointOnDocument(self: Canvas, content_point: dvui.Point, natural_scale: f32) bool {
|
||||
const img = self.getZoomedImageSize();
|
||||
const left_n = @as(f32, @floatFromInt(img.x)) / natural_scale;
|
||||
const top_n = @as(f32, @floatFromInt(img.y)) / natural_scale;
|
||||
const right_n = @as(f32, @floatFromInt(img.x + img.w)) / natural_scale;
|
||||
const bottom_n = @as(f32, @floatFromInt(img.y + img.h)) / natural_scale;
|
||||
|
||||
if (content_point.x < left_n or content_point.x >= right_n or
|
||||
content_point.y < top_n or content_point.y >= bottom_n)
|
||||
return null;
|
||||
|
||||
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_f{
|
||||
.x = px_x / self._zoom,
|
||||
.y = px_y / self._zoom,
|
||||
};
|
||||
return content_point.x >= left_n and content_point.x < right_n and
|
||||
content_point.y >= top_n and content_point.y < bottom_n;
|
||||
}
|
||||
|
||||
pub fn updateVisibleImageRect(self: *Canvas, viewport: dvui.Rect, scroll_offset: dvui.Point) bool {
|
||||
|
||||
Reference in New Issue
Block a user