minor refactor

This commit is contained in:
MihailRis 2024-03-20 09:10:35 +03:00
parent 4b25cc38d9
commit 1b1f11e0b8
6 changed files with 83 additions and 86 deletions

View File

@ -31,12 +31,13 @@ public:
};
class Engine {
EngineSettings& settings;
EnginePaths* paths;
std::unique_ptr<Assets> assets = nullptr;
std::shared_ptr<Screen> screen = nullptr;
std::vector<ContentPack> contentPacks;
EngineSettings& settings;
std::unique_ptr<Content> content = nullptr;
EnginePaths* paths;
std::unique_ptr<ResPaths> resPaths = nullptr;
uint64_t frame = 0;

View File

@ -7,7 +7,6 @@
#include <functional>
#include "../../content/ContentPack.h"
namespace gui {
class Panel;
}

View File

@ -26,4 +26,4 @@ namespace menus {
);
}
#endif // FRONTEND_MENU_MENU_COMMONS_H_
#endif // FRONTEND_MENU_MENU_COMMONS_H_

View File

@ -71,18 +71,17 @@ void GUI::actMouse(float delta) {
pressed = nullptr;
}
if (hover) {//WTF?! FIXME
for (int i = static_cast<int>(mousecode::BUTTON_1); i < static_cast<int>(mousecode::BUTTON_1)+12; i++) {
if (Events::jclicked(i)) {
hover->clicked(this, static_cast<mousecode>(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();

View File

@ -18,74 +18,70 @@ void Binding::reset(mousecode code) {
reset(inputtype::mouse, static_cast<int>(code));
}
namespace input_util {
std::string to_string(keycode code) {
int icode_repr = static_cast<int>(code);
std::string input_util::to_string(keycode code) {
int icode_repr = static_cast<int>(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";
}
}
return "unknown button";
}

View File

@ -3,9 +3,7 @@
#include <string>
/**
* @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_
#endif // WINDOW_INPUT_H_