diff --git a/src/gui/assets/layouts/layout_relative.h b/src/gui/assets/layouts/layout_relative.h new file mode 100644 index 0000000..46cdab2 --- /dev/null +++ b/src/gui/assets/layouts/layout_relative.h @@ -0,0 +1,90 @@ +/* + * @Author: DI JUNKUN + * @Date: 2024-06-14 + * Copyright (c) 2024 by DI JUNKUN, All Rights Reserved. + */ + +#ifndef _LAYOUT_STYLE_H_ +#define _LAYOUT_STYLE_H_ + +#include "render.h" + +#define TITLE_BAR_HEIGHT 0.0625f +#define TITLE_BAR_BUTTON_WIDTH 0.0625f +#define TITLE_BAR_BUTTON_HEIGHT 0.0625f +#define MENU_WINDOW_WIDTH_CN 300 +#define MENU_WINDOW_HEIGHT_CN 280 +#define LOCAL_WINDOW_WIDTH_CN 300 +#define LOCAL_WINDOW_HEIGHT_CN 280 +#define REMOTE_WINDOW_WIDTH_CN 300 +#define REMOTE_WINDOW_HEIGHT_CN 280 +#define MENU_WINDOW_WIDTH_EN 190 +#define MENU_WINDOW_HEIGHT_EN 245 +#define IPUT_WINDOW_WIDTH 160 +#define INPUT_WINDOW_PADDING_CN 66 +#define INPUT_WINDOW_PADDING_EN 96 +#define SETTINGS_WINDOW_WIDTH_CN 202 +#define SETTINGS_WINDOW_WIDTH_EN 248 +#if USE_CUDA +#if _WIN32 +#define SETTINGS_WINDOW_HEIGHT_CN 405 +#define SETTINGS_WINDOW_HEIGHT_EN 405 +#else +#define SETTINGS_WINDOW_HEIGHT_CN 375 +#define SETTINGS_WINDOW_HEIGHT_EN 375 +#endif +#else +#if _WIN32 +#define SETTINGS_WINDOW_HEIGHT_CN 375 +#define SETTINGS_WINDOW_HEIGHT_EN 375 +#else +#define SETTINGS_WINDOW_HEIGHT_CN 345 +#define SETTINGS_WINDOW_HEIGHT_EN 345 +#endif +#endif +#define SELF_HOSTED_SERVER_CONFIG_WINDOW_WIDTH_CN 228 +#define SELF_HOSTED_SERVER_CONFIG_WINDOW_WIDTH_EN 275 +#define SELF_HOSTED_SERVER_CONFIG_WINDOW_HEIGHT_CN 195 +#define SELF_HOSTED_SERVER_CONFIG_WINDOW_HEIGHT_EN 195 +#define LANGUAGE_SELECT_WINDOW_PADDING_CN 120 +#define LANGUAGE_SELECT_WINDOW_PADDING_EN 167 +#define VIDEO_QUALITY_SELECT_WINDOW_PADDING_CN 120 +#define VIDEO_QUALITY_SELECT_WINDOW_PADDING_EN 167 +#define VIDEO_FRAME_RATE_SELECT_WINDOW_PADDING_CN 120 +#define VIDEO_FRAME_RATE_SELECT_WINDOW_PADDING_EN 167 +#define VIDEO_ENCODE_FORMAT_SELECT_WINDOW_PADDING_CN 120 +#define VIDEO_ENCODE_FORMAT_SELECT_WINDOW_PADDING_EN 167 +#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_CN 171 +#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_EN 218 +#define ENABLE_TURN_CHECKBOX_PADDING_CN 171 +#define ENABLE_TURN_CHECKBOX_PADDING_EN 218 +#define ENABLE_SRTP_CHECKBOX_PADDING_CN 171 +#define ENABLE_SRTP_CHECKBOX_PADDING_EN 218 +#define ENABLE_SELF_HOSTED_SERVER_CHECKBOX_PADDING_CN 171 +#define ENABLE_SELF_HOSTED_SERVER_CHECKBOX_PADDING_EN 218 +#define ENABLE_AUTOSTART_PADDING_CN 171 +#define ENABLE_AUTOSTART_PADDING_EN 218 +#define ENABLE_DAEMON_PADDING_CN 171 +#define ENABLE_DAEMON_PADDING_EN 218 +#define ENABLE_MINIZE_TO_TRAY_PADDING_CN 171 +#define ENABLE_MINIZE_TO_TRAY_PADDING_EN 218 +#define SELF_HOSTED_SERVER_HOST_INPUT_BOX_PADDING_CN 90 +#define SELF_HOSTED_SERVER_HOST_INPUT_BOX_PADDING_EN 137 +#define SELF_HOSTED_SERVER_PORT_INPUT_BOX_PADDING_CN 90 +#define SELF_HOSTED_SERVER_PORT_INPUT_BOX_PADDING_EN 137 +#define SETTINGS_SELECT_WINDOW_WIDTH 73 +#define SELF_HOSTED_SERVER_INPUT_WINDOW_WIDTH 130 +#define SETTINGS_OK_BUTTON_PADDING_CN 65 +#define SETTINGS_OK_BUTTON_PADDING_EN 83 +#define SELF_HOSTED_SERVER_CONFIG_OK_BUTTON_PADDING_CN 78 +#define SELF_HOSTED_SERVER_CONFIG_OK_BUTTON_PADDING_EN 91 +#define UPDATE_NOTIFICATION_OK_BUTTON_PADDING_CN 162 +#define UPDATE_NOTIFICATION_OK_BUTTON_PADDING_EN 146 +#define UPDATE_NOTIFICATION_RESERVED_HEIGHT 120 +#define REQUEST_PERMISSION_WINDOW_WIDTH_CN 130 +#define REQUEST_PERMISSION_WINDOW_HEIGHT_CN 125 +#define REQUEST_PERMISSION_WINDOW_WIDTH_EN 260 +#define REQUEST_PERMISSION_WINDOW_HEIGHT_EN 125 +#define REQUEST_PERMISSION_WINDOW_CHECKBOX_PADDING_CN 90 +#define REQUEST_PERMISSION_WINDOW_CHECKBOX_PADDING_EN 210 +#endif \ No newline at end of file diff --git a/src/gui/render.cpp b/src/gui/render.cpp index d549c27..63d5c44 100644 --- a/src/gui/render.cpp +++ b/src/gui/render.cpp @@ -661,21 +661,28 @@ int Render::CreateMainWindow() { ImGui::SetCurrentContext(main_ctx_); - dpi_scale_ = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()); - LOG_INFO("System DPI scale before window creation: [{}]", dpi_scale_); - - UpdateWindowSizeWithDpiScale(dpi_scale_); - if (!SDL_CreateWindowAndRenderer( "Remote Desk", (int)main_window_width_, (int)main_window_height_, SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN, &main_window_, &main_renderer_)) { - LOG_ERROR("Error creating main_window_ and main_renderer_: {}", - SDL_GetError()); + LOG_ERROR("Error creating MainWindow and MainRenderer: {}", SDL_GetError()); return -1; } + float dpi_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()); + if (std::abs(dpi_scale_ - dpi_scale) > 0.01f) { + dpi_scale_ = dpi_scale; + + main_window_width_ = (int)(main_window_width_ * dpi_scale_); + main_window_height_ = (int)(main_window_height_ * dpi_scale_); + stream_window_width_ = (int)(stream_window_width_ * dpi_scale_); + stream_window_height_ = (int)(stream_window_height_ * dpi_scale_); + + SDL_SetWindowSize(main_window_, (int)main_window_width_, + (int)main_window_height_); + } + SDL_SetWindowResizable(main_window_, false); // for window region action @@ -752,8 +759,6 @@ int Render::CreateStreamWindow() { SetupFontAndStyle(false); - SDL_SetRenderScale(stream_renderer_, dpi_scale_, dpi_scale_); - ImGui_ImplSDL3_InitForSDLRenderer(stream_window_, stream_renderer_); ImGui_ImplSDLRenderer3_Init(stream_renderer_); @@ -913,9 +918,10 @@ int Render::DrawMainWindow() { ImGui_ImplSDL3_NewFrame(); ImGui::NewFrame(); + ImGuiIO& io = ImGui::GetIO(); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); - ImGui::SetNextWindowSize(ImVec2(main_window_width_, main_window_height_), + ImGui::SetNextWindowSize(ImVec2(io.DisplaySize.x, io.DisplaySize.y), ImGuiCond_Always); ImGui::Begin("MainRender", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | @@ -938,7 +944,6 @@ int Render::DrawMainWindow() { ImGui::End(); // Rendering - ImGuiIO& io = ImGui::GetIO(); (void)io; ImGui::Render(); SDL_SetRenderScale(main_renderer_, io.DisplayFramebufferScale.x, diff --git a/src/gui/toolbars/title_bar.cpp b/src/gui/toolbars/title_bar.cpp index d394787..99a1400 100644 --- a/src/gui/toolbars/title_bar.cpp +++ b/src/gui/toolbars/title_bar.cpp @@ -1,109 +1,81 @@ +#include "layout_relative.h" #include "localization.h" #include "rd_log.h" #include "render.h" -#define BUTTON_PADDING 36.0f * dpi_scale_ #define NEW_VERSION_ICON_RENDER_TIME_INTERVAL 2000 namespace crossdesk { int Render::TitleBar(bool main_window) { - ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(1.0f, 1.0f, 1.0f, 0.0f)); - ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); - ImGui::BeginChild( - main_window ? "MainTitleBar" : "StreamTitleBar", - ImVec2(main_window ? main_window_width_ : stream_window_width_, - title_bar_height_), - ImGuiChildFlags_Border, - ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration | - ImGuiWindowFlags_NoBringToFrontOnFocus); + ImGuiIO& io = ImGui::GetIO(); + float title_bar_width = io.DisplaySize.x; + float title_bar_height = io.DisplaySize.y * TITLE_BAR_HEIGHT; + float title_bar_button_width = io.DisplaySize.x * TITLE_BAR_BUTTON_WIDTH; + float title_bar_button_height = io.DisplaySize.y * TITLE_BAR_BUTTON_HEIGHT; + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); + ImGui::BeginChild(main_window ? "MainTitleBar" : "StreamTitleBar", + ImVec2(title_bar_width, title_bar_height), + ImGuiChildFlags_Border, + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoBringToFrontOnFocus); + ImGui::PopStyleVar(); ImGui::PopStyleColor(); + // get draw list ImDrawList* draw_list = ImGui::GetWindowDrawList(); - if (ImGui::BeginMenuBar()) { - ImGui::SetWindowFontScale(0.8f); - ImGui::SetCursorPosX( - (main_window ? main_window_width_ : stream_window_width_) - - (BUTTON_PADDING * 3 - 3.0f * dpi_scale_)); - ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0, 0, 0, 0.1f)); - ImGui::PushStyleColor(ImGuiCol_HeaderActive, + + ImGui::SetCursorPos( + ImVec2(title_bar_width - title_bar_button_width * 3, 0.0f)); + if (main_window) { + float bar_pos_x = title_bar_width - title_bar_button_width * 3 + + title_bar_button_width * 0.33f; + float bar_pos_y = title_bar_button_height * 0.5f; + + // draw menu icon + float menu_bar_line_size = title_bar_button_width * 0.33f; + draw_list->AddLine( + ImVec2(bar_pos_x, bar_pos_y - title_bar_button_height * 0.15f), + ImVec2(bar_pos_x + menu_bar_line_size, + bar_pos_y - title_bar_button_height * 0.15f), + IM_COL32(0, 0, 0, 255)); + draw_list->AddLine(ImVec2(bar_pos_x, bar_pos_y), + ImVec2(bar_pos_x + menu_bar_line_size, bar_pos_y), + IM_COL32(0, 0, 0, 255)); + draw_list->AddLine( + ImVec2(bar_pos_x, bar_pos_y + title_bar_button_height * 0.15f), + ImVec2(bar_pos_x + menu_bar_line_size, + bar_pos_y + title_bar_button_height * 0.15f), + IM_COL32(0, 0, 0, 255)); + + std::string title_bar_menu_button = "##title_bar_menu"; // ICON_FA_BARS; + std::string title_bar_menu = "##title_bar_menu"; + + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0.1f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - if (main_window) { - float bar_pos_x = ImGui::GetCursorPosX() + 6 * dpi_scale_; - float bar_pos_y = ImGui::GetCursorPosY() + 15 * dpi_scale_; - std::string menu_button = " "; // ICON_FA_BARS; - if (ImGui::BeginMenu(menu_button.c_str())) { - ImGui::SetWindowFontScale(0.6f); - if (ImGui::MenuItem( - localization::settings[localization_language_index_].c_str())) { - show_settings_window_ = true; - } + if (ImGui::Button( + title_bar_menu_button.c_str(), + ImVec2(title_bar_button_width, title_bar_button_height))) { + ImGui::OpenPopup(title_bar_menu.c_str()); + } + ImGui::PopStyleColor(3); - show_new_version_icon_in_menu_ = false; - - std::string about_str = - localization::about[localization_language_index_]; - if (update_available_) { - auto now_time = - std::chrono::duration_cast( - std::chrono::steady_clock::now().time_since_epoch()) - .count(); - - // every 2 seconds - if (now_time - new_version_icon_last_trigger_time_ >= - NEW_VERSION_ICON_RENDER_TIME_INTERVAL) { - show_new_version_icon_ = true; - new_version_icon_render_start_time_ = now_time; - new_version_icon_last_trigger_time_ = now_time; - } - - // render for 1 second - if (show_new_version_icon_) { - about_str = about_str + " " + ICON_FA_TRIANGLE_EXCLAMATION; - if (now_time - new_version_icon_render_start_time_ >= - NEW_VERSION_ICON_RENDER_TIME_INTERVAL / 2) { - show_new_version_icon_ = false; - } - } else { - about_str = about_str + " "; - } - } - - if (ImGui::MenuItem(about_str.c_str())) { - show_about_window_ = true; - } - - if (update_available_ && ImGui::IsItemHovered()) { - ImGui::BeginTooltip(); - ImGui::SetWindowFontScale(0.5f * dpi_scale_); - std::string new_version_available_str = - localization::new_version_available - [localization_language_index_] + - ": " + latest_version_; - ImGui::Text("%s", new_version_available_str.c_str()); - ImGui::SetWindowFontScale(1.0f); - ImGui::EndTooltip(); - } - - ImGui::EndMenu(); - } else { - show_new_version_icon_in_menu_ = true; + if (ImGui::BeginPopup(title_bar_menu.c_str())) { + ImGui::SetWindowFontScale(0.6f); + if (ImGui::MenuItem( + localization::settings[localization_language_index_].c_str())) { + show_settings_window_ = true; } - float menu_bar_line_size = 15.0f * dpi_scale_; - draw_list->AddLine(ImVec2(bar_pos_x, bar_pos_y - 6), - ImVec2(bar_pos_x + menu_bar_line_size, bar_pos_y - 6), - IM_COL32(0, 0, 0, 255)); - draw_list->AddLine(ImVec2(bar_pos_x, bar_pos_y), - ImVec2(bar_pos_x + menu_bar_line_size, bar_pos_y), - IM_COL32(0, 0, 0, 255)); - draw_list->AddLine(ImVec2(bar_pos_x, bar_pos_y + 6), - ImVec2(bar_pos_x + menu_bar_line_size, bar_pos_y + 6), - IM_COL32(0, 0, 0, 255)); + show_new_version_icon_in_menu_ = false; - if (update_available_ && show_new_version_icon_in_menu_) { + std::string about_str = localization::about[localization_language_index_]; + if (update_available_) { auto now_time = std::chrono::duration_cast( std::chrono::steady_clock::now().time_since_epoch()) .count(); @@ -118,139 +90,196 @@ int Render::TitleBar(bool main_window) { // render for 1 second if (show_new_version_icon_) { - ImGui::SetWindowFontScale(0.6f); - ImGui::SetCursorPos(ImVec2(bar_pos_x + 10, bar_pos_y - 17)); - ImGui::Text(ICON_FA_TRIANGLE_EXCLAMATION); - ImGui::SetWindowFontScale(1.0f); - + about_str = about_str + " " + ICON_FA_TRIANGLE_EXCLAMATION; if (now_time - new_version_icon_render_start_time_ >= NEW_VERSION_ICON_RENDER_TIME_INTERVAL / 2) { show_new_version_icon_ = false; } + } else { + about_str = about_str + " "; } } - { - SettingWindow(); - SelfHostedServerWindow(); - AboutWindow(); + if (ImGui::MenuItem(about_str.c_str())) { + show_about_window_ = true; } + + if (update_available_ && ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::SetWindowFontScale(0.5f * dpi_scale_); + std::string new_version_available_str = + localization::new_version_available[localization_language_index_] + + ": " + latest_version_; + ImGui::Text("%s", new_version_available_str.c_str()); + ImGui::SetWindowFontScale(1.0f); + ImGui::EndTooltip(); + } + + ImGui::EndMenu(); } else { - ImGui::SetWindowFontScale(1.2f); + show_new_version_icon_in_menu_ = true; } - ImGui::PopStyleColor(2); + if (update_available_ && show_new_version_icon_in_menu_) { + auto now_time = std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()) + .count(); + // every 2 seconds + if (now_time - new_version_icon_last_trigger_time_ >= + NEW_VERSION_ICON_RENDER_TIME_INTERVAL) { + show_new_version_icon_ = true; + new_version_icon_render_start_time_ = now_time; + new_version_icon_last_trigger_time_ = now_time; + } + + // render for 1 second + if (show_new_version_icon_) { + ImGui::SetWindowFontScale(0.6f); + ImGui::SetCursorPos(ImVec2(bar_pos_x + 10, bar_pos_y - 17)); + ImGui::Text(ICON_FA_TRIANGLE_EXCLAMATION); + ImGui::SetWindowFontScale(1.0f); + + if (now_time - new_version_icon_render_start_time_ >= + NEW_VERSION_ICON_RENDER_TIME_INTERVAL / 2) { + show_new_version_icon_ = false; + } + } + } + + { + SettingWindow(); + SelfHostedServerWindow(); + AboutWindow(); + } + } else { + ImGui::SetWindowFontScale(1.2f); + } + + ImGui::SetCursorPos(ImVec2( + title_bar_width - title_bar_button_width * (main_window ? 2 : 3), 0.0f)); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0.1f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); + + float minimize_pos_x = title_bar_width - + title_bar_button_width * (main_window ? 2 : 3) + + title_bar_button_width * 0.33f; + float minimize_pos_y = title_bar_height * 0.5f; + std::string window_minimize_button = "##minimize"; // ICON_FA_MINUS; + if (ImGui::Button(window_minimize_button.c_str(), + ImVec2(title_bar_button_width, title_bar_button_height))) { + SDL_MinimizeWindow(main_window ? main_window_ : stream_window_); + } + draw_list->AddLine( + ImVec2(minimize_pos_x, minimize_pos_y), + ImVec2(minimize_pos_x + title_bar_button_width * 0.33f, minimize_pos_y), + IM_COL32(0, 0, 0, 255)); + ImGui::PopStyleColor(3); + + if (!main_window) { + ImGui::SetCursorPos( + ImVec2(title_bar_width - title_bar_button_width * 2, 0.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); - ImGui::SetCursorPosX(main_window - ? (main_window_width_ - BUTTON_PADDING * 2) - : (stream_window_width_ - BUTTON_PADDING * 3)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0.1f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - float minimize_pos_x = ImGui::GetCursorPosX() + 12.0f * dpi_scale_; - float minimize_pos_y = ImGui::GetCursorPosY() + 15.0f * dpi_scale_; - std::string window_minimize_button = "##minimize"; // ICON_FA_MINUS; - if (ImGui::Button(window_minimize_button.c_str(), - ImVec2(BUTTON_PADDING, 30.0f * dpi_scale_))) { - SDL_MinimizeWindow(main_window ? main_window_ : stream_window_); - } - draw_list->AddLine(ImVec2(minimize_pos_x, minimize_pos_y), - ImVec2(minimize_pos_x + 12 * dpi_scale_, minimize_pos_y), - IM_COL32(0, 0, 0, 255)); - ImGui::PopStyleColor(2); - - if (!main_window) { - ImGui::SetCursorPosX(stream_window_width_ - BUTTON_PADDING * 2); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0.1f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, - ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - - if (window_maximized_) { - float pos_x_top = ImGui::GetCursorPosX() + 11 * dpi_scale_; - float pos_y_top = ImGui::GetCursorPosY() + 11 * dpi_scale_; - float pos_x_bottom = ImGui::GetCursorPosX() + 13 * dpi_scale_; - float pos_y_bottom = ImGui::GetCursorPosY() + 9 * dpi_scale_; - std::string window_restore_button = - "##restore"; // ICON_FA_WINDOW_RESTORE; - if (ImGui::Button(window_restore_button.c_str(), - ImVec2(BUTTON_PADDING, 30.0f * dpi_scale_))) { - SDL_RestoreWindow(stream_window_); - window_maximized_ = false; - } - draw_list->AddRect( - ImVec2(pos_x_top, pos_y_top), - ImVec2(pos_x_top + 12 * dpi_scale_, pos_y_top + 12 * dpi_scale_), - IM_COL32(0, 0, 0, 255)); - draw_list->AddRect(ImVec2(pos_x_bottom, pos_y_bottom), - ImVec2(pos_x_bottom + 12 * dpi_scale_, - pos_y_bottom + 12 * dpi_scale_), - IM_COL32(0, 0, 0, 255)); + if (!window_maximized_) { + float pos_x_top = title_bar_width - title_bar_button_width * 1.65f; + float pos_y_top = title_bar_button_height * 0.36f; + float pos_x_bottom = title_bar_width - title_bar_button_width * 1.6f; + float pos_y_bottom = title_bar_button_height * 0.28f; + std::string window_restore_button = + "##restore"; // ICON_FA_WINDOW_RESTORE; + if (ImGui::Button( + window_restore_button.c_str(), + ImVec2(title_bar_button_width, title_bar_button_height))) { + SDL_RestoreWindow(stream_window_); + window_maximized_ = false; + } + draw_list->AddRect(ImVec2(pos_x_top, pos_y_top), + ImVec2(pos_x_top + title_bar_button_height * 0.33f, + pos_y_top + title_bar_button_height * 0.33f), + IM_COL32(0, 0, 0, 255)); + draw_list->AddRect(ImVec2(pos_x_bottom, pos_y_bottom), + ImVec2(pos_x_bottom + title_bar_button_height * 0.33f, + pos_y_bottom + title_bar_button_height * 0.33f), + IM_COL32(0, 0, 0, 255)); + if (ImGui::IsItemHovered()) { draw_list->AddRectFilled( - ImVec2(pos_x_top + 1 * dpi_scale_, pos_y_top + 1 * dpi_scale_), - ImVec2(pos_x_top + 11 * dpi_scale_, pos_y_top + 11 * dpi_scale_), + ImVec2(pos_x_top + title_bar_button_height * 0.02f, + pos_y_top + title_bar_button_height * 0.01f), + ImVec2(pos_x_top + title_bar_button_height * 0.32f, + pos_y_top + title_bar_button_height * 0.31f), + IM_COL32(229, 229, 229, 255)); + } else { + draw_list->AddRectFilled( + ImVec2(pos_x_top + title_bar_button_height * 0.02f, + pos_y_top + title_bar_button_height * 0.01f), + ImVec2(pos_x_top + title_bar_button_height * 0.32f, + pos_y_top + title_bar_button_height * 0.31f), IM_COL32(255, 255, 255, 255)); - } else { - float maximize_pos_x = ImGui::GetCursorPosX() + 12 * dpi_scale_; - float maximize_pos_y = ImGui::GetCursorPosY() + 10 * dpi_scale_; - std::string window_maximize_button = - "##maximize"; // ICON_FA_SQUARE_FULL; - if (ImGui::Button(window_maximize_button.c_str(), - ImVec2(BUTTON_PADDING, 30.0f * dpi_scale_))) { - SDL_MaximizeWindow(stream_window_); - window_maximized_ = !window_maximized_; - } - draw_list->AddRect(ImVec2(maximize_pos_x, maximize_pos_y), - ImVec2(maximize_pos_x + 12, maximize_pos_y + 12), - IM_COL32(0, 0, 0, 255)); } - ImGui::PopStyleColor(2); - } - - ImGui::SetCursorPosX( - (main_window ? main_window_width_ : stream_window_width_) - - BUTTON_PADDING); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0, 0, 1.0f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0, 0, 0.5f)); - - float xmark_pos_x = ImGui::GetCursorPosX() + 18 * dpi_scale_; - float xmark_pos_y = ImGui::GetCursorPosY() + 16 * dpi_scale_; - float xmark_size = 12.0f * dpi_scale_; - std::string close_button = "##xmark"; // ICON_FA_XMARK; - if (ImGui::Button(close_button.c_str(), - ImVec2(BUTTON_PADDING, 30.0f * dpi_scale_))) { -#if _WIN32 - if (enable_minimize_to_tray_) { - tray_->MinimizeToTray(); - } else { -#endif - SDL_Event event; - event.type = SDL_EVENT_QUIT; - SDL_PushEvent(&event); -#if _WIN32 + } else { + float maximize_pos_x = title_bar_width - title_bar_button_width * 1.5f - + title_bar_button_height * 0.165f; + float maximize_pos_y = title_bar_button_height * 0.33f; + std::string window_maximize_button = + "##maximize"; // ICON_FA_SQUARE_FULL; + if (ImGui::Button( + window_maximize_button.c_str(), + ImVec2(title_bar_button_width, title_bar_button_height))) { + SDL_MaximizeWindow(stream_window_); + window_maximized_ = !window_maximized_; } -#endif + draw_list->AddRect( + ImVec2(maximize_pos_x, maximize_pos_y), + ImVec2(maximize_pos_x + title_bar_button_height * 0.33f, + maximize_pos_y + title_bar_button_height * 0.33f), + IM_COL32(0, 0, 0, 255)); } - draw_list->AddLine(ImVec2(xmark_pos_x - xmark_size / 2 - 0.25f, - xmark_pos_y - xmark_size / 2 + 0.75f), - ImVec2(xmark_pos_x + xmark_size / 2 - 1.5f, - xmark_pos_y + xmark_size / 2 - 0.5f), - IM_COL32(0, 0, 0, 255)); - draw_list->AddLine(ImVec2(xmark_pos_x + xmark_size / 2 - 1.75f, - xmark_pos_y - xmark_size / 2 + 0.75f), - ImVec2(xmark_pos_x - xmark_size / 2, - xmark_pos_y + xmark_size / 2 - 1.0f), - IM_COL32(0, 0, 0, 255)); - - ImGui::PopStyleColor(2); - - ImGui::PopStyleColor(); + ImGui::PopStyleColor(3); } - ImGui::EndMenuBar(); + float xmark_button_pos_x = title_bar_width - title_bar_button_width; + ImGui::SetCursorPos(ImVec2(xmark_button_pos_x, 0.0f)); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0, 0, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0, 0, 0.5f)); + + float xmark_pos_x = xmark_button_pos_x + title_bar_button_width * 0.5f; + float xmark_pos_y = title_bar_height * 0.5f; + float xmark_size = title_bar_button_width * 0.33f; + std::string close_button = "##xmark"; // ICON_FA_XMARK; + if (ImGui::Button(close_button.c_str(), + ImVec2(title_bar_button_width, title_bar_button_height))) { +#if _WIN32 + if (enable_minimize_to_tray_) { + tray_->MinimizeToTray(); + } else { +#endif + SDL_Event event; + event.type = SDL_EVENT_QUIT; + SDL_PushEvent(&event); +#if _WIN32 + } +#endif + } + draw_list->AddLine(ImVec2(xmark_pos_x - xmark_size / 2 - 0.25f, + xmark_pos_y - xmark_size / 2 + 0.75f), + ImVec2(xmark_pos_x + xmark_size / 2 - 1.5f, + xmark_pos_y + xmark_size / 2 - 0.5f), + IM_COL32(0, 0, 0, 255)); + draw_list->AddLine( + ImVec2(xmark_pos_x + xmark_size / 2 - 1.75f, + xmark_pos_y - xmark_size / 2 + 0.75f), + ImVec2(xmark_pos_x - xmark_size / 2, xmark_pos_y + xmark_size / 2 - 1.0f), + IM_COL32(0, 0, 0, 255)); + + ImGui::PopStyleColor(3); + ImGui::EndChild(); - ImGui::PopStyleColor(); return 0; } } // namespace crossdesk \ No newline at end of file