16 private bool _isResizing;
17 private float _resizeElapsedSeconds;
18 private float _resizeDurationSeconds;
19 private Size _resizeStart;
20 private Size _resizeTarget;
22 private bool _resizeReturnToStart;
23 private float _resizeReturnDurationSeconds;
24 private Size _resizeOriginalStart;
25 private Size _resizePeak;
27 private bool _isPulseMode;
28 private bool _pulseLoop;
29 private bool _pulseForward;
30 private float _pulseGrowDurationSeconds;
31 private float _pulseShrinkDurationSeconds;
34 private Size _resizeStartSizeForCollision;
36 internal void AdvanceResize(
float deltaSeconds)
41 if (_resizeDurationSeconds <= 0f)
49 _resizeElapsedSeconds += deltaSeconds;
51 float t = _resizeElapsedSeconds / _resizeDurationSeconds;
56 int w = (int)MathF.Round(
57 _resizeStart.Width + ((_resizeTarget.Width - _resizeStart.Width) * t));
59 int h = (int)MathF.Round(
60 _resizeStart.Height + ((_resizeTarget.Height - _resizeStart.Height) * t));
62 var next =
new Size(Math.Max(1, w), Math.Max(1, h));
64 if (next != _renderSize)
67 ApplyScaledCollisionAdjust(next);
74 private void CompleteResizeLeg()
83 _pulseForward =
false;
87 target: _resizeOriginalStart,
88 durationSeconds: _pulseShrinkDurationSeconds,
90 returnDurationSeconds: 0f);
100 start: _resizeOriginalStart,
102 durationSeconds: _pulseGrowDurationSeconds,
103 returnToStart:
false,
104 returnDurationSeconds: 0f);
109 _isPulseMode =
false;
115 if (_resizeReturnToStart)
119 target: _resizeOriginalStart,
120 durationSeconds: _resizeReturnDurationSeconds,
121 returnToStart:
false,
122 returnDurationSeconds: 0f);
131 private void StartResizeLeg(
134 float durationSeconds,
136 float returnDurationSeconds)
138 _resizeStart = start;
139 _resizeTarget = target;
140 _resizeDurationSeconds = Math.Max(0f, durationSeconds);
141 _resizeElapsedSeconds = 0f;
144 _resizeReturnToStart = returnToStart;
145 _resizeReturnDurationSeconds = Math.Max(0f, returnDurationSeconds);
148 _resizeStartSizeForCollision = start;
151 private void ApplyScaledCollisionAdjust(Size currentSize)
153 if (_resizeStartSizeForCollision.Width <= 0 ||
154 _resizeStartSizeForCollision.Height <= 0)
159 float sx = (float)currentSize.Width / _resizeStartSizeForCollision.Width;
160 float sy = (float)currentSize.Height / _resizeStartSizeForCollision.Height;
163 top: (
int)MathF.Round(_resizeStartCollisionAdjust.Top * sy),
164 bottom: (
int)MathF.Round(_resizeStartCollisionAdjust.Bottom * sy),
165 left: (
int)MathF.Round(_resizeStartCollisionAdjust.Left * sx),
166 right: (
int)MathF.Round(_resizeStartCollisionAdjust.Right * sx));
174 public void ResizeTo(Size targetSize,
float durationSeconds)
176 targetSize =
new Size(
177 Math.Max(1, targetSize.Width),
178 Math.Max(1, targetSize.Height));
180 _isPulseMode =
false;
187 durationSeconds: durationSeconds,
188 returnToStart:
false,
189 returnDurationSeconds: 0f);
197 public void ScaleBy(
float factor,
float durationSeconds)
199 factor = MathF.Max(0.01f, factor);
201 int w = (int)MathF.Round(
RenderSize.Width * factor);
202 int h = (int)MathF.Round(
RenderSize.Height * factor);
205 new Size(Math.Max(1, w), Math.Max(1, h)),
218 float growDurationSeconds,
219 float shrinkDurationSeconds,
222 targetSize =
new Size(
223 Math.Max(1, targetSize.Width),
224 Math.Max(1, targetSize.Height));
227 _resizePeak = targetSize;
231 _pulseForward =
true;
232 _pulseGrowDurationSeconds = Math.Max(0f, growDurationSeconds);
233 _pulseShrinkDurationSeconds = Math.Max(0f, shrinkDurationSeconds);
236 start: _resizeOriginalStart,
238 durationSeconds: _pulseGrowDurationSeconds,
239 returnToStart:
false,
240 returnDurationSeconds: 0f);
252 float growDurationSeconds,
253 float shrinkDurationSeconds,
256 factor = MathF.Max(0.01f, factor);
258 int w = (int)MathF.Round(
RenderSize.Width * factor);
259 int h = (int)MathF.Round(
RenderSize.Height * factor);
262 new Size(Math.Max(1, w), Math.Max(1, h)),
264 shrinkDurationSeconds,
273 public void StopPulse(
bool snapBack =
true,
float returnDuration = 0f)
275 Size originalSize = _resizeOriginalStart;
276 var originalCollisionAdjust = _resizeStartCollisionAdjust;
283 if (returnDuration <= 0f)
290 ResizeTo(originalSize, returnDuration);
300 _resizeReturnToStart =
false;
301 _isPulseMode =
false;
303 _pulseForward =
false;
Represents a movable visual element on a scene layer.
void PulseBy(float factor, float growDurationSeconds, float shrinkDurationSeconds, bool loop=false)
Pulses by a factor relative to the current render size.
void ResizeTo(Size targetSize, float durationSeconds)
Smoothly resizes the sprite to an absolute pixel size.
Size RenderSize
Gets or sets the render size.
void ScaleBy(float factor, float durationSeconds)
Scales the sprite by a factor relative to its current render size.
void PulseTo(Size targetSize, float growDurationSeconds, float shrinkDurationSeconds, bool loop=false)
Resizes to an absolute target size and then returns to the original size.
void CancelResize()
Cancels any in-progress resize or pulse.
void StopPulse(bool snapBack=true, float returnDuration=0f)
Stops the current pulse, optionally returning to the original size.
Action? ResizeComplete
Raised when a resize or pulse animation completes its current leg, or when cancelled.
virtual CollisionAdjust AdjustCollisionArea
Gets or sets the collision adjustment used to derive CollisionArea.
Per-edge inset amounts applied to visual bounds to produce a collision rectangle.