mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] use self-draw icon for title bar
This commit is contained in:
@@ -13,41 +13,36 @@ int Render::ControlBar() {
|
|||||||
ImGui::SetCursorPosX(is_control_bar_in_left_ ? (control_window_width_ + 5)
|
ImGui::SetCursorPosX(is_control_bar_in_left_ ? (control_window_width_ + 5)
|
||||||
: 53);
|
: 53);
|
||||||
// Mouse control
|
// Mouse control
|
||||||
std::string mouse = ICON_FA_COMPUTER_MOUSE;
|
std::string mouse =
|
||||||
|
mouse_control_button_pressed_ ? ICON_FA_HAND_BACK_FIST : ICON_FA_HAND;
|
||||||
if (ImGui::Button(mouse.c_str(), ImVec2(25, 25))) {
|
if (ImGui::Button(mouse.c_str(), ImVec2(25, 25))) {
|
||||||
if (mouse_control_button_label_ ==
|
if (connection_established_) {
|
||||||
localization::control_mouse[localization_language_index_] &&
|
|
||||||
connection_established_) {
|
|
||||||
mouse_control_button_pressed_ = true;
|
|
||||||
control_mouse_ = true;
|
control_mouse_ = true;
|
||||||
mouse_control_button_label_ =
|
|
||||||
localization::release_mouse[localization_language_index_];
|
|
||||||
} else {
|
} else {
|
||||||
control_mouse_ = false;
|
control_mouse_ = false;
|
||||||
mouse_control_button_label_ =
|
|
||||||
localization::control_mouse[localization_language_index_];
|
|
||||||
}
|
}
|
||||||
mouse_control_button_pressed_ = !mouse_control_button_pressed_;
|
mouse_control_button_pressed_ = !mouse_control_button_pressed_;
|
||||||
|
mouse_control_button_label_ =
|
||||||
|
mouse_control_button_pressed_
|
||||||
|
? localization::release_mouse[localization_language_index_]
|
||||||
|
: localization::control_mouse[localization_language_index_];
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
// Audio capture
|
// Audio capture
|
||||||
std::string audio = audio_capture_button_pressed_ ? ICON_FA_VOLUME_HIGH
|
std::string audio = audio_capture_button_pressed_ ? ICON_FA_VOLUME_XMARK
|
||||||
: ICON_FA_VOLUME_XMARK;
|
: ICON_FA_VOLUME_HIGH;
|
||||||
if (ImGui::Button(audio.c_str(), ImVec2(25, 25))) {
|
if (ImGui::Button(audio.c_str(), ImVec2(25, 25))) {
|
||||||
if (mouse_control_button_label_ ==
|
if (connection_established_) {
|
||||||
localization::audio_capture[localization_language_index_] &&
|
|
||||||
connection_established_) {
|
|
||||||
audio_capture_button_pressed_ = true;
|
|
||||||
audio_capture_ = true;
|
audio_capture_ = true;
|
||||||
audio_capture_button_label_ =
|
|
||||||
localization::mute[localization_language_index_];
|
|
||||||
} else {
|
} else {
|
||||||
control_mouse_ = false;
|
audio_capture_ = false;
|
||||||
audio_capture_button_label_ =
|
|
||||||
localization::audio_capture[localization_language_index_];
|
|
||||||
}
|
}
|
||||||
audio_capture_button_pressed_ = !audio_capture_button_pressed_;
|
audio_capture_button_pressed_ = !audio_capture_button_pressed_;
|
||||||
|
audio_capture_button_label_ =
|
||||||
|
audio_capture_button_pressed_
|
||||||
|
? localization::audio_capture[localization_language_index_]
|
||||||
|
: localization::mute[localization_language_index_];
|
||||||
|
|
||||||
RemoteAction remote_action;
|
RemoteAction remote_action;
|
||||||
remote_action.type = ControlType::audio_capture;
|
remote_action.type = ControlType::audio_capture;
|
||||||
@@ -62,6 +57,10 @@ int Render::ControlBar() {
|
|||||||
fullscreen_button_pressed_ ? ICON_FA_COMPRESS : ICON_FA_EXPAND;
|
fullscreen_button_pressed_ ? ICON_FA_COMPRESS : ICON_FA_EXPAND;
|
||||||
if (ImGui::Button(fullscreen.c_str(), ImVec2(25, 25))) {
|
if (ImGui::Button(fullscreen.c_str(), ImVec2(25, 25))) {
|
||||||
fullscreen_button_pressed_ = !fullscreen_button_pressed_;
|
fullscreen_button_pressed_ = !fullscreen_button_pressed_;
|
||||||
|
fullscreen_button_label_ =
|
||||||
|
fullscreen_button_pressed_
|
||||||
|
? localization::exit_fullscreen[localization_language_index_]
|
||||||
|
: localization::fullscreen[localization_language_index_];
|
||||||
if (fullscreen_button_pressed_) {
|
if (fullscreen_button_pressed_) {
|
||||||
SDL_SetWindowFullscreen(main_window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
SDL_SetWindowFullscreen(main_window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -327,8 +327,9 @@ int Render::Run() {
|
|||||||
config.GlyphMinAdvanceX =
|
config.GlyphMinAdvanceX =
|
||||||
13.0f; // Use if you want to make the icon monospaced
|
13.0f; // Use if you want to make the icon monospaced
|
||||||
static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
|
static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
|
||||||
io.Fonts->AddFontFromMemoryTTF(fa_regular_400_ttf, sizeof(fa_regular_400_ttf),
|
// io.Fonts->AddFontFromMemoryTTF(fa_regular_400_ttf,
|
||||||
30.0f, &config, icon_ranges);
|
// sizeof(fa_regular_400_ttf),
|
||||||
|
// 30.0f, &config, icon_ranges);
|
||||||
io.Fonts->AddFontFromMemoryTTF(fa_solid_900_ttf, sizeof(fa_solid_900_ttf),
|
io.Fonts->AddFontFromMemoryTTF(fa_solid_900_ttf, sizeof(fa_solid_900_ttf),
|
||||||
30.0f, &config, icon_ranges);
|
30.0f, &config, icon_ranges);
|
||||||
|
|
||||||
@@ -424,16 +425,22 @@ int Render::Run() {
|
|||||||
connect_button_pressed_
|
connect_button_pressed_
|
||||||
? localization::disconnect[localization_language_index_]
|
? localization::disconnect[localization_language_index_]
|
||||||
: localization::connect[localization_language_index_];
|
: localization::connect[localization_language_index_];
|
||||||
fullscreen_button_label_ =
|
|
||||||
fullscreen_button_pressed_
|
|
||||||
? localization::exit_fullscreen[localization_language_index_]
|
|
||||||
: localization::fullscreen[localization_language_index_];
|
|
||||||
|
|
||||||
mouse_control_button_label_ =
|
mouse_control_button_label_ =
|
||||||
mouse_control_button_pressed_
|
mouse_control_button_pressed_
|
||||||
? localization::release_mouse[localization_language_index_]
|
? localization::release_mouse[localization_language_index_]
|
||||||
: localization::control_mouse[localization_language_index_];
|
: localization::control_mouse[localization_language_index_];
|
||||||
|
|
||||||
|
audio_capture_button_label_ =
|
||||||
|
audio_capture_button_pressed_
|
||||||
|
? localization::mute[localization_language_index_]
|
||||||
|
: localization::audio_capture[localization_language_index_];
|
||||||
|
|
||||||
|
fullscreen_button_label_ =
|
||||||
|
fullscreen_button_pressed_
|
||||||
|
? localization::exit_fullscreen[localization_language_index_]
|
||||||
|
: localization::fullscreen[localization_language_index_];
|
||||||
|
|
||||||
settings_button_label_ =
|
settings_button_label_ =
|
||||||
localization::settings[localization_language_index_];
|
localization::settings[localization_language_index_];
|
||||||
inited_ = true;
|
inited_ = true;
|
||||||
@@ -519,6 +526,7 @@ int Render::Run() {
|
|||||||
connection_established_ = false;
|
connection_established_ = false;
|
||||||
received_frame_ = false;
|
received_frame_ = false;
|
||||||
is_client_mode_ = false;
|
is_client_mode_ = false;
|
||||||
|
audio_capture_button_pressed_ = false;
|
||||||
SDL_RestoreWindow(main_window_);
|
SDL_RestoreWindow(main_window_);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ class Render {
|
|||||||
bool control_bar_expand_ = true;
|
bool control_bar_expand_ = true;
|
||||||
bool fullscreen_button_pressed_ = false;
|
bool fullscreen_button_pressed_ = false;
|
||||||
bool mouse_control_button_pressed_ = false;
|
bool mouse_control_button_pressed_ = false;
|
||||||
bool audio_capture_button_pressed_ = true;
|
bool audio_capture_button_pressed_ = false;
|
||||||
bool show_settings_window_ = false;
|
bool show_settings_window_ = false;
|
||||||
bool received_frame_ = false;
|
bool received_frame_ = false;
|
||||||
bool is_create_connection_ = false;
|
bool is_create_connection_ = false;
|
||||||
|
|||||||
@@ -205,6 +205,11 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) {
|
|||||||
render->start_mouse_control_ = false;
|
render->start_mouse_control_ = false;
|
||||||
render->connection_established_ = false;
|
render->connection_established_ = false;
|
||||||
render->control_mouse_ = false;
|
render->control_mouse_ = false;
|
||||||
|
if (render->audio_capture_) {
|
||||||
|
render->StopSpeakerCapture();
|
||||||
|
render->audio_capture_ = false;
|
||||||
|
render->audio_capture_button_pressed_ = false;
|
||||||
|
}
|
||||||
render->exit_video_window_ = false;
|
render->exit_video_window_ = false;
|
||||||
render->remote_password_.clear();
|
render->remote_password_.clear();
|
||||||
if (render->dst_buffer_) {
|
if (render->dst_buffer_) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ int Render::TitleBar() {
|
|||||||
ImGuiChildFlags_Border,
|
ImGuiChildFlags_Border,
|
||||||
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration |
|
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration |
|
||||||
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
||||||
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
if (ImGui::BeginMenuBar()) {
|
if (ImGui::BeginMenuBar()) {
|
||||||
ImGui::SetCursorPosX(main_window_width_ - (streaming_
|
ImGui::SetCursorPosX(main_window_width_ - (streaming_
|
||||||
@@ -23,7 +24,10 @@ int Render::TitleBar() {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_HeaderActive,
|
ImGui::PushStyleColor(ImGuiCol_HeaderActive,
|
||||||
ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
if (!streaming_) {
|
if (!streaming_) {
|
||||||
if (ImGui::BeginMenu(ICON_FA_BARS)) {
|
float bar_pos_x = ImGui::GetCursorPosX() + 7;
|
||||||
|
float bar_pos_y = ImGui::GetCursorPosY() + 15;
|
||||||
|
std::string menu_button = " "; // ICON_FA_BARS;
|
||||||
|
if (ImGui::BeginMenu(menu_button.c_str())) {
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
if (ImGui::MenuItem(
|
if (ImGui::MenuItem(
|
||||||
localization::settings[localization_language_index_].c_str())) {
|
localization::settings[localization_language_index_].c_str())) {
|
||||||
@@ -36,6 +40,15 @@ int Render::TitleBar() {
|
|||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
draw_list->AddLine(ImVec2(bar_pos_x, bar_pos_y - 6),
|
||||||
|
ImVec2(bar_pos_x + 12, bar_pos_y - 6),
|
||||||
|
IM_COL32(0, 0, 0, 255));
|
||||||
|
draw_list->AddLine(ImVec2(bar_pos_x, bar_pos_y),
|
||||||
|
ImVec2(bar_pos_x + 12, bar_pos_y),
|
||||||
|
IM_COL32(0, 0, 0, 255));
|
||||||
|
draw_list->AddLine(ImVec2(bar_pos_x, bar_pos_y + 6),
|
||||||
|
ImVec2(bar_pos_x + 12, bar_pos_y + 6),
|
||||||
|
IM_COL32(0, 0, 0, 255));
|
||||||
ImGui::PopStyleColor(2);
|
ImGui::PopStyleColor(2);
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -51,11 +64,17 @@ int Render::TitleBar() {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0.1f));
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0.1f));
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
|
||||||
ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
std::string window_minimize_button = ICON_FA_MINUS;
|
|
||||||
|
float minimize_pos_x = ImGui::GetCursorPosX() + 12;
|
||||||
|
float minimize_pos_y = ImGui::GetCursorPosY() + 15;
|
||||||
|
std::string window_minimize_button = "##minimize"; // ICON_FA_MINUS;
|
||||||
if (ImGui::Button(window_minimize_button.c_str(),
|
if (ImGui::Button(window_minimize_button.c_str(),
|
||||||
ImVec2(BUTTON_PADDING, 30))) {
|
ImVec2(BUTTON_PADDING, 30))) {
|
||||||
SDL_MinimizeWindow(main_window_);
|
SDL_MinimizeWindow(main_window_);
|
||||||
}
|
}
|
||||||
|
draw_list->AddLine(ImVec2(minimize_pos_x, minimize_pos_y),
|
||||||
|
ImVec2(minimize_pos_x + 12, minimize_pos_y),
|
||||||
|
IM_COL32(0, 0, 0, 255));
|
||||||
ImGui::PopStyleColor(2);
|
ImGui::PopStyleColor(2);
|
||||||
|
|
||||||
if (streaming_) {
|
if (streaming_) {
|
||||||
@@ -65,19 +84,39 @@ int Render::TitleBar() {
|
|||||||
ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
|
||||||
if (window_maximized_) {
|
if (window_maximized_) {
|
||||||
std::string window_restore_button = ICON_FA_WINDOW_RESTORE;
|
float pos_x_top = ImGui::GetCursorPosX() + 11;
|
||||||
|
float pos_y_top = ImGui::GetCursorPosY() + 11;
|
||||||
|
float pos_x_bottom = ImGui::GetCursorPosX() + 13;
|
||||||
|
float pos_y_bottom = ImGui::GetCursorPosY() + 9;
|
||||||
|
std::string window_restore_button =
|
||||||
|
"##restore"; // ICON_FA_WINDOW_RESTORE;
|
||||||
if (ImGui::Button(window_restore_button.c_str(),
|
if (ImGui::Button(window_restore_button.c_str(),
|
||||||
ImVec2(BUTTON_PADDING, 30))) {
|
ImVec2(BUTTON_PADDING, 30))) {
|
||||||
SDL_RestoreWindow(main_window_);
|
SDL_RestoreWindow(main_window_);
|
||||||
window_maximized_ = !window_maximized_;
|
window_maximized_ = !window_maximized_;
|
||||||
}
|
}
|
||||||
|
draw_list->AddRect(ImVec2(pos_x_top, pos_y_top),
|
||||||
|
ImVec2(pos_x_top + 12, pos_y_top + 12),
|
||||||
|
IM_COL32(0, 0, 0, 255));
|
||||||
|
draw_list->AddRect(ImVec2(pos_x_bottom, pos_y_bottom),
|
||||||
|
ImVec2(pos_x_bottom + 12, pos_y_bottom + 12),
|
||||||
|
IM_COL32(0, 0, 0, 255));
|
||||||
|
draw_list->AddRectFilled(ImVec2(pos_x_top + 1, pos_y_top + 1),
|
||||||
|
ImVec2(pos_x_top + 11, pos_y_top + 11),
|
||||||
|
IM_COL32(255, 255, 255, 255));
|
||||||
} else {
|
} else {
|
||||||
std::string window_maximize_button = ICON_FA_SQUARE_FULL;
|
float maximize_pos_x = ImGui::GetCursorPosX() + 12;
|
||||||
|
float maximize_pos_y = ImGui::GetCursorPosY() + 10;
|
||||||
|
std::string window_maximize_button =
|
||||||
|
"##maximize"; // ICON_FA_SQUARE_FULL;
|
||||||
if (ImGui::Button(window_maximize_button.c_str(),
|
if (ImGui::Button(window_maximize_button.c_str(),
|
||||||
ImVec2(BUTTON_PADDING, 30))) {
|
ImVec2(BUTTON_PADDING, 30))) {
|
||||||
SDL_MaximizeWindow(main_window_);
|
SDL_MaximizeWindow(main_window_);
|
||||||
window_maximized_ = !window_maximized_;
|
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::PopStyleColor(2);
|
||||||
}
|
}
|
||||||
@@ -85,12 +124,27 @@ int Render::TitleBar() {
|
|||||||
ImGui::SetCursorPosX(main_window_width_ - BUTTON_PADDING);
|
ImGui::SetCursorPosX(main_window_width_ - BUTTON_PADDING);
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0, 0, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0, 0, 1.0f));
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0, 0, 0.5f));
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0, 0, 0.5f));
|
||||||
std::string close_button = ICON_FA_XMARK;
|
|
||||||
|
float xmark_pos_x = ImGui::GetCursorPosX() + 18;
|
||||||
|
float xmark_pos_y = ImGui::GetCursorPosY() + 16;
|
||||||
|
float xmark_size = 12.0f;
|
||||||
|
std::string close_button = "##xmark"; // ICON_FA_XMARK;
|
||||||
if (ImGui::Button(close_button.c_str(), ImVec2(BUTTON_PADDING, 30))) {
|
if (ImGui::Button(close_button.c_str(), ImVec2(BUTTON_PADDING, 30))) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
event.type = SDL_QUIT;
|
event.type = SDL_QUIT;
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
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(2);
|
||||||
|
|
||||||
ImGui::PopStyleColor(1);
|
ImGui::PopStyleColor(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user