PeriDyno 1.0.0
Loading...
Searching...
No Matches
imgui_impl_wt.cpp
Go to the documentation of this file.
1#include <imgui.h>
2#include <imgui_internal.h>
3
4#include "imgui_impl_wt.h"
5#include "imgui_impl_opengl3.h"
6
7#include <Wt/WEvent.h>
8
9ImGuiBackendWt::ImGuiBackendWt(Wt::WContainerWidget* parent)
10{
11 IMGUI_CHECKVERSION();
12 ctx = ImGui::CreateContext();
13 ImGui::SetCurrentContext(ctx);
14
15 const char* glsl_version = "#version 130";
16 ImGui_ImplOpenGL3_Init(glsl_version);
17}
18
20{
21 ImGui::SetCurrentContext(ctx);
22 ImGui_ImplOpenGL3_Shutdown();
23 ImGui::DestroyContext(ctx);
24}
25
26void ImGuiBackendWt::NewFrame(int width, int height)
27{
28 ImGui::SetCurrentContext(ctx);
29 auto& io = ImGui::GetIO();
30 io.DisplaySize.x = width;
31 io.DisplaySize.y = height;
32
33 ImGui_ImplOpenGL3_NewFrame();
34 ImGui::NewFrame();
35
36 //while (ctx->InputEventsQueue.Size > 0)
37 //{
38 // ImGui::EndFrame();
39 // ImGui::NewFrame();
40 //}
41}
42
44{
45 ImGui::Render();
46 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
47}
48
49bool ImGuiBackendWt::handleMousePressed(const Wt::WMouseEvent& evt)
50{
51 auto& io = ctx->IO;
52 int button = -1;
53 if (evt.button() == Wt::MouseButton::Left) button = 0;
54 if (evt.button() == Wt::MouseButton::Right) button = 1;
55 if (evt.button() == Wt::MouseButton::Middle) button = 2;
56 //io.AddMousePosEvent(evt.widget().x, evt.widget().y);
57 io.MousePos = ImVec2(evt.widget().x, evt.widget().y);
58 io.AddMouseButtonEvent(button, true);
59 return io.WantCaptureMouse;
60}
61
62bool ImGuiBackendWt::handleMouseDrag(const Wt::WMouseEvent& evt)
63{
64 auto& io = ctx->IO;
65 io.AddMousePosEvent(evt.widget().x, evt.widget().y);
66 return io.WantCaptureMouse;
67}
68
69bool ImGuiBackendWt::handleMouseReleased(const Wt::WMouseEvent& evt)
70{
71 auto& io = ctx->IO;
72 int button = -1;
73 if (evt.button() == Wt::MouseButton::Left) button = 0;
74 if (evt.button() == Wt::MouseButton::Right) button = 1;
75 if (evt.button() == Wt::MouseButton::Middle) button = 2;
76 //io.AddMousePosEvent(evt.widget().x, evt.widget().y);
77 io.MousePos = ImVec2(evt.widget().x, evt.widget().y);
78 io.AddMouseButtonEvent(button, false);
79 return io.WantCaptureMouse;
80}
81
bool handleMousePressed(const Wt::WMouseEvent &evt)
bool handleMouseReleased(const Wt::WMouseEvent &evt)
bool handleMouseDrag(const Wt::WMouseEvent &evt)
ImGuiContext * ctx
ImGuiBackendWt(Wt::WContainerWidget *parent)
void NewFrame(int width, int height)