#pragma once /** * @file handler.h */ #include #include #include #include #include #include "tree.h" #include "imgui/imgui.h" #include "nlohmann/json.hpp" namespace satdump { namespace viewer { /** * @brief SatDump's handler base class. * * Handlers are meant to handle displaying and maniipulating * data inside the viewer. To avoid code duplication, they may * also serve as headless processors. * * This implements all basic UI functions and handler tree system, * as it is intended for handlers to be able to contain any other * handler as a dependency. */ class Handler { private: TreeDrawerToClean tree_local; std::vector> subhandlers; std::mutex subhandlers_mtx; std::vector> subhandlers_marked_for_del; bool handler_can_be_dragged = true; bool handler_can_be_dragged_to = true; bool handler_can_subhandlers_be_dragged = true; public: /** * @brief Render viewer menu left sidebar */ virtual void drawMenu() = 0; /** * @brief Render viewer contents (center/left) */ virtual void drawContents(ImVec2 win_size) = 0; /** * @brief Render viewer menu bar (in the left sidebar) */ virtual void drawMenuBar() {} /** * @brief Render viewer menu bar (in the left sidebar) * @param h currently selected handler, to be replaced if * another is selected */ virtual void drawTreeMenu(std::shared_ptr &h); /** * @brief Get this handler's readable name * @return name as a string */ virtual std::string getName() { return "!!!Invalid!!!"; } /** * @brief Get this handler's ImGui ID for rendering in the tree * @return ID as a string */ std::string getTreeID() { return getName() + "##" + std::to_string((size_t)this); } /** * @brief Check if this handler contains any sub-handlers * @return true if subhandlers are present */ bool hasSubhandlers(); /** * @brief Add a new subhandler * @param handler the handler to add */ void addSubHandler(std::shared_ptr handler); /** * @brief Delete a subhandler * @param handler the handler to delete */ void delSubHandler(std::shared_ptr handler); /** * @brief Set if a handler can be dragged around in the tree * @param v true to have it be draggable */ void setCanBeDragged(bool v) { handler_can_be_dragged = v; } /** * @brief Set if a handler can be dragged to in the tree * @param v true to have it be a valid drag target */ void setCanBeDraggedTo(bool v) { handler_can_be_dragged_to = v; } /** * @brief Set if a handler's subhandlers can be dragged to in the tree * @param v true to have them be draggable */ void setSubHandlersCanBeDragged(bool v) { handler_can_subhandlers_be_dragged = v; } /** * @brief Optional, allows setting a configuration/state from JSON * @param p JSON object */ virtual void setConfig(nlohmann::json p) {} /** * @brief Optional, allows getting a configuration/state as JSON * @return JSON object */ virtual nlohmann::json getConfig(); public: static std::string getID(); // TODOREWORK static std::shared_ptr getInstance(); }; extern std::map()>> handlers_registry; // TODOREWORK? void registerHandlers(); } }