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;
177 Rectangle? screenBounds,
178 Rectangle? worldBounds,
179 string? nickname =
null)
181 if (renderSurfaceHost is
null)
182 throw new ArgumentNullException(nameof(renderSurfaceHost));
185 throw new ArgumentException(
"SceneLayer cannot be null when using DirectDrawingMode.SceneLayer", nameof(sceneLayer));
188 throw new ArgumentException(
"View cannot be null when using DirectDrawingMode.View", nameof(view));
191 throw new ArgumentException(
"worldBounds cannot be null when using DirectDrawingMode.SceneLayer", nameof(worldBounds));
194 throw new ArgumentException(
"screenBounds cannot be null when using DirectDrawingMode.View", nameof(screenBounds));
351 #region IDrawable members
363 public Guid
Id {
get; } = Guid.NewGuid();
451 PointF offset = view.GetEffectOffsetPx(layer:
null);
452 return new RectangleF(
494 var canvas = backbuffer.
Canvas;
497 bool useClip = _revealT < 0.999f;
501 var r =
new SKRect(destRectScreen.Left, destRectScreen.Top, destRectScreen.Right, destRectScreen.Bottom);
503 SKRect clipRect = _revealDir
switch
513 if (clipRect.Width <= 0f || clipRect.Height <= 0f)
520 var m = canvas.TotalMatrix;
522 canvas.ResetMatrix();
523 canvas.ClipRect(clipRect, SKClipOperation.Intersect, antialias:
false);
529 if (_opacity >= 0.999f)
531 OnDraw(backbuffer, destRectScreen);
535 using var layerPaint =
new SKPaint
537 Color =
new SKColor(255, 255, 255, (
byte)(_opacity * 255))
540 canvas.SaveLayer(destRectScreen.ToSKRect(), layerPaint);
541 OnDraw(backbuffer, destRectScreen);
549 #endregion IDrawable members
579 var clamped = Math.Clamp(value, 0f, 1f);
580 if (Math.Abs(clamped - _opacity) < 0.0001f)
587 else if (_opacity > 0f)
633 _fadeFrom = _opacity;
634 _fadeTo = Math.Clamp(targetOpacity, 0f, 1f);
635 _fadeDurationSec = Math.Max(0.0001f, durationSec);
636 _fadeElapsedSec = 0f;
662 return FadeTo(1f, durationSec);
683 return FadeTo(0f, durationSec);
719 _revealT = Math.Clamp(t01, 0f, 1f);
764 _revealAnimating =
true;
765 _revealElapsedSec = 0f;
766 _revealDurationSec = Math.Max(0.0001f, durationSec);
767 _revealEasing = easing;
769 _revealTarget = Math.Clamp(t01, 0f, 1f);
770 _revealStart = _revealT;
778 _revealAnimating =
false;
801 protected internal void ForceRefresh()
854 float dt = HighResTimer.GetDuration(
_lastTick, tick);
856 _fadeElapsedSec += dt;
857 float timeElapsed = Math.Clamp(_fadeElapsedSec / _fadeDurationSec, 0f, 1f);
859 _opacity = _fadeFrom + (_fadeTo - _fadeFrom) * timeElapsed;
866 if (timeElapsed >= 1f)
874 if (_revealAnimating)
876 float dt = HighResTimer.GetDuration(
_lastTick, tick);
877 _revealElapsedSec = Math.Min(_revealElapsedSec + dt, _revealDurationSec);
879 float u = _revealElapsedSec / _revealDurationSec;
880 _revealT = (_revealEasing is
null ? u : _revealEasing(u));
881 _revealT = _revealStart + (_revealTarget - _revealStart) * _revealT;
885 if (_revealElapsedSec >= _revealDurationSec)
886 _revealAnimating =
false;
907 #region IDisposable members
924 lock (RenderStateSynchronization.SyncRoot)
927 GC.SuppressFinalize(
this);
952 protected virtual void Dispose(
bool disposing)
967 #endregion IDisposable members
969 #region Equality & Operators
983 public override bool Equals(
object? obj) => ReferenceEquals(
this, obj);
1006 ReferenceEquals(left,
null) ? ReferenceEquals(right,
null) : left.
Equals(right);
1029 ReferenceEquals(left,
null) ? !ReferenceEquals(right,
null) : left.
CompareTo(right) < 0;
1041 ReferenceEquals(left,
null) || left.CompareTo(right) <= 0;
1053 !ReferenceEquals(left,
null) && left.CompareTo(right) > 0;
1065 ReferenceEquals(left,
null) ? ReferenceEquals(right,
null) : left.
CompareTo(right) >= 0;
1067 #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,...
A rectangular window on the render target with its own zoom and placement. Viewport never moves the w...
Rectangle TargetRectPx
Screen-space rectangle (in SCREEN / RenderSurface pixels) where this view is drawn....
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.