From a250a232597aaa20f1897dddbe1cb13fb8668243 Mon Sep 17 00:00:00 2001 From: stefnotch Date: Thu, 28 Jan 2021 16:13:45 +0100 Subject: [PATCH] Fix TexturePreview zooming Fix #164 --- Source/Editor/Viewport/Previews/TexturePreview.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Viewport/Previews/TexturePreview.cs b/Source/Editor/Viewport/Previews/TexturePreview.cs index d1904027a..5e1024609 100644 --- a/Source/Editor/Viewport/Previews/TexturePreview.cs +++ b/Source/Editor/Viewport/Previews/TexturePreview.cs @@ -159,13 +159,14 @@ namespace FlaxEditor.Viewport.Previews float prevScale = _viewScale; _viewScale = Mathf.Clamp(_viewScale + delta * 0.24f, 0.001f, 20.0f); - // Move view to make use of the control much more soother - //float coeff = (prevScale + (_viewScale - prevScale)) / prevScale; - //_viewPos += (location * coeff - location) / _viewScale; - //_viewPos += location / _viewScale; - Vector2 sizeDelta = (_viewScale - prevScale) * _textureRect.Size; + // Compensate for the Rectangle.MakeScaled + Vector2 sizeDelta = (_viewScale - prevScale) * _textureRect.Size * 0.5f; _viewPos += sizeDelta * 0.5f; + // Move to zoom position + Vector2 locationOnTexture = (location - _textureRect.Location) / _textureRect.Size; + _viewPos -= sizeDelta * locationOnTexture; + return true; }