Class AnimatedScreenObject
A ScreenObject that displays an animated set of ICellSurface surfaces.
Inherited Members
Namespace: SadConsole
Assembly: SadConsole.dll
Syntax
[DataContract]
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class AnimatedScreenObject : ScreenObject, IScreenSurface, IScreenObject, IPositionable, IComponentHost
Constructors
AnimatedScreenObject(string, IFont, Point, IEnumerable<ICellSurface>)
Declaration
[JsonConstructor]
public AnimatedScreenObject(string name, IFont font, Point fontSize, IEnumerable<ICellSurface> frames)
Parameters
Type | Name | Description |
---|---|---|
string | name | |
IFont | font | |
Point | fontSize | |
IEnumerable<ICellSurface> | frames |
AnimatedScreenObject(string, IEnumerable<ICellSurface>)
Creates a new animation with the specified name and frames.
Declaration
public AnimatedScreenObject(string name, IEnumerable<ICellSurface> frames)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the animation. |
IEnumerable<ICellSurface> | frames | The frames that make up the animation. |
AnimatedScreenObject(string, int, int)
Creates a new animation with the specified name, width, and height.
Declaration
public AnimatedScreenObject(string name, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the animation. |
int | width | The width of each frame this animation will have. |
int | height | The height of each frame this animation will have. |
AnimatedScreenObject(string, int, int, IFont, Point)
Creates a new animation with the specified name, width, and height.
Declaration
public AnimatedScreenObject(string name, int width, int height, IFont font, Point fontSize)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the animation. |
int | width | The width of each frame this animation will have. |
int | height | The height of each frame this animation will have. |
IFont | font | The font used with this animation. |
Point | fontSize | The size of the font. |
Fields
AddedTime
Time counter for the animation
Declaration
protected TimeSpan AddedTime
Field Value
Type | Description |
---|---|
TimeSpan |
CurrentFrameIndexValue
The current frame index being animated.
Declaration
protected int CurrentFrameIndexValue
Field Value
Type | Description |
---|---|
int |
IsMouseOver
Indicates that the mouse is currently over this console.
Declaration
protected bool IsMouseOver
Field Value
Type | Description |
---|---|
bool |
NewFrameHeight
The height to assign a frame when CreateFrame() is called.
Declaration
[DataMember]
protected int NewFrameHeight
Field Value
Type | Description |
---|---|
int |
NewFrameWidth
The width to assign a frame when CreateFrame() is called.
Declaration
[DataMember]
protected int NewFrameWidth
Field Value
Type | Description |
---|---|
int |
TimePerFrame
How much time per animated frame should be used.
Declaration
protected TimeSpan TimePerFrame
Field Value
Type | Description |
---|---|
TimeSpan |
Properties
AbsoluteArea
The pixel area on the screen this surface occupies.
Declaration
public Rectangle AbsoluteArea { get; }
Property Value
Type | Description |
---|---|
Rectangle |
AnimationDuration
The length of the animation.
Declaration
[DataMember]
public TimeSpan AnimationDuration { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
Center
Center of the animation used in positioning.
Declaration
[DataMember]
public Point Center { get; set; }
Property Value
Type | Description |
---|---|
Point |
CurrentFrame
Gets the current animation frame surface. A shortcut for
Frames[CurrentFrameIndex]
Declaration
public ICellSurface CurrentFrame { get; }
Property Value
Type | Description |
---|---|
ICellSurface |
CurrentFrameIndex
Gets or sets the current frame index to animate.
Declaration
public int CurrentFrameIndex { get; set; }
Property Value
Type | Description |
---|---|
int |
DefaultRendererName
The name of the default renderer for this object.
Declaration
public virtual string DefaultRendererName { get; }
Property Value
Type | Description |
---|---|
string |
FocusOnMouseClick
When true, this object will set IsFocused to true when the mouse is clicked.
Declaration
[DataMember]
public bool FocusOnMouseClick { get; set; }
Property Value
Type | Description |
---|---|
bool |
Font
Font used with rendering.
Declaration
public IFont Font { get; set; }
Property Value
Type | Description |
---|---|
IFont |
FontSize
The size of the Font cells applied to the object when rendering.
Declaration
public Point FontSize { get; set; }
Property Value
Type | Description |
---|---|
Point |
ForceRendererRefresh
Declaration
public bool ForceRendererRefresh { get; set; }
Property Value
Type | Description |
---|---|
bool |
Frames
The frames of the animated surface.
Declaration
[DataMember]
public List<ICellSurface> Frames { get; }
Property Value
Type | Description |
---|---|
List<ICellSurface> |
Height
The total height of the console.
Declaration
public int Height { get; }
Property Value
Type | Description |
---|---|
int |
HeightPixels
The height of the surface in pixels.
Declaration
public int HeightPixels { get; }
Property Value
Type | Description |
---|---|
int |
IsDirty
Declaration
public bool IsDirty { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsEmpty
Indicates the animation is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
IsPlaying
When true, Indicates the animation is currently animating. The Update(TimeSpan) method will advance the frames.
Declaration
[DataMember]
public bool IsPlaying { get; protected set; }
Property Value
Type | Description |
---|---|
bool |
MoveToFrontOnMouseClick
When true, this object will move to the front of its parent object when the mouse is clicked.
Declaration
[DataMember]
public bool MoveToFrontOnMouseClick { get; set; }
Property Value
Type | Description |
---|---|
bool |
Name
Gets the name of this animation.
Declaration
[DataMember]
public string Name { get; set; }
Property Value
Type | Description |
---|---|
string |
Renderer
The renderer used to draw this surface.
Declaration
[DataMember]
[JsonConverter(typeof(RendererJsonConverter))]
public IRenderer? Renderer { get; set; }
Property Value
Type | Description |
---|---|
IRenderer |
Repeat
Indicates whether or not this animation will repeat once it has finished animating.
Declaration
[DataMember]
public bool Repeat { get; set; }
Property Value
Type | Description |
---|---|
bool |
State
Gets the current animation state.
Declaration
public AnimatedScreenObject.AnimationState State { get; set; }
Property Value
Type | Description |
---|---|
AnimatedScreenObject.AnimationState |
Tint
A tint used in rendering.
Declaration
public Color Tint { get; set; }
Property Value
Type | Description |
---|---|
Color |
UsePixelPositioning
Treats the Position of the object as if it is pixels and not cells.
Declaration
public bool UsePixelPositioning { get; set; }
Property Value
Type | Description |
---|---|
bool |
ViewHeight
Gets or sets the visible height of the surface in cells.
Declaration
public int ViewHeight { get; set; }
Property Value
Type | Description |
---|---|
int |
ViewPosition
The position of the view within the console.
Declaration
public Point ViewPosition { get; set; }
Property Value
Type | Description |
---|---|
Point |
ViewWidth
Gets or sets the visible width of the surface in cells.
Declaration
public int ViewWidth { get; set; }
Property Value
Type | Description |
---|---|
int |
Width
The total width of the console.
Declaration
public int Width { get; }
Property Value
Type | Description |
---|---|
int |
WidthPixels
The width of the surface in pixels.
Declaration
public int WidthPixels { get; }
Property Value
Type | Description |
---|---|
int |
Methods
CreateFrame()
Creates a new frame with the same dimensions as this entity and adds it to the Frames collection of the entity.
Declaration
public ICellSurface CreateFrame()
Returns
Type | Description |
---|---|
ICellSurface | The created frame. |
CreateStatic(int, int, int, double, Color?, Color?)
Creates an animated surface that looks like static noise.
Declaration
public static AnimatedScreenObject CreateStatic(int width, int height, int frames, double blankChance, Color? background = null, Color? foreground = null)
Parameters
Type | Name | Description |
---|---|---|
int | width | The width of the surface. |
int | height | The height of the surface. |
int | frames | How many frames the animation should have. |
double | blankChance | Chance a character will be blank. Characters are between index 48-158. Chance is evaluated versus NextDouble(). |
Color? | background | The background color of the animation. Defaults to transparent. |
Color? | foreground | The foreground color of the animation. Defaults to white. |
Returns
Type | Description |
---|---|
AnimatedScreenObject | An animation. |
Dispose()
Declaration
public void Dispose()
Dispose(bool)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
~AnimatedScreenObject()
Disposes Renderer.
Declaration
protected ~AnimatedScreenObject()
FromImage(string, string, Point, TimeSpan, Point?, Point?, IFont?, Action<ColoredGlyphBase>?, TextureConvertMode, TextureConvertForegroundStyle, TextureConvertBackgroundStyle)
Converts an image file containing frames to an instance of AnimatedScreenObject.
Declaration
public static AnimatedScreenObject FromImage(string name, string filePath, Point frameLayout, TimeSpan frameDuration, Point? pixelPadding = null, Point? frameStartAndFinish = null, IFont? font = null, Action<ColoredGlyphBase>? action = null, TextureConvertMode convertMode = TextureConvertMode.Foreground, TextureConvertForegroundStyle convertForegroundStyle = TextureConvertForegroundStyle.Block, TextureConvertBackgroundStyle convertBackgroundStyle = TextureConvertBackgroundStyle.Pixel)
Parameters
Type | Name | Description |
---|---|---|
string | name | Name for the animation. |
string | filePath | File path to the image file. |
Point | frameLayout | Layout of frames in the image file: X number of columns, Y number of rows. |
TimeSpan | frameDuration | Duration for a frame in the animation. |
Point? | pixelPadding | Pixel padding separating frames: X between the columns, Y between the rows. |
Point? | frameStartAndFinish | Limits the number of frames copied to the animation. X first frame index, Y last frame index. |
IFont | font | IFont to be used when creating the AnimatedScreenObject. |
Action<ColoredGlyphBase> | action | Callback that will be applied to each ColoredGlyphBase when creating a frame. |
TextureConvertMode | convertMode | The mode used when converting the texture to a surface. |
TextureConvertForegroundStyle | convertForegroundStyle | The style to use when |
TextureConvertBackgroundStyle | convertBackgroundStyle | The style to use when |
Returns
Type | Description |
---|---|
AnimatedScreenObject | An instance of AnimatedScreenObject with converted frames. |
Remarks
This method assumes the image file contains only frames and optional padding between the frames, no border space.
Frame count is calculated by multiplying rows and columns from the frame layout. It can by limited by specifying frame start and finish indexes.
Frame size and the subsequent AnimatedScreenSurface size is calculated from the size of the image file, number of frames, padding and the font size ratio.
Load(string)
Loads a AnimatedScreenObject from a file.
Declaration
public static AnimatedScreenObject Load(string file)
Parameters
Type | Name | Description |
---|---|---|
string | file | The source file. |
Returns
Type | Description |
---|---|
AnimatedScreenObject | The animated surface. |
LostMouse(MouseScreenObjectState)
Called when the mouse is being used by something else.
Declaration
public override void LostMouse(MouseScreenObjectState state)
Parameters
Type | Name | Description |
---|---|---|
MouseScreenObjectState | state | The current state of the mouse based on this object. |
Overrides
OnMouseEnter(MouseScreenObjectState)
Raises the MouseEnter event.
Declaration
protected virtual void OnMouseEnter(MouseScreenObjectState state)
Parameters
Type | Name | Description |
---|---|---|
MouseScreenObjectState | state | Current mouse state in relation to this console. |
OnMouseExit(MouseScreenObjectState)
Raises the MouseExit event.
Declaration
protected virtual void OnMouseExit(MouseScreenObjectState state)
Parameters
Type | Name | Description |
---|---|---|
MouseScreenObjectState | state | Current mouse state in relation to this console. |
OnMouseLeftClicked(MouseScreenObjectState)
Raises the MouseButtonClicked event. Possibly moves the console to the top of it's parent's children collection.
Declaration
protected virtual void OnMouseLeftClicked(MouseScreenObjectState state)
Parameters
Type | Name | Description |
---|---|---|
MouseScreenObjectState | state | Current mouse state in relation to this console. |
OnMouseMove(MouseScreenObjectState)
Raises the MouseMove event.
Declaration
protected virtual void OnMouseMove(MouseScreenObjectState state)
Parameters
Type | Name | Description |
---|---|---|
MouseScreenObjectState | state | Current mouse state in relation to this console. |
OnRightMouseClicked(MouseScreenObjectState)
Raises the MouseButtonClicked event.
Declaration
protected virtual void OnRightMouseClicked(MouseScreenObjectState state)
Parameters
Type | Name | Description |
---|---|---|
MouseScreenObjectState | state | Current mouse state in relation to this console. |
ProcessMouse(MouseScreenObjectState)
Processes the mouse.
Declaration
public override 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.. |
Overrides
Render(TimeSpan)
Draws the animation's current frame and all SadComponents and Children.
Declaration
public override void Render(TimeSpan delta)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | delta | The time that has elapsed since the last call. |
Overrides
Restart()
Restarts the animation from the first frame.
Declaration
public void Restart()
Save(string)
Saves the AnimatedScreenObject to a file.
Declaration
public void Save(string file)
Parameters
Type | Name | Description |
---|---|---|
string | file | The destination file. |
Start()
Starts animating the frames.
Declaration
public void Start()
Stop()
Stops animating.
Declaration
public void Stop()
ToString()
Returns the value "ScreenSurface".
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The string "ScreenSurface". |
Overrides
Update(TimeSpan)
Updates the AnimatedScreenObject effects and all SadComponents and Children.
Declaration
public override void Update(TimeSpan delta)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | delta | The time that has elapsed since this method was last called. |
Overrides
UpdateAbsolutePosition()
Sets a value for AbsolutePosition based on the Position of this instance and the Parent instance.
Declaration
public override void UpdateAbsolutePosition()
Overrides
Events
AnimationStateChanged
Raised when the AnimatedScreenObject.AnimationState changes.
Declaration
public event EventHandler<AnimatedScreenObject.AnimationStateChangedEventArgs>? AnimationStateChanged
Event Type
Type | Description |
---|---|
EventHandler<AnimatedScreenObject.AnimationStateChangedEventArgs> |
MouseButtonClicked
Raised when the a mouse button is clicked on this object.
Declaration
public event EventHandler<MouseScreenObjectState>? MouseButtonClicked
Event Type
Type | Description |
---|---|
EventHandler<MouseScreenObjectState> |
MouseEnter
Raised when the mouse enters this object.
Declaration
public event EventHandler<MouseScreenObjectState>? MouseEnter
Event Type
Type | Description |
---|---|
EventHandler<MouseScreenObjectState> |
MouseExit
Raised when the mouse exits this object.
Declaration
public event EventHandler<MouseScreenObjectState>? MouseExit
Event Type
Type | Description |
---|---|
EventHandler<MouseScreenObjectState> |
MouseMove
Raised when the mouse moves around the this object.
Declaration
public event EventHandler<MouseScreenObjectState>? MouseMove
Event Type
Type | Description |
---|---|
EventHandler<MouseScreenObjectState> |