From 1b1f11e0b887d933e7eedd7b8ee4e5867b07e477 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 20 Mar 2024 09:10:35 +0300 Subject: [PATCH] minor refactor --- src/engine.h | 5 +- src/frontend/menu/menu.h | 1 - src/frontend/menu/menu_commons.h | 2 +- src/graphics/ui/GUI.cpp | 13 ++-- src/window/input.cpp | 126 +++++++++++++++---------------- src/window/input.h | 22 +++--- 6 files changed, 83 insertions(+), 86 deletions(-) diff --git a/src/engine.h b/src/engine.h index 1c2d0801..b48bbe02 100644 --- a/src/engine.h +++ b/src/engine.h @@ -31,12 +31,13 @@ public: }; class Engine { + EngineSettings& settings; + EnginePaths* paths; + std::unique_ptr assets = nullptr; std::shared_ptr screen = nullptr; std::vector contentPacks; - EngineSettings& settings; std::unique_ptr content = nullptr; - EnginePaths* paths; std::unique_ptr resPaths = nullptr; uint64_t frame = 0; diff --git a/src/frontend/menu/menu.h b/src/frontend/menu/menu.h index c7c27bd9..c505b3a6 100644 --- a/src/frontend/menu/menu.h +++ b/src/frontend/menu/menu.h @@ -7,7 +7,6 @@ #include #include "../../content/ContentPack.h" - namespace gui { class Panel; } diff --git a/src/frontend/menu/menu_commons.h b/src/frontend/menu/menu_commons.h index 3181c2d9..eb8543fc 100644 --- a/src/frontend/menu/menu_commons.h +++ b/src/frontend/menu/menu_commons.h @@ -26,4 +26,4 @@ namespace menus { ); } -#endif // FRONTEND_MENU_MENU_COMMONS_H_ \ No newline at end of file +#endif // FRONTEND_MENU_MENU_COMMONS_H_ diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index 5da55ee6..273f021c 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -71,18 +71,17 @@ void GUI::actMouse(float delta) { pressed = nullptr; } - if (hover) {//WTF?! FIXME - for (int i = static_cast(mousecode::BUTTON_1); i < static_cast(mousecode::BUTTON_1)+12; i++) { - if (Events::jclicked(i)) { - hover->clicked(this, static_cast(i)); + if (hover) { + for (mousecode code : MOUSECODES_ALL) { + if (Events::jclicked(code)) { + hover->clicked(this, code); } } } } -/** Processing user input and UI logic - * @param delta delta time -*/ +/// @brief Processing user input and UI logic +/// @param delta delta time void GUI::act(float delta) { while (!postRunnables.empty()) { runnable callback = postRunnables.back(); diff --git a/src/window/input.cpp b/src/window/input.cpp index 15aa820d..bcb03b46 100644 --- a/src/window/input.cpp +++ b/src/window/input.cpp @@ -18,74 +18,70 @@ void Binding::reset(mousecode code) { reset(inputtype::mouse, static_cast(code)); } -namespace input_util { - - std::string to_string(keycode code) { - int icode_repr = static_cast(code); +std::string input_util::to_string(keycode code) { + int icode_repr = static_cast(code); #ifdef _WIN32 - char name[64]; - int result = GetKeyNameTextA(glfwGetKeyScancode(icode_repr) << 16, name, 64); - if (result == NULL) return "Unknown"; - return std::string(name); + char name[64]; + int result = GetKeyNameTextA(glfwGetKeyScancode(icode_repr) << 16, name, 64); + if (result == NULL) return "Unknown"; + return std::string(name); #else - const char* name = glfwGetKeyName(icode_repr, glfwGetKeyScancode(icode_repr)); - if (name == nullptr) { - switch (icode_repr) { - case GLFW_KEY_TAB: return "Tab"; - case GLFW_KEY_LEFT_CONTROL: return "Left Ctrl"; - case GLFW_KEY_RIGHT_CONTROL: return "Right Ctrl"; - case GLFW_KEY_LEFT_ALT: return "Left Alt"; - case GLFW_KEY_RIGHT_ALT: return "Right Alt"; - case GLFW_KEY_LEFT_SHIFT: return "Left Shift"; - case GLFW_KEY_RIGHT_SHIFT: return "Right Shift"; - case GLFW_KEY_CAPS_LOCK: return "Caps-Lock"; - case GLFW_KEY_SPACE: return "Space"; - case GLFW_KEY_ESCAPE: return "Esc"; - case GLFW_KEY_ENTER: return "Enter"; - case GLFW_KEY_UP: return "Up"; - case GLFW_KEY_DOWN: return "Down"; - case GLFW_KEY_LEFT: return "Left"; - case GLFW_KEY_RIGHT: return "Right"; - case GLFW_KEY_BACKSPACE: return "Backspace"; - case GLFW_KEY_F1: return "F1"; - case GLFW_KEY_F2: return "F2"; - case GLFW_KEY_F3: return "F3"; - case GLFW_KEY_F4: return "F4"; - case GLFW_KEY_F5: return "F5"; - case GLFW_KEY_F6: return "F6"; - case GLFW_KEY_F7: return "F7"; - case GLFW_KEY_F8: return "F8"; - case GLFW_KEY_F9: return "F9"; - case GLFW_KEY_F10: return "F10"; - case GLFW_KEY_F11: return "F11"; - case GLFW_KEY_F12: return "F12"; - case GLFW_KEY_DELETE: return "Delete"; - case GLFW_KEY_HOME: return "Home"; - case GLFW_KEY_END: return "End"; - case GLFW_KEY_LEFT_SUPER: return "Left Super"; - case GLFW_KEY_RIGHT_SUPER: return "Right Super"; - case GLFW_KEY_PAGE_UP: return "Page Up"; - case GLFW_KEY_PAGE_DOWN: return "Page Down"; - case GLFW_KEY_INSERT: return "Insert"; - case GLFW_KEY_PRINT_SCREEN: return "Print Screen"; - case GLFW_KEY_NUM_LOCK: return "Num Lock"; - case GLFW_KEY_MENU: return "Menu"; - case GLFW_KEY_PAUSE: return "Pause"; - default: - return "Unknown"; - } + const char* name = glfwGetKeyName(icode_repr, glfwGetKeyScancode(icode_repr)); + if (name == nullptr) { + switch (icode_repr) { + case GLFW_KEY_TAB: return "Tab"; + case GLFW_KEY_LEFT_CONTROL: return "Left Ctrl"; + case GLFW_KEY_RIGHT_CONTROL: return "Right Ctrl"; + case GLFW_KEY_LEFT_ALT: return "Left Alt"; + case GLFW_KEY_RIGHT_ALT: return "Right Alt"; + case GLFW_KEY_LEFT_SHIFT: return "Left Shift"; + case GLFW_KEY_RIGHT_SHIFT: return "Right Shift"; + case GLFW_KEY_CAPS_LOCK: return "Caps-Lock"; + case GLFW_KEY_SPACE: return "Space"; + case GLFW_KEY_ESCAPE: return "Esc"; + case GLFW_KEY_ENTER: return "Enter"; + case GLFW_KEY_UP: return "Up"; + case GLFW_KEY_DOWN: return "Down"; + case GLFW_KEY_LEFT: return "Left"; + case GLFW_KEY_RIGHT: return "Right"; + case GLFW_KEY_BACKSPACE: return "Backspace"; + case GLFW_KEY_F1: return "F1"; + case GLFW_KEY_F2: return "F2"; + case GLFW_KEY_F3: return "F3"; + case GLFW_KEY_F4: return "F4"; + case GLFW_KEY_F5: return "F5"; + case GLFW_KEY_F6: return "F6"; + case GLFW_KEY_F7: return "F7"; + case GLFW_KEY_F8: return "F8"; + case GLFW_KEY_F9: return "F9"; + case GLFW_KEY_F10: return "F10"; + case GLFW_KEY_F11: return "F11"; + case GLFW_KEY_F12: return "F12"; + case GLFW_KEY_DELETE: return "Delete"; + case GLFW_KEY_HOME: return "Home"; + case GLFW_KEY_END: return "End"; + case GLFW_KEY_LEFT_SUPER: return "Left Super"; + case GLFW_KEY_RIGHT_SUPER: return "Right Super"; + case GLFW_KEY_PAGE_UP: return "Page Up"; + case GLFW_KEY_PAGE_DOWN: return "Page Down"; + case GLFW_KEY_INSERT: return "Insert"; + case GLFW_KEY_PRINT_SCREEN: return "Print Screen"; + case GLFW_KEY_NUM_LOCK: return "Num Lock"; + case GLFW_KEY_MENU: return "Menu"; + case GLFW_KEY_PAUSE: return "Pause"; + default: + return "Unknown"; } - return std::string(name); + } + return std::string(name); #endif // _WIN32 - } +} - std::string to_string(mousecode code) { - switch (code) { - case mousecode::BUTTON_1: return "LMB"; - case mousecode::BUTTON_2: return "RMB"; - case mousecode::BUTTON_3: return "MMB"; - } - return "unknown button"; +std::string input_util::to_string(mousecode code) { + switch (code) { + case mousecode::BUTTON_1: return "LMB"; + case mousecode::BUTTON_2: return "RMB"; + case mousecode::BUTTON_3: return "MMB"; } - -} \ No newline at end of file + return "unknown button"; +} diff --git a/src/window/input.h b/src/window/input.h index 331eeb41..61e45958 100644 --- a/src/window/input.h +++ b/src/window/input.h @@ -3,9 +3,7 @@ #include -/** -* @brief Represents glfw3 keycode values. -*/ +/// @brief Represents glfw3 keycode values. enum class keycode : int { ENTER = 257, TAB = 258, @@ -88,21 +86,25 @@ enum class keycode : int { }; -/** -* @brief Represents glfw3 mouse button IDs. -* @details There is a subset of glfw3 mouse button IDs. -*/ + +/// @brief Represents glfw3 mouse button IDs. +/// @details There is a subset of glfw3 mouse button IDs. enum class mousecode : int { BUTTON_1 = 0, // Left mouse button BUTTON_2 = 1, // Right mouse button BUTTON_3 = 2, // Middle mouse button }; +inline mousecode MOUSECODES_ALL[] { + mousecode::BUTTON_1, + mousecode::BUTTON_2, + mousecode::BUTTON_3 +}; namespace input_util { - // @return Key label by keycode + /// @return Key label by keycode std::string to_string(keycode code); - // @return Mouse button label by keycode + /// @return Mouse button label by keycode std::string to_string(mousecode code); } @@ -143,4 +145,4 @@ struct Binding { }; -#endif // WINDOW_INPUT_H_ \ No newline at end of file +#endif // WINDOW_INPUT_H_