guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
shape_mesh.hpp File Reference

Mesh builders shared by the shape render systems. More...

#include <vector>
#include <utility/graphic/color.hpp>
#include <utility/graphic/mesh.hpp>
#include <utility/graphic/orientation.hpp>
#include <utility/graphic/pose.hpp>
#include <utility/math/vector.hpp>
Include dependency graph for shape_mesh.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  guillaume
 A C++20 UI framework for desktop and XR, built as an entity-component-system.
namespace  guillaume::systems
 Rules. Every class here runs each frame on the entities that have the components it declares.

Functions

utility::graphic::PositionF guillaume::systems::shape::rotatePositionByQuaternion (const utility::graphic::PositionF &position, const utility::graphic::OrientationF &orientation)
 Rotate a 3D point around the origin by a quaternion.
std::vector< utility::graphic::PositionF > guillaume::systems::shape::transformToWorldVertices (const std::vector< utility::math::Vector2F > &localVertices, const utility::graphic::PositionF &center, const utility::graphic::OrientationF &orientation)
 Move 2D points of a shape's plane into world space.
bool guillaume::systems::shape::isInvisible (const utility::graphic::Color32Bit &color)
 Whether a color draws nothing.
utility::graphic::Color32Bit guillaume::systems::shape::opaqueColor (const utility::graphic::Color32Bit &color)
 Turn a translucent color into the opaque color it looks like.
utility::graphic::VertexF guillaume::systems::shape::createVertex (const utility::graphic::PositionF &position, const utility::graphic::Color32Bit &color)
 Make a mesh vertex from a position and a color.
void guillaume::systems::shape::buildTriangleFanVertices (utility::graphic::Mesh &mesh, const utility::graphic::PositionF &center, const std::vector< utility::graphic::PositionF > &outline, const utility::graphic::Color32Bit &color)
 Fill a closed outline with a fan of triangles around its center.
void guillaume::systems::shape::buildRingMesh (utility::graphic::Mesh &mesh, const utility::graphic::PositionF &center, const utility::graphic::OrientationF &orientation, float outerHalfWidth, float outerHalfHeight, float thickness, float startAngle, float sweepAngle, int segments, bool closed, const utility::graphic::Color32Bit &color)
 Build a ring, or a part of one, as a strip of triangles.
void guillaume::systems::shape::buildLineMesh (utility::graphic::Mesh &mesh, const utility::graphic::PositionF &center, const utility::graphic::OrientationF &orientation, float halfLength, float halfThickness, bool dashed, float dashLength, float gapLength, const utility::graphic::Color32Bit &color)
 Build a straight stroke along X, solid or dashed.
void guillaume::systems::shape::buildRoundedStrokeMesh (utility::graphic::Mesh &mesh, const utility::graphic::PositionF &center, const utility::graphic::OrientationF &orientation, float halfWidth, float halfHeight, float radius, float width, int arcSegments, const utility::graphic::Color32Bit &color)
 Build the border of a rounded rectangle as a band of constant width.

Detailed Description

Mesh builders shared by the shape render systems.

The functions of guillaume::systems::shape turn a center, an orientation and a few lengths into the vertices and triangle indices of a flat shape: a filled outline, a ring or arc, a straight stroke, a rounded-rectangle border. They read no component and keep no state.

Used by RectangleRender, EllipseRender, RingRender, ArcRender, LineRender, ScrimRender and FocusRingRender.

Shapes are described in their own plane (X to the right, Y along the height) around a center, then rotated by the orientation and moved to the center. Lengths are in the unit of components::Bound (dp).

Every builder writes indices counted from the first vertex of the mesh: pass an empty mesh, one per shape.

Definition in file shape_mesh.hpp.

Function Documentation

◆ buildLineMesh()

void guillaume::systems::shape::buildLineMesh ( utility::graphic::Mesh & mesh,
const utility::graphic::PositionF & center,
const utility::graphic::OrientationF & orientation,
float halfLength,
float halfThickness,
bool dashed,
float dashLength,
float gapLength,
const utility::graphic::Color32Bit & color )

Build a straight stroke along X, solid or dashed.

The stroke runs from -halfLength to +halfLength around the center and is centered on the X axis. A dashed stroke starts with a dash at the left end; the last dash is cut at the right end.

Parameters
meshThe mesh to fill. It must be empty: indices start at 0.
centerWorld position of the middle of the stroke.
orientationWorld orientation of the stroke.
halfLengthHalf the length of the stroke, in dp. The sign is ignored.
halfThicknessHalf the thickness of the stroke, in dp. The sign is ignored.
dashedTrue to split the stroke into dashes.
dashLengthLength of one dash, in dp. With a value of zero or less the stroke is drawn solid even when dashed is true.
gapLengthEmpty length between two dashes, in dp. A negative value is treated as zero.
colorColor given to every vertex.

Definition at line 210 of file shape_mesh.cpp.

◆ buildRingMesh()

void guillaume::systems::shape::buildRingMesh ( utility::graphic::Mesh & mesh,
const utility::graphic::PositionF & center,
const utility::graphic::OrientationF & orientation,
float outerHalfWidth,
float outerHalfHeight,
float thickness,
float startAngle,
float sweepAngle,
int segments,
bool closed,
const utility::graphic::Color32Bit & color )

Build a ring, or a part of one, as a strip of triangles.

