TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_renderer.h
Go to the documentation of this file.
1#pragma once
2
3#include <gui_core/gui_id.h>
4#include <gui_core/gui_base_types.h> // IntRect, int2, float2, color4b, color4f, float3x2
5#include <gui_core/graphics/gui_image.h> // ImageIndex (default args)
7
8#include <stdint.h>
9#include <span>
10
11namespace tachyon
12{
15
16 enum class VisualBoxStyleIndex : uint16_t;
17 enum class VisualColorStyleIndex : uint16_t;
18 enum class ElementState : uint8_t;
19
22 enum class TriangleEdges : uint8_t
23 {
24 None = 0,
25 Edge01 = 1 << 0,
26 Edge12 = 1 << 1,
27 Edge20 = 1 << 2,
28 };
30
31 struct LineStyle
32 {
35 float lineWidth = 0;
36 float dashSize = 0;
37 float dashOffset = 0;
38 float gradientOffset = 0.0f;
39 float gradientScale = 1.0f;
40 };
41
43 {
44 public:
45 virtual ~GUIRenderer() {}
46
47 virtual void Reset() = 0;
48
49
50 virtual void SetTransform(tachyon::float3x2 transformation) = 0;
53 virtual void SetOpacity(float /*opacity*/) {}
54
59 virtual void RenderBox(tachyon::IntRect rect, tachyon::IntRect clipRect,
60 uint32_t fromStyleIndex, uint32_t toStyleIndex, float blendT,
61 tachyon::VisualColorStyleIndex colorStyleIndex = {},
63 tachyon::IntRect snappedPx = {}) = 0;
64
66 static uint32_t StyleIndex(VisualBoxStyleIndex boxStyleIndex, tachyon::ElementState state);
67
69 tachyon::ElementState state, tachyon::VisualColorStyleIndex colorStyleIndex = {},
71
73 tachyon::VisualColorStyleIndex colorStyleIndex = {},
75
76 virtual void RenderLine(tachyon::int2 p0, tachyon::int2 p1, tachyon::int2 p2, tachyon::int2 p3, tachyon::IntRect clipRect, const LineStyle& lineStyle) = 0;
77 void RenderLine(tachyon::int2 p0, tachyon::int2 p1, tachyon::IntRect clipRect, const LineStyle& lineStyle) { RenderLine(p0, p0, p1, p1, clipRect, lineStyle); }
78
82 virtual void RenderCircle(tachyon::float2 center, float radius, tachyon::IntRect clipRect, const LineStyle& lineStyle) = 0;
83
84 virtual void RenderDot(tachyon::float2 pos, tachyon::IntRect clipRect, float size, tachyon::color4f color) = 0;
88
91 virtual void RenderQuad(tachyon::IntRect rect, tachyon::IntRect clipRect, tachyon::VisualColorStyleIndex colorStyleIndex, float cornerRadius = 0.0f, tachyon::ImageIndex textureIndex = tachyon::ImageIndex::Invalid) = 0;
94 virtual void RenderShadow(tachyon::IntRect rect, tachyon::IntRect clipRect, tachyon::VisualColorStyleIndex colorStyleIndex, float cornerRadius, int blur) = 0;
98 virtual void RenderOccluder(tachyon::IntRect /*rect*/, tachyon::IntRect /*clipRect*/) {}
99
104 virtual void RenderGlyph(tachyon::float2 pos, tachyon::float2 size, tachyon::float2 uvMin, tachyon::float2 uvMax, float scale, int bpp, int mode, VisualColorStyleIndex textColorIndex, tachyon::IntRect clipRect, tachyon::ImageIndex textureIndex = tachyon::ImageIndex::Invalid, float shadowBlur = -1.0f) = 0;
105
107 void RenderFilledPolygon(std::span<const tachyon::float2> points, tachyon::IntRect clipRect,
108 VisualColorStyleIndex colorIndex,
110
112 void RenderPolyline(std::span<const tachyon::int2> points, bool closed,
113 tachyon::IntRect clipRect, const LineStyle& style);
114
115 public:
116 virtual bool StartResizing(ID id) = 0;
117 virtual void StopResizing() = 0;
118
119 virtual bool BeginWindow(ID id) = 0;
120 virtual void EndWindow() = 0;
121
122 // Draw caching: a subtree's primitives are captured once and replayed translated.
123 // Called between BeginWindow and EndWindow; the defaults do nothing.
124
127 virtual void BeginScopeCapture(ID /*scopeId*/) {}
129 virtual void EndScopeCapture(ID /*scopeId*/) {}
131 virtual bool ReplayScopeCapture(ID /*scopeId*/, tachyon::int2 /*delta*/) { return false; }
133 virtual bool HasScopeCapture(ID /*scopeId*/) const { return false; }
135 virtual void InvalidateScopeCapture(ID /*scopeId*/) {}
137 virtual void ClearScopeCaptures() {}
138 };
139
141}
Definition gui_renderer.h:43
virtual void StopResizing()=0
void RenderLine(tachyon::int2 p0, tachyon::int2 p1, tachyon::IntRect clipRect, const LineStyle &lineStyle)
Definition gui_renderer.h:77
void RenderBox(tachyon::IntRect rect, tachyon::IntRect clipRect, VisualBoxStyleIndex boxStyleIndex, tachyon::ElementState state, tachyon::VisualColorStyleIndex colorStyleIndex={}, tachyon::ImageIndex textureIndex=tachyon::ImageIndex::Invalid, tachyon::IntRect snappedPx={})
virtual void InvalidateScopeCapture(ID)
Drops the capture of scopeId.
Definition gui_renderer.h:135
virtual void Reset()=0
virtual bool BeginWindow(ID id)=0
virtual void RenderGlyph(tachyon::float2 pos, tachyon::float2 size, tachyon::float2 uvMin, tachyon::float2 uvMax, float scale, int bpp, int mode, VisualColorStyleIndex textColorIndex, tachyon::IntRect clipRect, tachyon::ImageIndex textureIndex=tachyon::ImageIndex::Invalid, float shadowBlur=-1.0f)=0
A glyph from the text atlas.
virtual void RenderDot(tachyon::float2 pos, tachyon::IntRect clipRect, float size, tachyon::color4f color)=0
virtual void SetOpacity(float)
How opaque what is drawn from now on is, 0 to 1 (1 until set).
Definition gui_renderer.h:53
virtual void RenderLine(tachyon::int2 p0, tachyon::int2 p1, tachyon::int2 p2, tachyon::int2 p3, tachyon::IntRect clipRect, const LineStyle &lineStyle)=0
virtual void EndScopeCapture(ID)
Ends the capture of scopeId and draws it into the current window.
Definition gui_renderer.h:129
void RenderFilledPolygon(std::span< const tachyon::float2 > points, tachyon::IntRect clipRect, VisualColorStyleIndex colorIndex, tachyon::ImageIndex textureIndex=tachyon::ImageIndex::Invalid)
Convex polygon, fan-triangulated from points[0]; needs at least 3 points.
virtual void BeginScopeCapture(ID)
Starts recording primitives under scopeId, replacing its previous capture.
Definition gui_renderer.h:127
virtual bool HasScopeCapture(ID) const
True when scopeId has a non-empty capture.
Definition gui_renderer.h:133
virtual void SetTransform(tachyon::float3x2 transformation)=0
virtual ~GUIRenderer()
Definition gui_renderer.h:45
virtual void RenderShadow(tachyon::IntRect rect, tachyon::IntRect clipRect, tachyon::VisualColorStyleIndex colorStyleIndex, float cornerRadius, int blur)=0
A box shadow: rect is the shadow's shape, which fades out over blur pixels on either side of its edge...
virtual void EndWindow()=0
static uint32_t StyleIndex(VisualBoxStyleIndex boxStyleIndex, tachyon::ElementState state)
The flat GPU style index of boxStyleIndex in state, as RenderBox takes it.
virtual void RenderBox(tachyon::IntRect rect, tachyon::IntRect clipRect, uint32_t fromStyleIndex, uint32_t toStyleIndex, float blendT, tachyon::VisualColorStyleIndex colorStyleIndex={}, tachyon::ImageIndex textureIndex=tachyon::ImageIndex::Invalid, tachyon::IntRect snappedPx={})=0
Draws a styled box, blended from fromStyleIndex to toStyleIndex (flat GPU style indices) by blendT in...
virtual void RenderCircle(tachyon::float2 center, float radius, tachyon::IntRect clipRect, const LineStyle &lineStyle)=0
A circle outline lineStyle.lineWidth wide, exactly round.
virtual void RenderQuad(tachyon::IntRect rect, tachyon::IntRect clipRect, tachyon::VisualColorStyleIndex colorStyleIndex, float cornerRadius=0.0f, tachyon::ImageIndex textureIndex=tachyon::ImageIndex::Invalid)=0
Draws a filled, optionally rounded and textured rect: a box without borders, style blending or elemen...
virtual void RenderOccluder(tachyon::IntRect, tachyon::IntRect)
Draws nothing: marks rect as covered by opaque content drawn after this call, so what was drawn befor...
Definition gui_renderer.h:98
virtual bool StartResizing(ID id)=0
virtual void ClearScopeCaptures()
Drops every capture.
Definition gui_renderer.h:137
void RenderBox(tachyon::IntRect rect, tachyon::IntRect clipRect, VisualBoxStyleIndex boxStyleIndex, tachyon::VisualColorStyleIndex colorStyleIndex={}, tachyon::ImageIndex textureIndex=tachyon::ImageIndex::Invalid, tachyon::IntRect snappedPx={})
void RenderPolyline(std::span< const tachyon::int2 > points, bool closed, tachyon::IntRect clipRect, const LineStyle &style)
Outlined polyline; closed adds a segment from the last point back to the first.
virtual void RenderTriangle(tachyon::float2 p0, tachyon::float2 p1, tachyon::float2 p2, tachyon::IntRect clipRect, tachyon::VisualColorStyleIndex colorStyleIndex, tachyon::ImageIndex textureIndex=tachyon::ImageIndex::Invalid, TriangleEdges hardEdges=TriangleEdges::None)=0
A filled triangle.
virtual bool ReplayScopeCapture(ID, tachyon::int2)
Draws the capture of scopeId again, moved by delta pixels; false if there is none.
Definition gui_renderer.h:131
@ None
Definition gui_element_flags.h:19
TriangleEdges
A triangle's edges, for the ones drawn without a soft edge: where it meets another triangle of the sa...
Definition gui_renderer.h:23
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:37
@ Edge01
p0 to p1
Definition gui_renderer.h:25
@ Edge20
p2 to p0
Definition gui_renderer.h:27
@ None
Definition gui_renderer.h:24
@ Edge12
p1 to p2
Definition gui_renderer.h:26
@ Invalid
Definition gui_image.h:37
VisualColorStyleIndex
Index into StyleManager's color style pool; Invalid (0) draws nothing (transparent).
Definition gui_style.h:33
VisualBoxStyleIndex
Index into StyleManager's visual box style pool; Invalid (0) = none.
Definition gui_style_ref.h:17
ElementState
Interaction state bits of an element; they pick the Style::states variant it draws with.
Definition gui_style.h:42
#define TACHYON_ENUM_OPERATORS(EnumType)
Definition gui_enum_operators.h:6
Definition gui_logging.h:24
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
Definition gui_base_types.h:407
Definition gui_renderer.h:32
float gradientScale
fraction of gradient to cover
Definition gui_renderer.h:39
float dashOffset
Definition gui_renderer.h:37
float gradientOffset
start of gradient range [0,1]
Definition gui_renderer.h:38
float dashSize
Definition gui_renderer.h:36
float lineWidth
Definition gui_renderer.h:35
VisualColorStyleIndex colorStyleIndex
Defaults to VisualColorStyleIndex::Invalid.
Definition gui_renderer.h:34
Definition gui_base_types.h:395
Definition gui_base_types.h:121
2D affine transform matrix (2 rows x 3 columns): x' = r0.x*x + r0.y*y + r0.z y' = r1....
Definition gui_base_types.h:219
Integer 2D vector.
Definition gui_base_types.h:19