use imgui docking
This commit is contained in:
parent
6ff27718e4
commit
15c49f6626
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
|||
[submodule "quark/vendor/imgui"]
|
||||
path = quark/vendor/imgui
|
||||
url = https://github.com/ocornut/imgui
|
||||
[submodule "quark/vendor/glm"]
|
||||
path = quark/vendor/glm
|
||||
url = https://github.com/g-truc/glm
|
||||
|
|
|
@ -11,10 +11,10 @@ target_sources(quark
|
|||
src/quark/Application.cpp
|
||||
src/quark/Logger.cpp
|
||||
src/quark/LayerStack.cpp
|
||||
src/quark/IoTranslate.cpp
|
||||
|
||||
src/platform/linux/LinuxWindow.cpp
|
||||
src/platform/linux/LinuxInput.cpp
|
||||
src/platform/glfw/IoTranslateGlfw.cpp
|
||||
|
||||
src/quark/imgui/ImGuiLayer.cpp
|
||||
|
||||
|
@ -28,6 +28,10 @@ target_sources(quark
|
|||
src/quark/Window.hpp
|
||||
src/quark/Layer.hpp
|
||||
src/quark/LayerStack.hpp
|
||||
src/quark/Input.hpp
|
||||
src/quark/KeyCodes.hpp
|
||||
src/quark/MouseButtonCodes.hpp
|
||||
src/quark/IoTranslate.hpp
|
||||
|
||||
src/quark/events/Event.hpp
|
||||
src/quark/events/ApplicationEvent.hpp
|
||||
|
@ -49,10 +53,14 @@ target_compile_definitions(quark
|
|||
)
|
||||
|
||||
target_link_libraries(quark
|
||||
spdlog::spdlog
|
||||
PRIVATE
|
||||
glad
|
||||
glfw
|
||||
|
||||
PUBLIC
|
||||
spdlog::spdlog
|
||||
imgui
|
||||
glm
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace qk {
|
||||
ImGuiMouseButton TranslateMouseButton(int button);
|
||||
ImGuiKey TranslateKey(int key);
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
#include <imgui.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace qk {
|
||||
ImGuiMouseButton TranslateMouseButton(int button) {
|
||||
switch (button) {
|
||||
case GLFW_MOUSE_BUTTON_LEFT: return ImGuiMouseButton_Left;
|
||||
case GLFW_MOUSE_BUTTON_RIGHT: return ImGuiMouseButton_Right;
|
||||
case GLFW_MOUSE_BUTTON_MIDDLE: return ImGuiMouseButton_Middle;
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
ImGuiKey TranslateKey(int key) {
|
||||
switch (key) {
|
||||
case GLFW_KEY_TAB: return ImGuiKey_Tab;
|
||||
case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow;
|
||||
case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow;
|
||||
case GLFW_KEY_UP: return ImGuiKey_UpArrow;
|
||||
case GLFW_KEY_DOWN: return ImGuiKey_DownArrow;
|
||||
case GLFW_KEY_PAGE_UP: return ImGuiKey_PageUp;
|
||||
case GLFW_KEY_PAGE_DOWN: return ImGuiKey_PageDown;
|
||||
case GLFW_KEY_HOME: return ImGuiKey_Home;
|
||||
case GLFW_KEY_END: return ImGuiKey_End;
|
||||
case GLFW_KEY_INSERT: return ImGuiKey_Insert;
|
||||
case GLFW_KEY_DELETE: return ImGuiKey_Delete;
|
||||
case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace;
|
||||
case GLFW_KEY_SPACE: return ImGuiKey_Space;
|
||||
case GLFW_KEY_ENTER: return ImGuiKey_Enter;
|
||||
case GLFW_KEY_ESCAPE: return ImGuiKey_Escape;
|
||||
case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl;
|
||||
case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift;
|
||||
case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt;
|
||||
case GLFW_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper;
|
||||
case GLFW_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl;
|
||||
case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift;
|
||||
case GLFW_KEY_RIGHT_ALT: return ImGuiKey_RightAlt;
|
||||
case GLFW_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper;
|
||||
case GLFW_KEY_MENU: return ImGuiKey_Menu;
|
||||
case GLFW_KEY_0: return ImGuiKey_0;
|
||||
case GLFW_KEY_1: return ImGuiKey_1;
|
||||
case GLFW_KEY_2: return ImGuiKey_2;
|
||||
case GLFW_KEY_3: return ImGuiKey_3;
|
||||
case GLFW_KEY_4: return ImGuiKey_4;
|
||||
case GLFW_KEY_5: return ImGuiKey_5;
|
||||
case GLFW_KEY_6: return ImGuiKey_6;
|
||||
case GLFW_KEY_7: return ImGuiKey_7;
|
||||
case GLFW_KEY_8: return ImGuiKey_8;
|
||||
case GLFW_KEY_9: return ImGuiKey_9;
|
||||
case GLFW_KEY_A: return ImGuiKey_A;
|
||||
case GLFW_KEY_B: return ImGuiKey_B;
|
||||
case GLFW_KEY_C: return ImGuiKey_C;
|
||||
case GLFW_KEY_D: return ImGuiKey_D;
|
||||
case GLFW_KEY_E: return ImGuiKey_E;
|
||||
case GLFW_KEY_F: return ImGuiKey_F;
|
||||
case GLFW_KEY_G: return ImGuiKey_G;
|
||||
case GLFW_KEY_H: return ImGuiKey_H;
|
||||
case GLFW_KEY_I: return ImGuiKey_I;
|
||||
case GLFW_KEY_J: return ImGuiKey_J;
|
||||
case GLFW_KEY_K: return ImGuiKey_K;
|
||||
case GLFW_KEY_L: return ImGuiKey_L;
|
||||
case GLFW_KEY_M: return ImGuiKey_M;
|
||||
case GLFW_KEY_N: return ImGuiKey_N;
|
||||
case GLFW_KEY_O: return ImGuiKey_O;
|
||||
case GLFW_KEY_P: return ImGuiKey_P;
|
||||
case GLFW_KEY_Q: return ImGuiKey_Q;
|
||||
case GLFW_KEY_R: return ImGuiKey_R;
|
||||
case GLFW_KEY_S: return ImGuiKey_S;
|
||||
case GLFW_KEY_T: return ImGuiKey_T;
|
||||
case GLFW_KEY_U: return ImGuiKey_U;
|
||||
case GLFW_KEY_V: return ImGuiKey_V;
|
||||
case GLFW_KEY_W: return ImGuiKey_W;
|
||||
case GLFW_KEY_X: return ImGuiKey_X;
|
||||
case GLFW_KEY_Y: return ImGuiKey_Y;
|
||||
case GLFW_KEY_Z: return ImGuiKey_Z;
|
||||
case GLFW_KEY_F1: return ImGuiKey_F1;
|
||||
case GLFW_KEY_F2: return ImGuiKey_F2;
|
||||
case GLFW_KEY_F3: return ImGuiKey_F3;
|
||||
case GLFW_KEY_F4: return ImGuiKey_F4;
|
||||
case GLFW_KEY_F5: return ImGuiKey_F5;
|
||||
case GLFW_KEY_F6: return ImGuiKey_F6;
|
||||
case GLFW_KEY_F7: return ImGuiKey_F7;
|
||||
case GLFW_KEY_F8: return ImGuiKey_F8;
|
||||
case GLFW_KEY_F9: return ImGuiKey_F9;
|
||||
case GLFW_KEY_F10: return ImGuiKey_F10;
|
||||
case GLFW_KEY_F11: return ImGuiKey_F11;
|
||||
case GLFW_KEY_F12: return ImGuiKey_F12;
|
||||
case GLFW_KEY_F13: return ImGuiKey_F13;
|
||||
case GLFW_KEY_F14: return ImGuiKey_F14;
|
||||
case GLFW_KEY_F15: return ImGuiKey_F15;
|
||||
case GLFW_KEY_F16: return ImGuiKey_F16;
|
||||
case GLFW_KEY_F17: return ImGuiKey_F17;
|
||||
case GLFW_KEY_F18: return ImGuiKey_F18;
|
||||
case GLFW_KEY_F19: return ImGuiKey_F19;
|
||||
case GLFW_KEY_F20: return ImGuiKey_F20;
|
||||
case GLFW_KEY_F21: return ImGuiKey_F21;
|
||||
case GLFW_KEY_F22: return ImGuiKey_F22;
|
||||
case GLFW_KEY_F23: return ImGuiKey_F23;
|
||||
case GLFW_KEY_F24: return ImGuiKey_F24;
|
||||
case GLFW_KEY_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||
case GLFW_KEY_COMMA: return ImGuiKey_Comma;
|
||||
case GLFW_KEY_MINUS: return ImGuiKey_Minus;
|
||||
case GLFW_KEY_PERIOD: return ImGuiKey_Period;
|
||||
case GLFW_KEY_SLASH: return ImGuiKey_Slash;
|
||||
case GLFW_KEY_SEMICOLON: return ImGuiKey_Semicolon;
|
||||
case GLFW_KEY_EQUAL: return ImGuiKey_Equal;
|
||||
case GLFW_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket;
|
||||
case GLFW_KEY_BACKSLASH: return ImGuiKey_Backslash;
|
||||
case GLFW_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket;
|
||||
case GLFW_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent;
|
||||
case GLFW_KEY_CAPS_LOCK: return ImGuiKey_CapsLock;
|
||||
case GLFW_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock;
|
||||
case GLFW_KEY_NUM_LOCK: return ImGuiKey_NumLock;
|
||||
case GLFW_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen;
|
||||
case GLFW_KEY_PAUSE: return ImGuiKey_Pause;
|
||||
case GLFW_KEY_KP_0: return ImGuiKey_Keypad0;
|
||||
case GLFW_KEY_KP_1: return ImGuiKey_Keypad1;
|
||||
case GLFW_KEY_KP_2: return ImGuiKey_Keypad2;
|
||||
case GLFW_KEY_KP_3: return ImGuiKey_Keypad3;
|
||||
case GLFW_KEY_KP_4: return ImGuiKey_Keypad4;
|
||||
case GLFW_KEY_KP_5: return ImGuiKey_Keypad5;
|
||||
case GLFW_KEY_KP_6: return ImGuiKey_Keypad6;
|
||||
case GLFW_KEY_KP_7: return ImGuiKey_Keypad7;
|
||||
case GLFW_KEY_KP_8: return ImGuiKey_Keypad8;
|
||||
case GLFW_KEY_KP_9: return ImGuiKey_Keypad9;
|
||||
case GLFW_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal;
|
||||
case GLFW_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
||||
case GLFW_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
||||
case GLFW_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract;
|
||||
case GLFW_KEY_KP_ADD: return ImGuiKey_KeypadAdd;
|
||||
case GLFW_KEY_KP_ENTER: return ImGuiKey_KeypadEnter;
|
||||
case GLFW_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual;
|
||||
}
|
||||
|
||||
return ImGuiKey_None;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ namespace qk {
|
|||
auto window = std::any_cast<GLFWwindow*>(Application::GetInstance().GetWindow().GetNativeWindow());
|
||||
|
||||
int state = glfwGetKey(window, keyCode);
|
||||
return (state == GLFW_PRESS || state == GLFW_RELEASE);
|
||||
return (state == GLFW_PRESS || state == GLFW_REPEAT);
|
||||
}
|
||||
|
||||
bool LinuxInput::IntIsMouseDown(int button) {
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace qk {
|
|||
QK_CORE_INFO("Creating window {0} ({1}x{2})", data.title, data.width, data.height);
|
||||
|
||||
if (!GLFWInitialized) {
|
||||
// glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
|
||||
int success = glfwInit();
|
||||
QK_CORE_ASSERT(success, "Could not initialize GLFW");
|
||||
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#include "qkpch.hpp"
|
||||
#include "quark/Application.hpp"
|
||||
#include "quark/Logger.hpp"
|
||||
#include "quark/Input.hpp"
|
||||
|
||||
#include "quark/KeyCodes.hpp"
|
||||
#include "quark/MouseButtonCodes.hpp"
|
||||
|
||||
#include "quark/events/Event.hpp"
|
||||
#include "quark/events/MouseEvent.hpp"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Application.hpp"
|
||||
#include "quark/Core.hpp"
|
||||
#include "quark/Input.hpp"
|
||||
#include "quark/imgui/ImGuiLayer.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace qk {
|
||||
|
@ -11,19 +12,29 @@ namespace qk {
|
|||
|
||||
window = Window::Create();
|
||||
window->SetEventCallback(std::bind(&Application::OnEvent, this, std::placeholders::_1));
|
||||
|
||||
uiLayer = std::make_unique<ImGuiLayer>();
|
||||
}
|
||||
|
||||
void Application::Run() {
|
||||
uiLayer->OnAttach();
|
||||
|
||||
while(isRunning) {
|
||||
for (Layer* layer : layers) {
|
||||
layer->OnUpdate();
|
||||
}
|
||||
|
||||
auto [x, y] = Input::GetMousePosition();
|
||||
QK_CORE_TRACE("{0}, {1}", x, y);
|
||||
uiLayer->Begin();
|
||||
uiLayer->OnImGuiRender();
|
||||
for (Layer* layer : layers) {
|
||||
layer->OnImGuiRender();
|
||||
}
|
||||
uiLayer->End();
|
||||
|
||||
window->OnUpdate();
|
||||
}
|
||||
|
||||
uiLayer->OnDetach();
|
||||
}
|
||||
|
||||
void Application::OnEvent(Event& e) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "quark/Layer.hpp"
|
||||
#include "quark/LayerStack.hpp"
|
||||
#include "quark/events/ApplicationEvent.hpp"
|
||||
#include "quark/imgui/ImGuiLayer.hpp"
|
||||
|
||||
namespace qk {
|
||||
|
||||
|
@ -30,6 +31,7 @@ namespace qk {
|
|||
bool isRunning = true;
|
||||
|
||||
LayerStack layers;
|
||||
std::unique_ptr<ImGuiLayer> uiLayer;
|
||||
|
||||
public:
|
||||
static Application& GetInstance() {
|
||||
|
|
142
quark/src/quark/IoTranslate.cpp
Normal file
142
quark/src/quark/IoTranslate.cpp
Normal file
|
@ -0,0 +1,142 @@
|
|||
#include "IoTranslate.hpp"
|
||||
|
||||
#include "quark/MouseButtonCodes.hpp"
|
||||
#include "quark/KeyCodes.hpp"
|
||||
|
||||
namespace qk {
|
||||
ImGuiMouseButton MouseButtonToImGuiMouseButton(int button) {
|
||||
switch (button) {
|
||||
case QK_MOUSE_BUTTON_LEFT: return ImGuiMouseButton_Left;
|
||||
case QK_MOUSE_BUTTON_RIGHT: return ImGuiMouseButton_Right;
|
||||
case QK_MOUSE_BUTTON_MIDDLE: return ImGuiMouseButton_Middle;
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
ImGuiKey KeyToImGuiKey(int key) {
|
||||
switch (key) {
|
||||
case QK_KEY_TAB: return ImGuiKey_Tab;
|
||||
case QK_KEY_LEFT: return ImGuiKey_LeftArrow;
|
||||
case QK_KEY_RIGHT: return ImGuiKey_RightArrow;
|
||||
case QK_KEY_UP: return ImGuiKey_UpArrow;
|
||||
case QK_KEY_DOWN: return ImGuiKey_DownArrow;
|
||||
case QK_KEY_PAGE_UP: return ImGuiKey_PageUp;
|
||||
case QK_KEY_PAGE_DOWN: return ImGuiKey_PageDown;
|
||||
case QK_KEY_HOME: return ImGuiKey_Home;
|
||||
case QK_KEY_END: return ImGuiKey_End;
|
||||
case QK_KEY_INSERT: return ImGuiKey_Insert;
|
||||
case QK_KEY_DELETE: return ImGuiKey_Delete;
|
||||
case QK_KEY_BACKSPACE: return ImGuiKey_Backspace;
|
||||
case QK_KEY_SPACE: return ImGuiKey_Space;
|
||||
case QK_KEY_ENTER: return ImGuiKey_Enter;
|
||||
case QK_KEY_ESCAPE: return ImGuiKey_Escape;
|
||||
case QK_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl;
|
||||
case QK_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift;
|
||||
case QK_KEY_LEFT_ALT: return ImGuiKey_LeftAlt;
|
||||
case QK_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper;
|
||||
case QK_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl;
|
||||
case QK_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift;
|
||||
case QK_KEY_RIGHT_ALT: return ImGuiKey_RightAlt;
|
||||
case QK_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper;
|
||||
case QK_KEY_MENU: return ImGuiKey_Menu;
|
||||
case QK_KEY_0: return ImGuiKey_0;
|
||||
case QK_KEY_1: return ImGuiKey_1;
|
||||
case QK_KEY_2: return ImGuiKey_2;
|
||||
case QK_KEY_3: return ImGuiKey_3;
|
||||
case QK_KEY_4: return ImGuiKey_4;
|
||||
case QK_KEY_5: return ImGuiKey_5;
|
||||
case QK_KEY_6: return ImGuiKey_6;
|
||||
case QK_KEY_7: return ImGuiKey_7;
|
||||
case QK_KEY_8: return ImGuiKey_8;
|
||||
case QK_KEY_9: return ImGuiKey_9;
|
||||
case QK_KEY_A: return ImGuiKey_A;
|
||||
case QK_KEY_B: return ImGuiKey_B;
|
||||
case QK_KEY_C: return ImGuiKey_C;
|
||||
case QK_KEY_D: return ImGuiKey_D;
|
||||
case QK_KEY_E: return ImGuiKey_E;
|
||||
case QK_KEY_F: return ImGuiKey_F;
|
||||
case QK_KEY_G: return ImGuiKey_G;
|
||||
case QK_KEY_H: return ImGuiKey_H;
|
||||
case QK_KEY_I: return ImGuiKey_I;
|
||||
case QK_KEY_J: return ImGuiKey_J;
|
||||
case QK_KEY_K: return ImGuiKey_K;
|
||||
case QK_KEY_L: return ImGuiKey_L;
|
||||
case QK_KEY_M: return ImGuiKey_M;
|
||||
case QK_KEY_N: return ImGuiKey_N;
|
||||
case QK_KEY_O: return ImGuiKey_O;
|
||||
case QK_KEY_P: return ImGuiKey_P;
|
||||
case QK_KEY_Q: return ImGuiKey_Q;
|
||||
case QK_KEY_R: return ImGuiKey_R;
|
||||
case QK_KEY_S: return ImGuiKey_S;
|
||||
case QK_KEY_T: return ImGuiKey_T;
|
||||
case QK_KEY_U: return ImGuiKey_U;
|
||||
case QK_KEY_V: return ImGuiKey_V;
|
||||
case QK_KEY_W: return ImGuiKey_W;
|
||||
case QK_KEY_X: return ImGuiKey_X;
|
||||
case QK_KEY_Y: return ImGuiKey_Y;
|
||||
case QK_KEY_Z: return ImGuiKey_Z;
|
||||
case QK_KEY_F1: return ImGuiKey_F1;
|
||||
case QK_KEY_F2: return ImGuiKey_F2;
|
||||
case QK_KEY_F3: return ImGuiKey_F3;
|
||||
case QK_KEY_F4: return ImGuiKey_F4;
|
||||
case QK_KEY_F5: return ImGuiKey_F5;
|
||||
case QK_KEY_F6: return ImGuiKey_F6;
|
||||
case QK_KEY_F7: return ImGuiKey_F7;
|
||||
case QK_KEY_F8: return ImGuiKey_F8;
|
||||
case QK_KEY_F9: return ImGuiKey_F9;
|
||||
case QK_KEY_F10: return ImGuiKey_F10;
|
||||
case QK_KEY_F11: return ImGuiKey_F11;
|
||||
case QK_KEY_F12: return ImGuiKey_F12;
|
||||
case QK_KEY_F13: return ImGuiKey_F13;
|
||||
case QK_KEY_F14: return ImGuiKey_F14;
|
||||
case QK_KEY_F15: return ImGuiKey_F15;
|
||||
case QK_KEY_F16: return ImGuiKey_F16;
|
||||
case QK_KEY_F17: return ImGuiKey_F17;
|
||||
case QK_KEY_F18: return ImGuiKey_F18;
|
||||
case QK_KEY_F19: return ImGuiKey_F19;
|
||||
case QK_KEY_F20: return ImGuiKey_F20;
|
||||
case QK_KEY_F21: return ImGuiKey_F21;
|
||||
case QK_KEY_F22: return ImGuiKey_F22;
|
||||
case QK_KEY_F23: return ImGuiKey_F23;
|
||||
case QK_KEY_F24: return ImGuiKey_F24;
|
||||
case QK_KEY_APOSTROPHE: return ImGuiKey_Apostrophe;
|
||||
case QK_KEY_COMMA: return ImGuiKey_Comma;
|
||||
case QK_KEY_MINUS: return ImGuiKey_Minus;
|
||||
case QK_KEY_PERIOD: return ImGuiKey_Period;
|
||||
case QK_KEY_SLASH: return ImGuiKey_Slash;
|
||||
case QK_KEY_SEMICOLON: return ImGuiKey_Semicolon;
|
||||
case QK_KEY_EQUAL: return ImGuiKey_Equal;
|
||||
case QK_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket;
|
||||
case QK_KEY_BACKSLASH: return ImGuiKey_Backslash;
|
||||
case QK_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket;
|
||||
case QK_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent;
|
||||
case QK_KEY_CAPS_LOCK: return ImGuiKey_CapsLock;
|
||||
case QK_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock;
|
||||
case QK_KEY_NUM_LOCK: return ImGuiKey_NumLock;
|
||||
case QK_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen;
|
||||
case QK_KEY_PAUSE: return ImGuiKey_Pause;
|
||||
case QK_KEY_KP_0: return ImGuiKey_Keypad0;
|
||||
case QK_KEY_KP_1: return ImGuiKey_Keypad1;
|
||||
case QK_KEY_KP_2: return ImGuiKey_Keypad2;
|
||||
case QK_KEY_KP_3: return ImGuiKey_Keypad3;
|
||||
case QK_KEY_KP_4: return ImGuiKey_Keypad4;
|
||||
case QK_KEY_KP_5: return ImGuiKey_Keypad5;
|
||||
case QK_KEY_KP_6: return ImGuiKey_Keypad6;
|
||||
case QK_KEY_KP_7: return ImGuiKey_Keypad7;
|
||||
case QK_KEY_KP_8: return ImGuiKey_Keypad8;
|
||||
case QK_KEY_KP_9: return ImGuiKey_Keypad9;
|
||||
case QK_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal;
|
||||
case QK_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide;
|
||||
case QK_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
|
||||
case QK_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract;
|
||||
case QK_KEY_KP_ADD: return ImGuiKey_KeypadAdd;
|
||||
case QK_KEY_KP_ENTER: return ImGuiKey_KeypadEnter;
|
||||
case QK_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual;
|
||||
}
|
||||
|
||||
return ImGuiKey_None;
|
||||
}
|
||||
|
||||
}
|
||||
|
8
quark/src/quark/IoTranslate.hpp
Normal file
8
quark/src/quark/IoTranslate.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace qk {
|
||||
ImGuiMouseButton MouseButtonToImGuiMouseButton(int button);
|
||||
ImGuiKey KeyToImGuiKey(int key);
|
||||
}
|
125
quark/src/quark/KeyCodes.hpp
Normal file
125
quark/src/quark/KeyCodes.hpp
Normal file
|
@ -0,0 +1,125 @@
|
|||
#pragma once
|
||||
// IWYU pragma: private, include <quark.hpp>
|
||||
|
||||
#define QK_KEY_SPACE 32
|
||||
#define QK_KEY_APOSTROPHE 39 /* ' */
|
||||
#define QK_KEY_COMMA 44 /* , */
|
||||
#define QK_KEY_MINUS 45 /* - */
|
||||
#define QK_KEY_PERIOD 46 /* . */
|
||||
#define QK_KEY_SLASH 47 /* / */
|
||||
#define QK_KEY_0 48
|
||||
#define QK_KEY_1 49
|
||||
#define QK_KEY_2 50
|
||||
#define QK_KEY_3 51
|
||||
#define QK_KEY_4 52
|
||||
#define QK_KEY_5 53
|
||||
#define QK_KEY_6 54
|
||||
#define QK_KEY_7 55
|
||||
#define QK_KEY_8 56
|
||||
#define QK_KEY_9 57
|
||||
#define QK_KEY_SEMICOLON 59 /* ; */
|
||||
#define QK_KEY_EQUAL 61 /* = */
|
||||
#define QK_KEY_A 65
|
||||
#define QK_KEY_B 66
|
||||
#define QK_KEY_C 67
|
||||
#define QK_KEY_D 68
|
||||
#define QK_KEY_E 69
|
||||
#define QK_KEY_F 70
|
||||
#define QK_KEY_G 71
|
||||
#define QK_KEY_H 72
|
||||
#define QK_KEY_I 73
|
||||
#define QK_KEY_J 74
|
||||
#define QK_KEY_K 75
|
||||
#define QK_KEY_L 76
|
||||
#define QK_KEY_M 77
|
||||
#define QK_KEY_N 78
|
||||
#define QK_KEY_O 79
|
||||
#define QK_KEY_P 80
|
||||
#define QK_KEY_Q 81
|
||||
#define QK_KEY_R 82
|
||||
#define QK_KEY_S 83
|
||||
#define QK_KEY_T 84
|
||||
#define QK_KEY_U 85
|
||||
#define QK_KEY_V 86
|
||||
#define QK_KEY_W 87
|
||||
#define QK_KEY_X 88
|
||||
#define QK_KEY_Y 89
|
||||
#define QK_KEY_Z 90
|
||||
#define QK_KEY_LEFT_BRACKET 91 /* [ */
|
||||
#define QK_KEY_BACKSLASH 92 /* \ */
|
||||
#define QK_KEY_RIGHT_BRACKET 93 /* ] */
|
||||
#define QK_KEY_GRAVE_ACCENT 96 /* ` */
|
||||
#define QK_KEY_WORLD_1 161 /* non-US #1 */
|
||||
#define QK_KEY_WORLD_2 162 /* non-US #2 */
|
||||
|
||||
/* Function keys */
|
||||
#define QK_KEY_ESCAPE 256
|
||||
#define QK_KEY_ENTER 257
|
||||
#define QK_KEY_TAB 258
|
||||
#define QK_KEY_BACKSPACE 259
|
||||
#define QK_KEY_INSERT 260
|
||||
#define QK_KEY_DELETE 261
|
||||
#define QK_KEY_RIGHT 262
|
||||
#define QK_KEY_LEFT 263
|
||||
#define QK_KEY_DOWN 264
|
||||
#define QK_KEY_UP 265
|
||||
#define QK_KEY_PAGE_UP 266
|
||||
#define QK_KEY_PAGE_DOWN 267
|
||||
#define QK_KEY_HOME 268
|
||||
#define QK_KEY_END 269
|
||||
#define QK_KEY_CAPS_LOCK 280
|
||||
#define QK_KEY_SCROLL_LOCK 281
|
||||
#define QK_KEY_NUM_LOCK 282
|
||||
#define QK_KEY_PRINT_SCREEN 283
|
||||
#define QK_KEY_PAUSE 284
|
||||
#define QK_KEY_F1 290
|
||||
#define QK_KEY_F2 291
|
||||
#define QK_KEY_F3 292
|
||||
#define QK_KEY_F4 293
|
||||
#define QK_KEY_F5 294
|
||||
#define QK_KEY_F6 295
|
||||
#define QK_KEY_F7 296
|
||||
#define QK_KEY_F8 297
|
||||
#define QK_KEY_F9 298
|
||||
#define QK_KEY_F10 299
|
||||
#define QK_KEY_F11 300
|
||||
#define QK_KEY_F12 301
|
||||
#define QK_KEY_F13 302
|
||||
#define QK_KEY_F14 303
|
||||
#define QK_KEY_F15 304
|
||||
#define QK_KEY_F16 305
|
||||
#define QK_KEY_F17 306
|
||||
#define QK_KEY_F18 307
|
||||
#define QK_KEY_F19 308
|
||||
#define QK_KEY_F20 309
|
||||
#define QK_KEY_F21 310
|
||||
#define QK_KEY_F22 311
|
||||
#define QK_KEY_F23 312
|
||||
#define QK_KEY_F24 313
|
||||
#define QK_KEY_F25 314
|
||||
#define QK_KEY_KP_0 320
|
||||
#define QK_KEY_KP_1 321
|
||||
#define QK_KEY_KP_2 322
|
||||
#define QK_KEY_KP_3 323
|
||||
#define QK_KEY_KP_4 324
|
||||
#define QK_KEY_KP_5 325
|
||||
#define QK_KEY_KP_6 326
|
||||
#define QK_KEY_KP_7 327
|
||||
#define QK_KEY_KP_8 328
|
||||
#define QK_KEY_KP_9 329
|
||||
#define QK_KEY_KP_DECIMAL 330
|
||||
#define QK_KEY_KP_DIVIDE 331
|
||||
#define QK_KEY_KP_MULTIPLY 332
|
||||
#define QK_KEY_KP_SUBTRACT 333
|
||||
#define QK_KEY_KP_ADD 334
|
||||
#define QK_KEY_KP_ENTER 335
|
||||
#define QK_KEY_KP_EQUAL 336
|
||||
#define QK_KEY_LEFT_SHIFT 340
|
||||
#define QK_KEY_LEFT_CONTROL 341
|
||||
#define QK_KEY_LEFT_ALT 342
|
||||
#define QK_KEY_LEFT_SUPER 343
|
||||
#define QK_KEY_RIGHT_SHIFT 344
|
||||
#define QK_KEY_RIGHT_CONTROL 345
|
||||
#define QK_KEY_RIGHT_ALT 346
|
||||
#define QK_KEY_RIGHT_SUPER 347
|
||||
#define QK_KEY_MENU 348
|
|
@ -17,6 +17,7 @@ namespace qk {
|
|||
virtual void OnDetach() {}
|
||||
virtual void OnUpdate() {}
|
||||
virtual void OnEvent(Event& event) {}
|
||||
virtual void OnImGuiRender() {}
|
||||
|
||||
inline const std::string& GetName() const { return debugName; }
|
||||
|
||||
|
|
14
quark/src/quark/MouseButtonCodes.hpp
Normal file
14
quark/src/quark/MouseButtonCodes.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
// IWYU pragma: private, include <quark.hpp>
|
||||
|
||||
#define QK_MOUSE_BUTTON_1 0
|
||||
#define QK_MOUSE_BUTTON_2 1
|
||||
#define QK_MOUSE_BUTTON_3 2
|
||||
#define QK_MOUSE_BUTTON_4 3
|
||||
#define QK_MOUSE_BUTTON_5 4
|
||||
#define QK_MOUSE_BUTTON_6 5
|
||||
#define QK_MOUSE_BUTTON_7 6
|
||||
#define QK_MOUSE_BUTTON_8 7
|
||||
#define QK_MOUSE_BUTTON_LEFT QK_MOUSE_BUTTON_1
|
||||
#define QK_MOUSE_BUTTON_RIGHT QK_MOUSE_BUTTON_2
|
||||
#define QK_MOUSE_BUTTON_MIDDLE QK_MOUSE_BUTTON_3
|
|
@ -6,9 +6,10 @@
|
|||
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <quark.hpp>
|
||||
|
||||
#include "platform/IoTranslate.hpp"
|
||||
#include "quark/IoTranslate.hpp"
|
||||
#include "quark/Application.hpp"
|
||||
#include "quark/events/Event.hpp"
|
||||
|
||||
|
@ -40,140 +41,47 @@ namespace qk {
|
|||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
// io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(
|
||||
std::any_cast<GLFWwindow*>(app.GetWindow().GetNativeWindow()),
|
||||
true
|
||||
);
|
||||
ImGui_ImplOpenGL3_Init("#version 410");
|
||||
|
||||
QK_CORE_INFO("Initialized ImGui");
|
||||
}
|
||||
|
||||
void ImGuiLayer::OnDetach() {
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void ImGuiLayer::Begin() {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
|
||||
void ImGuiLayer::OnUpdate() {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
float time = (float)glfwGetTime();
|
||||
ImGui::GetIO().DeltaTime = (lastTime > 0.0f) ? (time - lastTime) : (1.0f / 60.0f);
|
||||
lastTime = time;
|
||||
|
||||
static bool show = true;
|
||||
ImGui::ShowDemoWindow(&show);
|
||||
void ImGuiLayer::End() {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
Application& app = Application::GetInstance();
|
||||
io.DisplaySize = ImVec2(app.GetWindow().GetWidth(), app.GetWindow().GetHeight());
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
void ImGuiLayer::OnEvent(Event& event) {
|
||||
EventDispatcher dispatcher(event);
|
||||
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
|
||||
GLFWwindow* backup_currnet_context = glfwGetCurrentContext();
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
|
||||
dispatcher.Dispatch<MouseButtonPressedEvent>(BIND_EVENT_CB(ImGuiLayer::OnMouseButtonPressed));
|
||||
dispatcher.Dispatch<MouseButtonReleasedEvent>(BIND_EVENT_CB(ImGuiLayer::OnMouseButtonReleased));
|
||||
dispatcher.Dispatch<MouseMovedEvent>(BIND_EVENT_CB(ImGuiLayer::OnMouseMoved));
|
||||
dispatcher.Dispatch<MouseScrolledEvent>(BIND_EVENT_CB(ImGuiLayer::OnMouseScrolled));
|
||||
|
||||
dispatcher.Dispatch<KeyPressedEvent>(BIND_EVENT_CB(ImGuiLayer::OnKeyPressedEvent));
|
||||
dispatcher.Dispatch<KeyReleasedEvent>(BIND_EVENT_CB(ImGuiLayer::OnKeyReleasedEvent));
|
||||
dispatcher.Dispatch<KeyTypedEvent>(BIND_EVENT_CB(ImGuiLayer::OnKeyTypedEvent));
|
||||
|
||||
dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_CB(ImGuiLayer::OnWindowResized));
|
||||
}
|
||||
|
||||
bool ImGuiLayer::OnMouseButtonPressed(MouseButtonPressedEvent& e) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddMouseButtonEvent(TranslateMouseButton(e.GetMouseButton()), true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGuiLayer::OnMouseButtonReleased(MouseButtonReleasedEvent& e) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddMouseButtonEvent(TranslateMouseButton(e.GetMouseButton()), false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGuiLayer::OnMouseMoved(MouseMovedEvent& e) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddMousePosEvent(e.GetX(), e.GetY());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGuiLayer::OnMouseScrolled(MouseScrolledEvent& e) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.AddMouseWheelEvent(e.GetX(), e.GetY());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGuiLayer::OnKeyPressedEvent(KeyPressedEvent& e) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuiKey key = TranslateKey(e.GetKeyCode());
|
||||
|
||||
if (key == ImGuiKey_LeftCtrl || key == ImGuiKey_RightCtrl) {
|
||||
io.AddKeyEvent(ImGuiMod_Ctrl, true);
|
||||
}
|
||||
|
||||
if (key == ImGuiKey_LeftShift || key == ImGuiKey_RightShift) {
|
||||
io.AddKeyEvent(ImGuiMod_Shift, true);
|
||||
}
|
||||
|
||||
if (key == ImGuiKey_LeftAlt || key == ImGuiKey_RightAlt) {
|
||||
io.AddKeyEvent(ImGuiMod_Alt, true);
|
||||
glfwMakeContextCurrent(backup_currnet_context);
|
||||
}
|
||||
|
||||
if (key == ImGuiKey_LeftSuper || key == ImGuiKey_RightSuper) {
|
||||
io.AddKeyEvent(ImGuiMod_Super, true);
|
||||
}
|
||||
|
||||
io.AddKeyEvent(key, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGuiLayer::OnKeyReleasedEvent(KeyReleasedEvent& e) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuiKey key = TranslateKey(e.GetKeyCode());
|
||||
|
||||
if (key == ImGuiKey_LeftCtrl || key == ImGuiKey_RightCtrl) {
|
||||
io.AddKeyEvent(ImGuiMod_Ctrl, false);
|
||||
}
|
||||
|
||||
if (key == ImGuiKey_LeftShift || key == ImGuiKey_RightShift) {
|
||||
io.AddKeyEvent(ImGuiMod_Shift, false);
|
||||
}
|
||||
|
||||
if (key == ImGuiKey_LeftAlt || key == ImGuiKey_RightAlt) {
|
||||
io.AddKeyEvent(ImGuiMod_Alt, false);
|
||||
}
|
||||
|
||||
if (key == ImGuiKey_LeftSuper || key == ImGuiKey_RightSuper) {
|
||||
io.AddKeyEvent(ImGuiMod_Super, false);
|
||||
}
|
||||
|
||||
io.AddKeyEvent(key, false);
|
||||
|
||||
return false;
|
||||
void ImGuiLayer::OnImGuiRender() {
|
||||
static bool show = true;
|
||||
ImGui::ShowDemoWindow(&show);
|
||||
}
|
||||
|
||||
bool ImGuiLayer::OnKeyTypedEvent(KeyTypedEvent& e) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
int c = e.GetKeyCode();
|
||||
|
||||
if (c > 0 && c < 0x10000) {
|
||||
io.AddInputCharacter(c);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGuiLayer::OnWindowResized(WindowResizeEvent& e) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.DisplaySize = ImVec2(e.GetWidth(), e.GetHeight());
|
||||
io.DisplayFramebufferScale = ImVec2(1.f, 1.f);
|
||||
|
||||
glViewport(0, 0, e.GetWidth(), e.GetHeight());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "quark/Layer.hpp"
|
||||
#include "quark/events/Event.hpp"
|
||||
#include "quark/events/MouseEvent.hpp"
|
||||
#include "quark/events/KeyEvent.hpp"
|
||||
#include "quark/events/ApplicationEvent.hpp"
|
||||
|
||||
namespace qk {
|
||||
class ImGuiLayer :
|
||||
|
@ -14,23 +10,13 @@ namespace qk {
|
|||
ImGuiLayer();
|
||||
~ImGuiLayer();
|
||||
|
||||
void OnAttach() override;
|
||||
void OnDetach() override;
|
||||
virtual void OnAttach() override;
|
||||
virtual void OnDetach() override;
|
||||
|
||||
void OnUpdate() override;
|
||||
void OnEvent(Event& event) override;
|
||||
void Begin();
|
||||
void End();
|
||||
|
||||
private:
|
||||
bool OnMouseButtonPressed(MouseButtonPressedEvent& e);
|
||||
bool OnMouseButtonReleased(MouseButtonReleasedEvent& e);
|
||||
bool OnMouseMoved(MouseMovedEvent& e);
|
||||
bool OnMouseScrolled(MouseScrolledEvent& e);
|
||||
|
||||
bool OnKeyPressedEvent(KeyPressedEvent& e);
|
||||
bool OnKeyReleasedEvent(KeyReleasedEvent& e);
|
||||
bool OnKeyTypedEvent(KeyTypedEvent& e);
|
||||
|
||||
bool OnWindowResized(WindowResizeEvent& e);
|
||||
virtual void OnImGuiRender() override;
|
||||
|
||||
private:
|
||||
float lastTime = 0.0f;
|
||||
|
|
11
quark/vendor/CMakeLists.txt
vendored
11
quark/vendor/CMakeLists.txt
vendored
|
@ -28,6 +28,7 @@ add_library(imgui
|
|||
|
||||
# TODO: this is shit
|
||||
imgui/backends/imgui_impl_opengl3.cpp
|
||||
imgui/backends/imgui_impl_glfw.cpp
|
||||
)
|
||||
|
||||
target_include_directories(imgui
|
||||
|
@ -39,3 +40,13 @@ set_property(
|
|||
PROPERTY POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
########################
|
||||
# GLM
|
||||
########################
|
||||
|
||||
add_subdirectory(glm)
|
||||
|
||||
set_property(
|
||||
TARGET glm
|
||||
PROPERTY POSITION_INDEPENDENT_CODE
|
||||
)
|
||||
|
|
1
quark/vendor/glm
vendored
Submodule
1
quark/vendor/glm
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 18feaec455f8ee1f256d91f515fb02d66268ba14
|
|
@ -1,5 +1,6 @@
|
|||
#include <quark.hpp>
|
||||
#include "quark/imgui/ImGuiLayer.hpp"
|
||||
#include <glm/vec3.hpp>
|
||||
#include "imgui.h"
|
||||
|
||||
class ExampleLayer :
|
||||
public qk::Layer
|
||||
|
@ -7,10 +8,25 @@ class ExampleLayer :
|
|||
public:
|
||||
ExampleLayer() :
|
||||
Layer("Example")
|
||||
{ }
|
||||
{
|
||||
glm::vec3 test = { 0.0f, 1.0f, 0.75f };
|
||||
}
|
||||
|
||||
void OnUpdate() override {
|
||||
// QK_TRACE("ExampleLayer::Update");
|
||||
|
||||
if (qk::Input::IsKeyDown(QK_KEY_TAB)) {
|
||||
QK_TRACE("Tab pressed");
|
||||
}
|
||||
}
|
||||
|
||||
void OnImGuiRender() override {
|
||||
static bool open = true;
|
||||
|
||||
if (ImGui::Begin("Example window", &open)) {
|
||||
ImGui::Text("Example text");
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
void OnEvent(qk::Event& event) override {
|
||||
|
@ -24,7 +40,6 @@ class Sandbox :
|
|||
public:
|
||||
Sandbox() {
|
||||
PushLayer(new ExampleLayer);
|
||||
PushOverlay(new qk::ImGuiLayer);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue