31 | 31 |
ImGuiImplMacOS::ImGuiImplMacOS(IRenderDevice* pDevice,
|
32 | 32 |
TEXTURE_FORMAT BackBufferFmt,
|
33 | 33 |
TEXTURE_FORMAT DepthBufferFmt,
|
|
34 |
Uint32 DisplayWidth,
|
|
35 |
Uint32 DisplayHeight,
|
34 | 36 |
Uint32 InitialVertexBufferSize,
|
35 | 37 |
Uint32 InitialIndexBufferSize) :
|
36 | 38 |
ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize)
|
37 | 39 |
{
|
38 | 40 |
ImGui_ImplOSX_Init();
|
|
41 |
ImGuiIO& io = ImGui::GetIO();
|
|
42 |
io.FontGlobalScale = 2;
|
|
43 |
io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight);
|
39 | 44 |
}
|
40 | 45 |
|
41 | 46 |
ImGuiImplMacOS::~ImGuiImplMacOS()
|
|
47 | 52 |
{
|
48 | 53 |
std::lock_guard<std::mutex> Lock(m_Mtx);
|
49 | 54 |
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;
|
54 | 55 |
ImGuiImplDiligent::NewFrame();
|
55 | 56 |
}
|
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 |
|
57 | 65 |
bool ImGuiImplMacOS::HandleOSXEvent(NSEvent *_Nonnull event, NSView *_Nonnull view)
|
58 | 66 |
{
|
59 | 67 |
std::lock_guard<std::mutex> Lock(m_Mtx);
|
|
67 | 75 |
io.MousePos = ImVec2(curPoint.x, viewRectPixels.size.height-1 - curPoint.y);
|
68 | 76 |
return io.WantCaptureMouse;
|
69 | 77 |
}
|
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 |
|
91 | 79 |
return ImGui_ImplOSX_HandleEvent((NSEvent*)event, (NSView*)view);
|
92 | 80 |
}
|
93 | 81 |
|
|
96 | 84 |
std::lock_guard<std::mutex> Lock(m_Mtx);
|
97 | 85 |
ImGuiImplDiligent::Render(pCtx);
|
98 | 86 |
}
|
99 | |
|
|
87 |
|
100 | 88 |
}
|