forked from samjviana/souls_vision
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheffect_bar.cpp
More file actions
123 lines (102 loc) · 4.69 KB
/
effect_bar.cpp
File metadata and controls
123 lines (102 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// Created by PC-SAMUEL on 27/11/2024.
//
#include "effect_bar.h"
#include "overlay.h"
#include "util.h"
#include "logger.h"
#include "config.h"
namespace souls_vision {
EffectBar::EffectBar(BarType _type, const std::string& iconPath, ImVec4 barColor, SIZE_T descriptorSize, D3D12_GPU_DESCRIPTOR_HANDLE srvHeapStart) {
type = _type;
backgroundInfo_ = Overlay::GetTexture("BarBG.png");
barInfo_ = Overlay::GetTexture("Bar.png");
edgeInfo_ = Overlay::GetTexture("BarEdge2.png");
frameInfo_ = Overlay::GetTexture("ConditionWaku.png");
iconInfo_ = Overlay::GetTexture(iconPath);
barColor_ = barColor;
srvHeapStart_ = srvHeapStart;
descriptorIncrementSize_ = descriptorSize;
if (!backgroundInfo_.textureResource || !barInfo_.textureResource || !edgeInfo_.textureResource || !frameInfo_.textureResource || !iconInfo_.textureResource) {
Logger::Error("Failed to load default textures.");
}
}
void EffectBar::Render(const BarSettings &settings, float paddingX, float paddingY, int decimals) {
if (!backgroundInfo_.textureResource || !barInfo_.textureResource || !edgeInfo_.textureResource || !frameInfo_.textureResource || !iconInfo_.textureResource) {
Logger::Error("Failed to retrieve one or more textures.");
return;
}
D3D12_GPU_DESCRIPTOR_HANDLE backgroundHandle = GetGpuDescriptorHandle(srvHeapStart_, descriptorIncrementSize_, backgroundInfo_.index);
D3D12_GPU_DESCRIPTOR_HANDLE barHandle = GetGpuDescriptorHandle(srvHeapStart_, descriptorIncrementSize_, barInfo_.index);
D3D12_GPU_DESCRIPTOR_HANDLE edgeHandle = GetGpuDescriptorHandle(srvHeapStart_, descriptorIncrementSize_, edgeInfo_.index);
D3D12_GPU_DESCRIPTOR_HANDLE frameHandle = GetGpuDescriptorHandle(srvHeapStart_, descriptorIncrementSize_, frameInfo_.index);
D3D12_GPU_DESCRIPTOR_HANDLE iconHandle = GetGpuDescriptorHandle(srvHeapStart_, descriptorIncrementSize_, iconInfo_.index);
auto backgroundTexID = static_cast<ImTextureID>(backgroundHandle.ptr);
auto barTexID = static_cast<ImTextureID>(barHandle.ptr);
auto edgeTexID = static_cast<ImTextureID>(edgeHandle.ptr);
auto frameTexID = static_cast<ImTextureID>(frameHandle.ptr);
auto iconTexID = static_cast<ImTextureID>(iconHandle.ptr);
float percentage = settings.currentValue / settings.maxValue;
ImVec2 iconSize = Config::effectBarIconSize;
ImVec2 barSize = ImVec2(
settings.size.x * 0.876,
settings.size.y * 0.73
);
ImVec2 barPosition = ImVec2(
paddingX + (iconSize.x - (iconSize.x * 0.14)),
paddingY + (iconSize.y / 2) - (barSize.y / 2)
);
ImVec2 uv0 = ImVec2(0.0f, 0.0f);
ImVec2 uv1 = ImVec2(percentage, 1.0f);
ImGui::SetCursorPos(barPosition);
ImVec4 tintColor = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
ImGui::Image(backgroundTexID, barSize, uv0, ImVec2(1.0f, 1.0f), tintColor);
ImGui::SetCursorPos(barPosition);
ImGui::Image(barTexID, ImVec2(barSize.x * percentage, barSize.y), uv0, uv1, barColor_);
ImVec2 clipMin = ImVec2(
barPosition.x,
settings.position.y + barPosition.y
);
ImVec2 clipMax = ImVec2(
settings.position.x + settings.size.x + paddingX,
settings.position.y + settings.size.y + paddingY
);
ImGui::PushClipRect(clipMin, clipMax, true);
ImVec2 edgeSize = ImVec2(
(float)settings.size.x * 0.2f,
(float)settings.size.y * 0.75f
);
ImVec2 edgePosition = ImVec2(
barPosition.x + (barSize.x * percentage) - (edgeSize.x * 0.92f),
barPosition.y - (edgeSize.y * 0.1f)
);
ImGui::SetCursorPos(ImVec2(edgePosition));
ImGui::Image(edgeTexID, edgeSize);
ImGui::PopClipRect();
ImVec2 framePosition = ImVec2(
paddingX + iconSize.x - (iconSize.x * 0.14),
paddingY + (iconSize.y / 2) - (settings.size.y / 2)
);
ImVec2 frameSize = ImVec2(
settings.size.x - iconSize.x,
settings.size.y
);
ImGui::SetCursorPos(framePosition);
ImGui::Image(frameTexID, frameSize);
ImVec2 iconPosition = ImVec2(paddingX, paddingY);
ImGui::SetCursorPos(iconPosition);
ImGui::Image(iconTexID, iconSize);
if (!settings.hideText) {
ImGui::PushFont(Overlay::font_);
std::string text = std::format("{:.{}f} / {:.{}f}", settings.currentValue, decimals, settings.maxValue, decimals);
ImVec2 textSize = ImGui::CalcTextSize(text.c_str());
ImVec2 textPosition = ImVec2(
barPosition.x + 10.0f,
paddingY + ((iconSize.y - textSize.y) * 0.5f)
);
ImGui::SetCursorPos(textPosition);
ImGui::Text("%s", text.c_str());
ImGui::PopFont();
}
}
} // souls_vision