Open 3D Engine LyShine Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
IDraw2d Class Referenceabstract

Class for 2D drawing in screen space. More...

#include <IDraw2d.h>

Inherited by CDraw2d.

Classes

struct  ImageOptions
 Struct used to pass additional image options. More...
 
struct  RenderState
 
struct  TextOptions
 Struct used to pass additional text options - mostly ones that do not change from call to call. More...
 
struct  VertexPosColUV
 Used to pass in arrays of vertices (e.g. to DrawQuad) More...
 

Public Types

enum class  HAlign { Left , Center , Right }
 Horizontal alignment can be used for both text and image drawing.
 
enum class  VAlign { Top , Center , Bottom }
 Vertical alignment can be used for both text and image drawing.
 
enum class  Rounding { None , Nearest , Down , Up }
 Used for specifying how to round positions to an exact pixel position for pixel-perfect rendering.
 
enum  { MAX_TEXT_STRING_LENGTH = 1024 }
 

Public Member Functions

virtual ~IDraw2d ()
 Implement virtual destructor just for safety.
 
virtual void DrawImage (AZ::Data::Instance< AZ::RPI::Image > image, AZ::Vector2 position, AZ::Vector2 size, float opacity=1.0f, float rotation=0.0f, const AZ::Vector2 *pivotPoint=nullptr, const AZ::Vector2 *minMaxTexCoords=nullptr, ImageOptions *imageOptions=nullptr)=0
 Draw a textured quad with the top left corner at the given position.
 
virtual void DrawImageAligned (AZ::Data::Instance< AZ::RPI::Image > image, AZ::Vector2 position, AZ::Vector2 size, HAlign horizontalAlignment, VAlign verticalAlignment, float opacity=1.0f, float rotation=0.0f, const AZ::Vector2 *minMaxTexCoords=nullptr, ImageOptions *imageOptions=nullptr)=0
 Draw a textured quad where the position specifies the point specified by the alignment.
 
virtual void DrawQuad (AZ::Data::Instance< AZ::RPI::Image > image, VertexPosColUV *verts, Rounding pixelRounding=Rounding::Nearest, bool clamp=false, const RenderState &renderState=RenderState{})=0
 Draw a textured quad where the position, color and uv of each point is specified explicitly.
 
virtual void DrawLine (AZ::Vector2 start, AZ::Vector2 end, AZ::Color color, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, const RenderState &renderState=RenderState{})=0
 Draw a line.
 
virtual void DrawLineTextured (AZ::Data::Instance< AZ::RPI::Image > image, VertexPosColUV *verts, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, const RenderState &renderState=RenderState{})=0
 Draw a line with a texture so it can be dotted or dashed.
 
virtual void DrawText (const char *textString, AZ::Vector2 position, float pointSize, float opacity=1.0f, TextOptions *textOptions=nullptr)=0
 Draw a text string. Only supports ASCII text.
 
virtual void DrawRectOutlineTextured (AZ::Data::Instance< AZ::RPI::Image > image, UiTransformInterface::RectPoints points, AZ::Vector2 rightVec, AZ::Vector2 downVec, AZ::Color color, uint32_t lineThickness=0)=0
 Draw a rectangular outline with a texture.
 
virtual AZ::Vector2 GetTextSize (const char *textString, float pointSize, TextOptions *textOptions=nullptr)=0
 Get the width and height (in pixels) that would be used to draw the given text string.
 
virtual float GetViewportWidth () const =0
 Get the width of the rendering viewport (in pixels).
 
virtual float GetViewportHeight () const =0
 Get the height of the rendering viewport (in pixels).
 
virtual float GetViewportDpiScalingFactor () const =0
 Get dpi scale factor.
 
virtual const ImageOptionsGetDefaultImageOptions () const =0
 Get the default values that would be used if no image options were passed in.
 
virtual const TextOptionsGetDefaultTextOptions () const =0
 Get the default values that would be used if no text options were passed in.
 
virtual void RenderDeferredPrimitives ()=0
 Render the primitives that have been deferred.
 
virtual void SetDeferPrimitives (bool deferPrimitives)=0
 Specify whether to defer future primitives or render them right away.
 
virtual bool GetDeferPrimitives ()=0
 Return whether future primitives will be deferred or rendered right away.
 
virtual void SetSortKey (int64_t key)=0
 Set sort key offset for following draws.
 

Detailed Description

Class for 2D drawing in screen space.

