git.s-ol.nu ~forks/DiligentTools / 9537d97
Updated imgui implementation on Mac; fixed window resize handling by imgui Egor Yusov 2 years ago
3 changed file(s) with 34 addition(s) and 55 deletion(s). Raw diff Collapse all Expand all
3737 ImGuiImplMacOS(IRenderDevice* pDevice,
3838 TEXTURE_FORMAT BackBufferFmt,
3939 TEXTURE_FORMAT DepthBufferFmt,
40 Uint32 DisplayWidth,
41 Uint32 DisplayHeight,
4042 Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize,
4143 Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize);
4244 ~ImGuiImplMacOS();
5153 virtual void NewFrame()override final;
5254 virtual void Render(IDeviceContext* pCtx)override final;
5355 bool HandleOSXEvent(NSEvent *_Nonnull event, NSView *_Nonnull view);
54
56 void SetDisplaySize(Uint32 DisplayWidth, Uint32 DisplayHeight);
57
5558 private:
5659 std::mutex m_Mtx;
5760 };
3131 ImGuiImplMacOS::ImGuiImplMacOS(IRenderDevice* pDevice,
3232 TEXTURE_FORMAT BackBufferFmt,
3333 TEXTURE_FORMAT DepthBufferFmt,
34 Uint32 DisplayWidth,
35 Uint32 DisplayHeight,
3436 Uint32 InitialVertexBufferSize,
3537 Uint32 InitialIndexBufferSize) :
3638 ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize)
3739 {
3840 ImGui_ImplOSX_Init();
41 ImGuiIO& io = ImGui::GetIO();
42 io.FontGlobalScale = 2;
43 io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight);
3944 }
4045
4146 ImGuiImplMacOS::~ImGuiImplMacOS()
4752 {
4853 std::lock_guard<std::mutex> Lock(m_Mtx);
4954 ImGui_ImplOSX_NewFrame(nil);
50 ImGuiIO& io = ImGui::GetIO();
51 io.DisplaySize = ImVec2(1600, 1200);
52 io.DisplayFramebufferScale = ImVec2(2, 2);
53 io.FontGlobalScale = 2;
5455 ImGuiImplDiligent::NewFrame();
5556 }
56
57
58 void ImGuiImplMacOS::SetDisplaySize(Uint32 DisplayWidth, Uint32 DisplayHeight)
59 {
60 std::lock_guard<std::mutex> Lock(m_Mtx);
61 ImGuiIO& io = ImGui::GetIO();
62 io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight);
63 }
64
5765 bool ImGuiImplMacOS::HandleOSXEvent(NSEvent *_Nonnull event, NSView *_Nonnull view)
5866 {
5967 std::lock_guard<std::mutex> Lock(m_Mtx);
6775 io.MousePos = ImVec2(curPoint.x, viewRectPixels.size.height-1 - curPoint.y);
6876 return io.WantCaptureMouse;
6977 }
70 else if (event.type == NSEventTypeKeyDown)
71 {
72 NSString* str = [event characters];
73 int len = (int)[str length];
74 for (int i = 0; i < len; i++)
75 {
76 int c = [str characterAtIndex:i];
77 // There appears to be a bug in handling of backspace
78 if (c==127)
79 {
80 if (!io.KeyCtrl)
81 {
82 for (int n = 0; n < IM_ARRAYSIZE(io.KeysDown); n++)
83 io.KeysDown[n] = false;
84 }
85 io.KeysDown[c] = true;
86 return io.WantCaptureKeyboard;
87 }
88 }
89 }
90
78
9179 return ImGui_ImplOSX_HandleEvent((NSEvent*)event, (NSView*)view);
9280 }
9381
9684 std::lock_guard<std::mutex> Lock(m_Mtx);
9785 ImGuiImplDiligent::Render(pCtx);
9886 }
99
87
10088 }
3131 ImGuiImplMacOS::ImGuiImplMacOS(IRenderDevice* pDevice,
3232 TEXTURE_FORMAT BackBufferFmt,
3333 TEXTURE_FORMAT DepthBufferFmt,
34 Uint32 DisplayWidth,
35 Uint32 DisplayHeight,
3436 Uint32 InitialVertexBufferSize,
3537 Uint32 InitialIndexBufferSize) :
3638 ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize)
3739 {
3840 ImGui_ImplOSX_Init();
41 ImGuiIO& io = ImGui::GetIO();
42 io.FontGlobalScale = 2;
43 io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight);
3944 }
4045
4146 ImGuiImplMacOS::~ImGuiImplMacOS()
4752 {
4853 std::lock_guard<std::mutex> Lock(m_Mtx);
4954 ImGui_ImplOSX_NewFrame(nil);
50 ImGuiIO& io = ImGui::GetIO();
51 io.DisplaySize = ImVec2(1600, 1200);
52 io.DisplayFramebufferScale = ImVec2(2, 2);
53 io.FontGlobalScale = 2;
5455 ImGuiImplDiligent::NewFrame();
5556 }
56
57
58 void ImGuiImplMacOS::SetDisplaySize(Uint32 DisplayWidth, Uint32 DisplayHeight)
59 {
60 std::lock_guard<std::mutex> Lock(m_Mtx);
61 ImGuiIO& io = ImGui::GetIO();
62 io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight);
63 }
64
5765 bool ImGuiImplMacOS::HandleOSXEvent(NSEvent *_Nonnull event, NSView *_Nonnull view)
5866 {
5967 std::lock_guard<std::mutex> Lock(m_Mtx);
6775 io.MousePos = ImVec2(curPoint.x, viewRectPixels.size.height-1 - curPoint.y);
6876 return io.WantCaptureMouse;
6977 }
70 else if (event.type == NSEventTypeKeyDown)
71 {
72 NSString* str = [event characters];
73 int len = (int)[str length];
74 for (int i = 0; i < len; i++)
75 {
76 int c = [str characterAtIndex:i];
77 // There appears to be a bug in handling of backspace
78 if (c==127)
79 {
80 if (!io.KeyCtrl)
81 {
82 for (int n = 0; n < IM_ARRAYSIZE(io.KeysDown); n++)
83 io.KeysDown[n] = false;
84 }
85 io.KeysDown[c] = true;
86 return io.WantCaptureKeyboard;
87 }
88 }
89 }
90
78
9179 return ImGui_ImplOSX_HandleEvent((NSEvent*)event, (NSView*)view);
9280 }
9381
9684 std::lock_guard<std::mutex> Lock(m_Mtx);
9785 ImGuiImplDiligent::Render(pCtx);
9886 }
99
87
10088 }