gui updates

This commit is contained in:
IlyaShurupov 2024-06-24 22:21:10 +03:00 committed by Ilya Shurupov
parent a55a5ec5cc
commit 4a557d7e5c
42 changed files with 1179 additions and 962 deletions

View file

@ -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();

View file

@ -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; }

View file

@ -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();

View file

@ -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 } });
}