mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Support localization(Simplified Chinese[source-han-sans-regular])
This commit is contained in:
BIN
font/SourceHanSans-Regular.ttf
Normal file
BIN
font/SourceHanSans-Regular.ttf
Normal file
Binary file not shown.
@@ -35,6 +35,8 @@
|
|||||||
#define MOUSE_CONTROL 1
|
#define MOUSE_CONTROL 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CHINESE_FONT 1
|
||||||
|
|
||||||
int screen_w = 1280, screen_h = 720;
|
int screen_w = 1280, screen_h = 720;
|
||||||
int window_w = 1280, window_h = 720;
|
int window_w = 1280, window_h = 720;
|
||||||
const int pixel_w = 1280, pixel_h = 720;
|
const int pixel_w = 1280, pixel_h = 720;
|
||||||
@@ -439,6 +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
|
||||||
|
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
|
||||||
|
#ifdef _WIN32
|
||||||
|
io.Fonts->AddFontFromFileTTF(
|
||||||
|
font_path.c_str(), 20.0f, NULL,
|
||||||
|
io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
|
||||||
|
#elif __APPLE__
|
||||||
|
io.Fonts->AddFontFromFileTTF(
|
||||||
|
"c:/windows/fonts/msyh.ttc", 16.0f, NULL,
|
||||||
|
io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
|
||||||
|
#elif __linux__
|
||||||
|
io.Fonts->AddFontFromFileTTF(
|
||||||
|
"c:/windows/fonts/msyh.ttc", 16.0f, NULL,
|
||||||
|
io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// Setup Dear ImGui style
|
// Setup Dear ImGui style
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
// ImGui::StyleColorsLight();
|
// ImGui::StyleColorsLight();
|
||||||
@@ -577,30 +602,53 @@ 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);
|
||||||
ImGui::SetNextWindowSize(ImVec2(190, 200));
|
|
||||||
|
|
||||||
|
#ifdef CHINESE_FONT
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(190, 250));
|
||||||
|
#else
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(190, 200));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CHINESE_FONT
|
||||||
|
ImGui::Begin(u8"<EFBFBD>˵<EFBFBD>", nullptr, ImGuiWindowFlags_NoResize);
|
||||||
|
#else
|
||||||
ImGui::Begin("Menu", nullptr, ImGuiWindowFlags_NoResize);
|
ImGui::Begin("Menu", nullptr, ImGuiWindowFlags_NoResize);
|
||||||
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
menu_hovered = ImGui::IsWindowHovered();
|
menu_hovered = ImGui::IsWindowHovered();
|
||||||
|
#ifdef CHINESE_FONT
|
||||||
|
ImGui::Text(u8" <20><><EFBFBD><EFBFBD>ID:");
|
||||||
|
#else
|
||||||
ImGui::Text(" LOCAL ID:");
|
ImGui::Text(" LOCAL ID:");
|
||||||
|
#endif
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(95);
|
ImGui::SetNextItemWidth(105);
|
||||||
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
|
||||||
|
ImGui::Text(u8" <20><><EFBFBD><EFBFBD>:");
|
||||||
|
#else
|
||||||
ImGui::Text(" PASSWORD:");
|
ImGui::Text(" PASSWORD:");
|
||||||
|
#endif
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(95);
|
ImGui::SetNextItemWidth(105);
|
||||||
|
|
||||||
char input_password_tmp[7] = "";
|
char input_password_tmp[7] = "";
|
||||||
strncpy(input_password_tmp, input_password, sizeof(input_password));
|
strncpy(input_password_tmp, input_password, sizeof(input_password));
|
||||||
|
|
||||||
|
#ifdef CHINESE_FONT
|
||||||
|
ImGui::InputTextWithHint("##server_pwd", u8"<EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>",
|
||||||
|
input_password, IM_ARRAYSIZE(input_password),
|
||||||
|
ImGuiInputTextFlags_CharsNoBlank);
|
||||||
|
#else
|
||||||
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);
|
||||||
|
#endif
|
||||||
if (strcmp(input_password_tmp, input_password)) {
|
if (strcmp(input_password_tmp, input_password)) {
|
||||||
cd_cache_file = fopen("cache.cd", "w+");
|
cd_cache_file = fopen("cache.cd", "w+");
|
||||||
if (cd_cache_file) {
|
if (cd_cache_file) {
|
||||||
@@ -622,9 +670,13 @@ int main(int argc, char *argv[]) {
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
static char remote_id[20] = "";
|
static char remote_id[20] = "";
|
||||||
|
#ifdef CHINESE_FONT
|
||||||
|
ImGui::Text(u8"Զ<EFBFBD><EFBFBD> ID:");
|
||||||
|
#else
|
||||||
ImGui::Text("REMOTE ID:");
|
ImGui::Text("REMOTE ID:");
|
||||||
|
#endif
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(95);
|
ImGui::SetNextItemWidth(105);
|
||||||
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 |
|
||||||
@@ -632,16 +684,30 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
|
|
||||||
|
#ifdef CHINESE_FONT
|
||||||
|
ImGui::Text(u8" <20><><EFBFBD><EFBFBD>:");
|
||||||
|
#else
|
||||||
ImGui::Text(" PASSWORD:");
|
ImGui::Text(" PASSWORD:");
|
||||||
|
#endif
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetNextItemWidth(95);
|
ImGui::SetNextItemWidth(105);
|
||||||
static char client_password[20] = "";
|
static char client_password[20] = "";
|
||||||
ImGui::InputTextWithHint("##client_pwd", "max 6 chars",
|
#ifdef CHINESE_FONT
|
||||||
|
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
|
||||||
if (ImGui::Button(connect_label)) {
|
ImGui::InputTextWithHint("##client_pwd", u8"<EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>",
|
||||||
|
client_password,
|
||||||
|
IM_ARRAYSIZE(client_password),
|
||||||
|
ImGuiInputTextFlags_CharsNoBlank);
|
||||||
|
#endif
|
||||||
|
#ifdef CHINESE_FONT
|
||||||
|
if (ImGui::Button(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")) {
|
||||||
|
#else
|
||||||
|
if (ImGui::Button("Connect")) {
|
||||||
|
#endif
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if ("ClientSignalConnected" == client_signal_status_str) {
|
if ("ClientSignalConnected" == client_signal_status_str) {
|
||||||
if (strcmp(connect_label, "Connect") == 0 && !joined) {
|
if (strcmp(connect_label, "Connect") == 0 && !joined) {
|
||||||
@@ -677,7 +743,11 @@ int main(int argc, char *argv[]) {
|
|||||||
ImGui::Spacing();
|
ImGui::Spacing();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
#ifdef CHINESE_FONT
|
||||||
|
if (ImGui::Button(u8"<EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD>")) {
|
||||||
|
#else
|
||||||
if (ImGui::Button("Resize Window")) {
|
if (ImGui::Button("Resize Window")) {
|
||||||
|
#endif
|
||||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||||
|
|
||||||
if (window_h != window_w * 9 / 16) {
|
if (window_h != window_w * 9 / 16) {
|
||||||
|
|||||||
Reference in New Issue
Block a user