From 0ba1c93ff4a29bbe5d87eca4671c72d992aadcc2 Mon Sep 17 00:00:00 2001 From: ink-soul Date: Mon, 12 Jun 2023 09:18:05 +0800 Subject: [PATCH] switch ttf file for preparing chinese UI --- base/ui.hpp | 19 ++++++++++++++++++- src/render/render.cpp | 14 +++++++------- src/render/render.h | 12 ++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/base/ui.hpp b/base/ui.hpp index c3dd542..b01d924 100644 --- a/base/ui.hpp +++ b/base/ui.hpp @@ -67,7 +67,7 @@ public: io.Fonts->AddFontFromMemoryTTF(fontAsset, size, 14.0f * scale); delete[] fontAsset; #else - std::string ttfFilePath = getAssetPath() + "/Roboto-Medium.ttf"; + std::string ttfFilePath = getAssetPath() + "/STXINWEI.TTF"; io.Fonts->AddFontFromFileTTF(ttfFilePath.data(), 16.0f); #endif io.Fonts->GetTexDataAsRGBA32(&fontData, &texWidth, &texHeight); @@ -248,7 +248,24 @@ public: vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); vkDestroyDescriptorPool(device, descriptorPool, nullptr); } + std::string string_to_utf8(const std::string& str) + { + int nwLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); + wchar_t* pwBuf = new wchar_t[nwLen + 1]; + memset(pwBuf, 0, nwLen * 2 + 2); + MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen); + int nLen = WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL); + char* pBuf = new char[nLen + 1]; + memset(pBuf, 0, nLen + 1); + WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL); + + std::string ret = pBuf; + delete[]pwBuf; + delete[]pBuf; + + return ret; + } void draw(VkCommandBuffer cmdBuffer) { vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); vkCmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr); diff --git a/src/render/render.cpp b/src/render/render.cpp index 4df1473..dc39d91 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -1680,8 +1680,8 @@ PlumageRender::PlumageRender() gui->text("%.1d fps (%.2f ms)", lastFPS, (1000.0f / lastFPS)); - if (gui->header("Scene")) { - if (gui->button("Open gltf file")) { + if (gui->header("model")) { + if (gui->button(gui->string_to_utf8("open gltf model").c_str())) { std::string filename = ""; char buffer[MAX_PATH]; OPENFILENAME ofn; @@ -1726,11 +1726,11 @@ PlumageRender::PlumageRender() } } - if (gui->header("Debug view")) { + if (gui->header("Debug ")) { const std::vector debugNamesInputs = { "none", "Base color", "Normal", "Occlusion", "Emissive", "Metallic", "Roughness" }; - if (gui->combo("Inputs", &debugViewInputs, debugNamesInputs)) { + if (gui->combo("input", &debugViewInputs, debugNamesInputs)) { shaderData.debugViewInputs = static_cast(debugViewInputs); updateShaderParams = true; } @@ -1744,13 +1744,13 @@ PlumageRender::PlumageRender() } if (models.scene.animations.size() > 0) { - if (gui->header("Animations")) { - gui->checkbox("Animate", &animate); + if (gui->header("animation")) { + gui->checkbox("pause", &animate); std::vector animationNames; for (auto animation : models.scene.animations) { animationNames.push_back(animation.name); } - gui->combo("Animation", &animationIndex, animationNames); + gui->combo("animation", &animationIndex, animationNames); } } diff --git a/src/render/render.h b/src/render/render.h index c471561..ac1c411 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -60,7 +60,19 @@ public: float debugViewInputs = 0; float debugViewEquation = 0; } shaderData; + struct ChinesesUI + { + const char * model = "u8模型"; + const char* openNewModel = "打开gltf模型"; + const char* environmentMap = "环境贴图"; + const char* environment = "环境光照"; + const char* debugInput = "输入"; + const char* debugPBREquation = "PBR计算参数"; + const char* animation = "动画"; + const char* pauseAnimation = "暂停动画"; + const char* animationSeq = "动画序列"; + }chineseUI; struct UniformBufferSet { Buffer scene; Buffer skybox;