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

#include <IDraw2d.h>

Public Member Functions

 Draw2dHelper (bool deferCalls=false)
 Start a section of 2D drawing function calls that will render to the default viewport.
 
 Draw2dHelper (IDraw2d *draw2d, bool deferCalls=false)
 
void InitCommon (IDraw2d *draw2d, bool deferCalls)
 
 ~Draw2dHelper ()
 End a section of 2D drawing function calls.
 
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)
 Draw a textured quad, optional rotation is counter-clockwise in degrees. More...
 
void DrawImageAligned (AZ::Data::Instance< AZ::RPI::Image > image, AZ::Vector2 position, AZ::Vector2 size, IDraw2d::HAlign horizontalAlignment, IDraw2d::VAlign verticalAlignment, float opacity=1.0f, float rotation=0.0f, const AZ::Vector2 *minMaxTexCoords=nullptr)
 Draw a textured quad where the position specifies the point specified by the alignment. More...
 
void DrawQuad (AZ::Data::Instance< AZ::RPI::Image > image, IDraw2d::VertexPosColUV *verts, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, bool clamp=false, const IDraw2d::RenderState &renderState=IDraw2d::RenderState{})
 Draw a textured quad where the position, color and uv of each point is specified explicitly. More...
 
void DrawLine (AZ::Vector2 start, AZ::Vector2 end, AZ::Color color, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, const IDraw2d::RenderState &renderState=IDraw2d::RenderState{})
 Draw a line. More...
 
void DrawLineTextured (AZ::Data::Instance< AZ::RPI::Image > image, IDraw2d::VertexPosColUV *verts, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, const IDraw2d::RenderState &renderState=IDraw2d::RenderState{})
 Draw a line with a texture so it can be dotted or dashed. More...
 
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)
 Draw a rect outline with a texture. More...
 
void DrawText (const char *textString, AZ::Vector2 position, float pointSize, float opacity=1.0f)
 Draw a text string. Only supports ASCII text. More...
 
AZ::Vector2 GetTextSize (const char *textString, float pointSize)
 Get the width and height (in pixels) that would be used to draw the given text string. More...
 
void SetImageBlendMode (const AZ::RHI::TargetBlendState &blendState)
 Set the blend mode used for images, default is GS_BLSRC_SRCALPHA|GS_BLDST_ONEMINUSSRCALPHA.
 
void SetImageColor (AZ::Vector3 color)
 Set the color used for DrawImage and other image drawing.
 
void SetImagePixelRounding (IDraw2d::Rounding round)
 Set whether images are rounded to have the points on exact pixel boundaries.
 
void SetImageDepthState (const AZ::RHI::DepthState &depthState)
 Set the base state (that blend mode etc is combined with) used for images, default is GS_NODEPTHTEST.
 
void SetImageClamp (bool clamp)
 Set image clamp mode.
 
void SetTextFont (AZStd::string_view fontName)
 Set the text font.
 
void SetTextEffectIndex (unsigned int effectIndex)
 Set the text font effect index.
 
void SetTextColor (AZ::Vector3 color)
 Set the text color.
 
void SetTextAlignment (IDraw2d::HAlign horizontalAlignment, IDraw2d::VAlign verticalAlignment)
 Set the text alignment.
 
void SetTextDropShadow (AZ::Vector2 offset, AZ::Color color)
 Set a drop shadow for text drawing. An alpha of zero disables drop shadow.
 
void SetTextRotation (float rotation)
 Set a rotation for the text. The text rotates around its position (taking into account alignment).
 
void SetTextDepthTestEnabled (bool enabled)
 Set wheter to enable depth test for the text.
 

Static Public Member Functions

static IDraw2dGetDefaultDraw2d ()
 Helper to get the default IDraw2d interface.
 
static AZ::Data::Instance< AZ::RPI::Image > LoadTexture (const AZStd::string &pathName)
 Helper to load a texture.
 
static AZ::Vector2 Align (AZ::Vector2 position, AZ::Vector2 size, IDraw2d::HAlign horizontalAlignment, IDraw2d::VAlign verticalAlignment)
 Given a position and size and an alignment return the top left corner of the aligned quad.
 
template<typename T >
static T RoundXY (T value, IDraw2d::Rounding roundingType)
 Round the X and Y coordinates of a point using the given rounding policy.
 

Protected Attributes

IDraw2d::ImageOptions m_imageOptions
 image options are stored locally and updated by member functions
 
IDraw2d::TextOptions m_textOptions
 text options are stored locally and updated by member functions
 
IDraw2dm_draw2d
 
bool m_previousDeferCalls
 

Detailed Description

Helper class for using the IDraw2d interface

The Draw2dHelper class is an inline wrapper that provides the convenience feature of automatically setting member options structures to their defaults and providing set functions.

Constructor & Destructor Documentation

◆ Draw2dHelper()

Draw2dHelper::Draw2dHelper ( IDraw2d draw2d,
bool  deferCalls = false 
)
inline

Start a section of 2D drawing function calls that will render to the viewport associated with the specified Draw2d object

Member Function Documentation

◆ DrawImage()

void Draw2dHelper::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 
)
inline

Draw a textured quad, optional rotation is counter-clockwise in degrees.

See IDraw2d:DrawImage for parameter descriptions

◆ DrawImageAligned()

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

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

See IDraw2d:DrawImageAligned for parameter descriptions

◆ DrawLine()

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

Draw a line.

See IDraw2d:DrawLine for parameter descriptions

◆ DrawLineTextured()

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

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

See IDraw2d:DrawLineTextured for parameter descriptions

◆ DrawQuad()

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

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

See IDraw2d:DrawQuad for parameter descriptions

◆ DrawRectOutlineTextured()

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

Draw a rect outline with a texture.

See IDraw2d:DrawRectOutlineTextured for parameter descriptions

◆ DrawText()

void Draw2dHelper::DrawText ( const char *  textString,
AZ::Vector2  position,
float  pointSize,
float  opacity = 1.0f 
)
inline

Draw a text string. Only supports ASCII text.

See IDraw2d:DrawText for parameter descriptions

◆ GetTextSize()

AZ::Vector2 Draw2dHelper::GetTextSize ( const char *  textString,
float  pointSize 
)
inline

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

See IDraw2d:GetTextSize for parameter descriptions


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