Gondwana Game Engine
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop, mobile, and web platforms using SkiaSharp for graphics and NAudio for sound.
Loading...
Searching...
No Matches
Gondwana.Drawing.Direct.DirectRectangle Class Reference

Renders a configurable rectangle with support for fill, border, rounded corners, dash patterns, color pulsing, and pattern fills. More...

Inheritance diagram for Gondwana.Drawing.Direct.DirectRectangle:
Gondwana.Drawing.Direct.DirectDrawingMovableBase Gondwana.Drawing.Direct.DirectDrawingBase Gondwana.Movement.IMovable Gondwana.Drawing.Direct.IDirectDrawable Gondwana.Drawing.IDrawable

Public Types

enum  StrokeAlign { Inside , Outside , Center }
 Defines how the stroke (outline) is positioned relative to the rectangle's boundary. More...
Public Types inherited from Gondwana.Drawing.Direct.DirectDrawingBase
enum  RevealDirection { LeftToRight , RightToLeft , TopToBottom , BottomToTop }
 Defines the direction from which a reveal animation progressively displays the direct drawing. More...

Public Member Functions

 DirectRectangle (Color color, RenderSurfaceHostBase renderSurfaceHost, SceneLayer sceneLayer, Rectangle worldBounds, string? nickname=null)
 Initializes a new instance of the DirectRectangle class for scene-layer (world-space) rendering.
 DirectRectangle (Color color, RenderSurfaceHostBase renderSurfaceHost, View view, Rectangle screenBounds, string? nickname=null)
 Initializes a new instance of the DirectRectangle class for view (screen-space) rendering.
DirectRectangle SetColor (Color color)
 Sets the base color used for both fill and stroke (unless a distinct border color is specified).
DirectRectangle SetBorderColor (Color color)
 Sets a distinct border (stroke) color, independent of the fill color.
DirectRectangle SetAlpha (int alpha)
 Sets the alpha (transparency) channel of the base color.
DirectRectangle SetFilled (bool isFilled)
 Sets whether the rectangle interior is filled with the base color (or pattern).
DirectRectangle SetStrokeWidth (float width)
 Sets the width (thickness) of the rectangle's stroke (outline) in pixels.
DirectRectangle SetCornerRadius (float radius)
 Sets the radius for rounded corners in pixels.
DirectRectangle SetDashPattern (float dashLength, float gapLength)
 Sets a simple repeating dash pattern using dash and gap lengths, in pixels.
DirectRectangle ClearDashPattern ()
 Removes any existing dash pattern, reverting to a solid stroke.
DirectRectangle SetBlendMode (SKBlendMode mode)
 Sets the blend mode used when rendering this rectangle onto the canvas.
DirectRectangle SetStrokeAlign (StrokeAlign align)
 Sets how the rectangle's stroke is positioned relative to its bounds.
DirectRectangle PulseFill (Color from, Color to, float periodSec, bool enabled=true, bool triangle=false)
 Initiates an animated color transition (pulse) for the rectangle's fill between two colors.
DirectRectangle PulseBorder (Color from, Color to, float periodSec, bool enabled=true, bool triangle=false)
 Initiates an animated color transition (pulse) for the rectangle's border between two colors.
DirectRectangle StopPulses ()
 Stops all active color pulsing animations (fill and border), reverting to static colors.
DirectRectangle SetFillPattern (SKBitmap bitmap, SKShaderTileMode tileX=SKShaderTileMode.Repeat, SKShaderTileMode tileY=SKShaderTileMode.Repeat, float scale=1f, SKPoint? offsetPx=null, SKFilterQuality filterQuality=SKFilterQuality.None)
 Sets the rectangle's fill to use a tiled bitmap pattern instead of a solid color.
DirectRectangle ClearFillPattern ()
 Removes the current pattern fill and reverts to solid color rendering.
override void Update (long tick)
 Performs per-frame update logic, including pulse animation advancement and physics integration.
Public Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingMovableBase
Vector2 GetPosition ()
 Gets the current position of this direct drawing in pixel coordinates.
void SetPosition (Vector2 p)
 Sets the position of this direct drawing to the specified pixel coordinates.