The outer edge is the ellipse of half extents (outerHalfWidth, outerHalfHeight). The inner edge is the same ellipse with both half extents reduced by thickness, never below zero. With closed true the last segment joins the first one (a full ring: pass a sweep of 2 * pi); with closed false the strip has two flat ends (an arc).

Parameters
meshThe mesh to fill. It must be empty: indices start at 0.
centerWorld position of the center of the ring.
orientationWorld orientation of the ring.
outerHalfWidthOuter half extent along X, in dp. The sign is ignored.
outerHalfHeightOuter half extent along Y, in dp. The sign is ignored.
thicknessDistance between the outer and inner edges, in dp.
startAngleAngle of the first sample, in radians. Zero points along +X and the angle grows towards +Y.
sweepAngleAngle covered from startAngle, in radians. A negative value sweeps the other way.
segmentsNumber of quads along the ring. A value of zero or less is treated as 1.
closedTrue to join the end to the start.
colorColor given to every vertex.

Definition at line 149 of file shape_mesh.cpp.

◆ buildRoundedStrokeMesh()

void guillaume::systems::shape::buildRoundedStrokeMesh ( utility::graphic::Mesh & mesh,
const utility::graphic::PositionF & center,
const utility::graphic::OrientationF & orientation,
float halfWidth,
float halfHeight,
float radius,
float width,
int arcSegments,
const utility::graphic::Color32Bit & color )

Build the border of a rounded rectangle as a band of constant width.

The band lies between the rounded rectangle of half extents (halfWidth, halfHeight) and corner radius radius, and the same rectangle inset by width on every side, whose corner radius is reduced by width (never below zero). It grows inwards: the outer edge never exceeds the given half extents.

Parameters
meshThe mesh to fill. It must be empty: indices start at 0.
centerWorld position of the center of the rectangle.
orientationWorld orientation of the rectangle.
halfWidthOuter half width, in dp.
halfHeightOuter half height, in dp.
radiusOuter corner radius, in dp. It is clamped between zero and the smaller half extent.
widthWidth of the band, in dp. It is clamped to the smaller half extent.
arcSegmentsNumber of segments per corner. A value of zero or less is treated as 1.
colorColor given to every vertex.

Definition at line 268 of file shape_mesh.cpp.

◆ buildTriangleFanVertices()

void guillaume::systems::shape::buildTriangleFanVertices ( utility::graphic::Mesh & mesh,
const utility::graphic::PositionF & center,
const std::vector< utility::graphic::PositionF > & outline,
const utility::graphic::Color32Bit & color )

Fill a closed outline with a fan of triangles around its center.

Adds the center as vertex 0, then the outline, and one triangle per outline edge, including the edge that closes the outline. The result is correct for convex outlines such as rectangles, rounded rectangles and ellipses.

Parameters
meshThe mesh to fill. It must be empty: indices start at 0.
centerWorld position shared by every triangle.
outlineWorld positions of the outline, in drawing order. With fewer than two points no visible triangle is produced.
colorColor given to every vertex.

Definition at line 113 of file shape_mesh.cpp.

◆ createVertex()

utility::graphic::VertexF guillaume::systems::shape::createVertex ( const utility::graphic::PositionF & position,
const utility::graphic::Color32Bit & color )

Make a mesh vertex from a position and a color.

Parameters
positionWorld position of the vertex.
colorColor of the vertex.
Returns
The vertex, with no other attribute set.

Definition at line 84 of file shape_mesh.cpp.

◆ isInvisible()

bool guillaume::systems::shape::isInvisible ( const utility::graphic::Color32Bit & color)

Whether a color draws nothing.

The shape builders add no geometry for such a color, and the render systems then submit nothing, so a transparent shape is not drawn.

Parameters
colorThe color to test.
Returns
True when the alpha is 0.

Definition at line 93 of file shape_mesh.cpp.

◆ opaqueColor()

utility::graphic::Color32Bit guillaume::systems::shape::opaqueColor ( const utility::graphic::Color32Bit & color)

Turn a translucent color into the opaque color it looks like.

The engine draws shapes with an opaque material, so alpha is ignored. A translucent color (a state layer, a disabled container, a shadow) is composited over the active scheme's Surface, which is what it is drawn on in most cases. Opaque and fully transparent colors are returned unchanged.

Parameters
colorThe color.
Returns
The color to put in the vertices.

Definition at line 99 of file shape_mesh.cpp.

Here is the call graph for this function:

◆ rotatePositionByQuaternion()

utility::graphic::PositionF guillaume::systems::shape::rotatePositionByQuaternion ( const utility::graphic::PositionF & position,
const utility::graphic::OrientationF & orientation )

Rotate a 3D point around the origin by a quaternion.

Parameters
positionThe point to rotate.
orientationThe rotation. It is normalized before use.
Returns
The rotated point.

Definition at line 33 of file shape_mesh.cpp.

◆ transformToWorldVertices()

std::vector< utility::graphic::PositionF > guillaume::systems::shape::transformToWorldVertices ( const std::vector< utility::math::Vector2F > & localVertices,
const utility::graphic::PositionF & center,
const utility::graphic::OrientationF & orientation )

Move 2D points of a shape's plane into world space.

Each point gets a zero depth, is rotated by orientation and is then translated by center.

Parameters
localVerticesThe points, relative to the center of the shape.
centerWorld position of the center of the shape.
orientationWorld orientation of the shape.
Returns
One world position per input point, in the same order.

Definition at line 64 of file shape_mesh.cpp.