summaryrefslogtreecommitdiff
path: root/src/bookmouse.cpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-25 10:53:18 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-25 10:53:18 -0500
commitb6e3cc840e255b78ee53e55b420aeee130e51ce1 (patch)
treea1cc9b47bb2858710358269059afd43808ca36cc /src/bookmouse.cpp
parent348a1bfb244288b1c78d8ce3c8d8a8cb5c1bdebc (diff)
Work on wrapping types.
Diffstat (limited to 'src/bookmouse.cpp')
-rw-r--r--src/bookmouse.cpp89
1 files changed, 62 insertions, 27 deletions
diff --git a/src/bookmouse.cpp b/src/bookmouse.cpp
index 65184ef..77c2304 100644
--- a/src/bookmouse.cpp
+++ b/src/bookmouse.cpp
@@ -2,6 +2,9 @@
#include <SDL_opengl.h>
#include <fud_array.hpp>
+#include <spdlog/spdlog.h>
+
+#include <atomic>
namespace bookmouse {
@@ -78,6 +81,9 @@ SDL_Event Bookmouse::pollEvent()
* hide them from your application based on those two flags.
*/
SDL_Event event{};
+ ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
+ ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
+
while (SDL_PollEvent(&event)) {
static_cast<void>(m_imgui.processEvent(event));
if (event.type == SDL_QUIT) {
@@ -93,20 +99,15 @@ SDL_Event Bookmouse::pollEvent()
void Bookmouse::updateState()
{
- bool my_tool_active{true};
- ImGui::Begin("My First Tool", &my_tool_active, ImGuiWindowFlags_MenuBar);
+ ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
+ ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
+ auto stateResult = ImGui::Begin(
+ "My First Tool",
+ &m_running, // Is this right?
+ ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_MenuBar);
+ IM_ASSERT(stateResult);
if (ImGui::BeginMenuBar()) {
- if (ImGui::BeginMenu("File")) {
- if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */
- }
- if (ImGui::MenuItem("Save", "Ctrl+S")) { /* Do stuff */
- }
- if (ImGui::MenuItem("Close", "Ctrl+W")) {
- my_tool_active = false;
- }
- ImGui::EndMenu();
- }
- ImGui::EndMenuBar();
+ menuBar();
}
// Edit a color stored as 4 floats
@@ -124,25 +125,59 @@ void Bookmouse::updateState()
// Display contents in a scrolling region
ImGui::TextColored(ImVec4(1, 1, 0, 1), "Important Stuff");
- ImGui::BeginChild("Scrolling");
- for (int n = 0; n < 50; n++)
- ImGui::Text("%04d: Some text", n);
- ImGui::EndChild();
+ ImGui::Text("%04d: Some text", 42);
ImGui::End();
}
+constexpr const char* OpenDialogHandle = "Open File";
+void Bookmouse::menuBar()
+{
+ bool clickOpen = false;
+ if (ImguiMenu menu{"File"}) {
+ IM_ASSERT(menu);
+ spdlog::debug("HERE {}", menu);
+ if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */
+ spdlog::debug("Open - m_openDialog was {}", m_openDialog);
+ clickOpen = true;
+ }
+ if (ImGui::MenuItem("Close", "Ctrl+Q")) {
+ m_running = false;
+ }
+ spdlog::debug("THERE");
+ }
+
+ if (ImguiMenu menu{"Help"}) {
+ IM_ASSERT(menu);
+ if (ImGui::MenuItem("About")) {
+ spdlog::debug("About");
+ }
+ ImGui::EndMenu();
+ }
+ ImGui::EndMenuBar();
+
+ if (clickOpen) {
+ clickOpen = false;
+ ImGui::OpenPopup(OpenDialogHandle);
+ }
+
+ openDialog();
+}
+
+void Bookmouse::openDialog() {
+ // if (ImGui::Begin("Another Window", &m_openDialog, 0)) {
+ if (ImGui::BeginPopupModal(OpenDialogHandle)) {
+ ImGui::Text("Hello from another window!");
+ if (ImGui::Button("Close Me")) {
+ m_openDialog = false;
+ ImGui::CloseCurrentPopup();
+ }
+ ImGui::EndPopup();
+ // ImGui::End();
+ }
+}
+
void Bookmouse::renderFrame()
{
- ImGui::Render();
- const auto& imguiIO = m_imgui.getIO();
- glViewport(0, 0, static_cast<int>(imguiIO.DisplaySize.x), static_cast<int>(imguiIO.DisplaySize.y));
- ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
- glClearColor(
- clear_color.x * clear_color.w,
- clear_color.y * clear_color.w,
- clear_color.z * clear_color.w,
- clear_color.w);
- glClear(GL_COLOR_BUFFER_BIT);
m_imgui.render();
}