TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::CustomDrawContext Class Reference

Passed to custom-draw callbacks (ElementStorage::AddCustomDraw / AddCustomDrawAfter): geometry lookups and drawing calls in a current space the callback switches with SetSpace or SetSpaceRaw, also between calls. More...

#include <gui_core/graphics/gui_custom_draw_context.h>

Public Member Functions

 CustomDrawContext (GUIRenderer &renderer, ElementStorage &storage, ElementRef elementRef, IntRect elementRectLayout, IntRect innerRectLayout, IntRect clipRectScreen, float3x2 renderTransform, int2 windowOffset, ITextSystem *textSystem=nullptr, float4 ownerPixelRect={}, IntRect ownerSnappedRect={}) noexcept
 Built by the renderer; callbacks receive it.
ElementRef Ref () const noexcept
 ElementRef this callback was registered on.
IntRect ElementRect () const noexcept
 Border-box of the registered element, in the CURRENT space.
IntRect ElementInnerRect () const noexcept
 Padding-box (inner content area) of the registered element, in the CURRENT space.
IntRect ClipRect () const noexcept
 Scissor region in SCREEN space. Applied implicitly by every Render* method.
void SetSpace (DrawSpace space)
 Set the current coordinate space.
void SetSpaceRaw (float3x2 spaceToWindowLocal)
 Set an arbitrary current space; spaceToWindowLocal maps current-space -> window-local.
float3x2 CurrentTransform () const noexcept
 The current space -> window-local transform.
