impr: Various small fixes and improvements

This commit is contained in:
WerWolv
2025-01-31 19:43:39 +01:00
parent e603c75bd3
commit e6ab2c3b7e
30 changed files with 132 additions and 83 deletions

View File

@@ -134,16 +134,22 @@ endif()
if (NOT IMHEX_EXTERNAL_PLUGIN_BUILD)
if (WIN32)
set_target_properties(libimhex PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
target_link_options(libimhex PRIVATE -Wl,--export-all-symbols)
if (NOT MSVC)
target_link_options(libimhex PRIVATE -Wl,--export-all-symbols)
endif()
target_link_libraries(libimhex PRIVATE Netapi32.lib)
elseif (APPLE)
find_library(FOUNDATION NAMES Foundation)
target_link_libraries(libimhex PUBLIC ${FOUNDATION})
endif ()
target_link_libraries(libimhex PRIVATE microtar libwolv ${NFD_LIBRARIES} magic dl)
target_link_libraries(libimhex PRIVATE microtar libwolv ${NFD_LIBRARIES} magic)
target_link_libraries(libimhex PUBLIC libpl ${IMGUI_LIBRARIES} ${JTHREAD_LIBRARIES})
if (NOT WIN32)
target_link_libraries(libimhex PRIVATE dl)
endif()
precompileHeaders(libimhex "${CMAKE_CURRENT_SOURCE_DIR}/include")
endif()

View File

@@ -362,7 +362,7 @@ namespace hex {
* @brief Returns all registered achievements
* @return All achievements
*/
static const std::unordered_map<std::string, std::unordered_map<std::string, std::unique_ptr<Achievement>>>& getAchievements();
static const std::unordered_map<UnlocalizedString, std::unordered_map<UnlocalizedString, std::unique_ptr<Achievement>>>& getAchievements();
/**
* @brief Returns all achievement start nodes
@@ -370,14 +370,14 @@ namespace hex {
* @param rebuild Whether to rebuild the list of start nodes
* @return All achievement start nodes
*/
static const std::unordered_map<std::string, std::vector<AchievementNode*>>& getAchievementStartNodes(bool rebuild = true);
static const std::unordered_map<UnlocalizedString, std::vector<AchievementNode*>>& getAchievementStartNodes(bool rebuild = true);
/**
* @brief Returns all achievement nodes
* @param rebuild Whether to rebuild the list of nodes
* @return All achievement nodes
*/
static const std::unordered_map<std::string, std::list<AchievementNode>>& getAchievementNodes(bool rebuild = true);
static const std::unordered_map<UnlocalizedString, std::list<AchievementNode>>& getAchievementNodes(bool rebuild = true);
/**
* @brief Loads the progress of all achievements from the achievements save file

View File

@@ -101,10 +101,9 @@ namespace hex {
public:
UnlocalizedString() = default;
template<typename T>
UnlocalizedString(T &&arg) : m_unlocalizedString(std::forward<T>(arg)) {
static_assert(!std::same_as<std::remove_cvref_t<T>, Lang>, "Expected a unlocalized name, got a localized one!");
}
UnlocalizedString(const std::string &string) : m_unlocalizedString(string) { }
UnlocalizedString(const char *string) : m_unlocalizedString(string) { }
UnlocalizedString(const Lang& arg) = delete;
[[nodiscard]] operator std::string() const {
return m_unlocalizedString;
@@ -149,3 +148,10 @@ namespace hex {
}
}
template<>
struct std::hash<hex::UnlocalizedString> {
std::size_t operator()(const hex::UnlocalizedString &string) const noexcept {
return std::hash<std::string>{}(string.get());
}
};

View File

@@ -2,6 +2,7 @@
#include <hex/helpers/fs.hpp>
#include <array>
#include <vector>
namespace hex::paths {

View File

@@ -9,6 +9,7 @@
#include <map>
#include <span>
#include <string>
#include <numbers>
#include <opengl_support.h>
#include <GLFW/glfw3.h>
@@ -219,11 +220,11 @@ namespace hex::gl {
this->mat[row*Columns + col] = value;
}
T &operator()( const int &row,const int &col) {
T &operator()( const unsigned&row, const unsigned&col) {
return this->mat[row*Columns + col];
}
const T &operator()(const unsigned& row,const unsigned& col ) const {
const T &operator()(const unsigned& row, const unsigned& col) const {
return this->mat[row*Columns + col];
}
@@ -401,7 +402,7 @@ namespace hex::gl {
T Sx, Cx, Sy, Cy, Sz, Cz;
Vector<T,3> angles = ypr;
if(!radians)
angles *= M_PI/180;
angles *= std::numbers::pi / 180;
Sx = -sin(angles[0]); Cx = cos(angles[0]);
Sy = -sin(angles[1]); Cy = cos(angles[1]);
@@ -524,7 +525,7 @@ namespace hex::gl {
Vector<T,3> rotationVector3 = {{rotationVector[0], rotationVector[1], rotationVector[2]}};
T theta = rotationVector3.magnitude();
if (!radians)
theta *= M_PI / 180;
theta *= std::numbers::pi / 180;
Vector<T,3> axis = rotationVector3;
if (theta != 0)
axis = axis.normalize();

View File

@@ -37,7 +37,7 @@ namespace hex {
template<typename T>
[[nodiscard]] std::vector<std::vector<T>> sampleChannels(const std::vector<T> &data, size_t count, size_t channels) {
if (channels == 0) return {};
size_t signalLength = std::max(1.0, double(data.size()) / channels);
size_t signalLength = std::max<double>(1.0, double(data.size()) / channels);
size_t stride = std::max(1.0, double(signalLength) / count);

View File

@@ -12,13 +12,13 @@
namespace hex {
static AutoReset<std::unordered_map<std::string, std::unordered_map<std::string, std::unique_ptr<Achievement>>>> s_achievements;
const std::unordered_map<std::string, std::unordered_map<std::string, std::unique_ptr<Achievement>>> &AchievementManager::getAchievements() {
static AutoReset<std::unordered_map<UnlocalizedString, std::unordered_map<UnlocalizedString, std::unique_ptr<Achievement>>>> s_achievements;
const std::unordered_map<UnlocalizedString, std::unordered_map<UnlocalizedString, std::unique_ptr<Achievement>>> &AchievementManager::getAchievements() {
return *s_achievements;
}
static AutoReset<std::unordered_map<std::string, std::list<AchievementManager::AchievementNode>>> s_nodeCategoryStorage;
std::unordered_map<std::string, std::list<AchievementManager::AchievementNode>>& getAchievementNodesMutable(bool rebuild) {
static AutoReset<std::unordered_map<UnlocalizedString, std::list<AchievementManager::AchievementNode>>> s_nodeCategoryStorage;
std::unordered_map<UnlocalizedString, std::list<AchievementManager::AchievementNode>>& getAchievementNodesMutable(bool rebuild) {
if (!s_nodeCategoryStorage->empty() || !rebuild)
return s_nodeCategoryStorage;
@@ -36,12 +36,12 @@ namespace hex {
return s_nodeCategoryStorage;
}
const std::unordered_map<std::string, std::list<AchievementManager::AchievementNode>>& AchievementManager::getAchievementNodes(bool rebuild) {
const std::unordered_map<UnlocalizedString, std::list<AchievementManager::AchievementNode>>& AchievementManager::getAchievementNodes(bool rebuild) {
return getAchievementNodesMutable(rebuild);
}
static AutoReset<std::unordered_map<std::string, std::vector<AchievementManager::AchievementNode*>>> s_startNodes;
const std::unordered_map<std::string, std::vector<AchievementManager::AchievementNode*>>& AchievementManager::getAchievementStartNodes(bool rebuild) {
static AutoReset<std::unordered_map<UnlocalizedString, std::vector<AchievementManager::AchievementNode*>>> s_startNodes;
const std::unordered_map<UnlocalizedString, std::vector<AchievementManager::AchievementNode*>>& AchievementManager::getAchievementStartNodes(bool rebuild) {
if (!s_startNodes->empty() || !rebuild)
return s_startNodes;
@@ -187,10 +187,10 @@ namespace hex {
const auto &category = newAchievement->getUnlocalizedCategory();
const auto &name = newAchievement->getUnlocalizedName();
auto [categoryIter, categoryInserted] = s_achievements->insert({ category, std::unordered_map<std::string, std::unique_ptr<Achievement>>{} });
auto [categoryIter, categoryInserted] = s_achievements->insert({ category, std::unordered_map<UnlocalizedString, std::unique_ptr<Achievement>>{} });
auto &[categoryKey, achievements] = *categoryIter;
auto [achievementIter, achievementInserted] = achievements.insert({ name, std::move(newAchievement) });
auto [achievementIter, achievementInserted] = achievements.emplace(name, std::move(newAchievement));
auto &[achievementKey, achievement] = *achievementIter;
achievementAdded();
@@ -239,7 +239,7 @@ namespace hex {
achievement->setProgress(progress);
} catch (const std::exception &e) {
log::warn("Failed to load achievement progress for '{}::{}': {}", categoryName, achievementName, e.what());
log::warn("Failed to load achievement progress for '{}::{}': {}", categoryName.get(), achievementName.get(), e.what());
}
}
}

View File

@@ -33,7 +33,7 @@ namespace hex {
namespace impl {
struct OnChange {
u32 id;
u64 id;
OnChangeCallback callback;
};
@@ -714,15 +714,15 @@ namespace hex {
namespace impl {
static AutoReset<std::map<std::string, std::unique_ptr<View>>> s_views;
const std::map<std::string, std::unique_ptr<View>>& getEntries() {
static AutoReset<std::map<UnlocalizedString, std::unique_ptr<View>>> s_views;
const std::map<UnlocalizedString, std::unique_ptr<View>>& getEntries() {
return *s_views;
}
void add(std::unique_ptr<View> &&view) {
log::debug("Registered new view: {}", view->getUnlocalizedName().get());
s_views->insert({ view->getUnlocalizedName(), std::move(view) });
s_views->emplace(view->getUnlocalizedName(), std::move(view));
}
}
@@ -1126,7 +1126,9 @@ namespace hex {
namespace ContentRegistry::HexEditor {
const int DataVisualizer::TextInputFlags = ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_AlwaysOverwrite;
int DataVisualizer::DefaultTextInputFlags() {
return ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_AlwaysOverwrite;
}
bool DataVisualizer::drawDefaultScalarEditingTextBox(u64 address, const char *format, ImGuiDataType dataType, u8 *data, ImGuiInputTextFlags flags) const {
struct UserData {
@@ -1144,7 +1146,7 @@ namespace hex {
};
ImGui::PushID(reinterpret_cast<void*>(address));
ImGuiExt::InputScalarCallback("##editing_input", dataType, data, format, flags | TextInputFlags | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int {
ImGuiExt::InputScalarCallback("##editing_input", dataType, data, format, flags | DefaultTextInputFlags() | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int {
auto &userData = *static_cast<UserData*>(data->UserData);
if (data->CursorPos >= userData.maxChars)
@@ -1175,7 +1177,7 @@ namespace hex {
};
ImGui::PushID(reinterpret_cast<void*>(address));
ImGui::InputText("##editing_input", data.data(), data.size() + 1, flags | TextInputFlags | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int {
ImGui::InputText("##editing_input", data.data(), data.size() + 1, flags | DefaultTextInputFlags() | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int {
auto &userData = *static_cast<UserData*>(data->UserData);
userData.data->resize(data->BufSize);

View File

@@ -15,7 +15,12 @@
#include <string>
#include <magic.h>
#include <unistd.h>
#if defined(_MSC_VER)
#include <direct.h>
#else
#include <unistd.h>
#endif
#if defined(OS_WINDOWS)
#define MAGIC_PATH_SEPARATOR ";"

View File

@@ -332,7 +332,7 @@ namespace hex::prv {
else if (category == "description")
return magic::getDescription(this);
else if (category == "provider_type")
return this->getTypeName();
return this->getTypeName().get();
else
return 0;
}

View File

@@ -289,7 +289,7 @@ public:
void SetLanguageDefinition(const LanguageDefinition& aLanguageDef);
const LanguageDefinition& GetLanguageDefinition() const { return mLanguageDefinition; }
static const Palette& GetPalette() { return sPaletteBase; }
static const Palette& GetPalette();
static void SetPalette(const Palette& aValue);
void SetErrorMarkers(const ErrorMarkers& aMarkers) { mErrorMarkers = aMarkers; }
@@ -613,7 +613,6 @@ private:
bool mIgnoreImGuiChild = false;
bool mShowWhitespaces = true;
static Palette sPaletteBase;
Palette mPalette = {};
LanguageDefinition mLanguageDefinition = {};
RegexList mRegexList;

View File

@@ -25,7 +25,7 @@ bool equals(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Bi
const int TextEditor::sCursorBlinkInterval = 1200;
const int TextEditor::sCursorBlinkOnTime = 800;
TextEditor::Palette TextEditor::sPaletteBase = TextEditor::GetDarkPalette();
TextEditor::Palette sPaletteBase = TextEditor::GetDarkPalette();
TextEditor::FindReplaceHandler::FindReplaceHandler() : mWholeWord(false),mFindRegEx(false),mMatchCase(false) {}
@@ -79,6 +79,8 @@ void TextEditor::SetLanguageDefinition(const LanguageDefinition &aLanguageDef) {
Colorize();
}
const TextEditor::Palette& TextEditor::GetPalette() { return sPaletteBase; }
void TextEditor::SetPalette(const Palette &aValue) {
sPaletteBase = aValue;
}

View File

@@ -25,16 +25,18 @@ if (NOT IMHEX_EXTERNAL_PLUGIN_BUILD)
set(GLFW_INCLUDE_DIRS ${glfw3_INCLUDE_DIRS})
set(GLFW_LIBRARIES ${glfw3_LIBRARIES})
if (NOT glfw3_FOUND OR "${GLFW_LIBRARIES}" STREQUAL "")
if (NOT glfw3_FOUND AND "${GLFW_LIBRARIES}" STREQUAL "")
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
if ("${GLFW_LIBRARIES}" MATCHES ".+dll")
set(GLFW_LIBRARIES "glfw3")
endif ()
else()
set(GLFW_LIBRARIES GLFW::GLFW)
endif ()
endif()
if ("${GLFW_LIBRARIES}" MATCHES ".+dll")
set(GLFW_LIBRARIES "glfw3")
endif ()
target_include_directories(imgui_backend PUBLIC ${FREETYPE_INCLUDE_DIRS} ${OpenGL_INCLUDE_DIRS})
target_link_directories(imgui_backend PUBLIC ${FREETYPE_LIBRARY_DIRS} ${OpenGL_LIBRARY_DIRS})
target_link_libraries(imgui_backend PUBLIC ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES})

View File

@@ -1,5 +1,10 @@
#pragma once
#if !defined(WINGDIAPI)
#define WINGDIAPI extern "C"
#define APIENTRY
#endif
#if defined(OS_WEB)
#define GLFW_INCLUDE_ES3
#include <GLES3/gl3.h>

View File

@@ -113,6 +113,11 @@
#define _CRT_SECURE_NO_WARNINGS
#endif
#if !defined(WINGDIAPI)
#define WINGDIAPI extern "C"
#define APIENTRY
#endif
#include "imgui.h"
#ifndef IMGUI_DISABLE
#include "imgui_impl_opengl3.h"