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