Working on health bar
This commit is contained in:
1 parent
8552725dfc
commit
22b0e1992f
12 files changed
+121
-57
No files matched your search
+36
-15
@@ -284,9 +284,22 @@ namespace ZL {
|
||||
|
||||
float x0 = rect.x;
|
||||
float y0 = rect.y;
|
||||
float x1 = rect.x + rect.w;
|
||||
float y1 = rect.y + rect.h;
|
||||
|
||||
float x1, u1;
|
||||
if (fillMode) {
|
||||
const float clamped = std::clamp(value, 0.0f, 1.0f);
|
||||
if (clamped <= 0.0f) {
|
||||
trackMesh.RefreshVBO();
|
||||
return;
|
||||
}
|
||||
x1 = rect.x + rect.w * clamped;
|
||||
u1 = clamped;
|
||||
} else {
|
||||
x1 = rect.x + rect.w;
|
||||
u1 = 1.0f;
|
||||
}
|
||||
|
||||
trackMesh.data.PositionData.push_back({ x0, y0, 0 });
|
||||
trackMesh.data.TexCoordData.push_back({ 0, 0 });
|
||||
|
||||
@@ -294,16 +307,16 @@ namespace ZL {
|
||||
trackMesh.data.TexCoordData.push_back({ 0, 1 });
|
||||
|
||||
trackMesh.data.PositionData.push_back({ x1, y1, 0 });
|
||||
trackMesh.data.TexCoordData.push_back({ 1, 1 });
|
||||
trackMesh.data.TexCoordData.push_back({ u1, 1 });
|
||||
|
||||
trackMesh.data.PositionData.push_back({ x0, y0, 0 });
|
||||
trackMesh.data.TexCoordData.push_back({ 0, 0 });
|
||||
|
||||
trackMesh.data.PositionData.push_back({ x1, y1, 0 });
|
||||
trackMesh.data.TexCoordData.push_back({ 1, 1 });
|
||||
trackMesh.data.TexCoordData.push_back({ u1, 1 });
|
||||
|
||||
trackMesh.data.PositionData.push_back({ x1, y0, 0 });
|
||||
trackMesh.data.TexCoordData.push_back({ 1, 0 });
|
||||
trackMesh.data.TexCoordData.push_back({ u1, 0 });
|
||||
|
||||
trackMesh.RefreshVBO();
|
||||
}
|
||||
@@ -566,6 +579,8 @@ namespace ZL {
|
||||
std::transform(orient.begin(), orient.end(), orient.begin(), ::tolower);
|
||||
s->vertical = (orient != "horizontal");
|
||||
}
|
||||
if (j.contains("fillMode")) s->fillMode = j["fillMode"].get<bool>();
|
||||
if (j.contains("interactive")) s->interactive = j["interactive"].get<bool>();
|
||||
|
||||
node->slider = s;
|
||||
}
|
||||
@@ -1162,6 +1177,7 @@ namespace ZL {
|
||||
value = std::clamp(value, 0.0f, 1.0f);
|
||||
if (fabs(s->value - value) < 1e-6f) return true;
|
||||
s->value = value;
|
||||
s->buildTrackMesh();
|
||||
s->buildKnobMesh();
|
||||
if (s->onValueChanged) s->onValueChanged(s->name, s->value);
|
||||
return true;
|
||||
@@ -1634,18 +1650,21 @@ namespace ZL {
|
||||
auto it = pressedSliders.find(fingerId);
|
||||
if (it != pressedSliders.end()) {
|
||||
auto s = it->second;
|
||||
float t;
|
||||
if (s->vertical) {
|
||||
t = (y - s->rect.y) / s->rect.h;
|
||||
if (s->interactive) {
|
||||
float t;
|
||||
if (s->vertical) {
|
||||
t = (y - s->rect.y) / s->rect.h;
|
||||
}
|
||||
else {
|
||||
t = (x - s->rect.x) / s->rect.w;
|
||||
}
|
||||
if (t < 0.0f) t = 0.0f;
|
||||
if (t > 1.0f) t = 1.0f;
|
||||
s->value = t;
|
||||
s->buildTrackMesh();
|
||||
s->buildKnobMesh();
|
||||
if (s->onValueChanged) s->onValueChanged(s->name, s->value);
|
||||
}
|
||||
else {
|
||||
t = (x - s->rect.x) / s->rect.w;
|
||||
}
|
||||
if (t < 0.0f) t = 0.0f;
|
||||
if (t > 1.0f) t = 1.0f;
|
||||
s->value = t;
|
||||
s->buildKnobMesh();
|
||||
if (s->onValueChanged) s->onValueChanged(s->name, s->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1676,6 +1695,7 @@ namespace ZL {
|
||||
}
|
||||
|
||||
for (auto& s : sliders) {
|
||||
if (!s->interactive) continue;
|
||||
if (s->rect.contains((float)x, (float)y)) {
|
||||
pressedSliders[fingerId] = s;
|
||||
float t;
|
||||
@@ -1688,6 +1708,7 @@ namespace ZL {
|
||||
if (t < 0.0f) t = 0.0f;
|
||||
if (t > 1.0f) t = 1.0f;
|
||||
s->value = t;
|
||||
s->buildTrackMesh();
|
||||
s->buildKnobMesh();
|
||||
if (s->onValueChanged) s->onValueChanged(s->name, s->value);
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user