Public Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingBase
RectangleF GetDrawLocationScreen (View view)
 Gets the screen-space drawing location for this direct drawing as seen from the specified view.
void Draw (BackbufferBase backbuffer, RectangleF destRectScreen)
 Renders this direct drawing to the backbuffer at the specified screen location.
DirectDrawingBase SetOpacity (float opacity)
 Instantly sets the opacity to the specified value without animation.
DirectDrawingBase FadeTo (float targetOpacity, float durationSec)
 Initiates a smooth fade transition to the specified target opacity over the given duration.
DirectDrawingBase FadeIn (float durationSec)
 Fades this direct drawing from its current opacity to fully opaque over the specified duration.
DirectDrawingBase FadeOut (float durationSec)
 Fades this direct drawing from its current opacity to fully transparent over the specified duration.
DirectDrawingBase CancelFade ()
 Cancels any active fade transition, leaving the opacity at its current value.
DirectDrawingBase SetReveal (float t01)
 Instantly sets the reveal progress to the specified value without animation.
DirectDrawingBase SetRevealDirection (RevealDirection dir)
 Sets the direction from which the reveal animation progresses.
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, optionally using a custom easing function.
int CompareTo (DirectDrawingBase? other)
 Compares this direct drawing to another for sorting by ZOrder.
void Dispose ()
 Releases all resources used by this DirectDrawingBase instance.
override bool Equals (object? obj)
 Determines whether the specified object is equal to the current direct drawing.
override int GetHashCode ()
 Returns a hash code for this direct drawing.

Protected Member Functions

override void OnDraw (BackbufferBase backbuffer, RectangleF destRectScreen)
 Renders the rectangle to the backbuffer with all configured properties and effects applied.
Protected Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingMovableBase
 DirectDrawingMovableBase (RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? name=null)
 Initializes a new instance of the DirectDrawingMovableBase class with integrated movement capabilities.
Protected Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingBase
void OnDraw (BackbufferBase backbuffer, RectangleF destRectScreen)
 Performs the concrete drawing for this direct drawing to the backbuffer.
 DirectDrawingBase (RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? nickname=null)
 Initializes a new instance of the DirectDrawingBase class.
virtual void Dispose (bool disposing)
 Releases resources used by this DirectDrawingBase instance.

Additional Inherited Members

Static Public Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingBase
static bool operator== (DirectDrawingBase? left, DirectDrawingBase? right)
 Determines whether two direct drawing instances are equal using reference equality.
static bool operator!= (DirectDrawingBase? left, DirectDrawingBase? right)
 Determines whether two direct drawing instances are not equal using reference equality.
static bool operator< (DirectDrawingBase? left, DirectDrawingBase? right)
 Determines whether the Z-order of the left direct drawing is less than the right.
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.
static bool operator> (DirectDrawingBase? left, DirectDrawingBase? right)
 Determines whether the Z-order of the left direct drawing is greater than the right.
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.
Protected Attributes inherited from Gondwana.Drawing.Direct.DirectDrawingBase
readonly RenderSurfaceHostBase _renderSurfaceHost
 The render surface host that manages this direct drawing's rendering pipeline.
Rectangle _screenBounds
 The current screen-space bounds for view-mode direct drawings, in pixels.
Rectangle _worldBounds
 The current world-space bounds for scene-layer-mode direct drawings, in pixels.
int _zOrder
 The Z-order used for draw sorting. Higher values draw later (on top).
bool _visible
 Indicates whether this direct drawing is currently visible and should be rendered.
long _lastTick = HighResTimer.GetCurrentTick()
 The last engine tick value used for delta-time calculations in Update.
Properties inherited from Gondwana.Drawing.Direct.DirectDrawingMovableBase
MovementController Movement [get]
 Gets the movement controller that manages physics-based position, velocity, and forces for this direct drawing.
MovementSpace PositionSpace [get]
 Gets the coordinate space in which this movable object's position is expressed.
Properties inherited from Gondwana.Drawing.Direct.DirectDrawingBase
bool HideWhenFullyTransparent = true [get, set]
 Gets or sets a value indicating whether this direct drawing should be automatically hidden when its opacity reaches zero during fade transitions.
