git.s-ol.nu ~forks/DiligentTools / 8678497
First implementation of imgui on Mac Egor Yusov 2 years ago
5 changed file(s) with 169 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
4545 elseif(PLATFORM_UNIVERSAL_WINDOWS)
4646 list(APPEND SOURCE src/ImGuiImplUWP.cpp)
4747 list(APPEND INTERFACE interface/ImGuiImplUWP.h)
48 elseif(PLATFORM_MACOS)
49 list(APPEND DEAR_IMGUI_SOURCE ${DEAR_IMGUI_PATH}/examples/imgui_impl_osx.mm)
50 list(APPEND DEAR_IMGUI_INCLUDE ${DEAR_IMGUI_PATH}/examples/imgui_impl_osx.h)
51
52 list(APPEND SOURCE src/ImGuiImplMacOS.mm)
53 list(APPEND INTERFACE interface/ImGuiImplMacOS.h)
4854 endif()
4955
5056 add_library(Diligent-Imgui STATIC ${SOURCE} ${INCLUDE} ${INTERFACE} ${DEAR_IMGUI_SOURCE} ${DEAR_IMGUI_INCLUDE} ${DEAR_IMGUI_INTERFACE} ${IMGUIZMO_QUAT_SOURCE})
4545 TEXTURE_FORMAT DepthBufferFmt,
4646 Uint32 InitialVertexBufferSize = DefaultInitialVBSize,
4747 Uint32 InitialIndexBufferSize = DefaultInitialIBSize);
48 ~ImGuiImplDiligent();
48 virtual ~ImGuiImplDiligent();
4949
5050 ImGuiImplDiligent (const ImGuiImplDiligent&) = delete;
5151 ImGuiImplDiligent ( ImGuiImplDiligent&&) = delete;
5353 ImGuiImplDiligent& operator = ( ImGuiImplDiligent&&) = delete;
5454
5555 virtual void NewFrame();
56 void Render(IDeviceContext* pCtx);
56 virtual void Render(IDeviceContext* pCtx);
5757
5858 // Use if you want to reset your rendering device without losing ImGui state.
5959 void InvalidateDeviceObjects();
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include <mutex>
26 #include "ImGuiImplDiligent.h"
27
28 @class NSEvent;
29 @class NSView;
30
31 namespace Diligent
32 {
33
34 class ImGuiImplMacOS final : public ImGuiImplDiligent
35 {
36 public:
37 ImGuiImplMacOS(IRenderDevice* pDevice,
38 TEXTURE_FORMAT BackBufferFmt,
39 TEXTURE_FORMAT DepthBufferFmt,
40 Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize,
41 Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize);
42 ~ImGuiImplMacOS();
43
44 //LRESULT Win32_ProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
45
46 ImGuiImplMacOS (const ImGuiImplMacOS&) = delete;
47 ImGuiImplMacOS ( ImGuiImplMacOS&&) = delete;
48 ImGuiImplMacOS& operator = (const ImGuiImplMacOS&) = delete;
49 ImGuiImplMacOS& operator = ( ImGuiImplMacOS&&) = delete;
50
51 virtual void NewFrame()override final;
52 virtual void Render(IDeviceContext* pCtx)override final;
53 bool HandleOSXEvent(NSEvent *_Nonnull event, NSView *_Nonnull view);
54
55 private:
56 std::mutex m_Mtx;
57 };
58
59 }
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #include "imgui.h"
24 #include "ImGuiImplMacOS.h"
25 #include "examples/imgui_impl_osx.h"
26 #import <Cocoa/Cocoa.h>
27
28 namespace Diligent
29 {
30
31 ImGuiImplMacOS::ImGuiImplMacOS(IRenderDevice* pDevice,
32 TEXTURE_FORMAT BackBufferFmt,
33 TEXTURE_FORMAT DepthBufferFmt,
34 Uint32 InitialVertexBufferSize,
35 Uint32 InitialIndexBufferSize) :
36 ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize)
37 {
38 ImGui_ImplOSX_Init();
39 }
40
41 ImGuiImplMacOS::~ImGuiImplMacOS()
42 {
43 ImGui_ImplOSX_Shutdown();
44 }
45
46 void ImGuiImplMacOS::NewFrame()
47 {
48 std::lock_guard<std::mutex> Lock(m_Mtx);
49 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 ImGuiImplDiligent::NewFrame();
55 }
56
57 bool ImGuiImplMacOS::HandleOSXEvent(NSEvent *_Nonnull event, NSView *_Nonnull view)
58 {
59 std::lock_guard<std::mutex> Lock(m_Mtx);
60 ImGuiIO& io = ImGui::GetIO();
61 if (event.type == NSEventTypeMouseMoved || event.type == NSEventTypeLeftMouseDragged)
62 {
63 NSRect viewRectPoints = [view bounds];
64 NSRect viewRectPixels = [view convertRectToBacking:viewRectPoints];
65 NSPoint curPoint = [view convertPoint:[event locationInWindow] fromView:nil];
66 curPoint = [view convertPointToBacking:curPoint];
67 io.MousePos = ImVec2(curPoint.x, viewRectPixels.size.height-1 - curPoint.y);
68 return io.WantCaptureMouse;
69 }
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
91 return ImGui_ImplOSX_HandleEvent((NSEvent*)event, (NSView*)view);
92 }
93
94 void ImGuiImplMacOS::Render(IDeviceContext* pCtx)
95 {
96 std::lock_guard<std::mutex> Lock(m_Mtx);
97 ImGuiImplDiligent::Render(pCtx);
98 }
99
100 }
671671 ////////////////////////////////////////////////////////////////////////////
672672 void imguiGizmo::buildSphere(const float radius, const int tessFactor)
673673 {
674 const int tess = tessFactor;
675674 const int div = tessFactor; //tessellation colors: meridians/div x paralles/div
676675 const int meridians = 32; //64/2;
677676 const int parallels = meridians/2;
760759 void imguiGizmo::buildCone(const float x0, const float x1, const float radius, const int slices)
761760 {
762761 const float height = x1-x0 ;
763 const float zStep = height;
764 const float rStep = radius/(float)slices;
765762
766763 // Scaling factors for vertex normals
767764