2021-01-27 00:00:20 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-02-08 22:25:25 +01:00
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-01-27 12:04:42 +01:00
|
|
|
#include <functional>
|
2022-03-03 09:24:09 +01:00
|
|
|
#include <string>
|
2021-01-27 12:04:42 +01:00
|
|
|
|
2022-01-24 00:46:19 +01:00
|
|
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
2021-01-27 00:00:20 +01:00
|
|
|
#include <imgui.h>
|
2022-01-24 00:46:19 +01:00
|
|
|
#include <imgui_internal.h>
|
2021-01-27 00:00:20 +01:00
|
|
|
|
2021-12-31 01:10:06 +01:00
|
|
|
#include <hex/helpers/fmt.hpp>
|
2021-08-21 00:51:50 +02:00
|
|
|
|
|
|
|
enum ImGuiCustomCol {
|
|
|
|
ImGuiCustomCol_DescButton,
|
|
|
|
ImGuiCustomCol_DescButtonHovered,
|
|
|
|
ImGuiCustomCol_DescButtonActive,
|
|
|
|
|
|
|
|
ImGuiCustomCol_ToolbarGray,
|
|
|
|
ImGuiCustomCol_ToolbarRed,
|
|
|
|
ImGuiCustomCol_ToolbarYellow,
|
|
|
|
ImGuiCustomCol_ToolbarGreen,
|
|
|
|
ImGuiCustomCol_ToolbarBlue,
|
|
|
|
ImGuiCustomCol_ToolbarPurple,
|
|
|
|
ImGuiCustomCol_ToolbarBrown,
|
|
|
|
|
2021-08-28 16:02:53 +02:00
|
|
|
ImGuiCustomCol_Highlight,
|
|
|
|
|
2023-05-19 21:18:38 +02:00
|
|
|
ImGuiCustomCol_IEEEToolSign,
|
|
|
|
ImGuiCustomCol_IEEEToolExp,
|
|
|
|
ImGuiCustomCol_IEEEToolMantissa,
|
|
|
|
|
2023-05-23 13:20:18 +02:00
|
|
|
ImGuiCustomCol_BlurBackground,
|
|
|
|
|
2021-08-21 00:51:50 +02:00
|
|
|
ImGuiCustomCol_COUNT
|
|
|
|
};
|
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
enum ImGuiCustomStyle {
|
|
|
|
ImGuiCustomStyle_WindowBlur,
|
|
|
|
|
|
|
|
ImGuiCustomStyle_COUNT
|
|
|
|
};
|
|
|
|
|
2021-01-27 00:00:20 +01:00
|
|
|
namespace ImGui {
|
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
class Texture {
|
|
|
|
public:
|
|
|
|
Texture() = default;
|
2022-10-13 15:13:53 +02:00
|
|
|
Texture(const ImU8 *buffer, int size, int width = 0, int height = 0);
|
2022-10-02 17:30:26 +02:00
|
|
|
explicit Texture(const char *path);
|
2023-01-20 21:16:28 +01:00
|
|
|
Texture(unsigned int texture, int width, int height);
|
2022-09-18 20:38:45 +02:00
|
|
|
Texture(const Texture&) = delete;
|
|
|
|
Texture(Texture&& other) noexcept;
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
~Texture();
|
|
|
|
|
2022-10-02 17:30:26 +02:00
|
|
|
Texture& operator=(const Texture&) = delete;
|
|
|
|
Texture& operator=(Texture&& other) noexcept;
|
2022-09-18 20:38:45 +02:00
|
|
|
|
|
|
|
[[nodiscard]] constexpr bool isValid() const noexcept {
|
|
|
|
return this->m_textureId != nullptr;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2023-01-05 09:30:15 +01:00
|
|
|
[[nodiscard]] constexpr operator ImTextureID() const noexcept {
|
2022-09-18 20:38:45 +02:00
|
|
|
return this->m_textureId;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
[[nodiscard]] auto getSize() const noexcept {
|
|
|
|
return ImVec2(this->m_width, this->m_height);
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
2022-02-06 01:32:15 +01:00
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
[[nodiscard]] constexpr auto getAspectRatio() const noexcept {
|
|
|
|
if (this->m_height == 0) return 1.0F;
|
2022-02-06 01:32:15 +01:00
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
return float(this->m_width) / float(this->m_height);
|
2022-02-06 01:32:15 +01:00
|
|
|
}
|
2022-09-18 20:38:45 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
ImTextureID m_textureId = nullptr;
|
|
|
|
int m_width = 0, m_height = 0;
|
2021-08-18 22:36:46 +02:00
|
|
|
};
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
bool IconHyperlink(const char *icon, const char *label, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
|
|
|
bool Hyperlink(const char *label, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
|
|
|
bool BulletHyperlink(const char *label, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
|
|
|
bool DescriptionButton(const char *label, const char *description, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
2021-01-27 12:04:42 +01:00
|
|
|
|
2023-05-11 12:00:45 +02:00
|
|
|
void HelpHover(const char *text);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void UnderlinedText(const char *label, ImColor color = ImGui::GetStyleColorVec4(ImGuiCol_Text), const ImVec2 &size_arg = ImVec2(0, 0));
|
2021-01-27 00:00:20 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void TextSpinner(const char *label);
|
2021-02-25 00:17:41 +01:00
|
|
|
|
2021-03-02 13:49:45 +01:00
|
|
|
void Header(const char *label, bool firstEntry = false);
|
2021-08-28 16:02:53 +02:00
|
|
|
void HeaderColored(const char *label, ImColor color, bool firstEntry);
|
2021-03-02 13:49:45 +01:00
|
|
|
|
2021-08-18 23:12:27 +02:00
|
|
|
void InfoTooltip(const char *text);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
bool TitleBarButton(const char *label, ImVec2 size_arg);
|
|
|
|
bool ToolBarButton(const char *symbol, ImVec4 color);
|
|
|
|
bool IconButton(const char *symbol, ImVec4 color, ImVec2 size_arg = ImVec2(0, 0));
|
2021-08-21 00:51:50 +02:00
|
|
|
|
2023-01-18 14:30:44 +01:00
|
|
|
bool InputIntegerPrefix(const char* label, const char *prefix, void *value, ImGuiDataType type, const char *format, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-05-30 16:36:46 +02:00
|
|
|
bool InputHexadecimal(const char* label, u32 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-02-08 22:25:25 +01:00
|
|
|
bool InputHexadecimal(const char* label, u64 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-02-08 21:10:48 +01:00
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
inline bool HasSecondPassed() {
|
|
|
|
return static_cast<ImU32>(ImGui::GetTime() * 100) % 100 <= static_cast<ImU32>(ImGui::GetIO().DeltaTime * 100);
|
|
|
|
}
|
|
|
|
|
2021-09-28 12:34:55 +02:00
|
|
|
void OpenPopupInWindow(const char *window_name, const char *popup_name);
|
2021-02-25 00:17:41 +01:00
|
|
|
|
|
|
|
struct ImHexCustomData {
|
|
|
|
ImVec4 Colors[ImGuiCustomCol_COUNT];
|
2023-05-22 12:00:35 +02:00
|
|
|
|
|
|
|
struct Styles {
|
|
|
|
float WindowBlur = 0.0F;
|
|
|
|
} styles;
|
2021-02-25 00:17:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ImU32 GetCustomColorU32(ImGuiCustomCol idx, float alpha_mul = 1.0F);
|
2021-08-21 00:51:50 +02:00
|
|
|
ImVec4 GetCustomColorVec4(ImGuiCustomCol idx, float alpha_mul = 1.0F);
|
2021-02-25 00:17:41 +01:00
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
inline ImHexCustomData::Styles& GetCustomStyle() {
|
|
|
|
auto &customData = *static_cast<ImHexCustomData *>(GImGui->IO.UserData);
|
|
|
|
|
|
|
|
return customData.styles;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetCustomStyleFloat(ImGuiCustomStyle idx);
|
|
|
|
ImVec2 GetCustomStyleVec2(ImGuiCustomStyle idx);
|
|
|
|
|
2021-02-25 00:17:41 +01:00
|
|
|
void StyleCustomColorsDark();
|
|
|
|
void StyleCustomColorsLight();
|
|
|
|
void StyleCustomColorsClassic();
|
2021-12-16 23:48:52 +01:00
|
|
|
|
|
|
|
void SmallProgressBar(float fraction, float yOffset = 0.0F);
|
2021-12-31 01:10:06 +01:00
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
inline void TextFormatted(const std::string &fmt, auto &&...args) {
|
2021-12-31 01:10:06 +01:00
|
|
|
ImGui::TextUnformatted(hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
|
|
|
}
|
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
inline void TextFormattedColored(ImColor color, const std::string &fmt, auto &&...args) {
|
2021-12-31 01:10:06 +01:00
|
|
|
ImGui::TextColored(color, "%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
|
|
|
}
|
2022-01-15 14:14:53 +01:00
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
inline void TextFormattedDisabled(const std::string &fmt, auto &&...args) {
|
2022-01-15 14:14:53 +01:00
|
|
|
ImGui::TextDisabled("%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
|
|
|
}
|
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
inline void TextFormattedWrapped(const std::string &fmt, auto &&...args) {
|
2022-01-15 14:14:53 +01:00
|
|
|
ImGui::TextWrapped("%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
|
|
|
}
|
2022-01-24 00:46:19 +01:00
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
inline void TextFormattedCentered(const std::string &fmt, auto &&...args) {
|
2022-02-19 18:02:44 +01:00
|
|
|
auto text = hex::format(fmt, std::forward<decltype(args)>(args)...);
|
2022-01-24 00:46:19 +01:00
|
|
|
auto availableSpace = ImGui::GetContentRegionAvail();
|
|
|
|
auto textSize = ImGui::CalcTextSize(text.c_str(), nullptr, false, availableSpace.x * 0.75F);
|
|
|
|
|
|
|
|
ImGui::SetCursorPos(((availableSpace - textSize) / 2.0F));
|
|
|
|
|
|
|
|
ImGui::PushTextWrapPos(availableSpace.x * 0.75F);
|
|
|
|
ImGui::TextFormattedWrapped("{}", text);
|
|
|
|
ImGui::PopTextWrapPos();
|
|
|
|
}
|
2022-03-03 09:24:09 +01:00
|
|
|
|
|
|
|
bool InputText(const char* label, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-09-19 11:29:51 +02:00
|
|
|
bool InputTextIcon(const char* label, const char *icon, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-07-05 00:00:00 +02:00
|
|
|
bool InputText(const char *label, std::u8string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-03-03 09:24:09 +01:00
|
|
|
bool InputTextMultiline(const char* label, std::string &buffer, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-07-23 20:38:38 +02:00
|
|
|
bool InputTextWithHint(const char *label, const char *hint, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-05-27 20:42:07 +02:00
|
|
|
|
|
|
|
bool InputScalarCallback(const char* label, ImGuiDataType data_type, void* p_data, const char* format, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data);
|
|
|
|
|
|
|
|
void HideTooltip();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
|
|
bool BitCheckbox(const char* label, bool* v);
|
2022-08-07 12:20:40 +02:00
|
|
|
|
2023-05-05 22:00:17 +02:00
|
|
|
bool DimmedButton(const char* label);
|
2023-05-11 12:00:45 +02:00
|
|
|
bool DimmedIconButton(const char *symbol, ImVec4 color, ImVec2 size_arg = ImVec2(0, 0));
|
2023-05-05 22:00:17 +02:00
|
|
|
|
2021-01-27 00:00:20 +01:00
|
|
|
}
|