RenderSurfaceHostBase RenderSurfaceHost [get]
 Gets the render surface host that manages this direct drawing's rendering pipeline.
DirectDrawingMode Mode [get]
 Gets the drawing mode that determines how this direct drawing is positioned and transformed.
SceneLayerSceneLayer [get]
 Gets the scene layer to which this direct drawing is attached, or null if the drawing is in view mode.
ViewView [get]
 Gets the view to which this direct drawing is attached, or null if the drawing is in scene-layer mode.
Rectangle ScreenBounds [get, set]
 Gets or sets the screen-space bounds of this direct drawing in pixels.
Rectangle WorldBounds [get, set]
 Gets or sets the world-space bounds of this direct drawing in pixels.
TypedValueBag ValueBag = new() [get]
 Gets the extensible value bag for storing arbitrary key-value data associated with this direct drawing.
Guid Id = Guid.NewGuid() [get]
 Gets the unique identifier for this direct drawing.
string? Nickname [get]
 Gets the optional human-readable name for this direct drawing.
int ZOrder [get, set]
 Gets or sets the Z-order (depth) used for sorting this direct drawing relative to other drawables.
bool Visible [get, set]
 Gets or sets a value indicating whether this direct drawing is visible and should be rendered.
float Opacity [get, set]
 Gets or sets the current opacity of this direct drawing.
Events inherited from Gondwana.Drawing.Direct.DirectDrawingBase
EventHandler< IDirectDrawable >? Disposing
 Occurs when this direct drawing is being disposed.
EventHandler< DirectDrawingBase >? FadeToCompleted
 Occurs when a fade transition initiated by FadeTo, FadeIn, or FadeOut completes.
Events inherited from Gondwana.Drawing.Direct.IDirectDrawable
EventHandler< IDirectDrawable >? Disposing
 Occurs when the object is being disposed.

Detailed Description

Renders a configurable rectangle with support for fill, border, rounded corners, dash patterns, color pulsing, and pattern fills.

DirectRectangle provides a high-performance, retained-mode rectangle rendering solution with extensive customization options. It supports both world-space (scene-layer mode) and screen-space (view mode) positioning, making it suitable for both in-game UI elements and world-space markers.

Key features:

  • Configurable fill color and optional distinct border color with independent alpha channels.
  • Stroke width and alignment control (inside, outside, or centered on the rectangle boundary).
  • Rounded corners with configurable radius.
  • Dash patterns for creating dashed or dotted borders.
  • Color pulsing animations for fill and/or border (sine or triangle wave).
  • Pattern fills using tiled bitmaps with configurable tiling modes and scaling.
  • Blend mode support for advanced compositing effects (screen, multiply, additive, etc.).
  • Physics-based movement via inherited DirectDrawingMovableBase capabilities.

Performance characteristics: DirectRectangle caches SKPaint instances and rebuilds them only when properties change, minimizing GC pressure and native interop overhead. Stroke alignment and dash patterns are computed per-frame but use efficient math operations.

All setter methods return this to enable fluent-style method chaining. Each setter automatically marks the affected screen regions as dirty to trigger rerendering on the next frame.

Thread safety: This class is not thread-safe. All operations should be performed on the UI thread.

// Filled panel with a distinct border and rounded corners
var panel = new DirectRectangle(Color.SteelBlue, renderSurfaceHost, view, screenBounds)
.SetFilled(true)
.SetBorderColor(Color.Navy)
.SetStrokeWidth(4f)
.SetCornerRadius(12f)
.SetDashPattern(8f, 4f); // dashed outline
// Soft glow using blend mode
var glow = new DirectRectangle(Color.FromArgb(64, 255, 200, 0), renderSurfaceHost, view, screenBounds2)
.SetFilled(true)
.SetBlendMode(SKBlendMode.Screen);
// Pulsing alert border
glow.PulseBorder(Color.FromArgb(255, 255, 64, 64), Color.FromArgb(80, 255, 0, 0), 1.2f);

Member Enumeration Documentation

◆ StrokeAlign

Defines how the stroke (outline) is positioned relative to the rectangle's boundary.

