载入中...
搜索中...
未找到
HudGeometry.h
浏览该文件的文档.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <cmath>
6#include <cstdint>
7
8namespace eve::ui {
9
11enum class FillDirection : uint8_t { Right = 0, Left, Down, Up };
12
15 float x = 0.f, y = 0.f, w = 0.f, h = 0.f;
16 float u0 = 0.f, v0 = 0.f, u1 = 1.f, v1 = 1.f;
17};
18
20inline float hudFraction(float value) { return std::isfinite(value) ? std::clamp(value, 0.f, 1.f) : 0.f; }
21
24 const float f = hudFraction(fraction);
25 LinearFillRect r{0.f, 0.f, 1.f, 1.f, 0.f, 0.f, 1.f, 1.f};
26 switch (direction) {
28 r.w = f;
29 if (!stretch) r.u1 = f;
30 break;
32 r.x = 1.f - f;
33 r.w = f;
34 if (!stretch) r.u0 = r.x;
35 break;
37 r.h = f;
38 if (!stretch) r.v1 = f;
39 break;
41 r.y = 1.f - f;
42 r.h = f;
43 if (!stretch) r.v0 = r.y;
44 break;
45 }
46 return r;
47}
48
53
55inline NinePatchAxis ninePatchAxis(float size, float nearBorder, float farBorder, float uv0, float uv1,
56 float textureSize, float scale) {
57 const float nearSize = std::min(nearBorder * scale, size * .5f);
58 const float farSize = std::min(farBorder * scale, size * .5f);
59 const float uvPerPixel = (uv1 - uv0) / textureSize;
60 return {nearSize, farSize, uv0 + nearSize / scale * uvPerPixel, uv1 - farSize / scale * uvPerPixel};
61}
62
68
71 std::array<RadialFillQuad, 64> quads{};
72 int count = 0;
73};
74
76inline RadialFillMesh radialFillMesh(float fraction, float startDegrees, bool clockwise, float innerRadius) {
78 const float f = hudFraction(fraction);
79 if (f <= 0.f || !std::isfinite(startDegrees)) return mesh;
80 const float inner = hudFraction(innerRadius);
81 if (inner >= 1.f) return mesh;
82 constexpr float pi = 3.14159265358979323846f;
83 const float start = std::fmod(startDegrees, 360.f) * pi / 180.f;
84 const float sweep = f * 2.f * pi * (clockwise ? 1.f : -1.f);
85 mesh.count = std::max(1, int(std::ceil(f * 64.f)));
86 for (int i = 0; i < mesh.count; ++i) {
87 const float a = start + sweep * float(i) / float(mesh.count);
88 const float b = start + sweep * float(i + 1) / float(mesh.count);
89 const float ax = std::cos(a) * .5f, ay = std::sin(a) * .5f;
90 const float bx = std::cos(b) * .5f, by = std::sin(b) * .5f;
91 mesh.quads[std::size_t(i)] = {.5f + ax, .5f + ay, .5f + bx, .5f + by,
92 .5f + ax * inner, .5f + ay * inner, .5f + bx * inner, .5f + by * inner};
93 }
94 return mesh;
95}
96
97} // namespace eve::ui
Duration start
double r
std::array< float, 3 > scale
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
OceanMeshSettings mesh
float f
Object::Ptr value
RoadLaneDirection direction
float size
Definition TreeMesh.cpp:158
float fraction
RadialFillMesh radialFillMesh(float fraction, float startDegrees, bool clockwise, float innerRadius)
Builds an elliptical sector/ring in [0,1] coordinates; zero degrees points right.
Definition HudGeometry.h:76
float hudFraction(float value)
Clamps finite fractions; invalid presentation data produces an empty fill.
Definition HudGeometry.h:20
LinearFillRect linearFillRect(float fraction, FillDirection direction, bool stretch)
Computes cropped geometry/UVs; stretch preserves the complete source UV rectangle.
Definition HudGeometry.h:23
NinePatchAxis ninePatchAxis(float size, float nearBorder, float farBorder, float uv0, float uv1, float textureSize, float scale)
Scales border geometry while retaining source texel coverage; scale/textureSize must be positive.
Definition HudGeometry.h:55
FillDirection
Direction of a linear image fill; geometry stays inside the original layout box.
Definition HudGeometry.h:11
Pure linear fill geometry, normalized to the original image rectangle.
Definition HudGeometry.h:14
One nine-patch axis, separating destination distances from source UVs.
Definition HudGeometry.h:50
Allocation-free radial mesh with at most 64 segments per complete turn.
Definition HudGeometry.h:70
std::array< RadialFillQuad, 64 > quads
Definition HudGeometry.h:71
One normalized quad of a radial ring; inner points coincide for a solid sector.
Definition HudGeometry.h:64