Fixed Input System

Gui_Panel_Refactor
Joeyrp 4 years ago
parent b0142f3348
commit 54982faa24

@ -17,7 +17,7 @@ Core:
✔ Dear ImGui class with basic initialization @done (9/10/2021, 1:42:19 PM) ✔ Dear ImGui class with basic initialization @done (9/10/2021, 1:42:19 PM)
✔ Debug log window @done (9/10/2021, 4:44:48 PM) ✔ Debug log window @done (9/10/2021, 4:44:48 PM)
☐ Add key to show debug log window ☐ Add key to show debug log window
. ☐ Add checkboxes to disable log categories and levels
Input: Input:
✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM) ✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM)

@ -182,6 +182,7 @@ namespace lunarium
void Core::RunGameLoop() void Core::RunGameLoop()
{ {
//glfwSetInputMode(mpWindow->GetWindow(), GLFW_STICKY_KEYS, GLFW_TRUE);
mFrameCounter.Reset(); mFrameCounter.Reset();
// TODO: Init frame counter // TODO: Init frame counter
@ -204,6 +205,12 @@ namespace lunarium
mpWindow->SetShouldCloseFlag(true); mpWindow->SetShouldCloseFlag(true);
} }
if (mpInput->IsKeyPressed(KeyCode::F3))
{
//Logger::Log(LogCategory::CORE, LogLevel::INFO, "Toggling the Debug Log Window");
LogGui::GetInstance().SetShow(!LogGui::GetInstance().IsShown());
}
// DEBUG: Graphics testing // DEBUG: Graphics testing
static int width = 500; static int width = 500;
if (mpInput->IsKeyDown(KeyCode::LEFT)) if (mpInput->IsKeyDown(KeyCode::LEFT))

@ -43,7 +43,7 @@ namespace lunarium
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
LogGui* LogGui::mpInstance = nullptr; LogGui* LogGui::mpInstance = nullptr;
LogGui::LogGui() LogGui::LogGui()
: mbShow(true), mListener(this) : mbShow(true), mListener(this), mbOglDebug(false)
{ {
} }
@ -77,21 +77,45 @@ namespace lunarium
if (!mbShow) if (!mbShow)
return; return;
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(300, 400), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Debug Log", &mbShow)) if (!ImGui::Begin("Debug Log", &mbShow))
{ {
ImGui::End(); ImGui::End();
return; return;
} }
ImGui::Checkbox("OGL_DEBUG", &mbOglDebug);
ImGui::Separator();
ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar); ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
for (int i = 0; i < mMsgHistory.size(); i++) for (int i = 0; i < mMsgHistory.size(); i++)
{ {
if (mMsgHistory[i].find("[OGL_DEBUG]") != std::string::npos && !mbOglDebug)
{
continue;
}
ImVec4 color(1.0f, 1.0f, 1.0f, 1.0f);
if (mMsgHistory[i].find("WANRING") != std::string::npos)
{
color = ImVec4(0.75f, 0.75f, 0.0f, 1.0f);
}
if (mMsgHistory[i].find("ERROR") != std::string::npos)
{
color = ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
}
const char* msg = mMsgHistory[i].c_str(); const char* msg = mMsgHistory[i].c_str();
int len = strlen(msg); int len = strlen(msg);
ImGui::TextUnformatted(msg);
ImGui::PushTextWrapPos(ImGui::GetWindowWidth());
ImGui::TextColored(color, msg);
ImGui::PopTextWrapPos();
} }
ImGui::PopStyleVar();
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f); ImGui::SetScrollHereY(1.0f);

@ -47,6 +47,8 @@ namespace lunarium
friend GuiListener; friend GuiListener;
GuiListener mListener; GuiListener mListener;
bool mbOglDebug;
private: private:
LogGui(); LogGui();
LogGui(const LogGui&) = delete; LogGui(const LogGui&) = delete;