The IDraw2d interface allows drawing images and text in 2D. Positions and sizes are specified in pixels in the current 2D viewport. The BeginDraw2d method should be called before calling the Draw methods to enter 2D mode and the EndDraw2d method should be called after calling the Draw methods to exit 2D mode. There is a helper class Draw2dHelper that encapsulates this in its constructor and destructor.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
MAX_TEXT_STRING_LENGTH 

Limit imposed by FFont. This is the max number of characters including the null terminator.

Member Function Documentation

◆ DrawImage()

virtual void IDraw2d::DrawImage ( AZ::Data::Instance< AZ::RPI::Image >  image,
AZ::Vector2  position,
AZ::Vector2  size,
float  opacity = 1.0f,
float  rotation = 0.0f,
const AZ::Vector2 *  pivotPoint = nullptr,
const AZ::Vector2 *  minMaxTexCoords = nullptr,
ImageOptions imageOptions = nullptr 
)
pure virtual

Draw a textured quad with the top left corner at the given position.

The image is drawn with the color specified by SetShapeColor and the opacity passed as an argument. If rotation is non-zero then the quad is rotated. If the pivot point is provided then the points of the quad are rotated about that point, otherwise they are rotated about the top left corner of the quad.

Parameters
texIdThe texture ID returned by ITexture::GetTextureID()
positionPosition of the top left corner of the quad (before rotation) in pixels
sizeThe width and height of the quad. Use texture width and height to avoid minification, magnification or stretching (assuming the minMaxTexCoords are left to the default)
opacityThe alpha value used when blending
rotationAngle of rotation in degrees counter-clockwise
pivotPointThe point about which the quad is rotated
minMaxTexCoordsAn optional two component array. The first component is the UV coord for the top left point of the quad and the second is the UV coord of the bottom right point of the quad
imageOptionsOptional struct specifying options that tend to be the same from call to call

Implemented in CDraw2d.

◆ DrawImageAligned()

virtual void IDraw2d::DrawImageAligned ( AZ::Data::Instance< AZ::RPI::Image >  image,
AZ::Vector2  position,
AZ::Vector2  size,
HAlign  horizontalAlignment,
VAlign  verticalAlignment,
float  opacity = 1.0f,
float  rotation = 0.0f,
const AZ::Vector2 *  minMaxTexCoords = nullptr,
ImageOptions imageOptions = nullptr 
)
pure virtual

Draw a textured quad where the position specifies the point specified by the alignment.

Rotation is always around the position.

Parameters
texIdThe texture ID returned by ITexture::GetTextureID()
positionPosition align point of the quad (before rotation) in pixels
sizeThe width and height of the quad. Use texture width and height to avoid minification, magnification or stretching (assuming the minMaxTexCoords are left to the default)
horizontalAlignmentSpecifies how the quad is horizontally aligned to the given position
verticalAlignmentSpecifies how the quad is vertically aligned to the given position
opacityThe alpha value used when blending
rotationAngle of rotation in degrees counter-clockwise
minMaxTexCoordsAn optional two component array. The first component is the UV coord for the top left point of the quad and the second is the UV coord of the bottom right point of the quad
imageOptionsOptional struct specifying options that tend to be the same from call to call

Implemented in CDraw2d.

◆ DrawLine()

virtual void IDraw2d::DrawLine ( AZ::Vector2  start,
AZ::Vector2  end,
AZ::Color  color,
IDraw2d::Rounding  pixelRounding = IDraw2d::Rounding::Nearest,
const RenderState renderState = RenderState{} 
)
pure virtual

Draw a line.

Parameters
startThe start position
endThe end position
colorThe color of the line
pixelRoundingWhether and how to round pixel coordinates
renderStateBlend mode and depth state

Implemented in CDraw2d.

◆ DrawLineTextured()

virtual void IDraw2d::DrawLineTextured ( AZ::Data::Instance< AZ::RPI::Image >  image,
VertexPosColUV verts,
IDraw2d::Rounding  pixelRounding = IDraw2d::Rounding::Nearest,
const RenderState renderState = RenderState{} 
)
pure virtual

Draw a line with a texture so it can be dotted or dashed.

Parameters
texIdThe texture ID returned by ITexture::GetTextureID()
vertsAn array of 2 vertices for the start and end points of the line
pixelRoundingWhether and how to round pixel coordinates
renderStateBlend mode and depth state

Implemented in CDraw2d.

◆ DrawQuad()