Stroke alignment determines whether the stroke width expands inward, outward, or is centered on the rectangle's edge.

Enumerator
Inside 

Draws the stroke entirely inside the rectangle's bounds. The outer edge of the stroke aligns with the rectangle boundary.

Outside 

Draws the stroke entirely outside the rectangle's bounds. The inner edge of the stroke aligns with the rectangle boundary, increasing the visual size.

Center 

Centers the stroke on the rectangle's boundary. Half the stroke width is drawn inside and half outside (default Skia behavior).

Constructor & Destructor Documentation

◆ DirectRectangle() [1/2]

Gondwana.Drawing.Direct.DirectRectangle.DirectRectangle ( Color color,
RenderSurfaceHostBase renderSurfaceHost,
SceneLayer sceneLayer,
Rectangle worldBounds,
string? nickname = null )

Initializes a new instance of the DirectRectangle class for scene-layer (world-space) rendering.

Parameters
colorThe base color used for fill and/or stroke (if no distinct border color is set).
renderSurfaceHostThe render surface host that manages rendering for this rectangle. Must not be null.
sceneLayerThe scene layer to which this rectangle is attached. The rectangle will be positioned in world coordinates relative to this layer.
worldBoundsThe world-space bounds in pixels defining the rectangle's position and size.
nicknameAn optional human-readable name for this rectangle, useful for debugging and identification.
Exceptions
ArgumentNullExceptionThrown when renderSurfaceHost is null.

This constructor creates a rectangle positioned in world coordinates that moves with the camera and is affected by the scene layer's parallax factor. Use this for in-game UI elements, selection markers, health bars, and other world-space visuals.

By default, the rectangle is created unfilled (outline only) with a 1-pixel stroke width. Use SetFilled and SetStrokeWidth to customize the appearance.

◆ DirectRectangle() [2/2]

Gondwana.Drawing.Direct.DirectRectangle.DirectRectangle ( Color color,
RenderSurfaceHostBase renderSurfaceHost,
View view,
Rectangle screenBounds,
string? nickname = null )

Initializes a new instance of the DirectRectangle class for view (screen-space) rendering.

Parameters
colorThe base color used for fill and/or stroke (if no distinct border color is set).
renderSurfaceHostThe render surface host that manages rendering for this rectangle. Must not be null.
viewThe view to which this rectangle is attached. The rectangle will be positioned in screen coordinates relative to this view's viewport.
screenBoundsThe screen-space bounds in pixels defining the rectangle's position and size within the viewport.
nicknameAn optional human-readable name for this rectangle, useful for debugging and identification.
Exceptions
ArgumentNullExceptionThrown when renderSurfaceHost is null.

This constructor creates a rectangle positioned in screen coordinates that remains fixed on screen regardless of camera movement. Use this for HUD panels, buttons, borders, focus indicators, and other screen-space UI elements.

By default, the rectangle is created unfilled (outline only) with a 1-pixel stroke width. Use SetFilled and SetStrokeWidth to customize the appearance.

Member Function Documentation

◆ ClearDashPattern()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.ClearDashPattern ( )

Removes any existing dash pattern, reverting to a solid stroke.

Returns
This DirectRectangle instance for method chaining.

After calling this method, the rectangle's stroke will be drawn as a solid, continuous line instead of a dashed pattern.

No dirty-rectangle marking is performed by this method alone; the effect becomes visible on the next render pass if the rectangle is already dirty from other property changes.

◆ ClearFillPattern()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.ClearFillPattern ( )

Removes the current pattern fill and reverts to solid color rendering.

Returns
This DirectRectangle instance for method chaining.

After calling this method, the rectangle's fill will use the solid color set by SetColor instead of the tiled bitmap pattern. The pattern shader is disposed to free resources.

The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.

◆ OnDraw()

override void Gondwana.Drawing.Direct.DirectRectangle.OnDraw ( BackbufferBase backbuffer,
RectangleF destRectScreen )
protected

Renders the rectangle to the backbuffer with all configured properties and effects applied.

Parameters
backbufferThe backbuffer providing the canvas and rendering context.
destRectScreenThe destination rectangle in screen pixel coordinates where the rectangle should be rendered.

