Show / Hide Table of Contents

Class ScreenObject

A generic object processed by SadConsole. Provides parent/child, components, and position.

Inheritance
object
ScreenObject
AnimatedScreenObject
Entity
Zone
ScreenSurface
SplashScreenManager
Implements
IScreenObject
IPositionable
IComponentHost
Inherited Members
object.GetType()
object.MemberwiseClone()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadConsole
Assembly: SadConsole.dll
Syntax
[DataContract]
[JsonObject(MemberSerialization.OptIn)]
public class ScreenObject : IScreenObject, IPositionable, IComponentHost

Constructors

ScreenObject()

Creates a new instance of this class.

Declaration
public ScreenObject()

Fields

ComponentsEmpty

A filtered list from SadComponents that is not set for update, render, mouse, or keyboard.

Declaration
protected List<IComponent> ComponentsEmpty
Field Value
Type Description
List<IComponent>

ComponentsKeyboard

A filtered list from SadComponents where IsKeyboard is true.

Declaration
protected List<IComponent> ComponentsKeyboard
Field Value
Type Description
List<IComponent>

ComponentsMouse

A filtered list from SadComponents where IsMouse is true.

Declaration
protected List<IComponent> ComponentsMouse
Field Value
Type Description
List<IComponent>

ComponentsRender

A filtered list from SadComponents where IsRender is true.

Declaration
protected List<IComponent> ComponentsRender
Field Value
Type Description
List<IComponent>

ComponentsUpdate

A filtered list from SadComponents where IsUpdate is true.

Declaration
protected List<IComponent> ComponentsUpdate
Field Value
Type Description
List<IComponent>

Properties

AbsolutePosition

A position that's based on the current Position, as interpreted by the implementing class, in pixels.

Declaration
public Point AbsolutePosition { get; protected set; }
Property Value
Type Description
Point
Remarks

Most objects will implement this property based on Position which usually depends on the Parent object's position.

Children

The child objects of this instance.

Declaration
public ScreenObjectCollection Children { get; protected set; }
Property Value
Type Description
ScreenObjectCollection

FocusedMode

How the object should handle becoming active.

Declaration
[DataMember]
public FocusBehavior FocusedMode { get; set; }
Property Value
Type Description
FocusBehavior

IgnoreParentPosition

When true, this object should ignore it's parent position when calculating AbsolutePosition; otherwise false.

Declaration
[DataMember]
public bool IgnoreParentPosition { get; set; }
Property Value
Type Description
bool

IsEnabled

Gets or sets the visibility of this object.

Declaration
[DataMember]
public bool IsEnabled { get; set; }
Property Value
Type Description
bool

IsExclusiveMouse

Gets or sets whether or not this object has exclusive access to the mouse events.

Declaration
[DataMember]
public bool IsExclusiveMouse { get; set; }
Property Value
Type Description
bool

IsFocused

Gets or sets this console as the focused object for input.

Declaration
public bool IsFocused { get; set; }
Property Value
Type Description
bool

IsVisible

Gets or sets the visibility of this object.

Declaration
[DataMember]
public bool IsVisible { get; set; }
Property Value
Type Description
bool

Parent

The parent object that this instance is a child of.

Declaration
public IScreenObject? Parent { get; set; }
Property Value
Type Description
IScreenObject

Position

A position that is based on the current Position and Parent position, in pixels.

Declaration
public Point Position { get; set; }
Property Value
Type Description
Point

SadComponents

A collection of components processed by this console.

Declaration
public ObservableCollection<IComponent> SadComponents { get; protected set; }
Property Value
Type Description
ObservableCollection<IComponent>

SortOrder

Indicates the sorting order this object should use when parented. Sorting is a manual operation on the Children collection.

Declaration
[DataMember]
public uint SortOrder { get; set; }
Property Value
Type Description
uint

UseKeyboard

When true, this object will use the keyboard; otherwise false.

Declaration
[DataMember]
public bool UseKeyboard { get; set; }
Property Value
Type Description
bool

UseMouse

When true, this object will use the mouse; otherwise false.

Declaration
[DataMember]
public bool UseMouse { get; set; }
Property Value
Type Description
bool

Methods

Components_FilterAddItem(IComponent, List<IComponent>, List<IComponent>, List<IComponent>, List<IComponent>, List<IComponent>)

Adds a component to the provided collections, based on its configuration.