@ -18,7 +18,7 @@ namespace lunarium
InputManager::InputManager() InputManager::InputManager()
: mpWindow(nullptr) : mpWindow(nullptr)
{ {
memset(mKeyboardState, 0, NUM_KEYS); memset(mKeyboardState, 0, 512);
} }
void InputManager::Initialize(Window* pWindow) void InputManager::Initialize(Window* pWindow)
@ -51,21 +51,21 @@ namespace lunarium
bool altHeld = mpWindow->IsKeyDown(KeyCode::ALT); bool altHeld = mpWindow->IsKeyDown(KeyCode::ALT);
for (int i = 0; i < NUM_KEYS; i++) for (int i = 0; i < KeyCodeList.size(); i++)
{ {
Keyboard::Key key = Keyboard::GetInstance()->GetKey((KeyCode)i); Keyboard::Key key = Keyboard::GetInstance()->GetKey((KeyCode)KeyCodeList[i]);
bool keyIsDown = mpWindow->IsKeyDown(KeyCodeList[i]); bool keyIsDown = mpWindow->IsKeyDown(KeyCodeList[i]);
// Mouse Buttons are a special case // Mouse Buttons are a special case
if (IsMouseButton(i)) if (IsMouseButton(KeyCodeList[i]))
{ {
if (keyIsDown) if (keyIsDown)
{ {
mKeyboardState[i] = KEY_DOWN; mKeyboardState[KeyCodeList[i]] = KEY_DOWN;
} }
else else
{ {
mKeyboardState[i] = KEY_UP; mKeyboardState[KeyCodeList[i]] = KEY_UP;
} }
continue; continue;
@ -83,9 +83,10 @@ namespace lunarium
} }
// Key was just pressed this frame // Key was just pressed this frame
if (KEY_UP == mKeyboardState[i]) if (KEY_UP == mKeyboardState[KeyCodeList[i]])
{ {
mKeyboardState[i] = KEY_DOWN; //Logger::Log(LogCategory::CORE, LogLevel::INFO, "Key Down: %d, %s", KeyCodeList[i], key.Name.c_str());
mKeyboardState[KeyCodeList[i]] = KEY_DOWN;
KeyPress kp; KeyPress kp;
kp.Key = key; kp.Key = key;
@ -99,9 +100,9 @@ namespace lunarium
else else
{ {
// Key was just released this frame // Key was just released this frame
if (KEY_DOWN == mKeyboardState[i]) if (KEY_DOWN == mKeyboardState[KeyCodeList[i]])
{ {
mKeyboardState[i] = KEY_UP; mKeyboardState[KeyCodeList[i]] = KEY_UP;
mKeyEvents.KeysReleased.push_back(key); mKeyEvents.KeysReleased.push_back(key);
} }
} }
@ -137,7 +138,6 @@ namespace lunarium
return false; return false;
} }
// TODO: FIX WINDOWS SPECIFIC CODE:
glm::vec2 InputManager::GetMousePosition() glm::vec2 InputManager::GetMousePosition()
{ {
// POINT p; // POINT p;

@ -84,7 +84,7 @@ namespace lunarium
private: private:
Window* mpWindow; Window* mpWindow;
unsigned char mKeyboardState[NUM_KEYS]; unsigned char mKeyboardState[512];
//unsigned char mKeyboardPreviousState[NUM_KEYS]; //unsigned char mKeyboardPreviousState[NUM_KEYS];
std::vector<KeyCode> mModifiers; std::vector<KeyCode> mModifiers;
}; };

@ -124,6 +124,21 @@ namespace lunarium
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::RIGHT, { KeyCode::RIGHT, "Right Arrow", "Right Arrow", (char)(0), (char)(0) })); mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::RIGHT, { KeyCode::RIGHT, "Right Arrow", "Right Arrow", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::DOWN, { KeyCode::DOWN, "Down Arrow", "Down Arrow", (char)(0), (char)(0) })); mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::DOWN, { KeyCode::DOWN, "Down Arrow", "Down Arrow", (char)(0), (char)(0) }));
// F Keys
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F1, { KeyCode::F1, "F1", "F1", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F2, { KeyCode::F2, "F2", "F2", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F3, { KeyCode::F3, "F3", "F3", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F4, { KeyCode::F4, "F4", "F4", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F5, { KeyCode::F5, "F5", "F5", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F6, { KeyCode::F6, "F6", "F6", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F7, { KeyCode::F7, "F7", "F7", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F8, { KeyCode::F8, "F8", "F8", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F9, { KeyCode::F9, "F9", "F9", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F10, { KeyCode::F10, "F10", "F10", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F11, { KeyCode::F11, "F11", "F11", (char)(0), (char)(0) }));
mKeyboard.insert(std::pair<KeyCode, Key>(KeyCode::F12, { KeyCode::F12, "F12", "F12", (char)(0), (char)(0) }));
// Set up the cross references // Set up the cross references
InitKeysByName(); InitKeysByName();
InitKeysByAscii(); InitKeysByAscii();

@ -11,6 +11,7 @@
#define KEY_CODES_H_ #define KEY_CODES_H_
#include "window.h" #include "window.h"
#include <vector>
namespace lunarium namespace lunarium
{ {
@ -122,8 +123,6 @@ namespace lunarium
MOUSE_X1_BUTTON = GLFW_MOUSE_BUTTON_4, MOUSE_X1_BUTTON = GLFW_MOUSE_BUTTON_4,
MOUSE_X2_BUTTON = GLFW_MOUSE_BUTTON_5, MOUSE_X2_BUTTON = GLFW_MOUSE_BUTTON_5,
NUM_KEYS,
// ALTERNATE NAMES // ALTERNATE NAMES
SHIFT = GLFW_KEY_LEFT_SHIFT, SHIFT = GLFW_KEY_LEFT_SHIFT,
CONTROL = GLFW_KEY_LEFT_CONTROL, CONTROL = GLFW_KEY_LEFT_CONTROL,
@ -132,7 +131,7 @@ namespace lunarium
KEY_UNKNOWN = 0xFFFF KEY_UNKNOWN = 0xFFFF
}; };
static int KeyCodeList[] = { static std::vector<int> KeyCodeList = {
KeyCode::A, KeyCode::A,
KeyCode::B, KeyCode::B,
KeyCode::C, KeyCode::C,

Loading…
Cancel
Save