Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
2e168856
Commit
2e168856
authored
Mar 03, 2019
by
chili
Browse files
imgui minimal test
parent
dc0f33f5
Changes
12
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
2e168856
...
@@ -260,3 +260,4 @@ paket-files/
...
@@ -260,3 +260,4 @@ paket-files/
__pycache__/
__pycache__/
*.pyc
*.pyc
*.cso
*.cso
/hw3d/imgui.ini
hw3d/App.cpp
View file @
2e168856
...
@@ -9,6 +9,9 @@
...
@@ -9,6 +9,9 @@
#include "ChiliMath.h"
#include "ChiliMath.h"
#include "Surface.h"
#include "Surface.h"
#include "GDIPlusManager.h"
#include "GDIPlusManager.h"
#include "imgui/imgui.h"
#include "imgui/imgui_impl_win32.h"
#include "imgui/imgui_impl_dx11.h"
GDIPlusManager
gdipm
;
GDIPlusManager
gdipm
;
...
@@ -85,6 +88,21 @@ void App::DoFrame()
...
@@ -85,6 +88,21 @@ void App::DoFrame()
d
->
Update
(
wnd
.
kbd
.
KeyIsPressed
(
VK_SPACE
)
?
0.0
f
:
dt
);
d
->
Update
(
wnd
.
kbd
.
KeyIsPressed
(
VK_SPACE
)
?
0.0
f
:
dt
);
d
->
Draw
(
wnd
.
Gfx
()
);
d
->
Draw
(
wnd
.
Gfx
()
);
}
}
// imgui stuff
ImGui_ImplDX11_NewFrame
();
ImGui_ImplWin32_NewFrame
();
ImGui
::
NewFrame
();
static
bool
show_demo_window
=
true
;
if
(
show_demo_window
)
{
ImGui
::
ShowDemoWindow
(
&
show_demo_window
);
}
ImGui
::
Render
();
ImGui_ImplDX11_RenderDrawData
(
ImGui
::
GetDrawData
()
);
// present
wnd
.
Gfx
().
EndFrame
();
wnd
.
Gfx
().
EndFrame
();
}
}
...
...
hw3d/App.h
View file @
2e168856
#pragma once
#pragma once
#include "Window.h"
#include "Window.h"
#include "ChiliTimer.h"
#include "ChiliTimer.h"
#include "ImguiManager.h"
class
App
class
App
{
{
...
@@ -12,6 +13,7 @@ public:
...
@@ -12,6 +13,7 @@ public:
private:
private:
void
DoFrame
();
void
DoFrame
();
private:
private:
ImguiManager
imgui
;
Window
wnd
;
Window
wnd
;
ChiliTimer
timer
;
ChiliTimer
timer
;
std
::
vector
<
std
::
unique_ptr
<
class
Drawable
>>
drawables
;
std
::
vector
<
std
::
unique_ptr
<
class
Drawable
>>
drawables
;
...
...
hw3d/Graphics.cpp
View file @
2e168856
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <cmath>
#include <cmath>
#include <DirectXMath.h>
#include <DirectXMath.h>
#include "GraphicsThrowMacros.h"
#include "GraphicsThrowMacros.h"
#include "imgui/imgui_impl_dx11.h"
namespace
wrl
=
Microsoft
::
WRL
;
namespace
wrl
=
Microsoft
::
WRL
;
namespace
dx
=
DirectX
;
namespace
dx
=
DirectX
;
...
@@ -107,6 +108,9 @@ Graphics::Graphics( HWND hWnd )
...
@@ -107,6 +108,9 @@ Graphics::Graphics( HWND hWnd )
vp
.
TopLeftX
=
0.0
f
;
vp
.
TopLeftX
=
0.0
f
;
vp
.
TopLeftY
=
0.0
f
;
vp
.
TopLeftY
=
0.0
f
;
pContext
->
RSSetViewports
(
1u
,
&
vp
);
pContext
->
RSSetViewports
(
1u
,
&
vp
);
// init imgui d3d impl
ImGui_ImplDX11_Init
(
pDevice
.
Get
(),
pContext
.
Get
()
);
}
}
void
Graphics
::
EndFrame
()
void
Graphics
::
EndFrame
()
...
...
hw3d/ImguiManager.cpp
0 → 100644
View file @
2e168856
#include "ImguiManager.h"
#include "imgui/imgui.h"
ImguiManager
::
ImguiManager
()
{
IMGUI_CHECKVERSION
();
ImGui
::
CreateContext
();
ImGui
::
StyleColorsDark
();
}
ImguiManager
::~
ImguiManager
()
{
ImGui
::
DestroyContext
();
}
hw3d/ImguiManager.h
0 → 100644
View file @
2e168856
#pragma once
class
ImguiManager
{
public:
ImguiManager
();
~
ImguiManager
();
};
hw3d/Window.cpp
View file @
2e168856
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include <sstream>
#include <sstream>
#include "resource.h"
#include "resource.h"
#include "WindowsThrowMacros.h"
#include "WindowsThrowMacros.h"
#include "imgui/imgui_impl_win32.h"
// Window Class Stuff
// Window Class Stuff
...
@@ -98,12 +99,15 @@ Window::Window( int width,int height,const char* name )
...
@@ -98,12 +99,15 @@ Window::Window( int width,int height,const char* name )
}
}
// newly created windows start off as hidden
// newly created windows start off as hidden
ShowWindow
(
hWnd
,
SW_SHOWDEFAULT
);
ShowWindow
(
hWnd
,
SW_SHOWDEFAULT
);
// Init ImGui Win32 Impl
ImGui_ImplWin32_Init
(
hWnd
);
// create graphics object
// create graphics object
pGfx
=
std
::
make_unique
<
Graphics
>
(
hWnd
);
pGfx
=
std
::
make_unique
<
Graphics
>
(
hWnd
);
}
}
Window
::~
Window
()
Window
::~
Window
()
{
{
ImGui_ImplWin32_Shutdown
();
DestroyWindow
(
hWnd
);
DestroyWindow
(
hWnd
);
}
}
...
@@ -175,6 +179,11 @@ LRESULT CALLBACK Window::HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPARAM
...
@@ -175,6 +179,11 @@ LRESULT CALLBACK Window::HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPARAM
LRESULT
Window
::
HandleMsg
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
LRESULT
Window
::
HandleMsg
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
{
{
if
(
ImGui_ImplWin32_WndProcHandler
(
hWnd
,
msg
,
wParam
,
lParam
)
)
{
return
true
;
}
switch
(
msg
)
switch
(
msg
)
{
{
// we don't want the DefProc to handle this message because
// we don't want the DefProc to handle this message because
...
...
hw3d/hw3d.vcxproj
View file @
2e168856
...
@@ -157,6 +157,7 @@
...
@@ -157,6 +157,7 @@
<ClCompile
Include=
"DxgiInfoManager.cpp"
/>
<ClCompile
Include=
"DxgiInfoManager.cpp"
/>
<ClCompile
Include=
"GDIPlusManager.cpp"
/>
<ClCompile
Include=
"GDIPlusManager.cpp"
/>
<ClCompile
Include=
"Graphics.cpp"
/>
<ClCompile
Include=
"Graphics.cpp"
/>
<ClCompile
Include=
"ImguiManager.cpp"
/>
<ClCompile
Include=
"imgui\imgui.cpp"
/>
<ClCompile
Include=
"imgui\imgui.cpp"
/>
<ClCompile
Include=
"imgui\imgui_demo.cpp"
/>
<ClCompile
Include=
"imgui\imgui_demo.cpp"
/>
<ClCompile
Include=
"imgui\imgui_draw.cpp"
/>
<ClCompile
Include=
"imgui\imgui_draw.cpp"
/>
...
@@ -202,6 +203,7 @@
...
@@ -202,6 +203,7 @@
<ClInclude
Include=
"GDIPlusManager.h"
/>
<ClInclude
Include=
"GDIPlusManager.h"
/>
<ClInclude
Include=
"Graphics.h"
/>
<ClInclude
Include=
"Graphics.h"
/>
<ClInclude
Include=
"GraphicsThrowMacros.h"
/>
<ClInclude
Include=
"GraphicsThrowMacros.h"
/>
<ClInclude
Include=
"ImguiManager.h"
/>
<ClInclude
Include=
"imgui\imconfig.h"
/>
<ClInclude
Include=
"imgui\imconfig.h"
/>
<ClInclude
Include=
"imgui\imgui.h"
/>
<ClInclude
Include=
"imgui\imgui.h"
/>
<ClInclude
Include=
"imgui\imgui_impl_dx11.h"
/>
<ClInclude
Include=
"imgui\imgui_impl_dx11.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
2e168856
...
@@ -147,6 +147,9 @@
...
@@ -147,6 +147,9 @@
<ClCompile
Include=
"imgui\imgui_impl_win32.cpp"
>
<ClCompile
Include=
"imgui\imgui_impl_win32.cpp"
>
<Filter>
imgui
</Filter>
<Filter>
imgui
</Filter>
</ClCompile>
</ClCompile>
<ClCompile
Include=
"ImguiManager.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
@@ -299,6 +302,9 @@
...
@@ -299,6 +302,9 @@
<ClInclude
Include=
"imgui\imgui_impl_win32.h"
>
<ClInclude
Include=
"imgui\imgui_impl_win32.h"
>
<Filter>
imgui
</Filter>
<Filter>
imgui
</Filter>
</ClInclude>
</ClInclude>
<ClInclude
Include=
"ImguiManager.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"hw3d.rc"
>
<ResourceCompile
Include=
"hw3d.rc"
>
...
...
hw3d/imgui/imgui_impl_dx11.h
View file @
2e168856
...
@@ -9,9 +9,9 @@
...
@@ -9,9 +9,9 @@
// https://github.com/ocornut/imgui
// https://github.com/ocornut/imgui
#pragma once
#pragma once
#include "../ChiliWin.h"
struct
ID3D11Device
;
#include "../Graphics.h"
struct
ID3D11DeviceContext
;
#include "imgui.h"
IMGUI_IMPL_API
bool
ImGui_ImplDX11_Init
(
ID3D11Device
*
device
,
ID3D11DeviceContext
*
device_context
);
IMGUI_IMPL_API
bool
ImGui_ImplDX11_Init
(
ID3D11Device
*
device
,
ID3D11DeviceContext
*
device_context
);
IMGUI_IMPL_API
void
ImGui_ImplDX11_Shutdown
();
IMGUI_IMPL_API
void
ImGui_ImplDX11_Shutdown
();
...
...
hw3d/imgui/imgui_impl_win32.cpp
View file @
2e168856
...
@@ -9,11 +9,6 @@
...
@@ -9,11 +9,6 @@
#include "imgui.h"
#include "imgui.h"
#include "imgui_impl_win32.h"
#include "imgui_impl_win32.h"
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <XInput.h>
#include <tchar.h>
#include <tchar.h>
// CHANGELOG
// CHANGELOG
...
@@ -46,7 +41,7 @@ static bool g_HasGamepad = false;
...
@@ -46,7 +41,7 @@ static bool g_HasGamepad = false;
static
bool
g_WantUpdateHasGamepad
=
true
;
static
bool
g_WantUpdateHasGamepad
=
true
;
// Functions
// Functions
bool
ImGui_ImplWin32_Init
(
void
*
hwnd
)
bool
ImGui_ImplWin32_Init
(
HWND
hwnd
)
{
{
if
(
!::
QueryPerformanceFrequency
((
LARGE_INTEGER
*
)
&
g_TicksPerSecond
))
if
(
!::
QueryPerformanceFrequency
((
LARGE_INTEGER
*
)
&
g_TicksPerSecond
))
return
false
;
return
false
;
...
@@ -54,7 +49,7 @@ bool ImGui_ImplWin32_Init(void* hwnd)
...
@@ -54,7 +49,7 @@ bool ImGui_ImplWin32_Init(void* hwnd)
return
false
;
return
false
;
// Setup back-end capabilities flags
// Setup back-end capabilities flags
g_hWnd
=
(
HWND
)
hwnd
;
g_hWnd
=
hwnd
;
ImGuiIO
&
io
=
ImGui
::
GetIO
();
ImGuiIO
&
io
=
ImGui
::
GetIO
();
io
.
BackendFlags
|=
ImGuiBackendFlags_HasMouseCursors
;
// We can honor GetMouseCursor() values (optional)
io
.
BackendFlags
|=
ImGuiBackendFlags_HasMouseCursors
;
// We can honor GetMouseCursor() values (optional)
io
.
BackendFlags
|=
ImGuiBackendFlags_HasSetMousePos
;
// We can honor io.WantSetMousePos requests (optional, rarely used)
io
.
BackendFlags
|=
ImGuiBackendFlags_HasSetMousePos
;
// We can honor io.WantSetMousePos requests (optional, rarely used)
...
@@ -145,57 +140,6 @@ static void ImGui_ImplWin32_UpdateMousePos()
...
@@ -145,57 +140,6 @@ static void ImGui_ImplWin32_UpdateMousePos()
io
.
MousePos
=
ImVec2
((
float
)
pos
.
x
,
(
float
)
pos
.
y
);
io
.
MousePos
=
ImVec2
((
float
)
pos
.
x
,
(
float
)
pos
.
y
);
}
}
#ifdef _MSC_VER
#pragma comment(lib, "xinput")
#endif
// Gamepad navigation mapping
static
void
ImGui_ImplWin32_UpdateGamepads
()
{
ImGuiIO
&
io
=
ImGui
::
GetIO
();
memset
(
io
.
NavInputs
,
0
,
sizeof
(
io
.
NavInputs
));
if
((
io
.
ConfigFlags
&
ImGuiConfigFlags_NavEnableGamepad
)
==
0
)
return
;
// Calling XInputGetState() every frame on disconnected gamepads is unfortunately too slow.
// Instead we refresh gamepad availability by calling XInputGetCapabilities() _only_ after receiving WM_DEVICECHANGE.
if
(
g_WantUpdateHasGamepad
)
{
XINPUT_CAPABILITIES
caps
;
g_HasGamepad
=
(
XInputGetCapabilities
(
0
,
XINPUT_FLAG_GAMEPAD
,
&
caps
)
==
ERROR_SUCCESS
);
g_WantUpdateHasGamepad
=
false
;
}
XINPUT_STATE
xinput_state
;
io
.
BackendFlags
&=
~
ImGuiBackendFlags_HasGamepad
;
if
(
g_HasGamepad
&&
XInputGetState
(
0
,
&
xinput_state
)
==
ERROR_SUCCESS
)
{
const
XINPUT_GAMEPAD
&
gamepad
=
xinput_state
.
Gamepad
;
io
.
BackendFlags
|=
ImGuiBackendFlags_HasGamepad
;
#define MAP_BUTTON(NAV_NO, BUTTON_ENUM) { io.NavInputs[NAV_NO] = (gamepad.wButtons & BUTTON_ENUM) ? 1.0f : 0.0f; }
#define MAP_ANALOG(NAV_NO, VALUE, V0, V1) { float vn = (float)(VALUE - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; }
MAP_BUTTON
(
ImGuiNavInput_Activate
,
XINPUT_GAMEPAD_A
);
// Cross / A
MAP_BUTTON
(
ImGuiNavInput_Cancel
,
XINPUT_GAMEPAD_B
);
// Circle / B
MAP_BUTTON
(
ImGuiNavInput_Menu
,
XINPUT_GAMEPAD_X
);
// Square / X
MAP_BUTTON
(
ImGuiNavInput_Input
,
XINPUT_GAMEPAD_Y
);
// Triangle / Y
MAP_BUTTON
(
ImGuiNavInput_DpadLeft
,
XINPUT_GAMEPAD_DPAD_LEFT
);
// D-Pad Left
MAP_BUTTON
(
ImGuiNavInput_DpadRight
,
XINPUT_GAMEPAD_DPAD_RIGHT
);
// D-Pad Right
MAP_BUTTON
(
ImGuiNavInput_DpadUp
,
XINPUT_GAMEPAD_DPAD_UP
);
// D-Pad Up
MAP_BUTTON
(
ImGuiNavInput_DpadDown
,
XINPUT_GAMEPAD_DPAD_DOWN
);
// D-Pad Down
MAP_BUTTON
(
ImGuiNavInput_FocusPrev
,
XINPUT_GAMEPAD_LEFT_SHOULDER
);
// L1 / LB
MAP_BUTTON
(
ImGuiNavInput_FocusNext
,
XINPUT_GAMEPAD_RIGHT_SHOULDER
);
// R1 / RB
MAP_BUTTON
(
ImGuiNavInput_TweakSlow
,
XINPUT_GAMEPAD_LEFT_SHOULDER
);
// L1 / LB
MAP_BUTTON
(
ImGuiNavInput_TweakFast
,
XINPUT_GAMEPAD_RIGHT_SHOULDER
);
// R1 / RB
MAP_ANALOG
(
ImGuiNavInput_LStickLeft
,
gamepad
.
sThumbLX
,
-
XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE
,
-
32768
);
MAP_ANALOG
(
ImGuiNavInput_LStickRight
,
gamepad
.
sThumbLX
,
+
XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE
,
+
32767
);
MAP_ANALOG
(
ImGuiNavInput_LStickUp
,
gamepad
.
sThumbLY
,
+
XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE
,
+
32767
);
MAP_ANALOG
(
ImGuiNavInput_LStickDown
,
gamepad
.
sThumbLY
,
-
XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE
,
-
32767
);
#undef MAP_BUTTON
#undef MAP_ANALOG
}
}
void
ImGui_ImplWin32_NewFrame
()
void
ImGui_ImplWin32_NewFrame
()
{
{
ImGuiIO
&
io
=
ImGui
::
GetIO
();
ImGuiIO
&
io
=
ImGui
::
GetIO
();
...
@@ -229,9 +173,6 @@ void ImGui_ImplWin32_NewFrame()
...
@@ -229,9 +173,6 @@ void ImGui_ImplWin32_NewFrame()
g_LastMouseCursor
=
mouse_cursor
;
g_LastMouseCursor
=
mouse_cursor
;
ImGui_ImplWin32_UpdateMouseCursor
();
ImGui_ImplWin32_UpdateMouseCursor
();
}
}
// Update game controllers (if available)
ImGui_ImplWin32_UpdateGamepads
();
}
}
// Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions.
// Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions.
...
...
hw3d/imgui/imgui_impl_win32.h
View file @
2e168856
...
@@ -8,10 +8,13 @@
...
@@ -8,10 +8,13 @@
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
#pragma once
#pragma once
#include "../ChiliWin.h"
#include "imgui.h"
IMGUI_IMPL_API
bool
ImGui_ImplWin32_Init
(
void
*
hwnd
);
IMGUI_IMPL_API
bool
ImGui_ImplWin32_Init
(
HWND
hwnd
);
IMGUI_IMPL_API
void
ImGui_ImplWin32_Shutdown
();
IMGUI_IMPL_API
void
ImGui_ImplWin32_Shutdown
();
IMGUI_IMPL_API
void
ImGui_ImplWin32_NewFrame
();
IMGUI_IMPL_API
void
ImGui_ImplWin32_NewFrame
();
LRESULT
ImGui_ImplWin32_WndProcHandler
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
);
// Handler for Win32 messages, update mouse/keyboard data.
// Handler for Win32 messages, update mouse/keyboard data.
// You may or not need this for your implementation, but it can serve as reference for handling inputs.
// You may or not need this for your implementation, but it can serve as reference for handling inputs.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment