Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Mar 20, 2024
1 parent 4b25cc3 commit 1b1f11e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 86 deletions.
5 changes: 3 additions & 2 deletions src/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ class initialize_error : public std::runtime_error {
};

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;
Expand Down
1 change: 0 additions & 1 deletion src/frontend/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <functional>
#include "../../content/ContentPack.h"


namespace gui {
class Panel;
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/menu/menu_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ namespace menus {
);
}

#endif // FRONTEND_MENU_MENU_COMMONS_H_
#endif // FRONTEND_MENU_MENU_COMMONS_H_
13 changes: 6 additions & 7 deletions src/graphics/ui/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
126 changes: 61 additions & 65 deletions src/window/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
#endif // _WIN32
}
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";
}
22 changes: 12 additions & 10 deletions src/window/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

#include <string>

/**
* @brief Represents glfw3 keycode values.
*/
/// @brief Represents glfw3 keycode values.
enum class keycode : int {
ENTER = 257,
TAB = 258,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -143,4 +145,4 @@ struct Binding {
};


#endif // WINDOW_INPUT_H_
#endif // WINDOW_INPUT_H_

0 comments on commit 1b1f11e

Please sign in to comment.