gui updates
This commit is contained in:
parent
a55a5ec5cc
commit
4a557d7e5c
42 changed files with 1179 additions and 962 deletions
|
|
@ -1,5 +1,8 @@
|
|||
|
||||
#include "GraphicApplication.hpp"
|
||||
#include <GL/glew.h>
|
||||
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
using namespace tp;
|
||||
|
|
@ -13,6 +16,10 @@ public:
|
|||
}
|
||||
|
||||
virtual void drawFrame(Canvas* canvas) override {
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
ImGui::ShowDemoWindow();
|
||||
|
||||
ImGui::Text("Frames processed per second: %f", this->mFramesProcessedPerSecond);
|
||||
ImGui::Text("Frames drawn per second: %f", this->mFramesDrawnPerSecond);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,39 @@ DebugGUI::DebugGUI(Window* window) {
|
|||
io.Fonts->AddFontFromFileTTF("Font.ttf", 20.f);
|
||||
|
||||
io.ConfigInputTrickleEventQueue = false;
|
||||
|
||||
// appearance
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
auto& colors = ImGui::GetStyle().Colors;
|
||||
colors[ImGuiCol_WindowBg] = ImVec4{ 0.1f, 0.105f, 0.11f, 1.0f };
|
||||
|
||||
// Headers
|
||||
colors[ImGuiCol_Header] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
||||
|
||||
// Buttons
|
||||
colors[ImGuiCol_Button] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
||||
|
||||
// Frame BG
|
||||
colors[ImGuiCol_FrameBg] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f };
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
||||
|
||||
// Tabs
|
||||
colors[ImGuiCol_Tab] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
||||
colors[ImGuiCol_TabHovered] = ImVec4{ 0.38f, 0.3805f, 0.381f, 1.0f };
|
||||
colors[ImGuiCol_TabActive] = ImVec4{ 0.28f, 0.2805f, 0.281f, 1.0f };
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f };
|
||||
|
||||
// Title
|
||||
colors[ImGuiCol_TitleBg] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f };
|
||||
}
|
||||
|
||||
DebugGUI::~DebugGUI() {
|
||||
|
|
@ -47,6 +80,12 @@ DebugGUI::~DebugGUI() {
|
|||
delete mContext;
|
||||
}
|
||||
|
||||
void DebugGUI::procBegin() {
|
||||
}
|
||||
|
||||
void DebugGUI::procEnd() {
|
||||
}
|
||||
|
||||
void DebugGUI::drawBegin() {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@
|
|||
|
||||
using namespace tp;
|
||||
|
||||
EventHandler::EventHandler() = default;
|
||||
EventHandler::EventHandler() {
|
||||
mTimerEvent.reset();
|
||||
}
|
||||
|
||||
EventHandler::~EventHandler() = default;
|
||||
|
||||
void EventHandler::postEvent(InputID inputID, InputEvent inputEvent) {
|
||||
|
|
@ -16,6 +19,12 @@ bool EventHandler::isEvents() {
|
|||
mMutex.lock();
|
||||
auto res = mEventQueue.length();
|
||||
mMutex.unlock();
|
||||
|
||||
if (mTimerEvent.isTimeout()) {
|
||||
mTimerEvent.reset();
|
||||
res = true;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -35,6 +44,12 @@ bool transitionsReduce[4][4] = {
|
|||
|
||||
void EventHandler::processEvent() {
|
||||
mMutex.lock();
|
||||
|
||||
if (!mEventQueue.size()) {
|
||||
mMutex.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
auto lastEvent = &mEventQueue.last();
|
||||
|
||||
const auto& eventData = lastEvent->second;
|
||||
|
|
@ -56,7 +71,7 @@ void EventHandler::processEvent() {
|
|||
|
||||
mInputStates[(int) inputId].mCurrentState = transitions[currentState][reportedEvent];
|
||||
|
||||
// printf("%i - %i \n", reportedEvent, mInputStates[(int) InputID::A].mCurrentState);
|
||||
// printf("%i - %i \n", reportedEvent, mInputStates[(int) InputID::MOUSE1].mCurrentState);
|
||||
|
||||
if (transitionsReduce[currentState][reportedEvent]) {
|
||||
mEventQueue.popFront();
|
||||
|
|
@ -65,6 +80,17 @@ void EventHandler::processEvent() {
|
|||
break;
|
||||
}
|
||||
|
||||
case InputEvent::Type::SCROLL:
|
||||
{
|
||||
if (mScrollDelta == Vec2F { 0, 0 }) {
|
||||
mScrollDelta = eventData.scrollDelta;
|
||||
} else {
|
||||
mEventQueue.popFront();
|
||||
mScrollDelta = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
mEventQueue.popFront();
|
||||
|
|
@ -95,6 +121,6 @@ bool EventHandler::isDown(InputID id) const {
|
|||
mInputStates[(int) id].mCurrentState == InputState::State::HOLD;
|
||||
}
|
||||
|
||||
halnf EventHandler::getScrollY() const { return 0; }
|
||||
halnf EventHandler::getScrollY() const { return mScrollDelta.y; }
|
||||
|
||||
Vec2F EventHandler::getPointerDelta() const { return mPointer - mPointerPrev; }
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ void Application::run() {
|
|||
}
|
||||
|
||||
while (!mWindow->shouldClose()) {
|
||||
if (mProcTimer.isTimeout()) {
|
||||
mWindow->processEvents();
|
||||
|
||||
mWindow->processEvents();
|
||||
if (mProcTimer.isTimeout() || eventHandler->isEvents()) {
|
||||
|
||||
while (eventHandler->isEvents()) {
|
||||
eventHandler->processEvent();
|
||||
|
|
|
|||
|
|
@ -89,7 +89,8 @@ void Window::destroyWindow(Window* window) {
|
|||
bool Window::shouldClose() const { return glfwWindowShouldClose(mContext->window); }
|
||||
|
||||
void Window::processEvents() {
|
||||
glfwWaitEvents();
|
||||
glfwPollEvents();
|
||||
// glfwWaitEvents();
|
||||
checkAxisUpdates();
|
||||
}
|
||||
|
||||
|
|
@ -119,13 +120,13 @@ void Window::checkAxisUpdates() {
|
|||
double x, y;
|
||||
glfwGetCursorPos(mContext->window, &x, &y);
|
||||
|
||||
int posX, posY;
|
||||
glfwGetWindowPos(mContext->window, &posX, &posY);
|
||||
// int posX, posY;
|
||||
// glfwGetWindowPos(mContext->window, &posX, &posY);
|
||||
|
||||
if (mPointerPos != Vec2F{ (halnf) x, (halnf) y }) {
|
||||
mPointerPos = { (halnf) x, (halnf) y };
|
||||
|
||||
auto pos = Vec2F{ (halnf) posX, (halnf) posY };
|
||||
// auto pos = Vec2F{ (halnf) posX, (halnf) posY };
|
||||
RectF windowRec = { { 0, 0 }, mSize };
|
||||
|
||||
if (windowRec.isInside(mPointerPos)) {
|
||||
|
|
@ -167,9 +168,16 @@ static void mouseButtonCallback(GLFWwindow* window, int button, int action, int
|
|||
);
|
||||
} else if (action == GLFW_RELEASE) {
|
||||
eventHandler->postEvent(id, { InputEvent::Type::BUTTON_ACTION, InputEvent::ButtonAction::RELEASE, {} });
|
||||
// eventHandler->postEvent(id, { InputEvent::Type::BUTTON_ACTION, InputEvent::ButtonAction::NONE, {} });
|
||||
}
|
||||
}
|
||||
|
||||
static void scrollCallback(GLFWwindow* window, double xOffset, double yOffset) {
|
||||
// ignore for now
|
||||
auto* self = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
||||
if (!self) return;
|
||||
|
||||
EventHandler* eventHandler = self->getEventHandler();
|
||||
if (!eventHandler) return;
|
||||
|
||||
eventHandler->postEvent(InputID::SCROLL, { InputEvent::Type::SCROLL, {}, {}, { xOffset, yOffset } });
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "Vec.hpp"
|
||||
#include "List.hpp"
|
||||
#include "Map.hpp"
|
||||
#include "Timing.hpp"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ namespace tp {
|
|||
BUTTON_ACTION,
|
||||
MOUSE_DELTA,
|
||||
MOUSE_POS,
|
||||
SCROLL,
|
||||
} type = Type::NONE;
|
||||
|
||||
enum class ButtonAction {
|
||||
|
|
@ -26,6 +28,7 @@ namespace tp {
|
|||
} buttonAction = ButtonAction::NONE;
|
||||
|
||||
Vec2F mouseEvent = { 0, 0 };
|
||||
Vec2F scrollDelta = { 0, 0 };
|
||||
};
|
||||
|
||||
class InputState {
|
||||
|
|
@ -89,10 +92,13 @@ namespace tp {
|
|||
// input states
|
||||
Vec2F mPointer;
|
||||
Vec2F mPointerPrev;
|
||||
Vec2F mScrollDelta;
|
||||
|
||||
halnf mPointerPressure = 0;
|
||||
|
||||
InputState mInputStates[(int) InputID::LAST_KEY_CODE]{};
|
||||
|
||||
Timer mTimerEvent = Timer(1000);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -17,8 +17,8 @@ namespace tp {
|
|||
explicit DebugGUI(Window* window);
|
||||
~DebugGUI();
|
||||
|
||||
void procBegin() {}
|
||||
void procEnd() {}
|
||||
void procBegin();
|
||||
void procEnd();
|
||||
|
||||
void drawBegin();
|
||||
void drawEnd();
|
||||
|
|
|
|||
|
|
@ -143,8 +143,10 @@ namespace tp {
|
|||
MOUSE4 = 504,
|
||||
MOUSE5 = 505,
|
||||
|
||||
LAST_KEY_CODE = 508,
|
||||
SCROLL,
|
||||
|
||||
WINDOW_RESIZE = 1000,
|
||||
WINDOW_RESIZE,
|
||||
|
||||
LAST_KEY_CODE,
|
||||
};
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ namespace tp {
|
|||
~Window();
|
||||
|
||||
public:
|
||||
static Window* createWindow(Vec2F size = { 500.f, 500.f }, const char* title = "Window");
|
||||
static Window* createWindow(Vec2F size = { 1000.f, 700.f }, const char* title = "Window");
|
||||
static void destroyWindow(Window* window);
|
||||
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue