Table of Contents

Class RDFormsDrawingLayer

Namespace
RDCore.Forms.Avalonia.Controls
Assembly
RDCore.Forms.Avalonia.dll

The drawing surface of a form or a PictureBox: the layer its drawing statements draw on, under its controls.

public sealed class RDFormsDrawingLayer : Control, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, INamed, IInputElement, IDataTemplateHost, ISetterValue, IDrawingSurface
Inheritance
AvaloniaObject
Animatable
StyledElement
Visual
Layoutable
Interactive
InputElement
Control
RDFormsDrawingLayer
Implements
IDataContextProvider
ILogical
IThemeVariantHost
IResourceHost
IResourceNode
IStyleHost
ISetLogicalParent
ISetInheritanceParent
INamed
IInputElement
IDataTemplateHost
ISetterValue
Inherited Members
Control.FocusAdornerProperty
Control.TagProperty
Control.ContextMenuProperty
Control.ContextFlyoutProperty
Control.RequestBringIntoViewEvent
Control.LoadedEvent
Control.UnloadedEvent
Control.SizeChangedEvent
Control.FocusAdorner
Control.DataTemplates
Control.ContextMenu
Control.ContextFlyout
Control.IsLoaded
Control.Tag
Control.Loaded
Control.Unloaded
Control.SizeChanged
InputElement.FocusableProperty
InputElement.IsEnabledProperty
InputElement.IsEffectivelyEnabledProperty
InputElement.CursorProperty
InputElement.IsKeyboardFocusWithinProperty
InputElement.IsFocusedProperty
InputElement.IsHitTestVisibleProperty
InputElement.IsPointerOverProperty
InputElement.IsTabStopProperty
InputElement.GotFocusEvent
InputElement.GettingFocusEvent
InputElement.LostFocusEvent
InputElement.LosingFocusEvent
InputElement.KeyDownEvent
InputElement.KeyUpEvent
InputElement.TabIndexProperty
InputElement.TextInputEvent
InputElement.TextInputMethodClientRequestedEvent
InputElement.PointerEnteredEvent
InputElement.PointerExitedEvent
InputElement.PointerMovedEvent
InputElement.PointerPressedEvent
InputElement.PointerReleasedEvent
InputElement.PointerCaptureLostEvent
InputElement.PointerWheelChangedEvent
InputElement.ContextRequestedEvent
InputElement.ContextCanceledEvent
InputElement.IsHoldingEnabledProperty
InputElement.IsHoldWithMouseEnabledProperty
InputElement.PinchEvent
InputElement.PinchEndedEvent
InputElement.PullGestureEvent
InputElement.PullGestureEndedEvent
InputElement.SwipeGestureEvent
InputElement.SwipeGestureEndedEvent
InputElement.ScrollGestureEvent
InputElement.ScrollGestureInertiaStartingEvent
InputElement.ScrollGestureEndedEvent
InputElement.PointerTouchPadGestureMagnifyEvent
InputElement.PointerTouchPadGestureRotateEvent
InputElement.PointerTouchPadGestureSwipeEvent
InputElement.TappedEvent
InputElement.RightTappedEvent
InputElement.HoldingEvent
InputElement.DoubleTappedEvent
InputElement.Focus(NavigationMethod, KeyModifiers)
InputElement.GetIsHoldingEnabled(StyledElement)
InputElement.GetIsHoldWithMouseEnabled(StyledElement)
InputElement.Focusable
InputElement.IsEnabled
InputElement.Cursor
InputElement.IsKeyboardFocusWithin
InputElement.IsFocused
InputElement.IsHitTestVisible
InputElement.IsPointerOver
InputElement.IsTabStop
InputElement.IsEffectivelyEnabled
InputElement.TabIndex
InputElement.KeyBindings
InputElement.GestureRecognizers
InputElement.GotFocus
InputElement.GettingFocus
InputElement.LostFocus
InputElement.LosingFocus
InputElement.KeyDown
InputElement.KeyUp
InputElement.TextInput
InputElement.TextInputMethodClientRequested
InputElement.PointerEntered
InputElement.PointerExited
InputElement.PointerMoved
InputElement.PointerPressed
InputElement.PointerReleased
InputElement.PointerCaptureLost
InputElement.PointerWheelChanged
InputElement.ContextRequested
InputElement.ContextCanceled
InputElement.Pinch
InputElement.PinchEnded
InputElement.PullGesture
InputElement.PullGestureEnded
InputElement.ScrollGesture
InputElement.ScrollGestureInertiaStarting
InputElement.ScrollGestureEnded
InputElement.PointerTouchPadGestureMagnify
InputElement.PointerTouchPadGestureRotate
InputElement.SwipeGesture
InputElement.SwipeGestureEnded
InputElement.PointerTouchPadGestureSwipe
InputElement.Tapped
InputElement.RightTapped
InputElement.Holding
InputElement.DoubleTapped
Interactive.RaiseEvent(RoutedEventArgs)
Layoutable.DesiredSizeProperty
Layoutable.WidthProperty
Layoutable.HeightProperty
Layoutable.MinWidthProperty
Layoutable.MaxWidthProperty
Layoutable.MinHeightProperty
Layoutable.MaxHeightProperty
Layoutable.MarginProperty
Layoutable.HorizontalAlignmentProperty
Layoutable.VerticalAlignmentProperty
Layoutable.UseLayoutRoundingProperty
Layoutable.UpdateLayout()
Layoutable.ApplyTemplate()
Layoutable.Measure(Size)
Layoutable.Arrange(Rect)
Layoutable.InvalidateMeasure()
Layoutable.InvalidateArrange()
Layoutable.Width
Layoutable.Height
Layoutable.MinWidth
Layoutable.MaxWidth
Layoutable.MinHeight
Layoutable.MaxHeight
Layoutable.Margin
Layoutable.HorizontalAlignment
Layoutable.VerticalAlignment
Layoutable.DesiredSize
Layoutable.IsMeasureValid
Layoutable.IsArrangeValid
Layoutable.UseLayoutRounding
Layoutable.EffectiveViewportChanged
Layoutable.LayoutUpdated
Visual.BoundsProperty
Visual.ClipToBoundsProperty
Visual.ClipProperty
Visual.IsVisibleProperty
Visual.OpacityProperty
Visual.OpacityMaskProperty
Visual.CacheModeProperty
Visual.EffectProperty
Visual.HasMirrorTransformProperty
Visual.RenderTransformProperty
Visual.RenderTransformOriginProperty
Visual.FlowDirectionProperty
Visual.VisualParentProperty
Visual.ZIndexProperty
Visual.GetFlowDirection(Visual)
Visual.SetFlowDirection(Visual, FlowDirection)
Visual.InvalidateVisual()
Visual.Bounds
Visual.ClipToBounds
Visual.Clip
Visual.IsEffectivelyVisible
Visual.IsVisible
Visual.Opacity
Visual.OpacityMask
Visual.CacheMode
Visual.Effect
Visual.HasMirrorTransform
Visual.RenderTransform
Visual.RenderTransformOrigin
Visual.FlowDirection
Visual.ZIndex
Visual.AttachedToVisualTree
Visual.DetachedFromVisualTree
StyledElement.DataContextProperty
StyledElement.NameProperty
StyledElement.ParentProperty
StyledElement.TemplatedParentProperty
StyledElement.ThemeProperty
StyledElement.BeginInit()
StyledElement.EndInit()
StyledElement.ApplyStyling()
StyledElement.Name
StyledElement.Classes
StyledElement.DataContext
StyledElement.IsInitialized
StyledElement.Styles
StyledElement.StyleKey
StyledElement.Resources
StyledElement.TemplatedParent
StyledElement.Theme
StyledElement.Parent
StyledElement.ActualThemeVariant
StyledElement.AttachedToLogicalTree
StyledElement.DetachedFromLogicalTree
StyledElement.DataContextChanged
StyledElement.Initialized
StyledElement.ResourcesChanged
StyledElement.ActualThemeVariantChanged
Animatable.TransitionsProperty
Animatable.Transitions
AvaloniaObject.CheckAccess()
AvaloniaObject.VerifyAccess()
AvaloniaObject.ClearValue(AvaloniaProperty)
AvaloniaObject.ClearValue<T>(AvaloniaProperty<T>)
AvaloniaObject.ClearValue<T>(StyledProperty<T>)
AvaloniaObject.ClearValue<T>(DirectPropertyBase<T>)
AvaloniaObject.GetHashCode()
AvaloniaObject.GetValue(AvaloniaProperty)
AvaloniaObject.GetValue<T>(StyledProperty<T>)
AvaloniaObject.GetValue<T>(DirectPropertyBase<T>)
AvaloniaObject.GetBaseValue<T>(StyledProperty<T>)
AvaloniaObject.IsAnimating(AvaloniaProperty)
AvaloniaObject.IsSet(AvaloniaProperty)
AvaloniaObject.SetValue<T>(StyledProperty<T>, T, BindingPriority)
AvaloniaObject.SetValue<T>(DirectPropertyBase<T>, T)
AvaloniaObject.SetCurrentValue<T>(StyledProperty<T>, T)
AvaloniaObject.Bind(AvaloniaProperty, BindingBase)
AvaloniaObject.CoerceValue(AvaloniaProperty)
AvaloniaObject.this[AvaloniaProperty]
AvaloniaObject.this[IndexerDescriptor]
AvaloniaObject.Dispatcher
AvaloniaObject.PropertyChanged

