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)
✔ Debug log window @done (9/10/2021, 4:44:48 PM)
☐ Add key to show debug log window
.
☐ Add checkboxes to disable log categories and levels
Input:
✔ 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()
{
//glfwSetInputMode(mpWindow->GetWindow(), GLFW_STICKY_KEYS, GLFW_TRUE);
mFrameCounter.Reset();
// TODO: Init frame counter
@ -204,6 +205,12 @@ namespace lunarium
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
static int width = 500;
if (mpInput->IsKeyDown(KeyCode::LEFT))

@ -43,7 +43,7 @@ namespace lunarium
////////////////////////////////////////////////////////////
LogGui* LogGui::mpInstance = nullptr;
LogGui::LogGui()
: mbShow(true), mListener(this)
: mbShow(true), mListener(this), mbOglDebug(false)
{
}
@ -77,21 +77,45 @@ namespace lunarium
if (!mbShow)
return;
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(300, 400), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Debug Log", &mbShow))
{
ImGui::End();
return;
}
ImGui::Checkbox("OGL_DEBUG", &mbOglDebug);
ImGui::Separator();
ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
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();
int len = strlen(msg);
ImGui::TextUnformatted(msg);
ImGui::PushTextWrapPos(ImGui::GetWindowWidth());
ImGui::TextColored(color, msg);
ImGui::PopTextWrapPos();
}
ImGui::PopStyleVar();
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);

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

@ -18,7 +18,7 @@ namespace lunarium
InputManager::InputManager()
: mpWindow(nullptr)
{
memset(mKeyboardState, 0, NUM_KEYS);
memset(mKeyboardState, 0, 512);
}
void InputManager::Initialize(Window* pWindow)
@ -51,21 +51,21 @@ namespace lunarium
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]);
// Mouse Buttons are a special case
if (IsMouseButton(i))
if (IsMouseButton(KeyCodeList[i]))
{
if (keyIsDown)
{
mKeyboardState[i] = KEY_DOWN;
mKeyboardState[KeyCodeList[i]] = KEY_DOWN;
}
else
{
mKeyboardState[i] = KEY_UP;
mKeyboardState[KeyCodeList[i]] = KEY_UP;
}
continue;
@ -83,9 +83,10 @@ namespace lunarium
}
// 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;
kp.Key = key;
@ -99,9 +100,9 @@ namespace lunarium
else
{
// 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);
}
}
@ -137,7 +138,6 @@ namespace lunarium
return false;
}
// TODO: FIX WINDOWS SPECIFIC CODE:
glm::vec2 InputManager::GetMousePosition()
{
// POINT p;

@ -84,7 +84,7 @@ namespace lunarium
private:
Window* mpWindow;
unsigned char mKeyboardState[NUM_KEYS];
unsigned char mKeyboardState[512];
//unsigned char mKeyboardPreviousState[NUM_KEYS];
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::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
InitKeysByName();
InitKeysByAscii();

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

Loading…
Cancel
Save