Merged in david_gileadi/unity-ui-extensions/gradient-zoom-offset (pull request #18)

Improve the offset range when zoomed
pull/413/head
David Gileadi 2017-10-19 12:11:56 +00:00 committed by Simon Jackson
commit 5530b10453
1 changed files with 12 additions and 9 deletions

View File

@ -126,8 +126,8 @@ namespace UnityEngine.UI.Extensions
}
float width = 1f / w / Zoom;
float zoomOffset = ((w * Zoom) - w) * width * 0.5f;
float offset = Offset - zoomOffset;
float zoomOffset = (1 - (1 / Zoom)) * 0.5f;
float offset = (Offset * (1 - zoomOffset)) - zoomOffset;
if (ModifyVertices)
{
@ -428,20 +428,23 @@ namespace UnityEngine.UI.Extensions
List<float> FindStops(float zoomOffset, Rect bounds)
{
List<float> stops = new List<float>();
var scaledOffset = Offset * Zoom;
var offset = Offset * (1 - zoomOffset);
var startBoundary = zoomOffset - offset;
var endBoundary = (1 - zoomOffset) - offset;
foreach (var color in EffectGradient.colorKeys)
{
if (color.time >= (1 - (zoomOffset + scaledOffset)))
if (color.time >= endBoundary)
break;
if (color.time > (zoomOffset - scaledOffset))
stops.Add(((color.time - 0.5f) * Zoom) + 0.5f + scaledOffset);
if (color.time > startBoundary)
stops.Add((color.time - startBoundary) * Zoom);
}
foreach (var alpha in EffectGradient.alphaKeys)
{
if (alpha.time >= (1 - (zoomOffset + scaledOffset)))
if (alpha.time >= endBoundary)
break;
if (alpha.time > (zoomOffset - scaledOffset))
stops.Add(((alpha.time - 0.5f) * Zoom) + 0.5f + scaledOffset);
if (alpha.time > startBoundary)
stops.Add((alpha.time - startBoundary) * Zoom);
}
float min = bounds.xMin;