/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/ThirdParty/RmlUi/Source/Core/GeometryBackgroundBorder.h
109 строк
5 KB
C-Core
Updated RmlUi to 6.2 and added some improvements (#1813)
10 фев 2026, 01:19
Не верифицирован
10 фев 2026, 01:19
58e2d41
Код
Авторство
О чём код?
#pragma once #include "../../Include/RmlUi/Core/Types.h" #include "../../Include/RmlUi/Core/Vertex.h" namespace Rml { class Box; // Ordered by top, right, bottom, left. using EdgeSizes = Array<float, 4>; // Ordered by top-left, top-right, bottom-right, bottom-left. using CornerSizes = Array<float, 4>; using CornerSizes2 = Array<Vector2f, 4>; using CornerPositions = Array<Vector2f, 4>; // The background-border metrics specify an inner and an outer rectangular area, whose corners can be rounded. struct BorderMetrics { // Outer corner positions (e.g. at border edge) CornerPositions positions_outer; // Inner corner positions (e.g. at padding edge) CornerPositions positions_inner; // Curved borders are drawn as circles (outer border) and ellipses (inner border) around the centers. CornerPositions positions_circle_center; // Radii of the outer edges, always circles. CornerSizes outer_radii; // Radii of the inner edges, 2-dimensional as these can be elliptic. // The inner radii is effectively the (signed) distance from the circle center to the inner edge. // They can also be zero or negative, in which case a sharp corner should be drawn instead of an arc. CornerSizes2 inner_radii; }; class GeometryBackgroundBorder { public: // Construct the background-border geometry drawer, passing in the target vertex and index lists to be filled by later draw operations. GeometryBackgroundBorder(Vector<Vertex>& vertices, Vector<int>& indices); /// Compute background-border metrics used by later draw operations. /// @param outer_position Top-left position of the outer edge. /// @param edge_sizes Widths of the border. /// @param inner_size Size of the inner area. /// @param outer_radii The radius of the outer edge at each corner. /// @return The computed metrics. static BorderMetrics ComputeBorderMetrics(Vector2f outer_position, EdgeSizes edge_sizes, Vector2f inner_size, CornerSizes outer_radii); // Generate geometry for the background, defined by the inner area of the border metrics. void DrawBackground(const BorderMetrics& metrics, ColourbPremultiplied color); /// Generate geometry for the border, defined by the intersection of the outer and inner areas of the border metrics. void DrawBorder(const BorderMetrics& metrics, EdgeSizes edge_sizes, const ColourbPremultiplied border_colors[4]); private: enum Edge { TOP, RIGHT, BOTTOM, LEFT }; enum Corner { TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT }; // -- Background -- // All draw operations place vertices in clockwise order. // Draw the corner, delegate to the specific corner shape drawing function. void DrawBackgroundCorner(Corner corner, Vector2f pos_inner, Vector2f pos_circle_center, float R, Vector2f r, ColourbPremultiplied color); // Add a single point. void DrawPoint(Vector2f pos, ColourbPremultiplied color); // Draw an arc by placing vertices along the ellipse formed by the two-axis radius r, spaced evenly between angles a0,a1 (inclusive). Colors are // interpolated. void DrawArc(Vector2f pos_center, Vector2f r, float a0, float a1, ColourbPremultiplied color0, ColourbPremultiplied color1, int num_points); // Generates triangles by connecting the added vertices. void FillBackground(int index_start); // -- Border -- // All draw operations place the first and last vertices in the following manner. // Let N be the number of vertices placed, and the numbers be indices into the newly placed vertices: // 0: Inner edge, aligned with the previous corner // 1: Outer edge, aligned with the previous corner // N-2: Inner edge, aligned with the next corner // N-1: Outer edge, aligned with the next corner // Where 'next' corner means along the clockwise direction. This way we can easily fill the triangles of the edges in FillEdge(). // Draw the corner, delegate to the specific corner shape drawing function. void DrawBorderCorner(Corner corner, Vector2f pos_outer, Vector2f pos_inner, Vector2f pos_circle_center, float R, Vector2f r, ColourbPremultiplied color0, ColourbPremultiplied color1); // Draw a sharp border corner, ie. no border-radius. Does not produce any triangles. void DrawPointPoint(Vector2f pos_outer, Vector2f pos_inner, ColourbPremultiplied color0, ColourbPremultiplied color1); // Draw an arc along the outer edge (radius R), and an arc along the inner edge (two-axis radius r), // spaced evenly between angles a0,a1 (inclusive). Connect them by triangles. Colors are interpolated. void DrawArcArc(Vector2f pos_center, float R, Vector2f r, float a0, float a1, ColourbPremultiplied color0, ColourbPremultiplied color1, int num_points); // Draw an arc along the outer edge, and connect them by triangles to a point on the inner edge. void DrawArcPoint(Vector2f pos_center, Vector2f pos_inner, float R, float a0, float a1, ColourbPremultiplied color0, ColourbPremultiplied color1, int num_points); // Add triangles between the previous corner to another one specified by the index (possibly yet-to-be-drawn). void FillEdge(int index_next_corner); // -- Tools -- int GetNumPoints(float R) const; Vector<Vertex>& vertices; Vector<int>& indices; }; } // namespace Rml