2020-12-22 18:10:01 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <imgui.h>
|
2021-09-20 23:40:36 +02:00
|
|
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
|
|
|
#include <imgui_internal.h>
|
2021-12-31 01:10:06 +01:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2021-02-25 21:50:57 +01:00
|
|
|
|
|
|
|
#include <fontawesome_font.h>
|
2021-08-04 14:01:24 +02:00
|
|
|
#include <codicons_font.h>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
#include <hex/api/imhex_api.hpp>
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/api/event.hpp>
|
2021-01-27 14:26:24 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2022-02-27 23:25:39 +01:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/api/localization.hpp>
|
2021-09-08 15:18:24 +02:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
class View {
|
|
|
|
public:
|
2021-03-03 22:26:17 +01:00
|
|
|
explicit View(std::string unlocalizedViewName);
|
2020-12-22 18:10:01 +01:00
|
|
|
virtual ~View() = default;
|
|
|
|
|
|
|
|
virtual void drawContent() = 0;
|
2021-02-07 14:29:13 +01:00
|
|
|
virtual void drawAlwaysVisible() { }
|
2022-02-01 18:09:40 +01:00
|
|
|
[[nodiscard]] virtual bool isAvailable() const;
|
|
|
|
[[nodiscard]] virtual bool shouldProcess() const { return this->isAvailable() && this->getWindowOpenState(); }
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
static void drawCommonInterfaces();
|
|
|
|
|
2021-09-22 17:56:06 +02:00
|
|
|
static void showMessagePopup(const std::string &message);
|
2021-09-08 15:18:24 +02:00
|
|
|
static void showErrorPopup(const std::string &errorMessage);
|
|
|
|
static void showFatalPopup(const std::string &errorMessage);
|
2022-02-21 21:46:25 +01:00
|
|
|
static void showYesNoQuestionPopup(const std::string &message, const std::function<void()> &yesCallback, const std::function<void()> &noCallback);
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
static void showFileChooserPopup(const std::vector<std::fs::path> &paths, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::fs::path)> &callback);
|
2022-01-23 21:52:43 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
[[nodiscard]] virtual bool hasViewMenuItemEntry() const;
|
|
|
|
[[nodiscard]] virtual ImVec2 getMinSize() const;
|
|
|
|
[[nodiscard]] virtual ImVec2 getMaxSize() const;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
[[nodiscard]] bool &getWindowOpenState();
|
|
|
|
[[nodiscard]] const bool &getWindowOpenState() const;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] const std::string &getUnlocalizedName() const;
|
2022-01-18 00:10:10 +01:00
|
|
|
[[nodiscard]] std::string getName() const;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-09-22 17:56:06 +02:00
|
|
|
static void confirmButtons(const std::string &textLeft, const std::string &textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn);
|
|
|
|
static void discardNavigationRequests();
|
2021-01-04 00:19:56 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
static inline std::string toWindowName(const std::string &unlocalizedName) {
|
2021-09-20 20:42:30 +02:00
|
|
|
return LangEntry(unlocalizedName) + "###" + unlocalizedName;
|
2021-03-03 22:26:17 +01:00
|
|
|
}
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
static ImFontAtlas *getFontAtlas() { return View::s_fontAtlas; }
|
|
|
|
static void setFontAtlas(ImFontAtlas *atlas) { View::s_fontAtlas = atlas; }
|
|
|
|
|
|
|
|
static ImFontConfig getFontConfig() { return View::s_fontConfig; }
|
|
|
|
static void setFontConfig(ImFontConfig config) { View::s_fontConfig = config; }
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
private:
|
2021-03-03 22:26:17 +01:00
|
|
|
std::string m_unlocalizedViewName;
|
2021-04-12 21:08:36 +02:00
|
|
|
bool m_windowOpen = false;
|
2021-12-23 15:11:38 +01:00
|
|
|
std::map<Shortcut, std::function<void()>> m_shortcuts;
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
static std::string s_popupMessage;
|
|
|
|
|
2022-02-21 21:46:25 +01:00
|
|
|
static std::function<void()> s_yesCallback, s_noCallback;
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
static u32 s_selectableFileIndex;
|
2022-03-04 11:36:37 +01:00
|
|
|
static std::vector<std::fs::path> s_selectableFiles;
|
|
|
|
static std::function<void(std::fs::path)> s_selectableFileOpenCallback;
|
2022-02-01 18:09:40 +01:00
|
|
|
static std::vector<nfdfilteritem_t> s_selectableFilesValidExtensions;
|
|
|
|
|
|
|
|
static ImFontAtlas *s_fontAtlas;
|
|
|
|
static ImFontConfig s_fontConfig;
|
|
|
|
|
2021-12-23 15:11:38 +01:00
|
|
|
friend class ShortcutManager;
|
2020-12-22 18:10:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|