Add XCUI new editor sandbox phase 1
This commit is contained in:
60
new_editor/src/XCUIBackend/XCUIEditorFontSetup.cpp
Normal file
60
new_editor/src/XCUIBackend/XCUIEditorFontSetup.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "XCUIBackend/XCUIEditorFontSetup.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace XCUIBackend {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr float kUiFontSize = 18.0f;
|
||||
constexpr const char* kPrimaryUiFontPath = "C:/Windows/Fonts/segoeui.ttf";
|
||||
constexpr const char* kChineseFallbackFontPath = "C:/Windows/Fonts/msyh.ttc";
|
||||
|
||||
} // namespace
|
||||
|
||||
bool BuildDefaultXCUIEditorFontAtlas(::ImFontAtlas& atlas, ::ImFont*& outDefaultFont) {
|
||||
outDefaultFont = nullptr;
|
||||
atlas.Clear();
|
||||
|
||||
ImFontConfig baseConfig = {};
|
||||
baseConfig.OversampleH = 2;
|
||||
baseConfig.OversampleV = 1;
|
||||
baseConfig.PixelSnapH = true;
|
||||
|
||||
outDefaultFont = atlas.AddFontFromFileTTF(
|
||||
kPrimaryUiFontPath,
|
||||
kUiFontSize,
|
||||
&baseConfig,
|
||||
atlas.GetGlyphRangesDefault());
|
||||
|
||||
if (outDefaultFont != nullptr) {
|
||||
ImFontConfig mergeConfig = baseConfig;
|
||||
mergeConfig.MergeMode = true;
|
||||
mergeConfig.PixelSnapH = true;
|
||||
atlas.AddFontFromFileTTF(
|
||||
kChineseFallbackFontPath,
|
||||
kUiFontSize,
|
||||
&mergeConfig,
|
||||
atlas.GetGlyphRangesChineseSimplifiedCommon());
|
||||
} else {
|
||||
outDefaultFont = atlas.AddFontFromFileTTF(
|
||||
kChineseFallbackFontPath,
|
||||
kUiFontSize,
|
||||
&baseConfig,
|
||||
atlas.GetGlyphRangesChineseSimplifiedCommon());
|
||||
}
|
||||
|
||||
if (outDefaultFont == nullptr) {
|
||||
ImFontConfig fallbackConfig = baseConfig;
|
||||
fallbackConfig.SizePixels = kUiFontSize;
|
||||
outDefaultFont = atlas.AddFontDefault(&fallbackConfig);
|
||||
}
|
||||
|
||||
return outDefaultFont != nullptr;
|
||||
}
|
||||
|
||||
} // namespace XCUIBackend
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user