This method is called automatically by the rendering pipeline. It performs the following operations:

  1. Rebuilds paint objects if properties have changed since the last draw.
  2. Calculates stroke rectangle based on alignment mode (inside, outside, center).
  3. Adjusts corner radius based on stroke alignment to maintain visual consistency.
  4. Applies dash pattern to the stroke paint if configured.
  5. Draws the filled rectangle if SetFilled is true (using color or pattern).
  6. Draws the stroke (border) with opaque rendering to avoid blend artifacts.

The stroke is rendered using SKBlendMode.Src (source replace) mode with full opacity to ensure crisp borders without color blending artifacts, regardless of the configured blend mode. This is restored after the stroke is drawn.

Do not call this method directly from game code. To trigger a redraw, call DirectDrawingBase.ForceRefresh or modify properties that affect appearance.

◆ PulseBorder()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.PulseBorder ( Color from,
Color to,
float periodSec,
bool enabled = true,
bool triangle = false )

Initiates an animated color transition (pulse) for the rectangle's border between two colors.

Parameters
fromThe starting color of the pulse animation.
toThe ending color of the pulse animation.
periodSecThe duration of one complete pulse cycle in seconds. Minimum value is 0.0001 seconds.
enabledtrue to enable the pulse animation (default); false to disable it.
triangletrue to use a triangle wave (linear ramp up then down); false to use a sine wave (smooth ease in/out, default).
Returns
This DirectRectangle instance for method chaining.

The border pulse creates a smooth color transition that repeats continuously. The color interpolates from from to to and back, creating an attention-grabbing effect useful for selection indicators, focus outlines, or warning borders.

The animation is updated each frame via Update and uses high-resolution timing for smooth, consistent animation regardless of frame rate.

To stop all pulsing (fill and border), call StopPulses. Disabling via enabled = false stops the animation but preserves the settings for later re-enabling.

◆ PulseFill()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.PulseFill ( Color from,
Color to,
float periodSec,
bool enabled = true,
bool triangle = false )

Initiates an animated color transition (pulse) for the rectangle's fill between two colors.

Parameters
fromThe starting color of the pulse animation.
toThe ending color of the pulse animation.
periodSecThe duration of one complete pulse cycle in seconds. Minimum value is 0.0001 seconds.
enabledtrue to enable the pulse animation (default); false to disable it.
triangletrue to use a triangle wave (linear ramp up then down); false to use a sine wave (smooth ease in/out, default).
Returns
This DirectRectangle instance for method chaining.

The fill pulse creates a smooth color transition that repeats continuously. The color interpolates from from to to and back, creating an attention-grabbing effect useful for alerts, health indicators, or animated UI elements.

The animation is updated each frame via Update and uses high-resolution timing for smooth, consistent animation regardless of frame rate.

To stop all pulsing (fill and border), call StopPulses. Disabling via enabled = false stops the animation but preserves the settings for later re-enabling.

◆ SetAlpha()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetAlpha ( int alpha)

Sets the alpha (transparency) channel of the base color.

Parameters
alphaThe alpha value from 0 (fully transparent) to 255 (fully opaque).
Returns
This DirectRectangle instance for method chaining.

This method modifies only the alpha channel of the base color, preserving the RGB components. It affects the fill transparency and, if no distinct border color is set, also affects the stroke transparency.

If a distinct border color has been set via SetBorderColor, its alpha remains unchanged by this method. To modify the border alpha independently, call SetBorderColor with a color containing the desired alpha value.

The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.

◆ SetBlendMode()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetBlendMode ( SKBlendMode mode)

Sets the blend mode used when rendering this rectangle onto the canvas.

Parameters
modeThe blend mode to apply. See SKBlendMode for available options.
Returns
This DirectRectangle instance for method chaining.

Blend modes determine how the rectangle's pixels combine with the existing pixels on the render surface. For example:

  • SKBlendMode.SrcOver – Default; draws over existing content with transparency.
  • SKBlendMode.Screen – Brightens overlapping areas; useful for glow effects.
  • SKBlendMode.Multiply – Darkens overlapping colors; good for shading overlays.
  • SKBlendMode.Plus – Additive blending; great for light or energy effects.

