47 public event EventHandler<IDirectDrawable>?
Disposing;
87 protected long _lastTick = HighResTimer.GetCurrentTick();
89 private bool _disposed =
false;
92 private float _opacity = 1f;
93 private float _fadeFrom, _fadeTo;
94 private float _fadeDurationSec, _fadeElapsedSec;
95 private bool _isFading;
113 private float _revealT = 1f;
117 private bool _revealAnimating;
118 private float _revealElapsedSec, _revealDurationSec;
119 private Func<float, float>? _revealEasing;
120 private float _revealStart = 1f, _revealTarget = 1f;
178 Rectangle? screenBounds,
179 Rectangle? worldBounds,
180 string? nickname =
null)
182 if (renderSurfaceHost is
null)
183 throw new ArgumentNullException(nameof(renderSurfaceHost));
186 throw new ArgumentException(
187 "SceneLayer cannot be null when using DirectDrawingMode.SceneLayer",
191 throw new ArgumentException(
"View cannot be null when using DirectDrawingMode.View", nameof(view));
194 throw new ArgumentException(
195 "worldBounds cannot be null when using DirectDrawingMode.SceneLayer",
196 nameof(worldBounds));
199 throw new ArgumentException(
200 "screenBounds cannot be null when using DirectDrawingMode.View",
201 nameof(screenBounds));
359 #region IDrawable members
371 public Guid
Id {
get; } = Guid.NewGuid();
459 PointF offset = view.GetEffectOffsetPx(layer:
null);
461 return new RectangleF(
503 var canvas = backbuffer.
Canvas;
506 bool useClip = _revealT < 0.999f;
513 destRectScreen.Right,
514 destRectScreen.Bottom);
516 SKRect clipRect = _revealDir
switch
521 r.Left + r.Width * _revealT,
524 r.Right - r.Width * _revealT,
532 r.Top + r.Height * _revealT),
535 r.Bottom - r.Height * _revealT,
542 if (clipRect.Width <= 0f || clipRect.Height <= 0f)
549 var m = canvas.TotalMatrix;
551 canvas.ResetMatrix();
552 canvas.ClipRect(clipRect, SKClipOperation.Intersect, antialias:
false);
558 if (_opacity >= 0.999f)
560 OnDraw(backbuffer, destRectScreen);
564 using var layerPaint =
new SKPaint
570 (
byte)(_opacity * 255))
573 canvas.SaveLayer(destRectScreen.ToSKRect(), layerPaint);
574 OnDraw(backbuffer, destRectScreen);
582 #endregion IDrawable members
612 var clamped = Math.Clamp(value, 0f, 1f);
614 if (Math.Abs(clamped - _opacity) < 0.0001f)
621 else if (_opacity > 0f)
667 _fadeFrom = _opacity;
668 _fadeTo = Math.Clamp(targetOpacity, 0f, 1f);
669 _fadeDurationSec = Math.Max(0.0001f, durationSec);
670 _fadeElapsedSec = 0f;
696 return FadeTo(1f, durationSec);
717 return FadeTo(0f, durationSec);
753 _revealT = Math.Clamp(t01, 0f, 1f);
798 _revealAnimating =
true;
799 _revealElapsedSec = 0f;
800 _revealDurationSec = Math.Max(0.0001f, durationSec);
801 _revealEasing = easing;
803 _revealTarget = Math.Clamp(t01, 0f, 1f);
804 _revealStart = _revealT;
812 _revealAnimating =
false;
835 protected internal void ForceRefresh()
889 float dt = HighResTimer.GetDuration(
_lastTick, tick);
891 _fadeElapsedSec += dt;
892 float timeElapsed = Math.Clamp(_fadeElapsedSec / _fadeDurationSec, 0f, 1f);
894 _opacity = _fadeFrom + (_fadeTo - _fadeFrom) * timeElapsed;
901 if (timeElapsed >= 1f)
909 if (_revealAnimating)
911 float dt = HighResTimer.GetDuration(
_lastTick, tick);
912 _revealElapsedSec = Math.Min(_revealElapsedSec + dt, _revealDurationSec);
914 float u = _revealElapsedSec / _revealDurationSec;
915 _revealT = (_revealEasing is
null ? u : _revealEasing(u));
916 _revealT = _revealStart + (_revealTarget - _revealStart) * _revealT;
920 if (_revealElapsedSec >= _revealDurationSec)
921 _revealAnimating =
false;
942 #region IDisposable members
959 lock (RenderStateSynchronization.SyncRoot)
962 GC.SuppressFinalize(
this);
987 protected virtual void Dispose(
bool disposing)
1002 #endregion IDisposable members
1004 #region Equality & Operators
1018 public override bool Equals(
object? obj) => ReferenceEquals(
this, obj);
1041 ReferenceEquals(left,
null) ? ReferenceEquals(right,
null) : left.
Equals(right);
1064 ReferenceEquals(left,
null) ? !ReferenceEquals(right,
null) : left.
CompareTo(right) < 0;
1076 ReferenceEquals(left,
null) || left.CompareTo(right) <= 0;
1088 !ReferenceEquals(left,
null) && left.CompareTo(right) > 0;
1100 ReferenceEquals(left,
null) ? ReferenceEquals(right,
null) : left.
CompareTo(right) >= 0;
1102 #endregion Equality & Operators
Provides the base implementation for direct drawing objects that can be rendered to the backbuffer wi...
void OnDraw(BackbufferBase backbuffer, RectangleF destRectScreen)
Performs the concrete drawing for this direct drawing to the backbuffer.
DirectDrawingBase SetRevealDirection(RevealDirection dir)
Sets the direction from which the reveal animation progresses.
DirectDrawingBase CancelReveal()
Stops an active reveal animation at its current progress.
int ZOrder
Gets or sets the Z-order (depth) used for sorting this direct drawing relative to other drawables.
static bool operator>(DirectDrawingBase? left, DirectDrawingBase? right)
Determines whether the Z-order of the left direct drawing is greater than the right.
DirectDrawingBase RevealTo(float t01, float durationSec, Func< float, float >? easing=null)
Initiates a smooth reveal animation to the specified target progress over the given duration,...
int _zOrder
The Z-order used for draw sorting. Higher values draw later (on top).
static bool operator==(DirectDrawingBase? left, DirectDrawingBase? right)
Determines whether two direct drawing instances are equal using reference equality.
DirectDrawingBase FadeOut(float durationSec)
Fades this direct drawing from its current opacity to fully transparent over the specified duration.
void Dispose()
Releases all resources used by this DirectDrawingBase instance.
bool HideWhenFullyTransparent
Gets or sets a value indicating whether this direct drawing should be automatically hidden when its o...
override int GetHashCode()
Returns a hash code for this direct drawing.
View? View
Gets the view to which this direct drawing is attached, or null if the drawing is in scene-layer mode...
long _lastTick
The last engine tick value used for delta-time calculations in Update.
TypedValueBag ValueBag
Gets the extensible value bag for storing arbitrary key-value data associated with this direct drawin...
bool _visible
Indicates whether this direct drawing is currently visible and should be rendered.
virtual void Update(long tick)
Performs per-frame update logic for this direct drawing, including fade and reveal animations.
int CompareTo(DirectDrawingBase? other)
Compares this direct drawing to another for sorting by ZOrder.
bool Visible
Gets or sets a value indicating whether this direct drawing is visible and should be rendered.
RectangleF GetDrawLocationScreen(View view)
Gets the screen-space drawing location for this direct drawing as seen from the specified view.
float Opacity
Gets or sets the current opacity of this direct drawing.
static bool operator>=(DirectDrawingBase? left, DirectDrawingBase? right)
Determines whether the Z-order of the left direct drawing is greater than or equal to the right.
static bool operator!=(DirectDrawingBase? left, DirectDrawingBase? right)
Determines whether two direct drawing instances are not equal using reference equality.
DirectDrawingBase FadeTo(float targetOpacity, float durationSec)
Initiates a smooth fade transition to the specified target opacity over the given duration.
static bool operator<(DirectDrawingBase? left, DirectDrawingBase? right)
Determines whether the Z-order of the left direct drawing is less than the right.
readonly RenderSurfaceHostBase _renderSurfaceHost
The render surface host that manages this direct drawing's rendering pipeline.
string? Nickname
Gets the optional human-readable name for this direct drawing.
EventHandler< IDirectDrawable >? Disposing
Occurs when this direct drawing is being disposed.
DirectDrawingBase SetReveal(float t01)
Instantly sets the reveal progress to the specified value without animation.
Guid Id
Gets the unique identifier for this direct drawing.
RenderSurfaceHostBase RenderSurfaceHost
Gets the render surface host that manages this direct drawing's rendering pipeline.
override bool Equals(object? obj)
Determines whether the specified object is equal to the current direct drawing.
DirectDrawingBase FadeIn(float durationSec)
Fades this direct drawing from its current opacity to fully opaque over the specified duration.
Rectangle _worldBounds
The current world-space bounds for scene-layer-mode direct drawings, in pixels.
SceneLayer? SceneLayer
Gets the scene layer to which this direct drawing is attached, or null if the drawing is in view mode...
static bool operator<=(DirectDrawingBase? left, DirectDrawingBase? right)
Determines whether the Z-order of the left direct drawing is less than or equal to the right.
Rectangle _screenBounds
The current screen-space bounds for view-mode direct drawings, in pixels.
DirectDrawingBase CancelFade()
Cancels any active fade transition, leaving the opacity at its current value.
Rectangle WorldBounds
Gets or sets the world-space bounds of this direct drawing in pixels.
DirectDrawingMode Mode
Gets the drawing mode that determines how this direct drawing is positioned and transformed.
void Draw(BackbufferBase backbuffer, RectangleF destRectScreen)
Renders this direct drawing to the backbuffer at the specified screen location.
virtual void Dispose(bool disposing)
Releases resources used by this DirectDrawingBase instance.
RevealDirection
Defines the direction from which a reveal animation progressively displays the direct drawing.
@ BottomToTop
Reveals the drawing from the bottom edge toward the top edge.
@ RightToLeft
Reveals the drawing from the right edge toward the left edge.
@ LeftToRight
Reveals the drawing from the left edge toward the right edge.
@ TopToBottom
Reveals the drawing from the top edge toward the bottom edge.
EventHandler< DirectDrawingBase >? FadeToCompleted
Occurs when a fade transition initiated by FadeTo, FadeIn, or FadeOut completes.
DirectDrawingBase SetOpacity(float opacity)
Instantly sets the opacity to the specified value without animation.
DirectDrawingBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? nickname=null)
Initializes a new instance of the DirectDrawingBase class.
Rectangle ScreenBounds
Gets or sets the screen-space bounds of this direct drawing in pixels.
Manages the lifecycle, registration, and retrieval of all direct drawing objects in the Gondwana engi...
static DirectDrawingManager Instance
Gets the singleton instance of the direct drawing manager.
Represents a base class for managing a graphical backbuffer, and is the in-memory surface where rende...
SKCanvas Canvas
Gets the SkiaSharp canvas used for drawing operations on this backbuffer.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Scene Scene
Gets the source Scenes.Scene used for rendering operations.
RectangleF WorldRectToScreenRect(SceneLayer layer, RectangleF worldRect)
Converts a world-space pixel rectangle into a screen-space rectangle for this View,...
ReadOnlyCollection< SceneLayer > SceneLayers
Gets a read-only collection of all layers in this scene, in their current order.
A flexible, strongly-typed value container intended for runtime-attached metadata and ephemeral engin...
Represents any drawable object (movable or static) that can render directly to a RenderSurfaceHost,...
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.
@ View
Performs direct drawing at the view level using screen-space coordinates.
@ SceneLayer
Performs direct drawing within a scene layer using world-space coordinates.