Declaration
public static void Components_FilterAddItem(IComponent component, List<IComponent> componentsRender, List<IComponent> componentsUpdate, List<IComponent> componentsKeyboard, List<IComponent> componentsMouse, List<IComponent> componentsEmpty)
Parameters
Type Name Description
IComponent component

The component.

List<IComponent> componentsRender

The render collection.

List<IComponent> componentsUpdate

The update collection.

List<IComponent> componentsKeyboard

The keyboard collection.

List<IComponent> componentsMouse

The mouse collection.

List<IComponent> componentsEmpty

The empty collection.

Components_FilterRemoveItem(IComponent, List<IComponent>, List<IComponent>, List<IComponent>, List<IComponent>, List<IComponent>)

Removes a component to the provided collections, based on its configuration.

Declaration
public static void Components_FilterRemoveItem(IComponent component, List<IComponent> componentsRender, List<IComponent> componentsUpdate, List<IComponent> componentsKeyboard, List<IComponent> componentsMouse, List<IComponent> componentsEmpty)
Parameters
Type Name Description
IComponent component

The component.

List<IComponent> componentsRender

The render collection.

List<IComponent> componentsUpdate

The update collection.

List<IComponent> componentsKeyboard

The keyboard collection.

List<IComponent> componentsMouse

The mouse collection.

List<IComponent> componentsEmpty

The empty collection.

Components_Sort(List<IComponent>, List<IComponent>, List<IComponent>, List<IComponent>, List<IComponent>)

Helper to sort the components in the split collections.

Declaration
public static void Components_Sort(List<IComponent> componentsRender, List<IComponent> componentsUpdate, List<IComponent> componentsKeyboard, List<IComponent> componentsMouse, List<IComponent> componentsEmpty)
Parameters
Type Name Description
List<IComponent> componentsRender

The render collection.

List<IComponent> componentsUpdate

The update collection.

List<IComponent> componentsKeyboard

The keyboard collection.

List<IComponent> componentsMouse

The mouse collection.

List<IComponent> componentsEmpty

The empty collection.

GetSadComponent<TComponent>()

Gets the first component of the specified type.

Declaration
public TComponent? GetSadComponent<TComponent>() where TComponent : class, IComponent
Returns
Type Description
TComponent

The component if found, otherwise null.

Type Parameters
Name Description
TComponent

The component to find.

GetSadComponents<TComponent>()

Gets components of the specified types.

Declaration
public IEnumerable<TComponent> GetSadComponents<TComponent>() where TComponent : class, IComponent
Returns
Type Description
IEnumerable<TComponent>

The components found.

Type Parameters
Name Description
TComponent

The component to find

HasSadComponent<TComponent>(out TComponent?)

Indicates whether or not the component exists in the SadComponents collection.

Declaration
public bool HasSadComponent<TComponent>(out TComponent? component) where TComponent : class, IComponent
Parameters
Type Name Description
TComponent component
Returns
Type Description
bool

true when the component exists; otherwise false.

Type Parameters
Name Description
TComponent

The component to find.

LostMouse(MouseScreenObjectState)

Called when the mouse is being used by something else.

Declaration
public virtual void LostMouse(MouseScreenObjectState state)
Parameters
Type Name Description
MouseScreenObjectState state

The current state of the mouse based on this object.

OnEnabledChanged()

Called when the paused status of the object changes.

Declaration
protected virtual void OnEnabledChanged()

OnFocusLost()

Called when this object's focus has been lost.

Declaration
public virtual void OnFocusLost()

OnFocused()

Called when this object is focused.

Declaration
public virtual void OnFocused()

OnParentChanged(IScreenObject?, IScreenObject?)

Raises the ParentChanged event.

Declaration
protected virtual void OnParentChanged(IScreenObject? oldParent, IScreenObject? newParent)
Parameters
Type Name Description
IScreenObject oldParent

The previous parent.

IScreenObject newParent

The new parent.

OnPositionChanged(Point, Point)

Raises the PositionChanged event.

Declaration
protected virtual void OnPositionChanged(Point oldPosition, Point newPosition)
Parameters
Type Name Description
Point oldPosition

The previous position.

Point newPosition

The new position.

OnPositionChanging(Point, Point)

Raises the PositionChanging event.

Declaration
protected virtual void OnPositionChanging(Point oldPosition, Point newPosition)
Parameters
Type Name Description
Point oldPosition

The previous position.

Point newPosition

The new position.

OnSadComponentAdded(IComponent)

Called when a component is added to the SadComponents collection.

Declaration
protected virtual void OnSadComponentAdded(IComponent component)
Parameters
Type Name Description
IComponent component

