新增configure_imgui(ImGuiIO&)

This commit is contained in:
Nanako 2024-06-08 21:29:20 +08:00
parent a2a9e48476
commit 1c4d196dd8
4 changed files with 55 additions and 9 deletions

View File

@ -11,7 +11,43 @@ std::string get_window_title() {
return "Arona";
}
void configure_imgui(ImGuiIO& io) {
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
io.ConfigViewportsNoAutoMerge = true;
// io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // Enable DPI scaling
// io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // Enable DPI scaling
// Setup Dear ImGui style
ImGui::StyleColorsClassic();
ImGuiStyle* style = &ImGui::GetStyle();
style->TabRounding = 0;
// ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Load Fonts
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
// - Read 'docs/FONTS.md' for more instructions and details.
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
//io.Fonts->AddFontDefault();
io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 24.0f);
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != nullptr);
}
void draw_imgui(float delta_time) {
// 全局dockspace
ImGui::DockSpaceOverViewport();
ImGui::Begin("Arona");
if (ImGui::Button("Test")) {
get_arona_application()->test();

@ -1 +1 @@
Subproject commit 6f7b5d0ee2fe9948ab871a530888a6dc5c960700
Subproject commit 6d948ab47ecf984239af01434f3ed03808dbf188

View File

@ -1,20 +1,26 @@
#pragma once
#include <string>
#include "imgui.h"
extern int init_imgui();
extern void configure_imgui(ImGuiIO& io);
extern bool imgui_new_frame();
extern void draw_imgui();
extern void draw_imgui(float delta_time);
extern void render_imgui();
extern void shutdown_imgui();
extern void tick_imgui(float delta_time);
inline void run_imgui() {
init_imgui();
while (true) {
if (!imgui_new_frame()) {
break;
}
draw_imgui();
ImGuiIO& io = ImGui::GetIO();
tick_imgui(io.DeltaTime);
draw_imgui(io.DeltaTime);
render_imgui();
}
shutdown_imgui();

View File

@ -49,12 +49,8 @@ int init_imgui() {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
configure_imgui(io);
// Setup Platform/Renderer backends
ImGui_ImplWin32_Init(hwnd);
@ -78,7 +74,7 @@ bool imgui_new_frame() {
return false;
// Handle window being minimized or screen locked
if (g_SwapChainOccluded && g_pSwapChain->Present(0, DXGI_PRESENT_TEST) == DXGI_STATUS_OCCLUDED)
if (g_SwapChainOccluded && g_pSwapChain->Present(1, DXGI_PRESENT_TEST) == DXGI_STATUS_OCCLUDED)
{
::Sleep(10);
return true;
@ -104,12 +100,20 @@ bool imgui_new_frame() {
void render_imgui() {
// Rendering
ImGui::Render();
ImGuiIO& io = ImGui::GetIO();
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
const float clear_color_with_alpha[4] = { clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w };
g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, nullptr);
g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, clear_color_with_alpha);
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
// Update and Render additional Platform Windows
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
// Present
HRESULT hr = g_pSwapChain->Present(1, 0); // Present with vsync
//HRESULT hr = g_pSwapChain->Present(0, 0); // Present without vsync