add font msyh.ttc && Basic main panel for UI widgets
This commit is contained in:
parent
d7a3083816
commit
75eb1fc143
@ -1,5 +1,7 @@
|
|||||||
#ifndef __CONFIG_HPP__
|
#ifndef __CONFIG_HPP__
|
||||||
#define __CONFIG_HPP__
|
#define __CONFIG_HPP__
|
||||||
|
|
||||||
|
// 主窗体标题
|
||||||
|
#define MAIN_FRAME_TITTLE L"DLT Splitter —— Dev by : LuChiChick"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
9
Inc/UI_Layout.hpp
Normal file
9
Inc/UI_Layout.hpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef __UI_LAYOUT__
|
||||||
|
#define __UI_LAYOUT__
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
|
// UI布局
|
||||||
|
void UI_Layout();
|
||||||
|
|
||||||
|
#endif
|
||||||
113
Src/Main.cpp
113
Src/Main.cpp
@ -9,10 +9,12 @@ extern "C"
|
|||||||
#include "d3d11.h"
|
#include "d3d11.h"
|
||||||
#include "tchar.h"
|
#include "tchar.h"
|
||||||
#include "wchar.h"
|
#include "wchar.h"
|
||||||
|
}
|
||||||
|
|
||||||
// 自定义头文件
|
// 自定义头文件
|
||||||
#include "Global_Variables.hpp"
|
#include "Config.hpp" // 配置文件
|
||||||
}
|
#include "Global_Variables.hpp" // 全局变量相关
|
||||||
|
#include "UI_Layout.hpp" // UI布局相关
|
||||||
|
|
||||||
// 辅助函数声明
|
// 辅助函数声明
|
||||||
bool CreateDeviceD3D(HWND hWnd); // 创建 Direct 3D 设备
|
bool CreateDeviceD3D(HWND hWnd); // 创建 Direct 3D 设备
|
||||||
@ -52,17 +54,17 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
RegisterClassExW(&wc);
|
RegisterClassExW(&wc);
|
||||||
|
|
||||||
// 创建窗体
|
// 创建窗体
|
||||||
HWND hwnd = CreateWindowW(wc.lpszClassName, // 创建的窗体类名
|
HWND hwnd = CreateWindowW(wc.lpszClassName, // 创建的窗体类名
|
||||||
L"DLT Splitter —— Dev by: LuChiChick", // 窗体标题
|
MAIN_FRAME_TITTLE, // 窗体标题
|
||||||
WS_OVERLAPPEDWINDOW, // 窗体风格为标准可重叠的顶层窗口
|
WS_OVERLAPPEDWINDOW, // 窗体风格为标准可重叠的顶层窗口
|
||||||
100, // 起始坐标x
|
100, // 起始坐标x
|
||||||
100, // 起始坐标y
|
100, // 起始坐标y
|
||||||
(int)(1280 * main_scale), // 窗体长
|
(int)(1280 * main_scale), // 窗体长
|
||||||
(int)(720 * main_scale), // 窗体宽
|
(int)(720 * main_scale), // 窗体宽
|
||||||
nullptr, // 父窗体句柄
|
nullptr, // 父窗体句柄
|
||||||
nullptr, // 菜单句柄
|
nullptr, // 菜单句柄
|
||||||
wc.hInstance, // 创建实例句柄
|
wc.hInstance, // 创建实例句柄
|
||||||
nullptr); // 额外的事件参数指针
|
nullptr); // 额外的事件参数指针
|
||||||
|
|
||||||
// 在窗体内创建 Direct 3D 设备
|
// 在窗体内创建 Direct 3D 设备
|
||||||
if (!CreateDeviceD3D(hwnd))
|
if (!CreateDeviceD3D(hwnd))
|
||||||
@ -138,12 +140,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
// io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf");
|
// io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf");
|
||||||
// ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf");
|
// ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf");
|
||||||
// IM_ASSERT(font != nullptr);
|
// IM_ASSERT(font != nullptr);
|
||||||
}
|
|
||||||
|
|
||||||
// Our state
|
// 加载字体为微软雅黑
|
||||||
bool show_demo_window = true;
|
io.Fonts->AddFontFromFileTTF("c:/windows/Fonts/msyh.ttc", 15.0f * main_scale, NULL, io.Fonts->GetGlyphRangesChineseFull());
|
||||||
bool show_another_window = false;
|
}
|
||||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
|
||||||
|
|
||||||
// 主事件循环
|
// 主事件循环
|
||||||
bool done = false;
|
bool done = false;
|
||||||
@ -176,61 +176,44 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
ImGui_ImplWin32_NewFrame();
|
ImGui_ImplWin32_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 此处进行UI布局
|
||||||
if (show_demo_window)
|
UI_Layout();
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
|
||||||
|
|
||||||
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
|
// 渲染部分
|
||||||
{
|
{
|
||||||
static float f = 0.0f;
|
// 调用 ImGui 渲染器进行预渲染
|
||||||
static int counter = 0;
|
ImGui::Render();
|
||||||
|
|
||||||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
// 设置D3D渲染目标
|
||||||
|
g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, nullptr);
|
||||||
|
|
||||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
// 创建一个带透明度通道的RGB色
|
||||||
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
ImGui::Checkbox("Another Window", &show_another_window);
|
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};
|
||||||
|
// 使用创建的RGB色擦除D3D渲染画布
|
||||||
|
g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, clear_color_with_alpha);
|
||||||
|
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
// 渲染 ImGui 原始画面
|
||||||
ImGui::ColorEdit3("clear color", (float *)&clear_color); // Edit 3 floats representing a color
|
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
// 启用脱离窗口渲染时更新主窗体外的部分
|
||||||
counter++;
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
ImGui::SameLine();
|
{
|
||||||
ImGui::Text("counter = %d", counter);
|
ImGui::UpdatePlatformWindows();
|
||||||
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
// 呈现当前帧到画布
|
||||||
ImGui::End();
|
// HRESULT hr = g_pSwapChain->Present(0, 0); // 非垂直同步
|
||||||
|
HRESULT hr = g_pSwapChain->Present(1, 0); // 垂直同步
|
||||||
|
// HRESULT hr = g_pSwapChain->Present(2, 0); // 等待双倍的垂直同步时间
|
||||||
|
|
||||||
|
// 更新交换链阻塞状态
|
||||||
|
g_SwapChainOccluded = (hr == DXGI_STATUS_OCCLUDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Show another simple window.
|
|
||||||
if (show_another_window)
|
|
||||||
{
|
|
||||||
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
|
|
||||||
ImGui::Text("Hello from another window!");
|
|
||||||
if (ImGui::Button("Close Me"))
|
|
||||||
show_another_window = false;
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rendering
|
|
||||||
ImGui::Render();
|
|
||||||
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
|
|
||||||
g_SwapChainOccluded = (hr == DXGI_STATUS_OCCLUDED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收尾清理工作
|
// 收尾清理工作
|
||||||
|
|||||||
35
Src/UI_Layout.cpp
Normal file
35
Src/UI_Layout.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "UI_Layout.hpp"
|
||||||
|
|
||||||
|
// UI布局
|
||||||
|
void UI_Layout()
|
||||||
|
{
|
||||||
|
// 配置窗口绘制位置为Dear ImGUI生成的主窗口
|
||||||
|
const ImGuiViewport *viewport = ImGui::GetMainViewport();
|
||||||
|
// 下一个窗体绘制到主窗体位置
|
||||||
|
ImGui::SetNextWindowPos(viewport->WorkPos);
|
||||||
|
// 下一个窗体绘制为主窗体大小
|
||||||
|
ImGui::SetNextWindowSize(viewport->WorkSize);
|
||||||
|
// 设置下一个焦点窗体为主窗体
|
||||||
|
ImGui::SetNextWindowViewport(viewport->ID);
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); // 绘制风格栈压入窗口圆角为0
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); // 绘制风格栈压入窗体边框宽度为0
|
||||||
|
|
||||||
|
// 窗体选项配置
|
||||||
|
ImGuiWindowFlags window_flags = ImGuiWindowFlags_None;
|
||||||
|
// 设置窗体相关属性,无标题栏,无折叠标志,不可重塑大小,不可移动
|
||||||
|
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
|
||||||
|
// 设置窗体相关属性,收到焦点时不移动到前台,禁用焦点事件
|
||||||
|
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
|
||||||
|
// 设置窗体相关属性,不允许停靠
|
||||||
|
window_flags |= ImGuiWindowFlags_NoDocking;
|
||||||
|
|
||||||
|
ImGui::Begin("Main Panel", NULL, window_flags);
|
||||||
|
{
|
||||||
|
// 退出绘制风格栈中的设置项
|
||||||
|
ImGui::PopStyleVar(2);
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
ImGui::ShowDemoWindow(nullptr);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user