Gorgon
Show / Hide Table of Contents

Class DefaultToolRenderer<T>

A default implementation of a IToolRenderer.

Inheritance
object
GorgonNamedObject
DefaultToolRenderer<T>
Implements
IToolRenderer
IGorgonNamedObject
IDisposable
Inherited Members
GorgonNamedObject.GetHashCode()
GorgonNamedObject.ToString()
GorgonNamedObject.Name
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Editor.Rendering
Assembly: Gorgon.Editor.API.dll
Syntax
public class DefaultToolRenderer<T> : GorgonNamedObject, IToolRenderer, IGorgonNamedObject, IDisposable where T : class, IEditorTool
Type Parameters
Name Description
T

The type of view model for the renderer. Must implement the IEditorTool interface, and be a reference type.

Remarks

This renderer does the bare minimum to present content on the view. Tool plug in UI developers should inherit from this class to take advantage of the default functionality it provides.

The default renderer provides basic support for rendering tool specific content.

Renderers will also receive access to the view model applied to the view, so the renderer can respond to changes on the tool UI and adjust the visuals appropriately. The view model must implement the IEditorTool interface before they can be used with a renderer.

Constructors

| Edit this page View Source

DefaultToolRenderer(string, Gorgon2D, GorgonSwapChain, T)

Initializes a new instance of the DefaultToolRenderer<T> class.

Declaration
protected DefaultToolRenderer(string name, Gorgon2D renderer, GorgonSwapChain swapChain, T dataContext)
Parameters
Type Name Description
string name

The name of the renderer.

Gorgon2D renderer

The main renderer for the content view.

GorgonSwapChain swapChain

The swap chain for the content view.

T dataContext

The view model to assign to the renderer.

See Also
IToolRenderer
IEditorTool
Gorgon2D

Properties

| Edit this page View Source

BackgroundColor

Property to set or return the color to use when clearing the swap chain.

Declaration
public GorgonColor BackgroundColor { get; set; }
Property Value
Type Description
GorgonColor
Remarks

This value defaults to the background color of the view.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

BackgroundPattern

Property to return the default texture used to draw the background.

Declaration
protected GorgonTexture2DView BackgroundPattern { get; }
Property Value
Type Description
GorgonTexture2DView
See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

ClientSize

Property to return the size of the view client area.

Declaration
public Size2 ClientSize { get; }
Property Value
Type Description
Size2
See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

DataContext

Property to return the data context assigned to this view.

Declaration
public T DataContext { get; }
Property Value
Type Description
T
See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

Graphics

Property to return the graphics interface used to create graphics objects.

Declaration
protected GorgonGraphics Graphics { get; }
Property Value
Type Description
GorgonGraphics
See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

IsEnabled

Property to set or return whether the renderer is enabled.

Declaration
public bool IsEnabled { get; set; }
Property Value
Type Description
bool
See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

MainRenderTarget

Property to return the primary render target.

Declaration
protected GorgonRenderTarget2DView MainRenderTarget { get; }
Property Value
Type Description
GorgonRenderTarget2DView
Remarks

Developers can use this property to reset the render target back to the original target after rendering to another target.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

PixelFormat

Property to return the pixel format for the view.

Declaration
protected BufferFormat PixelFormat { get; }
Property Value
Type Description
BufferFormat
See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

Renderer

Property to return the 2D renderer used to draw onto the content view.

Declaration
protected Gorgon2D Renderer { get; }
Property Value
Type Description
Gorgon2D
See Also
IToolRenderer
IEditorTool
Gorgon2D

Methods

| Edit this page View Source

CalculateScaling(Size2F, Size2F)

Function to calculate scaling to the specified size, bounded by the client area of the rendering control.

Declaration
protected float CalculateScaling(Size2F size, Size2F windowSize)
Parameters
Type Name Description
Size2F size

The size of the area to zoom into.

Size2F windowSize

The size of the window.

Returns
Type Description
float

The scaling factor to apply.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()
See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

Dispose(bool)

Releases unmanaged and - optionally - managed resources.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

true to release both managed and unmanaged resources; false to release only unmanaged resources.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

LoadResources()

Function to load resources for the renderer.

Declaration
public void LoadResources()
Remarks

This method is used to load any required temporary resources for the renderer prior to rendering content. This must be paired with a call to UnloadResources() when the renderer is no longer in use to ensure efficient memory usage.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

OnLoad()

Function called when the renderer needs to load any resource data.

Declaration
protected virtual void OnLoad()
Remarks

Developers can override this method to set up their own resources specific to their renderer. Any resources set up in this method should be cleaned up in the associated OnUnload() method.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

OnPropertyChanged(string)

Function called when a property on the DataContext has been changed.

Declaration
protected virtual void OnPropertyChanged(string propertyName)
Parameters
Type Name Description
string propertyName

The name of the property that was changed.

Remarks

Developers should override this method to detect changes on the content view model and reflect those changes in the rendering.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

OnPropertyChanging(string)

Function called when a property on the DataContext is changing.

Declaration
protected virtual void OnPropertyChanging(string propertyName)
Parameters
Type Name Description
string propertyName

The name of the property that is changing.

Remarks

Developers should override this method to detect changes on the content view model and reflect those changes in the rendering.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

OnRenderBackground()

Function to render the background.

Declaration
protected virtual void OnRenderBackground()
Remarks

Developers can override this method to render a custom background.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

OnRenderContent()

Function to render the content.

Declaration
protected virtual void OnRenderContent()
Remarks

This is the method that developers should override in order to draw their content to the view.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

OnResizeBegin()

Function called when the view is about to be resized.

Declaration
protected virtual void OnResizeBegin()
Remarks

Developers can override this method to handle cases where the view window is resized and the content has size dependent data (e.g. render targets).

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

OnResizeEnd()

Function called when the view has been resized.

Declaration
protected virtual void OnResizeEnd()
Remarks

Developers can override this method to handle cases where the view window is resized and the content has size dependent data (e.g. render targets).

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

OnUnload()

Function called when the renderer needs to clean up any resource data.

Declaration
protected virtual void OnUnload()
Remarks

Developers should always override this method if they've overridden the OnLoad() method. Failure to do so can cause memory leakage.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

Render()

Function to render the content.

Declaration
public void Render()
Remarks

This method is called by the view to render the content.

See Also
IToolRenderer
IEditorTool
Gorgon2D
| Edit this page View Source

UnloadResources()

Function to unload resources from the renderer.

Declaration
public void UnloadResources()
Remarks

This method is used to unload temporary resources for the renderer when it is no longer needed. Failure to call this may result in memory leakage.

See Also
IToolRenderer
IEditorTool
Gorgon2D

Implements

IToolRenderer
IGorgonNamedObject
IDisposable

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)

See Also

IToolRenderer
IEditorTool
Gorgon2D
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author