Remarks

It covers the component's inside, and keeps what is drawn on it in a bitmap whatever the component's AutoRedraw, as large as the inside has been. Where AutoRedraw is False, the component raises Paint once the surface is shown, and each time its inside grows.

It draws as GDI does, with no smoothing. A point is placed on the pixel nearest its twips, rounded half to even. A line is drawn as a Line control draws it. A box covers both of its corners. Lines are dashed only where they are one pixel wide, and a fill's lines are eight pixels apart from the surface's corner. The component's DrawMode combines each pixel of a point, a line and a fill with the pixel under it, GDI's raster operation of that number: what is drawn there, or else the Picture's pixel over the BackColor.

A Picture set on the component erases what is drawn, and so does a BackColor set on a PictureBox, or a new BackColor on a form. CurrentX and CurrentY are kept.

While it is shown, Of(ComponentInstance) gives it for its component. It takes no input. From its creation, its component's scale follows ScaleRules.

Constructors

RDFormsDrawingLayer(ComponentInstance)

Creates the drawing surface of a form's root or a PictureBox.

public RDFormsDrawingLayer(ComponentInstance component)

Parameters

component ComponentInstance

The form's root or the PictureBox.

Exceptions

ArgumentNullException

component is null.

Properties

Component

The form's root or the PictureBox the surface draws for.