int2 ScreenToCurrent (int2 screenPoint) const
 Convert a SCREEN-space input (e.g.
IntRect GetElementRect (const ElementRef &ref) const noexcept
 Lookups for OTHER elements (returns rects in the CURRENT space).
IntRect GetInnerRect (const ElementRef &ref) const noexcept
 Padding-box of another element, in the CURRENT space; empty when not found.
ElementRef GetParentRef (const ElementRef &ref) const noexcept
 Tree navigation for other elements.
ElementRef GetNextSiblingRef (const ElementRef &ref) const noexcept
int2 GetContentSize (const ElementRef &ref) const noexcept
 Size of the bounds of an element's children (can exceed its inner size when it scrolls), in pixels.
int2 GetInnerSize (const ElementRef &ref) const noexcept
 Size of an element's padding-box, in pixels.
void RenderBox (IntRect rect, VisualBoxStyleIndex styleIndex, ElementState state, VisualColorStyleIndex colorStyleIndex={}, ImageIndex textureIndex=ImageIndex::Invalid) const
 A styled box (background, border, radius) like an element's.
void RenderBox (IntRect rect, VisualBoxStyleIndex styleIndex, VisualColorStyleIndex colorStyleIndex={}, ImageIndex textureIndex=ImageIndex::Invalid) const
void RenderBox (IntRect rect, VisualBoxStyleIndex styleIndex, ElementState fromState, ElementState toState, float t) const
 A styled box part way from its fromState variant to its toState one: t = 0 is all fromState, 1 all toState.
void RenderBox (IntRect rect, IntRect subClip, VisualBoxStyleIndex styleIndex, ElementState state, VisualColorStyleIndex colorStyleIndex={}, ImageIndex textureIndex=ImageIndex::Invalid) const
 RenderBox variants with a sub-clip.
void RenderBox (IntRect rect, IntRect subClip, VisualBoxStyleIndex styleIndex, VisualColorStyleIndex colorStyleIndex={}, ImageIndex textureIndex=ImageIndex::Invalid) const
void RenderQuad (IntRect rect, VisualColorStyleIndex colorStyleIndex, float cornerRadius=0.0f, ImageIndex textureIndex=ImageIndex::Invalid) const
 A plain filled rect (no border or element state), optionally rounded or textured.
void RenderQuad (IntRect rect, IntRect subClip, VisualColorStyleIndex colorStyleIndex, float cornerRadius=0.0f, ImageIndex textureIndex=ImageIndex::Invalid) const
 RenderQuad with a sub-clip in the same space as rect.
void RenderLine (int2 p0, int2 p1, const LineStyle &style) const
 A straight line from p0 to p1.
void RenderLine (int2 p0, int2 p1, int2 p2, int2 p3, const LineStyle &style) const
 A curve from p0 to p3 shaped by the control points p1 and p2 (Bezier-like).
void RenderDot (float2 pos, float size, color4f color) const
 A filled, anti-aliased dot centered on pos; size is its diameter.
void RenderTriangle (float2 p0, float2 p1, float2 p2, VisualColorStyleIndex colorStyleIndex, ImageIndex textureIndex=ImageIndex::Invalid, TriangleEdges hardEdges=TriangleEdges::None) const
 A filled triangle; see GUIRenderer::RenderTriangle for hardEdges.
void RenderCircle (float2 center, float radius, const LineStyle &style) const
 A circle outline, stroked with style; see GUIRenderer::RenderCircle.
void RenderCircle (int2 center, float radius, const LineStyle &style) const
 see above
void RenderDisc (int2 center, float radius, VisualColorStyleIndex colorStyleIndex) const
 A filled, anti-aliased disc (a quad rounded to a circle).
void RenderFilledPolygon (std::span< const float2 > points, VisualColorStyleIndex colorStyleIndex, ImageIndex textureIndex=ImageIndex::Invalid) const
 Filled convex polygon via fan triangulation.
void RenderPolyline (std::span< const int2 > points, bool closed, const LineStyle &style, float cornerRadius=0.0f) const
 Outlined polyline.
void RenderText (TextID textId, IntRect rect, float extraScale=1.0f) const
 Draw a previously-registered text (textSystem->RegisterText) within rect, expressed in the CURRENT space like every other Render* coord.

Detailed Description

Passed to custom-draw callbacks (ElementStorage::AddCustomDraw / AddCustomDrawAfter): geometry lookups and drawing calls in a current space the callback switches with SetSpace or SetSpaceRaw, also between calls.

Render* coordinates and the rects the accessors return are in the current space, so they pass straight through; convert other inputs, such as the cursor position, with ScreenToCurrent. In Screen space a rect matches the screen only for elements without a transformed ancestor.

Constructor & Destructor Documentation

◆ CustomDrawContext()

tachyon::CustomDrawContext::CustomDrawContext ( GUIRenderer & renderer,
ElementStorage & storage,
ElementRef elementRef,
IntRect elementRectLayout,
IntRect innerRectLayout,
IntRect clipRectScreen,
float3x2 renderTransform,
int2 windowOffset,
ITextSystem * textSystem = nullptr,
float4 ownerPixelRect = {},
IntRect ownerSnappedRect = {} )
inlinenoexcept

Built by the renderer; callbacks receive it.

Member Function Documentation

◆ Ref()

ElementRef tachyon::CustomDrawContext::Ref ( ) const
inlinenoexcept

ElementRef this callback was registered on.

◆ ElementRect()

IntRect tachyon::CustomDrawContext::ElementRect ( ) const
inlinenoexcept

Border-box of the registered element, in the CURRENT space.

◆ ElementInnerRect()

IntRect tachyon::CustomDrawContext::ElementInnerRect ( ) const
inlinenoexcept

Padding-box (inner content area) of the registered element, in the CURRENT space.

◆ ClipRect()

IntRect tachyon::CustomDrawContext::ClipRect ( ) const
inlinenoexcept

Scissor region in SCREEN space. Applied implicitly by every Render* method.

◆ SetSpace()

void tachyon::CustomDrawContext::SetSpace ( DrawSpace space)

Set the current coordinate space.

Local (default) = the registered element's content space; Screen = absolute layout (same space as stored rects / screenPos). Re-points the renderer transform for subsequent Render* calls.

◆ SetSpaceRaw()

void tachyon::CustomDrawContext::SetSpaceRaw ( float3x2 spaceToWindowLocal)

Set an arbitrary current space; spaceToWindowLocal maps current-space -> window-local.

◆ CurrentTransform()

float3x2 tachyon::CustomDrawContext::CurrentTransform ( ) const
inlinenoexcept

The current space -> window-local transform.

◆ ScreenToCurrent()

int2 tachyon::CustomDrawContext::ScreenToCurrent ( int2 screenPoint) const

Convert a SCREEN-space input (e.g.

cursor position, in absolute layout) into the current space. For foreign inputs that are not themselves rendering values.

◆ GetElementRect()

IntRect tachyon::CustomDrawContext::GetElementRect ( const ElementRef & ref) const
noexcept

Lookups for OTHER elements (returns rects in the CURRENT space).

◆ GetInnerRect()

IntRect tachyon::CustomDrawContext::GetInnerRect ( const ElementRef & ref) const
noexcept

Padding-box of another element, in the CURRENT space; empty when not found.

◆ GetParentRef()

ElementRef tachyon::CustomDrawContext::GetParentRef ( const ElementRef & ref) const
noexcept

Tree navigation for other elements.

◆ GetNextSiblingRef()

ElementRef tachyon::CustomDrawContext::GetNextSiblingRef ( const ElementRef & ref) const
noexcept

◆ GetContentSize()

int2 tachyon::CustomDrawContext::GetContentSize ( const ElementRef & ref) const
noexcept

Size of the bounds of an element's children (can exceed its inner size when it scrolls), in pixels.

◆ GetInnerSize()

int2 tachyon::CustomDrawContext::GetInnerSize ( const ElementRef & ref) const
noexcept

Size of an element's padding-box, in pixels.

◆ RenderBox() [1/5]

void tachyon::CustomDrawContext::RenderBox ( IntRect rect,
VisualBoxStyleIndex styleIndex,
ElementState state,
VisualColorStyleIndex colorStyleIndex = {},
ImageIndex textureIndex = ImageIndex::Invalid ) const

A styled box (background, border, radius) like an element's.

state picks the style's hover / pressed / ... variant; without it the base style is used. colorStyleIndex overrides the background; textureIndex fills it with an image.

◆ RenderBox() [2/5]

void tachyon::CustomDrawContext::RenderBox ( IntRect rect,
VisualBoxStyleIndex styleIndex,
VisualColorStyleIndex colorStyleIndex = {},
ImageIndex textureIndex = ImageIndex::Invalid ) const

◆ RenderBox() [3/5]

void tachyon::CustomDrawContext::RenderBox ( IntRect rect,
VisualBoxStyleIndex styleIndex,
ElementState fromState,
ElementState toState,
float t ) const

A styled box part way from its fromState variant to its toState one: t = 0 is all fromState, 1 all toState.

◆ RenderBox() [4/5]

void tachyon::CustomDrawContext::RenderBox ( IntRect rect,
IntRect subClip,
VisualBoxStyleIndex styleIndex,
ElementState state,
VisualColorStyleIndex colorStyleIndex = {},
ImageIndex textureIndex = ImageIndex::Invalid ) const

RenderBox variants with a sub-clip.

Final scissor = ClipRect() & subClip. subClip is in the same space as rect.

◆ RenderBox() [5/5]

void tachyon::CustomDrawContext::RenderBox ( IntRect rect,
IntRect subClip,
VisualBoxStyleIndex styleIndex,
VisualColorStyleIndex colorStyleIndex = {},
ImageIndex textureIndex = ImageIndex::Invalid ) const

◆ RenderQuad() [1/2]

void tachyon::CustomDrawContext::RenderQuad ( IntRect rect,
VisualColorStyleIndex colorStyleIndex,
float cornerRadius = 0.0f,
ImageIndex textureIndex = ImageIndex::Invalid ) const

A plain filled rect (no border or element state), optionally rounded or textured.

◆ RenderQuad() [2/2]

void tachyon::CustomDrawContext::RenderQuad ( IntRect rect,
IntRect subClip,
VisualColorStyleIndex colorStyleIndex,
float cornerRadius = 0.0f,
ImageIndex textureIndex = ImageIndex::Invalid ) const

RenderQuad with a sub-clip in the same space as rect.

◆ RenderLine() [1/2]

void tachyon::CustomDrawContext::RenderLine ( int2 p0,
int2 p1,
const LineStyle & style ) const

A straight line from p0 to p1.

◆ RenderLine() [2/2]

void tachyon::CustomDrawContext::RenderLine ( int2 p0,
int2 p1,
int2 p2,
int2 p3,
const LineStyle & style ) const

A curve from p0 to p3 shaped by the control points p1 and p2 (Bezier-like).

◆ RenderDot()

void tachyon::CustomDrawContext::RenderDot ( float2 pos,
float size,
color4f color ) const

A filled, anti-aliased dot centered on pos; size is its diameter.

◆ RenderTriangle()

void tachyon::CustomDrawContext::RenderTriangle ( float2 p0,
float2 p1,
float2 p2,
VisualColorStyleIndex colorStyleIndex,
ImageIndex textureIndex = ImageIndex::Invalid,
TriangleEdges hardEdges = TriangleEdges::None ) const

A filled triangle; see GUIRenderer::RenderTriangle for hardEdges.

◆ RenderCircle() [1/2]

void tachyon::CustomDrawContext::RenderCircle ( float2 center,
float radius,
const LineStyle & style ) const

A circle outline, stroked with style; see GUIRenderer::RenderCircle.

◆ RenderCircle() [2/2]

void tachyon::CustomDrawContext::RenderCircle ( int2 center,
float radius,
const LineStyle & style ) const

see above

◆ RenderDisc()

void tachyon::CustomDrawContext::RenderDisc ( int2 center,
float radius,
VisualColorStyleIndex colorStyleIndex ) const

A filled, anti-aliased disc (a quad rounded to a circle).

◆ RenderFilledPolygon()

void tachyon::CustomDrawContext::RenderFilledPolygon ( std::span< const float2 > points,
VisualColorStyleIndex colorStyleIndex,
ImageIndex textureIndex = ImageIndex::Invalid ) const

Filled convex polygon via fan triangulation.

◆ RenderPolyline()

void tachyon::CustomDrawContext::RenderPolyline ( std::span< const int2 > points,
bool closed,
const LineStyle & style,
float cornerRadius = 0.0f ) const

Outlined polyline.

cornerRadius > 0 (open polylines) turns each bend into a short arc between the straight runs, up to half of either neighbouring run.

◆ RenderText()

void tachyon::CustomDrawContext::RenderText ( TextID textId,
IntRect rect,
float extraScale = 1.0f ) const

Draw a previously-registered text (textSystem->RegisterText) within rect, expressed in the CURRENT space like every other Render* coord.

The glyph raster scale is taken from the current transform (so it stays crisp under DPI/zoom); extraScale multiplies it. No-op if the context has no text system.


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