virtual void IDraw2d::DrawQuad ( AZ::Data::Instance< AZ::RPI::Image >  image,
VertexPosColUV verts,
Rounding  pixelRounding = Rounding::Nearest,
bool  clamp = false,
const RenderState renderState = RenderState{} 
)
pure virtual

Draw a textured quad where the position, color and uv of each point is specified explicitly.

Parameters
texIdThe texture ID returned by ITexture::GetTextureID()
vertsAn array of 4 vertices, in clockwise order (e.g. top left, top right, bottom right, bottom left)
pixelRoundingWhether and how to round pixel coordinates
renderStateBlend mode and depth state

Implemented in CDraw2d.

◆ DrawRectOutlineTextured()

virtual void IDraw2d::DrawRectOutlineTextured ( AZ::Data::Instance< AZ::RPI::Image >  image,
UiTransformInterface::RectPoints  points,
AZ::Vector2  rightVec,
AZ::Vector2  downVec,
AZ::Color  color,
uint32_t  lineThickness = 0 
)
pure virtual

Draw a rectangular outline with a texture.

Parameters
imageThe texture to be used for drawing the outline
pointsThe rect's vertices (top left, top right, bottom right, bottom left)
rightVecRight vector. Specified because the rect's width/height could be 0
downVecDown vector. Specified because the rect's width/height could be 0
colorThe color of the outline
lineThicknessThe thickness in pixels of the outline. If 0, it will be based on image height

Implemented in CDraw2d.

◆ DrawText()

virtual void IDraw2d::DrawText ( const char *  textString,
AZ::Vector2  position,
float  pointSize,
float  opacity = 1.0f,
TextOptions textOptions = nullptr 
)
pure virtual

Draw a text string. Only supports ASCII text.

The font and effect used to render the text are specified in the textOptions structure

Parameters
textStringA null terminated ASCII text string. May contain
characters
positionPosition of the text in pixels. Alignment values in textOptions affect actual position
pointSizeThe size of the font to use
opacityThe opacity (alpha value) to use to draw the text
textOptionsPointer to an options struct. If null the default options are used

Implemented in CDraw2d.

◆ GetDefaultImageOptions()

virtual const ImageOptions & IDraw2d::GetDefaultImageOptions ( ) const
pure virtual

Get the default values that would be used if no image options were passed in.

This is a convenient way to initialize the imageOptions struct

Implemented in CDraw2d.

◆ GetDefaultTextOptions()

virtual const TextOptions & IDraw2d::GetDefaultTextOptions ( ) const
pure virtual

Get the default values that would be used if no text options were passed in.

This is a convenient way to initialize the textOptions struct

Implemented in CDraw2d.

◆ GetDeferPrimitives()

virtual bool IDraw2d::GetDeferPrimitives ( )
pure virtual

Return whether future primitives will be deferred or rendered right away.

Implemented in CDraw2d.

◆ GetTextSize()

virtual AZ::Vector2 IDraw2d::GetTextSize ( const char *  textString,
float  pointSize,
TextOptions textOptions = nullptr 
)
pure virtual

Get the width and height (in pixels) that would be used to draw the given text string.

Pass the same parameter values that would be used to draw the string

Implemented in CDraw2d.

◆ GetViewportDpiScalingFactor()

virtual float IDraw2d::GetViewportDpiScalingFactor ( ) const
pure virtual

Get dpi scale factor.

Implemented in CDraw2d.

◆ GetViewportHeight()

virtual float IDraw2d::GetViewportHeight ( ) const
pure virtual

Get the height of the rendering viewport (in pixels).

Implemented in CDraw2d.

◆ GetViewportWidth()

virtual float IDraw2d::GetViewportWidth ( ) const
pure virtual

Get the width of the rendering viewport (in pixels).

Implemented in CDraw2d.

◆ RenderDeferredPrimitives()

virtual void IDraw2d::RenderDeferredPrimitives ( )
pure virtual

Render the primitives that have been deferred.

Implemented in CDraw2d.

◆ SetDeferPrimitives()

virtual void IDraw2d::SetDeferPrimitives ( bool  deferPrimitives)
pure virtual

Specify whether to defer future primitives or render them right away.

Implemented in CDraw2d.

◆ SetSortKey()

virtual void IDraw2d::SetSortKey ( int64_t  key)
pure virtual

Set sort key offset for following draws.

Implemented in CDraw2d.


The documentation for this class was generated from the following file: