Class DefaultContentRenderer<T>
A default implementation of a IContentRenderer.
Inherited Members
Namespace: Gorgon.Editor.Rendering
Assembly: Gorgon.Editor.API.dll
Syntax
public class DefaultContentRenderer<T> : GorgonNamedObject, IContentRenderer, IGorgonNamedObject, IDisposable where T : class, IVisualEditorContent
Type Parameters
Name | Description |
---|---|
T | The type of view model for the renderer. Must implement the IVisualEditorContent interface, and be a reference type. |
Remarks
This renderer does the bare minimum to present content on the view. Content plug in UI developers should inherit from this class to take advantage of the default functionality it provides.
The default renderer provides support for panning, and zooming on content and will animate those functions. Inherited renderers will receive these functions, but can override them as needed. The panning operation can activated by pressing CTRL + Middle mouse button, the scrollbars on the view control, or moving the mouse wheel (press Shift to move horizontally). Zooming can be activated by moving the mouse wheel while holding the CTRL key.
The panning and zooming operations (which were a pain in the ass to write) use a camera (a GorgonOrthoCamera) to apply the offsets and scaling for the pan/zoom operations. This camera is exposed to inherting classes through the Camera property and developers must pass this camera to the Gorgon2D.Begin(Gorgon2DBatchState, GorgonCameraCommon) method so that panning and zooming can be applied to the content. Conversely, the developer can opt not to use the camera and render directly to the client area should they so choose.
When applying the camera to your own custom content rendering the coordinate system will change to be in world space, meaning that the content will be relative to the center of the content dimensions. For example, if the content is 640x480, then 0x0 will be the center of the content, -320x-240 will be the upper left, and 320x240 will be the lower right. So rendering a sprite at 0x0 will put it in the center of the view.
Renderers will also receive access to the view model applied to the view, so the renderer can respond to changes on the content and adjust the visuals appropriately. The view model must implement the IVisualEditorContent interface before they can be used with a renderer.
Constructors
| Edit this page View SourceDefaultContentRenderer(string, Gorgon2D, GorgonSwapChain, T)
Initializes a new instance of the DefaultContentRenderer<T> class.
Declaration
protected DefaultContentRenderer(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
Properties
| Edit this page View SourceBackgroundColor
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
| Edit this page View SourceBackgroundPattern
Property to return the default texture used to draw the background.
Declaration
protected GorgonTexture2DView BackgroundPattern { get; }
Property Value
Type | Description |
---|---|
GorgonTexture2DView |
See Also
| Edit this page View SourceCamera
Property to return the camera used to control the content view.
Declaration
protected virtual GorgonOrthoCamera Camera { get; }
Property Value
Type | Description |
---|---|
GorgonOrthoCamera |
Remarks
The camera is responsible for panning and zooming on the content. Developers should pass this in to their Begin(Gorgon2DBatchState, GorgonCameraCommon) calls so that their content renders correctly.
This property can also be used to retrieve the current camera position on the view, and the current zoom value.
Plug in developers can override this property and return their own camera if necessary.
See Also
| Edit this page View SourceCanPanHorizontally
Property to set or return whether the content can be horizontally panned.
Declaration
public bool CanPanHorizontally { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceCanPanVertically
Property to set or return whether the content can be vertically panned.
Declaration
public bool CanPanVertically { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceCanZoom
Property to set or return whether the content can be zoomed.
Declaration
public bool CanZoom { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceClientSize
Property to return the size of the view client area.
Declaration
public Size2 ClientSize { get; }
Property Value
Type | Description |
---|---|
Size2 |
See Also
| Edit this page View SourceContentSize
Property to return the size of the content in camera space.
Declaration
public Size2F ContentSize { get; }
Property Value
Type | Description |
---|---|
Size2F |
See Also
| Edit this page View SourceDataContext
Property to return the data context assigned to this view.
Declaration
public T DataContext { get; }
Property Value
Type | Description |
---|---|
T |
See Also
| Edit this page View SourceFonts
Property to return the font factory used to generate fonts for the renderer.
Declaration
protected GorgonFontFactory Fonts { get; }
Property Value
Type | Description |
---|---|
GorgonFontFactory |
See Also
| Edit this page View SourceGraphics
Property to return the graphics interface used to create graphics objects.
Declaration
protected GorgonGraphics Graphics { get; }
Property Value
Type | Description |
---|---|
GorgonGraphics |
See Also
| Edit this page View SourceIsEnabled
Property to set or return whether the renderer is enabled.
Declaration
public bool IsEnabled { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceMainRenderTarget
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
| Edit this page View SourceOffset
Property to return the offset of the image.
Declaration
public Vector2 Offset { get; }
Property Value
Type | Description |
---|---|
Vector2 |
See Also
| Edit this page View SourcePixelFormat
Property to return the pixel format for the view.
Declaration
protected BufferFormat PixelFormat { get; }
Property Value
Type | Description |
---|---|
BufferFormat |
See Also
| Edit this page View SourceRenderRegion
Property to set or return the region to render into.
Declaration
public RectangleF RenderRegion { get; protected set; }
Property Value
Type | Description |
---|---|
RectangleF |
Remarks
Developers can set this value to constrain where the content and the background are drawn on the view. This value does not have any scaling or offsetting applied and is always in the same space as the the client area in the view.
If an empty rectangle is passed to this property, then the full client area of the view is used.
See Also
| Edit this page View SourceRenderer
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
| Edit this page View SourceZoom
Property to return the current zoom level.
Declaration
public float Zoom { get; }
Property Value
Type | Description |
---|---|
float |
See Also
| Edit this page View SourceZoomLevel
Property to return the current zoom level.
Declaration
public ZoomLevels ZoomLevel { get; protected set; }
Property Value
Type | Description |
---|---|
ZoomLevels |
See Also
Methods
| Edit this page View SourceCenterView()
Function to center the view.
Declaration
public void CenterView()
See Also
| Edit this page View SourceDispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
See Also
| Edit this page View SourceDispose(bool)
Releases unmanaged and - optionally - managed resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
|
See Also
| Edit this page View SourceForceMoveTo(Vector2, float, bool)
Function to move the camera to the offset position, and, optionally, the zoom to the offset.
Declaration
protected void ForceMoveTo(Vector2 offset, float zoom, bool ignoreBoundaries)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | offset | The offset to apply to the view, in client space. |
float | zoom | The amount to zoom, normalized percentage (1 = 100%, 0.5 = 50%, 4 = 400%, etc...). |
bool | ignoreBoundaries | true to ignore the region boundaries, false to respect them. |
Remarks
This method animates the camera to move it to a location on the content, with an optional zoom scale value. To put the camera at a desired location without zooming, or animation use the SetOffset(Vector2) method.
To zoom to the current window size, set the zoom
value to less than or equal to 0.
See Also
| Edit this page View SourceGetNearestZoomFromRectangle(RectangleF)
Function to retrieve the nearest zoom level that fits within the specified rectangle.
Declaration
protected ZoomLevels GetNearestZoomFromRectangle(RectangleF region)
Parameters
Type | Name | Description |
---|---|---|
RectangleF | region | The region to zoom in on. |
Returns
Type | Description |
---|---|
ZoomLevels | The zoom level value needed to fit within the content window. |
See Also
| Edit this page View SourceGetZoomValue(float)
Function to adjust a zoom value based on the input zoom value.
Declaration
protected virtual float GetZoomValue(float requestedZoom)
Parameters
Type | Name | Description |
---|---|---|
float | requestedZoom | The zoom value to adjust. |
Returns
Type | Description |
---|---|
float | The adjusted zoom value. |
Remarks
Developers can override this method to update the requestedZoom
value so that it conforms to the UI workflow. By default it adjusts the requestedZoom
value
to snap to the ZoomLevels values.
See Also
| Edit this page View SourceLoadResources()
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
| Edit this page View SourceMoveTo(Vector2, float)
Function to move the camera to the offset position, and, optionally, the zoom to the offset.
Declaration
public void MoveTo(Vector2 offset, float zoom)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | offset | The offset to apply to the view, in client space. |
float | zoom | The amount to zoom, normalized percentage (1 = 100%, 0.5 = 50%, 4 = 400%, etc...). |
Remarks
This method animates the camera to move it to a location on the content, with an optional zoom scale value. To put the camera at a desired location without zooming, or animation use the SetOffset(Vector2) method.
To zoom to the current window size, set the zoom
value to less than or equal to 0.
See Also
| Edit this page View SourceOnCameraMoved()
Function called when the camera is panned.
Declaration
protected virtual void OnCameraMoved()
Remarks
Developers can override this method to implement a custom action when the camera is panned around the view.
See Also
| Edit this page View SourceOnCameraZoomed()
Function called when the camera is zoomed.
Declaration
protected virtual void OnCameraZoomed()
Remarks
Developers can override this method to implement a custom action when the camera is zoomed in or out.
See Also
| Edit this page View SourceOnCenterView()
Function to center the view.
Declaration
protected virtual void OnCenterView()
Remarks
Developers can override this method to provide custom centering of the view. The default is to zoom to the current client size of the window.
See Also
| Edit this page View SourceOnKeyDown(KeyEventArgs)
Function to handle a key down event.
Declaration
protected virtual void OnKeyDown(KeyEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
KeyEventArgs | args | The arguments for the event. |
Remarks
Developers can override this method to handle a key down event in their own content view.
See Also
| Edit this page View SourceOnKeyUp(KeyEventArgs)
Function to handle a key updown event.
Declaration
protected virtual void OnKeyUp(KeyEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
KeyEventArgs | args | The arguments for the event. |
Remarks
Developers can override this method to handle a key up event in their own content view.
See Also
| Edit this page View SourceOnLoad()
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
| Edit this page View SourceOnMouseDown(MouseArgs)
Function to handle a mouse down event.
Declaration
protected virtual void OnMouseDown(MouseArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseArgs | args | The arguments for the event. |
Remarks
Developers can override this method to handle a mouse down event in their own content view.
See Also
| Edit this page View SourceOnMouseMove(MouseArgs)
Function to handle a mouse move event.
Declaration
protected virtual void OnMouseMove(MouseArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseArgs | args | The arguments for the event. |
Remarks
Developers can override this method to handle a mouse move event in their own content view.
See Also
| Edit this page View SourceOnMouseUp(MouseArgs)
Function to handle a mouse up event.
Declaration
protected virtual void OnMouseUp(MouseArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseArgs | args | The arguments for the event. |
Remarks
Developers can override this method to handle a mouse up event in their own content view.
See Also
| Edit this page View SourceOnMouseWheel(MouseArgs)
Function to handle a mouse wheel event.
Declaration
protected virtual void OnMouseWheel(MouseArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseArgs | args | The arguments for the event. |
Remarks
Developers can override this method to handle a mouse wheel event in their own content view.
See Also
| Edit this page View SourceOnPreviewKeyDown(PreviewKeyDownEventArgs)
Function to handle a preview key down event.
Declaration
protected virtual void OnPreviewKeyDown(PreviewKeyDownEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
PreviewKeyDownEventArgs | args | The arguments for the event. |
Remarks
Developers can override this method to handle a preview key down event in their own content view.
See Also
| Edit this page View SourceOnPropertyChanged(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
| Edit this page View SourceOnPropertyChanging(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
| Edit this page View SourceOnRenderBackground()
Function to render the background.
Declaration
protected virtual void OnRenderBackground()
Remarks
Developers can override this method to render a custom background.
See Also
| Edit this page View SourceOnRenderContent()
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
| Edit this page View SourceOnResizeBegin()
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
| Edit this page View SourceOnResizeEnd()
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
| Edit this page View SourceOnUnload()
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
| Edit this page View SourceRender()
Function to render the content.
Declaration
public void Render()
Remarks
This method is called by the view to render the content.
See Also
| Edit this page View SourceSetOffset(Vector2)
Function to set the offset of the view.
Declaration
public void SetOffset(Vector2 offset)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | offset | The offset to apply to the view. |
See Also
| Edit this page View SourceSetZoom(float)
Function to set the zoom on the view.
Declaration
public void SetZoom(float zoom)
Parameters
Type | Name | Description |
---|---|---|
float | zoom | The zoom value to apply. |
See Also
| Edit this page View SourceToCamera(RectangleF, Size2?)
Function to convert a rectangle into camera space from client space.
Declaration
protected RectangleF ToCamera(RectangleF rect, Size2? targetSize = null)
Parameters
Type | Name | Description |
---|---|---|
RectangleF | rect | The client space rectangle |
Size2? | targetSize | The size of the render target. |
Returns
Type | Description |
---|---|
RectangleF | The camera space rectangle. |
Remarks
If the targetSize
is omitted, then the current render target at slot 0 in RenderTargets will be used.
See Also
| Edit this page View SourceToCamera(Size2F, Size2?)
Function to convert a size into camera space from client space.
Declaration
protected Size2F ToCamera(Size2F size, Size2? targetSize = null)
Parameters
Type | Name | Description |
---|---|---|
Size2F | size | The client space size. |
Size2? | targetSize | The size of the render target. |
Returns
Type | Description |
---|---|
Size2F | The camera space size. |
Remarks
If the targetSize
is omitted, then the current render target at slot 0 in RenderTargets will be used.
See Also
| Edit this page View SourceToCamera(Vector2, Size2?)
Function to convert a vector into camera space from client space.
Declaration
protected Vector2 ToCamera(Vector2 vector, Size2? targetSize = null)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The client space vector. |
Size2? | targetSize | [Optional] The size of the render target. |
Returns
Type | Description |
---|---|
Vector2 | The camera space vector. |
Remarks
If the targetSize
is omitted, then the current render target at slot 0 in RenderTargets will be used.
See Also
| Edit this page View SourceToClient(RectangleF, Size2?)
Function to convert a rectangle into client space from camera space.
Declaration
protected RectangleF ToClient(RectangleF rect, Size2? targetSize = null)
Parameters
Type | Name | Description |
---|---|---|
RectangleF | rect | The camera space rectangle |
Size2? | targetSize | The size of the render target. |
Returns
Type | Description |
---|---|
RectangleF | The client space rectangle. |
Remarks
If the targetSize
is omitted, then the current render target at slot 0 in RenderTargets will be used.
See Also
| Edit this page View SourceToClient(Size2F, Size2?)
Function to convert a size into client space from camera space.
Declaration
protected Size2F ToClient(Size2F size, Size2? targetSize = null)
Parameters
Type | Name | Description |
---|---|---|
Size2F | size | The camera space size. |
Size2? | targetSize | The size of the render target. |
Returns
Type | Description |
---|---|
Size2F | The client space size. |
Remarks
If the targetSize
is omitted, then the current render target at slot 0 in RenderTargets will be used.
See Also
| Edit this page View SourceToClient(Vector2, Size2?)
Function to convert a vector into client space from camera space.
Declaration
protected Vector2 ToClient(Vector2 vector, Size2? targetSize = null)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The camera space vector. |
Size2? | targetSize | The size of the render target. |
Returns
Type | Description |
---|---|
Vector2 | The client space vector. |
Remarks
If the targetSize
is omitted, then the current render target at slot 0 in RenderTargets will be used.
See Also
| Edit this page View SourceUnloadResources()
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.