The component added.

OnSadComponentRemoved(IComponent)

Called when a component is removed from the SadComponents collection.

Declaration
protected virtual void OnSadComponentRemoved(IComponent component)
Parameters
Type Name Description
IComponent component

The component removed.

OnSerializingMethod(StreamingContext)

Nothing.

Declaration
[OnSerializing]
protected void OnSerializingMethod(StreamingContext context)
Parameters
Type Name Description
StreamingContext context

Nothing.

OnVisibleChanged()

Called when the visibility of the object changes.

Declaration
protected virtual void OnVisibleChanged()

ProcessKeyboard(Keyboard)

Called by the engine to process the keyboard.

Declaration
public virtual bool ProcessKeyboard(Keyboard keyboard)
Parameters
Type Name Description
Keyboard keyboard

Keyboard information.

Returns
Type Description
bool

True when the keyboard had data and this console did something with it.

ProcessMouse(MouseScreenObjectState)

Processes the mouse.

Declaration
public virtual bool ProcessMouse(MouseScreenObjectState state)
Parameters
Type Name Description
MouseScreenObjectState state

The mouse state related to this object.

Returns
Type Description
bool

True when this object should halt further mouse processing..

Render(TimeSpan)

Draws all SadComponents and Children.

Declaration
public virtual void Render(TimeSpan delta)
Parameters
Type Name Description
TimeSpan delta

The time that has elapsed since the last call.

Remarks

Only processes if IsVisible is true.

SortComponents()

Sorts the components based on the SortOrder value.

Declaration
public void SortComponents()

ToString()

Returns the value "ScreenObject".

Declaration
public override string ToString()
Returns
Type Description
string

The string "ScreenObject".

Overrides
object.ToString()

Update(TimeSpan)

Updates all SadComponents and Children.

Declaration
public virtual void Update(TimeSpan delta)
Parameters
Type Name Description
TimeSpan delta

The time that has elapsed since the last call.

Remarks

Only processes if IsEnabled is true.

UpdateAbsolutePosition()

Sets a value for AbsolutePosition based on the Position of this instance and the Parent instance.

Declaration
public virtual void UpdateAbsolutePosition()

Events

FocusLost

Raised when the IsFocused property is false.

Declaration
public event EventHandler? FocusLost
Event Type
Type Description
EventHandler

Focused

Raised when the IsFocused property is true.

Declaration
public event EventHandler? Focused
Event Type
Type Description
EventHandler

IsEnabledChanged

Raised when the IsEnabled property changes.

Declaration
public event EventHandler? IsEnabledChanged
Event Type
Type Description
EventHandler

IsVisibleChanged

Raised when the IsVisible property changes.

Declaration
public event EventHandler? IsVisibleChanged
Event Type
Type Description
EventHandler

ParentChanged

Raised when the Parent property changes.

Declaration
public event EventHandler<ValueChangedEventArgs<IScreenObject?>>? ParentChanged
Event Type
Type Description
EventHandler<ValueChangedEventArgs<IScreenObject>>

PositionChanged

Declaration
public event EventHandler<ValueChangedEventArgs<Point>>? PositionChanged
Event Type
Type Description
EventHandler<ValueChangedEventArgs<Point>>

PositionChanging

Declaration
public event EventHandler<ValueChangedEventArgs<Point>>? PositionChanging
Event Type
Type Description
EventHandler<ValueChangedEventArgs<Point>>

Implements

IScreenObject
IPositionable
IComponentHost

Extension Methods

Keyboard.RemoveKeyboardHook(IScreenObject, Func<IScreenObject, Keyboard, bool>)
Keyboard.RemoveKeyboardHooks(IScreenObject)
Keyboard.WithKeyboard(IScreenObject, Func<IScreenObject, Keyboard, bool>)
Mouse.RemoveMouseHook(IScreenObject, Func<IScreenObject, MouseScreenObjectState, bool>)
Mouse.RemoveMouseHooks(IScreenObject)
Mouse.WithMouse(IScreenObject, Func<IScreenObject, MouseScreenObjectState, bool>)
Update.RemoveUpdateHook(IScreenObject, Action<IScreenObject, TimeSpan>)
Update.RemoveUpdateHooks(IScreenObject)
Update.WithUpdate(IScreenObject, Action<IScreenObject, TimeSpan>)
ExtensionsSystem.GetDebuggerDisplayValue(object)
In this article

Back to top

Back to top Generated by DocFX