public ComponentInstance Component { get; }

Property Value

ComponentInstance

CurrentX

The horizontal position the next drawing starts from, in the component's scale. The point is kept in whole twips from the inside's top left corner: a value set is rounded to the nearest twip, and a change of scale keeps the point where it is. A new surface starts at the corner.

public double CurrentX { get; set; }

Property Value

double

CurrentY

The vertical position the next drawing starts from, in the component's scale, kept as CurrentX is.

public double CurrentY { get; set; }

Property Value

double

Inside

The size of its component's inside, in pixels.

public PixelSize Inside { get; }

Property Value

PixelSize

Picture

The picture drawn under the surface, at its size in pixels from the top left corner, or null for none. Its owner sets it as the component's Picture is decoded; Point and the raster operations read its pixels. Setting it erases nothing: the component's Picture set does.

public Bitmap? Picture { get; set; }

Property Value

Bitmap

Methods

Circle(GraphicsPoint, double, FormColor?, double?, double?, double?)

Draws a circle, an ellipse, an arc or a sector: VB's Circle statement.

public void Circle(GraphicsPoint centre, double radius, FormColor? color = null, double? start = null, double? end = null, double? aspect = null)

Parameters

centre GraphicsPoint

The centre.

radius double

The radius, in the component's horizontal units.

color FormColor?

The colour, or null for the component's ForeColor.

start double?

Where an arc starts, in radians counterclockwise from three o'clock, or null for 0. A negative angle also draws a radius to that end; with both negative, the sector is closed and filled.

end double?

Where an arc ends, as start, or null for 2π.

aspect double?

Its height over its width, or null for 1, a circle. Below 1 the radius is the horizontal one, and above 1 the vertical one.

Exceptions

FormErrorException

Error 5 where start or end is outside -2π to 2π.

Cls()

Clears what was drawn, and sets CurrentX and CurrentY to 0: VB's Cls method.

public void Cls()

Line(GraphicsPoint?, GraphicsPoint, FormColor?, LineBox)

Draws a line or a box: VB's Line statement.

public void Line(GraphicsPoint? from, GraphicsPoint to, FormColor? color = null, LineBox box = LineBox.None)

Parameters

from GraphicsPoint?

The first point, or null to start at CurrentX and CurrentY.

to GraphicsPoint

The second point. A relative one is measured from the first point.

color FormColor?

The colour, or null for the component's ForeColor.

box LineBox

