1.Use Windows font file 'simhei.ttf'; 2.Add test button for fullscreen

This commit is contained in:
dijunkun
2024-05-27 17:06:09 +08:00
parent f1512812ad
commit 905539a6eb
2 changed files with 73 additions and 45 deletions

Binary file not shown.

View File

@@ -441,32 +441,29 @@ int main(int argc, char *argv[]) {
io.ConfigFlags |= io.ConfigFlags |=
ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
#ifdef CHINESE_FONT #if CHINESE_FONT
std::string default_font_path = "../../../../font/SourceHanSans-Regular.ttf";
std::ifstream font_path_f(default_font_path.c_str());
std::string font_path = font_path_f.good()
? "../../../../font/SourceHanSans-Regular.ttf"
: "SourceHanSans-Regular.ttf";
// Load Fonts // Load Fonts
#ifdef _WIN32 #ifdef _WIN32
io.Fonts->AddFontFromFileTTF( std::string default_font_path = "c:/windows/fonts/simhei.ttf";
font_path.c_str(), 20.0f, NULL, std::ifstream font_path_f(default_font_path.c_str());
io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); std::string font_path =
font_path_f.good() ? "c:/windows/fonts/simhei.ttf" : "";
if (!font_path.empty()) {
io.Fonts->AddFontFromFileTTF(font_path.c_str(), 13.0f, NULL,
io.Fonts->GetGlyphRangesChineseFull());
}
#elif __APPLE__ #elif __APPLE__
io.Fonts->AddFontFromFileTTF( io.Fonts->AddFontFromFileTTF("c:/windows/fonts/msyh.ttc", 13.0f, NULL,
"c:/windows/fonts/msyh.ttc", 16.0f, NULL, io.Fonts->GetGlyphRangesChineseFull());
io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
#elif __linux__ #elif __linux__
io.Fonts->AddFontFromFileTTF( io.Fonts->AddFontFromFileTTF("c:/windows/fonts/msyh.ttc", 13.0f, NULL,
"c:/windows/fonts/msyh.ttc", 16.0f, NULL, io.Fonts->GetGlyphRangesChineseFull());
io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
#endif #endif
#endif #endif
// Setup Dear ImGui style // Setup Dear ImGui style
ImGui::StyleColorsDark(); // ImGui::StyleColorsDark();
// ImGui::StyleColorsLight(); ImGui::StyleColorsLight();
// Setup Platform/Renderer backends // Setup Platform/Renderer backends
ImGui_ImplSDL2_InitForSDLRenderer(window, sdlRenderer); ImGui_ImplSDL2_InitForSDLRenderer(window, sdlRenderer);
@@ -603,48 +600,58 @@ int main(int argc, char *argv[]) {
const ImGuiViewport *main_viewport = ImGui::GetMainViewport(); const ImGuiViewport *main_viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Once); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Once);
#ifdef CHINESE_FONT // ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
ImGui::SetNextWindowSize(ImVec2(190, 250));
#if CHINESE_FONT
ImGui::SetNextWindowSize(ImVec2(160, 210));
#else #else
ImGui::SetNextWindowSize(ImVec2(190, 200)); ImGui::SetNextWindowSize(ImVec2(180, 210));
#endif #endif
#ifdef CHINESE_FONT #if CHINESE_FONT
ImGui::Begin(u8"<EFBFBD>˵<EFBFBD>", nullptr, ImGuiWindowFlags_NoResize); ImGui::Begin(u8"<EFBFBD>˵<EFBFBD>", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove);
#else #else
ImGui::Begin("Menu", nullptr, ImGuiWindowFlags_NoResize); ImGui::Begin("Menu", nullptr, ImGuiWindowFlags_NoResize);
#endif #endif
{ {
menu_hovered = ImGui::IsWindowHovered(); menu_hovered = ImGui::IsWindowHovered();
#ifdef CHINESE_FONT #if CHINESE_FONT
ImGui::Text(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID:"); ImGui::Text(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID:");
#else #else
ImGui::Text("LOCAL ID:"); ImGui::Text("LOCAL ID:");
#endif #endif
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetNextItemWidth(105); ImGui::SetNextItemWidth(90);
#if CHINESE_FONT
ImGui::SetCursorPosX(60.0f);
#else
ImGui::SetCursorPosX(80.0f);
#endif
ImGui::InputText( ImGui::InputText(
"##local_id", (char *)mac_addr_str.c_str(), "##local_id", (char *)mac_addr_str.c_str(),
mac_addr_str.length() + 1, mac_addr_str.length() + 1,
ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_ReadOnly); ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_ReadOnly);
#ifdef CHINESE_FONT #if CHINESE_FONT
ImGui::Text(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"); ImGui::Text(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
#else #else
ImGui::Text("PASSWORD:"); ImGui::Text("PASSWORD:");
#endif #endif
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetNextItemWidth(105);
char input_password_tmp[7] = ""; char input_password_tmp[7] = "";
std::string input_password_str = "123456";
strncpy(input_password_tmp, input_password, sizeof(input_password)); strncpy(input_password_tmp, input_password, sizeof(input_password));
ImGui::SetNextItemWidth(90);
#ifdef CHINESE_FONT #if CHINESE_FONT
ImGui::SetCursorPosX(60.0f);
ImGui::InputTextWithHint("##server_pwd", u8"<EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>", ImGui::InputTextWithHint("##server_pwd", u8"<EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>",
input_password, IM_ARRAYSIZE(input_password), input_password, IM_ARRAYSIZE(input_password),
ImGuiInputTextFlags_CharsNoBlank); ImGuiInputTextFlags_CharsNoBlank);
#else #else
ImGui::SetCursorPosX(80.0f);
ImGui::InputTextWithHint("##server_pwd", "max 6 chars", input_password, ImGui::InputTextWithHint("##server_pwd", "max 6 chars", input_password,
IM_ARRAYSIZE(input_password), IM_ARRAYSIZE(input_password),
ImGuiInputTextFlags_CharsNoBlank); ImGuiInputTextFlags_CharsNoBlank);
@@ -670,13 +677,18 @@ int main(int argc, char *argv[]) {
{ {
{ {
static char remote_id[20] = ""; static char remote_id[20] = "";
#ifdef CHINESE_FONT #if CHINESE_FONT
ImGui::Text(u8"Զ<EFBFBD><EFBFBD>ID:"); ImGui::Text(u8"Զ<EFBFBD><EFBFBD>ID:");
#else #else
ImGui::Text("REMOTE ID:"); ImGui::Text("REMOTE ID:");
#endif #endif
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetNextItemWidth(105); ImGui::SetNextItemWidth(90);
#if CHINESE_FONT
ImGui::SetCursorPosX(60.0f);
#else
ImGui::SetCursorPosX(80.0f);
#endif
ImGui::InputTextWithHint("##remote_id", mac_addr_str.c_str(), ImGui::InputTextWithHint("##remote_id", mac_addr_str.c_str(),
remote_id, IM_ARRAYSIZE(remote_id), remote_id, IM_ARRAYSIZE(remote_id),
ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsUppercase |
@@ -684,26 +696,32 @@ int main(int argc, char *argv[]) {
ImGui::Spacing(); ImGui::Spacing();
#ifdef CHINESE_FONT #if CHINESE_FONT
ImGui::Text(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"); ImGui::Text(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
#else #else
ImGui::Text("PASSWORD:"); ImGui::Text("PASSWORD:");
#endif #endif
ImGui::SameLine(); ImGui::SameLine();
ImGui::SetNextItemWidth(105); ImGui::SetNextItemWidth(90);
static char client_password[20] = ""; static char client_password[20] = "";
#ifdef CHINESE_FONT #if CHINESE_FONT
ImGui::SetCursorPosX(60.0f);
ImGui::InputTextWithHint("##client_pwd", u8"<EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>", ImGui::InputTextWithHint("##client_pwd", u8"<EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>",
client_password, client_password,
IM_ARRAYSIZE(client_password), IM_ARRAYSIZE(client_password),
ImGuiInputTextFlags_CharsNoBlank); ImGuiInputTextFlags_CharsNoBlank);
#else #else
ImGui::InputTextWithHint("##client_pwd", u8"<EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>", ImGui::SetCursorPosX(80.0f);
ImGui::InputTextWithHint("##client_pwd", "max 6 chars",
client_password, client_password,
IM_ARRAYSIZE(client_password), IM_ARRAYSIZE(client_password),
ImGuiInputTextFlags_CharsNoBlank); ImGuiInputTextFlags_CharsNoBlank);
#endif #endif
#ifdef CHINESE_FONT
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
#if CHINESE_FONT
if (ImGui::Button(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) { if (ImGui::Button(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) {
#else #else
if (ImGui::Button("Connect")) { if (ImGui::Button("Connect")) {
@@ -743,7 +761,7 @@ int main(int argc, char *argv[]) {
ImGui::Spacing(); ImGui::Spacing();
{ {
#ifdef CHINESE_FONT #if CHINESE_FONT
if (ImGui::Button(u8"<EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD>")) { if (ImGui::Button(u8"<EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD>")) {
#else #else
if (ImGui::Button("Resize Window")) { if (ImGui::Button("Resize Window")) {
@@ -758,6 +776,16 @@ int main(int argc, char *argv[]) {
} }
} }
ImGui::SameLine();
#if CHINESE_FONT
if (ImGui::Button(u8"ȫ<EFBFBD><EFBFBD>")) {
#else
if (ImGui::Button("FULLSCREEN")) {
#endif
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
}
ImGui::End(); ImGui::End();
} }