This mode applies to both the fill and stroke paints. Changing it affects how the rectangle visually interacts with whatever was previously drawn.

No dirty-rectangle marking is performed by this method alone; the effect becomes visible on the next render pass if the rectangle is already dirty from other property changes.

◆ SetBorderColor()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetBorderColor ( Color color)

Sets a distinct border (stroke) color, independent of the fill color.

Parameters
colorThe border color to apply.
Returns
This DirectRectangle instance for method chaining.

When a border color is set, the stroke uses this color instead of the base color set by SetColor. This allows for rectangles with different fill and outline colors, such as a white panel with a dark border.

The border color has its own alpha channel, independent of the fill's alpha. To remove the distinct border color and revert to using the base color, call SetColor again without setting a border color, or set the border color to match the base color.

The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame. If border pulsing is active, calling this method will not affect the pulsing animation until StopPulses is called.

◆ SetColor()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetColor ( Color color)

Sets the base color used for both fill and stroke (unless a distinct border color is specified).

Parameters
colorThe new base color.
Returns
This DirectRectangle instance for method chaining.

This color is used for the fill when SetFilled is true, and for the stroke (border) unless a distinct border color has been set via SetBorderColor.

The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame. If color pulsing is active, calling this method will not affect the pulsing animation until StopPulses is called.

◆ SetCornerRadius()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetCornerRadius ( float radius)

Sets the radius for rounded corners in pixels.

Parameters
radiusThe corner radius in pixels. A value of 0 produces sharp (90-degree) corners. Larger values create more rounded corners.
Returns
This DirectRectangle instance for method chaining.

Rounded corners are applied uniformly to all four corners of the rectangle. The radius specifies how far from the corner the curve begins. If the radius is larger than half the rectangle's width or height, the corners may overlap, producing unexpected results.

Rounded corners work with both filled and outlined rectangles, as well as with stroke alignment modes. The corner radius is adjusted internally based on stroke alignment to maintain visual consistency.

No dirty-rectangle marking is performed by this method alone; the effect becomes visible on the next render pass if the rectangle is already dirty from other property changes.

◆ SetDashPattern()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetDashPattern ( float dashLength,
float gapLength )

Sets a simple repeating dash pattern using dash and gap lengths, in pixels.

Parameters
dashLengthLength of each visible dash, in pixels.
gapLengthLength of the transparent gap between dashes, in pixels.
Returns
This DirectRectangle instance for method chaining.

This is a shorthand for creating a repeating [dash, gap] pattern (e.g., (8, 4) for 8 px dash, 4 px gap). The pattern is applied to the stroke (outline) only and has no effect on filled rectangles without a stroke.

Dash patterns are useful for creating dashed borders, focus indicators, or selection outlines. The pattern repeats continuously around the rectangle's perimeter.

To remove the dash pattern and revert to a solid stroke, call ClearDashPattern.

No dirty-rectangle marking is performed by this method alone; the effect becomes visible on the next render pass if the rectangle is already dirty from other property changes.

◆ SetFilled()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetFilled ( bool isFilled)

Sets whether the rectangle interior is filled with the base color (or pattern).

Parameters
isFilledtrue to fill the rectangle interior; false to draw only the outline (stroke).
Returns
This DirectRectangle instance for method chaining.

When filled, the rectangle's interior is drawn using the fill paint (base color or pattern). When not filled, only the stroke (outline) is visible if SetStrokeWidth is greater than zero.

You can combine fill and stroke to create rectangles with both a filled interior and a visible border, which is common for UI panels and buttons.

The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.

◆ SetFillPattern()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetFillPattern ( SKBitmap bitmap,
SKShaderTileMode tileX = SKShaderTileMode::Repeat,
SKShaderTileMode tileY = SKShaderTileMode::Repeat,
float scale = 1f,
SKPoint? offsetPx = null,
SKFilterQuality filterQuality = SKFilterQuality::None )

Sets the rectangle's fill to use a tiled bitmap pattern instead of a solid color.