Whether to draw the line, the box whose corners are the two points (filled as the component's FillStyle says), or the box filled with color.

OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is added to a rooted visual tree.

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is removed from a rooted visual tree.

protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

PSet(GraphicsPoint, FormColor?)

Draws a point: VB's PSet statement. A DrawWidth above 1 draws a dot that wide, centred on the point.

public void PSet(GraphicsPoint point, FormColor? color = null)

Parameters

point GraphicsPoint

The point.

color FormColor?

The colour, or null for the component's ForeColor.

PaintPicture(byte[], double, double, double?, double?, double?, double?, double?, double?, int)

Draws a picture, or a rectangle of it, stretched to a rectangle of the surface: VB's PaintPicture method.

public void PaintPicture(byte[] picture, double x1, double y1, double? width1 = null, double? height1 = null, double? x2 = null, double? y2 = null, double? width2 = null, double? height2 = null, int opcode = 13369376)

Parameters

picture byte[]

The picture, as its file holds it.

x1 double

The destination's left edge, in the component's scale.

y1 double

The destination's top edge, in the component's scale.

width1 double?

The destination's width, or null for the source's. A negative width mirrors the picture across.

height1 double?

The destination's height, or null for the source's. A negative height mirrors it down.

x2 double?

The source's left edge within the picture, in the component's horizontal units, or null for 0.

y2 double?

The source's top edge within the picture, in the component's vertical units, or null for 0.

width2 double?

The source's width, or null for the rest of the picture's width from x2. A negative width mirrors the source.

height2 double?

The source's height, or null for the rest of the picture's height from y2.

opcode int

The raster operation: GDI's ternary raster operation of the opcode's third byte, over the pattern, the source and what shows on the surface. vbSrcCopy (&HCC0020) unless said otherwise.

Remarks

The picture's size in the scale is its size at 96 pixels an inch. Every position is placed on the pixel nearest it. The destination covers width1 pixels from x1, rightward or, for a negative width, leftward from it; the source likewise. A destination pixel takes the source pixel under its centre. A part of the source outside the picture draws nothing, so the destination is cut in proportion; a transparent part of the picture shows what is under it.

The pattern is the component's fill: its FillColor where its FillStyle is Solid, and its FillColor lines over its BackColor where it is hatched. Where the FillStyle is Transparent, an opcode that reads the pattern draws nothing. The DrawMode, CurrentX, CurrentY and the component's Picture play no part and are kept.

Exceptions

FormErrorException

Error 481 where picture is empty or is not a picture. Error 6 where a position or a size is too large for a pixel. Error 5 where a width or a height is under half a pixel, or the source lies wholly left of or above the picture, or starts at its right or bottom edge; a source that starts past that edge draws nothing.

Point(double, double)

The colour at a point: VB's Point method.

public int Point(double x, double y)

Parameters

x double

The point's horizontal coordinate, in the component's scale.

y double

The point's vertical coordinate, in the component's scale.

Returns

int

The RGB colour drawn there, or else the pixel of the component's Picture there, or else its BackColor, as a VB colour (red in the low byte); -1 where the point is outside the component's inside.

Print(IReadOnlyList<PrintItem>, bool)

Prints an output list at the current point: VB's Print method.

public void Print(IReadOnlyList<PrintItem> items, bool endsLine = true)

Parameters

items IReadOnlyList<PrintItem>

The items, in order. An empty list prints nothing.

endsLine bool

Whether the list ends the line, as one with no ; or , at its end does: CurrentX then goes to the scale's 0 and CurrentY down a line. A list that ends with a comma ends with a PrintItem.Tab instead.

Remarks

The text is drawn in the component's Font and ForeColor, its top left corner at the current point, on the pixel nearest it. FontTransparent False fills each line's cell with the BackColor first. DrawMode does not apply to text.

A column is the font's average character width, and a print zone 14 columns. Columns and zones count from the scale's 0, and a position is moved to the pixel nearest it. A text item moves CurrentX to its end and CurrentY to the pixel it is drawn on. PrintItem.Spc moves on its columns, to the column boundary at or after that. PrintItem.Tab with a column moves to the column's start, or to its start on the next line where the current point is past it; with none, it moves to the next zone boundary past the current point.

Render(DrawingContext)

Renders the visual to a Avalonia.Media.DrawingContext.

public override void Render(DrawingContext context)

Parameters

context DrawingContext

The drawing context.

Scale()

Sets the component's scale back to twips from its inside corner: VB's Scale statement with no coordinates.

public void Scale()

Scale(double, double, double, double)

Sets a user scale on the component: VB's Scale (x1, y1)-(x2, y2). The first point is the inside's top left corner and the second its bottom right one.

public void Scale(double x1, double y1, double x2, double y2)

Parameters

x1 double

The left edge's coordinate.

y1 double

The top edge's coordinate.

x2 double

The right edge's coordinate.

y2 double

The bottom edge's coordinate.

TextHeight(string)

The height of a text in the component's Font: VB's TextHeight method.

public double TextHeight(string text)

Parameters

text string

The text. A carriage return, a line feed, or both together start a new line.

Returns

double

Its lines times the font's line height, in the component's vertical units; one line for an empty text.

TextWidth(string)

The width of a text in the component's Font: VB's TextWidth method.

public double TextWidth(string text)

Parameters

text string

The text. A carriage return, a line feed, or both together start a new line.

Returns

double

The width of its longest line, in the component's horizontal units; 0 for an empty text.