RunicVTT Open Source Virtual Tabletop for TTRPG using P2P
Loading...
Searching...
No Matches
ApplicationHandler.h
Go to the documentation of this file.
1#pragma once
2
3#include <GL/glew.h>
4#include <GLFW/glfw3.h>
5
6#include "Renderer.h"
7#include "Shader.h"
8#include "VertexBuffer.h"
9#include "IndexBuffer.h"
10#include "VertexArray.h"
11#include "VertexBufferLayout.h"
12#include "Texture.h"
13
14#include "glm/glm.hpp"
15#include "glm/gtc/matrix_transform.hpp"
16
17#include <filesystem>
18#include <iostream>
19#include <thread>
20#include <mutex>
21#include <condition_variable>
22
23#include "imgui.h"
24#include "imgui_internal.h"
25#include "imgui_impl_glfw.h"
26#include "imgui_impl_opengl3.h"
27#include "GameTableManager.h"
28#include "DirectoryWindow.h"
29#include "flecs.h"
30#include "PathManager.h"
31#include "NoteEditorUI.h"
32#include "NotesManager.h"
33
34//#include "ConsoleUtils.h"
35
36namespace fs = std::filesystem;
37
38struct MapFBO
39{
40 GLuint fboID;
41 GLuint textureID;
42 GLuint rboID; // Renderbuffer for depth/stencil (optional but recommended for 3D)
43 int width;
44 int height;
45
47 {
48 this->fboID = 0;
49 this->textureID = 0;
50 this->rboID = 0;
51 this->width = 0;
52 this->height = 0;
53 }
54};
56{
57
58public:
59 ApplicationHandler(GLFWwindow* window, std::shared_ptr<DirectoryWindow> map_directory, std::shared_ptr<DirectoryWindow> marker_directory);
61 int run();
62
63 void pushStatusToast(const std::string& msg, ImGuiToaster::Level lvl, float durationSec = 5.0f)
64 {
65 if (toaster_)
66 toaster_->Push(lvl, msg, durationSec);
67 }
68
69private:
70 std::shared_ptr<ImGuiToaster> toaster_;
71 void renderMainMenuBar();
72 void renderDockSpace();
73 void renderMapFBO(VertexArray& va, IndexBuffer& ib, Shader& shader, Shader& grid_shader, Renderer& renderer);
75
76 void CreateMapFBO(int width, int height);
77 void ResizeMapFBO(int newWidth, int newHeight);
78 void DeleteMapFBO();
79 void TickAutoSave();
80 void GetMousePosInItem(ImVec2& out_item_size, ImVec2& item_screen_pos);
81
82 std::shared_ptr<MapFBO> map_fbo;
83 GLFWwindow* window;
84 flecs::world ecs;
85 std::shared_ptr<GameTableManager> game_table_manager;
86 std::shared_ptr<DirectoryWindow> map_directory;
87 std::shared_ptr<DirectoryWindow> marker_directory;
88 std::shared_ptr<NotesManager> notes_manager;
89 std::shared_ptr<NoteEditorUI> note_editor_ui;
90
92
93 glm::vec2 current_fbo_mouse_pos = glm::vec2(0, 0);
94 ImVec2 current_map_relative_mouse_pos = ImVec2(0, 0);
95
96 //DEBUG STUFF --------------------------------------
97
98 bool g_draw_debug_circle = false;
99 void DrawDebugCircle(ImVec2 coords, bool is_relative_to_window, ImU32 color, float radius = 10.0f)
100 {
101 ImDrawList* draw_list = ImGui::GetForegroundDrawList();
102 ImVec2 final_screen_pos = coords;
103
104 if (is_relative_to_window)
105 {
106 // This conversion means 'coords' is relative to the current ImGui window's top-left.
107 // For debugging mouse clicks on an ImGui::Image, you generally calculate
108 // relative to the image, and then add the image's global position.
109 // So, for mouse click debug, you'll usually pass false for is_relative_to_window
110 // after converting your calculated points back to global screen space.
111 final_screen_pos.x += ImGui::GetWindowPos().x;
112 final_screen_pos.y += ImGui::GetWindowPos().y;
113 }
114
115 draw_list->AddCircleFilled(final_screen_pos, radius, color, 16);
116 }
117
118 //void handleToasterDebug()
119 //{
120 // if (ImGui::IsKeyPressed(ImGuiKey_1))
121 // pushStatusToast("Info: Hello!", ImGuiToaster::Level::Info, 5.0f);
122 // if (ImGui::IsKeyPressed(ImGuiKey_2))
123 // pushStatusToast("Good: Saved", ImGuiToaster::Level::Good, 4.0f);
124 // if (ImGui::IsKeyPressed(ImGuiKey_3))
125 // pushStatusToast("Warning: Ping high", ImGuiToaster::Level::Warning, 6.0f);
126 // if (ImGui::IsKeyPressed(ImGuiKey_4))
127 // pushStatusToast("Error: Failed op", ImGuiToaster::Level::Error);
128 //}
129};
std::shared_ptr< GameTableManager > game_table_manager
void pushStatusToast(const std::string &msg, ImGuiToaster::Level lvl, float durationSec=5.0f)
std::shared_ptr< DirectoryWindow > map_directory
std::shared_ptr< DirectoryWindow > marker_directory
std::shared_ptr< NotesManager > notes_manager
ApplicationHandler(GLFWwindow *window, std::shared_ptr< DirectoryWindow > map_directory, std::shared_ptr< DirectoryWindow > marker_directory)
std::shared_ptr< MapFBO > map_fbo
void CreateMapFBO(int width, int height)
void GetMousePosInItem(ImVec2 &out_item_size, ImVec2 &item_screen_pos)
std::shared_ptr< NoteEditorUI > note_editor_ui
void DrawDebugCircle(ImVec2 coords, bool is_relative_to_window, ImU32 color, float radius=10.0f)
void renderMapFBO(VertexArray &va, IndexBuffer &ib, Shader &shader, Shader &grid_shader, Renderer &renderer)
void ResizeMapFBO(int newWidth, int newHeight)
std::shared_ptr< ImGuiToaster > toaster_
Definition Message.h:28
GLuint textureID