Parameters
bitmapThe source bitmap to tile across the rectangle's interior.
tileXThe horizontal tiling mode (Repeat, Mirror, or Clamp). Default is Repeat.
tileYThe vertical tiling mode (Repeat, Mirror, or Clamp). Default is Repeat.
scaleOptional uniform scale factor applied to the bitmap. 1.0 = native size (default).
offsetPxOptional offset in pixels to shift the pattern origin. Null = no offset (default).
filterQualityThe filter quality to use when scaling the pattern. Default is None (nearest-neighbor).
Returns
This DirectRectangle instance for method chaining.

Pattern fills replace the solid color fill with a repeating texture. The bitmap is tiled according to the specified tile modes and scaled/offset as configured. This is useful for textured panels, patterned backgrounds, or decorative UI elements.

The base color set by SetColor tints the pattern multiplicatively. Set it to white to preserve the pattern's original colors, or use another color to apply a tint.

The pattern uses the rectangle's current coordinate space (world or screen). The scale parameter affects the pattern's size, while offsetPx shifts the pattern's origin, allowing for animated or scrolling textures.

The bitmap is not owned by this DirectRectangle; the caller must manage its lifetime and ensure it remains valid while in use.

This method automatically enables filled mode (SetFilled(true)) to make the pattern visible. The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.

To remove the pattern and return to solid color fill, call ClearFillPattern.

◆ SetStrokeAlign()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetStrokeAlign ( StrokeAlign align)

Sets how the rectangle's stroke is positioned relative to its bounds.

Parameters
alignThe stroke alignment mode. See StrokeAlign for available options.
Returns
This DirectRectangle instance for method chaining.

Determines whether the stroke (outline) is drawn inside, outside, or centered on the rectangle's boundary:

This only affects visible strokes (outlined or bordered rectangles). Filled rectangles are not impacted by stroke alignment.

No dirty-rectangle marking is performed by this method alone; the effect becomes visible on the next render pass if the rectangle is already dirty from other property changes.

◆ SetStrokeWidth()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.SetStrokeWidth ( float width)

Sets the width (thickness) of the rectangle's stroke (outline) in pixels.

Parameters
widthThe stroke width in pixels. A value of 0 results in no visible stroke.
Returns
This DirectRectangle instance for method chaining.

The stroke width determines how thick the rectangle's outline appears. Combined with SetStrokeAlign, you can control whether the stroke is drawn inside, outside, or centered on the rectangle boundary.

For pixel-perfect rendering at 1-pixel width, consider disabling antialiasing or using integer coordinates for the rectangle bounds.

The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.

◆ StopPulses()

DirectRectangle Gondwana.Drawing.Direct.DirectRectangle.StopPulses ( )

Stops all active color pulsing animations (fill and border), reverting to static colors.

Returns
This DirectRectangle instance for method chaining.

After calling this method, the rectangle's fill and border colors are restored to the values set by SetColor and SetBorderColor. The pulse animation state (period, wave type, colors) is preserved but disabled, so you can re-enable it later by calling PulseFill or PulseBorder again.

The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.

◆ Update()

override void Gondwana.Drawing.Direct.DirectRectangle.Update ( long tick)
virtual

Performs per-frame update logic, including pulse animation advancement and physics integration.

Parameters
tickThe current engine tick value from HighResTimer.

This method overrides DirectDrawingMovableBase.Update to add color pulsing animation support. It performs the following operations:

  1. Calculates elapsed time since the last update using high-resolution timing.
  2. Advances the pulse time accumulator for sine/triangle wave generation.
  3. Updates the fill color if fill pulsing is enabled, interpolating between the pulse colors.
  4. Updates the border color if border pulsing is enabled, interpolating between the pulse colors.
  5. Marks affected regions as dirty if color changes occurred.
  6. Calls base.Update(tick) to perform physics integration and fade/reveal animations.

The pulse animation uses a continuous time accumulator that wraps around the specified period, ensuring smooth, consistent animation. Color interpolation is performed in RGB space with linear blending (including alpha channel).

Override this method in derived classes to add custom per-frame logic. Always call base.Update(tick) to preserve pulsing, movement, and fade/reveal functionality.

Reimplemented from Gondwana.Drawing.Direct.DirectDrawingMovableBase.