[feat] remove menu bar and move menu button to title bar

This commit is contained in:
dijunkun
2024-08-01 17:28:39 +08:00
parent 7b42923418
commit d17c70c2c8
17 changed files with 5856 additions and 245 deletions

5658
fonts/fa_regular_400.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,7 @@ static std::vector<std::string> exit_fullscreen = {u8" 退出全屏",
" Exit fullscreen"}; " Exit fullscreen"};
static std::vector<std::string> control_mouse = {u8" 控制", " Control"}; static std::vector<std::string> control_mouse = {u8" 控制", " Control"};
static std::vector<std::string> release_mouse = {u8" 释放", " Release"}; static std::vector<std::string> release_mouse = {u8" 释放", " Release"};
static std::vector<std::string> settings = {u8" 设置", " Settings"}; static std::vector<std::string> settings = {u8"设置", "Settings"};
static std::vector<std::string> language = {u8"语言:", "Language:"}; static std::vector<std::string> language = {u8"语言:", "Language:"};
static std::vector<std::string> language_zh = {u8"中文", "Chinese"}; static std::vector<std::string> language_zh = {u8"中文", "Chinese"};
static std::vector<std::string> language_en = {u8"英文", "English"}; static std::vector<std::string> language_en = {u8"英文", "English"};

View File

@@ -544,11 +544,11 @@ int Render::Run() {
ImGui::Spacing(); ImGui::Spacing();
if (ImGui::Button(settings_button_label_.c_str())) { if (ImGui::Button(settings_button_label_.c_str())) {
settings_button_pressed_ = !settings_button_pressed_; show_settings_window_ = !show_settings_window_;
settings_window_pos_reset_ = true; settings_window_pos_reset_ = true;
} }
if (settings_button_pressed_) { if (show_settings_window_) {
if (settings_window_pos_reset_) { if (settings_window_pos_reset_) {
const ImGuiViewport *viewport = ImGui::GetMainViewport(); const ImGuiViewport *viewport = ImGui::GetMainViewport();
if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) { if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) {
@@ -690,7 +690,7 @@ int Render::Run() {
// OK // OK
if (ImGui::Button( if (ImGui::Button(
localization::ok[localization_language_index_].c_str())) { localization::ok[localization_language_index_].c_str())) {
settings_button_pressed_ = false; show_settings_window_ = false;
// Language // Language
if (language_button_value_ == 0) { if (language_button_value_ == 0) {
@@ -751,7 +751,7 @@ int Render::Run() {
// Cancel // Cancel
if (ImGui::Button( if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) { localization::cancel[localization_language_index_].c_str())) {
settings_button_pressed_ = false; show_settings_window_ = false;
if (language_button_value_ != language_button_value_last_) { if (language_button_value_ != language_button_value_last_) {
language_button_value_ = language_button_value_last_; language_button_value_ = language_button_value_last_;
} }

View File

@@ -122,7 +122,7 @@ class Render {
bool connect_button_pressed_ = false; bool connect_button_pressed_ = false;
bool fullscreen_button_pressed_ = false; bool fullscreen_button_pressed_ = false;
bool mouse_control_button_pressed_ = false; bool mouse_control_button_pressed_ = false;
bool settings_button_pressed_ = false; bool show_settings_window_ = false;
bool received_frame_ = false; bool received_frame_ = false;
bool is_create_connection_ = false; bool is_create_connection_ = false;
bool audio_buffer_fresh_ = false; bool audio_buffer_fresh_ = false;

View File

@@ -7,8 +7,8 @@
#pragma once #pragma once
#define FONT_ICON_FILE_NAME_FAR "fa-regular-400.ttf" // #define FONT_ICON_FILE_NAME_FAR "fa-regular-400.ttf"
#define FONT_ICON_FILE_NAME_FAS "fa-solid-900.ttf" // #define FONT_ICON_FILE_NAME_FAS "fa-solid-900.ttf"
#define ICON_MIN_FA 0xe005 #define ICON_MIN_FA 0xe005
#define ICON_MAX_16_FA 0xf8ff #define ICON_MAX_16_FA 0xf8ff

View File

@@ -0,0 +1,56 @@
#include "IconsFontAwesome6.h"
#include "layout_style.h"
#include "localization.h"
#include "rd_log.h"
#include "render.h"
int Render::AboutWindow() {
if (show_about_window_) {
const ImGuiViewport *viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(ImVec2(
(viewport->WorkSize.x - viewport->WorkPos.x - about_window_width_) / 2,
(viewport->WorkSize.y - viewport->WorkPos.y - about_window_height_) /
2));
ImGui::SetNextWindowSize(ImVec2(about_window_width_, about_window_height_));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::SetWindowFontScale(0.5f);
ImGui::Begin(
localization::about[localization_language_index_].c_str(), nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);
ImGui::SetWindowFontScale(1.0f);
ImGui::SetWindowFontScale(0.5f);
std::string version;
#ifdef RD_VERSION
version = RD_VERSION;
#else
version = "Unknown";
#endif
std::string text =
localization::version[localization_language_index_] + ": " + version;
ImGui::Text("%s", text.c_str());
ImGui::SetCursorPosX(about_window_width_ * 0.42f);
ImGui::SetCursorPosY(about_window_height_ * 0.75f);
// OK
if (ImGui::Button(localization::ok[localization_language_index_].c_str())) {
show_about_window_ = false;
}
ImGui::SetWindowFontScale(1.0f);
ImGui::SetWindowFontScale(0.5f);
ImGui::End();
ImGui::SetWindowFontScale(1.0f);
ImGui::PopStyleVar(3);
ImGui::PopStyleColor();
}
return 0;
}

View File

@@ -3,7 +3,7 @@
int Render::ControlWindow() { int Render::ControlWindow() {
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
static bool a, b, c, d, e; static bool a, b, c, d, e;
ImGui::SetNextWindowPos(ImVec2(0, 0 + title_bar_height_), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + 2), ImGuiCond_Always);
ImGui::SetWindowFontScale(0.5f); ImGui::SetWindowFontScale(0.5f);
auto time_duration = ImGui::GetTime() - control_bar_button_pressed_time_; auto time_duration = ImGui::GetTime() - control_bar_button_pressed_time_;

View File

@@ -7,19 +7,18 @@
#include "render.h" #include "render.h"
int Render::LocalWindow() { int Render::LocalWindow() {
ImGui::SetNextWindowPos(ImVec2(0, menu_window_height_ + title_bar_height_), ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Always);
ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::BeginChild("LocalDesktopWindow", ImGui::BeginChild(
ImVec2(local_window_width_, "LocalDesktopWindow",
main_window_height_default_ - title_bar_height_ - ImVec2(local_window_width_, main_window_height_default_ -
menu_window_height_ - status_bar_height_), title_bar_height_ - status_bar_height_),
ImGuiChildFlags_Border, ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);

View File

@@ -5,7 +5,7 @@ int Render::MainWindow() {
ImGui::SetNextWindowSize( ImGui::SetNextWindowSize(
ImVec2(main_window_width_default_, main_window_height_default_), ImVec2(main_window_width_default_, main_window_height_default_),
ImGuiCond_Always); ImGuiCond_Always);
MenuWindow();
LocalWindow(); LocalWindow();
RemoteWindow(); RemoteWindow();
StatusBar(); StatusBar();

View File

@@ -1,91 +0,0 @@
#include "IconsFontAwesome6.h"
#include "layout_style.h"
#include "localization.h"
#include "rd_log.h"
#include "render.h"
int Render::MenuWindow() {
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(255, 255, 255, 1));
static bool a, b, c, d, e;
ImGui::SetNextWindowPos(ImVec2(0, 0 + title_bar_height_), ImGuiCond_Always);
ImGui::SetWindowFontScale(0.8f);
ImGui::BeginChild(
"MenuWindow", ImVec2(main_window_width_, menu_window_height_),
ImGuiChildFlags_Border,
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(1.0f);
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu(ICON_FA_BARS, true)) {
ImGui::SetWindowFontScale(0.5f);
if (ImGui::MenuItem(
localization::about[localization_language_index_].c_str())) {
show_about_window_ = true;
}
ImGui::SetWindowFontScale(1.0f);
ImGui::EndMenu();
}
ImGui::Dummy(ImVec2(main_window_width_ - 97, 0));
SettingButton();
if (show_about_window_) {
AboutWindow();
}
}
ImGui::EndChild();
return 0;
}
int Render::AboutWindow() {
const ImGuiViewport *viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(ImVec2(
(viewport->WorkSize.x - viewport->WorkPos.x - about_window_width_) / 2,
(viewport->WorkSize.y - viewport->WorkPos.y - about_window_height_) / 2));
ImGui::SetNextWindowSize(ImVec2(about_window_width_, about_window_height_));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::SetWindowFontScale(0.5f);
ImGui::Begin(localization::about[localization_language_index_].c_str(),
nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);
ImGui::SetWindowFontScale(1.0f);
ImGui::SetWindowFontScale(0.5f);
std::string version;
#ifdef RD_VERSION
version = RD_VERSION;
#else
version = "Unknown";
#endif
std::string text =
localization::version[localization_language_index_] + ": " + version;
ImGui::Text("%s", text.c_str());
ImGui::SetCursorPosX(about_window_width_ * 0.42f);
ImGui::SetCursorPosY(about_window_height_ * 0.75f);
// OK
if (ImGui::Button(localization::ok[localization_language_index_].c_str())) {
show_about_window_ = false;
}
ImGui::SetWindowFontScale(1.0f);
ImGui::SetWindowFontScale(0.5f);
ImGui::End();
ImGui::SetWindowFontScale(1.0f);
ImGui::PopStyleVar(3);
ImGui::PopStyleColor();
return 0;
}

View File

@@ -5,16 +5,15 @@
#include "render.h" #include "render.h"
int Render::RemoteWindow() { int Render::RemoteWindow() {
ImGui::SetNextWindowPos( ImGui::SetNextWindowPos(ImVec2(local_window_width_ - 1, title_bar_height_),
ImVec2(local_window_width_ - 1, menu_window_height_ + title_bar_height_), ImGuiCond_Always);
ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::BeginChild("RemoteDesktopWindow", ImGui::BeginChild("RemoteDesktopWindow",
ImVec2(main_window_width_ - local_window_width_ + 1, ImVec2(main_window_width_ - local_window_width_ + 1,
main_window_height_default_ - title_bar_height_ - main_window_height_default_ - title_bar_height_ -
menu_window_height_ - status_bar_height_), status_bar_height_),
ImGuiChildFlags_Border, ImGuiChildFlags_Border,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |

View File

@@ -7,7 +7,8 @@
#include "IconsFontAwesome6.h" #include "IconsFontAwesome6.h"
#include "OPPOSans_Regular.h" #include "OPPOSans_Regular.h"
#include "device_controller_factory.h" #include "device_controller_factory.h"
#include "fa-solid-900.h" #include "fa_regular_400.h"
#include "fa_solid_900.h"
#include "layout_style.h" #include "layout_style.h"
#include "localization.h" #include "localization.h"
#include "platform.h" #include "platform.h"
@@ -18,44 +19,47 @@
#define REFRESH_EVENT (SDL_USEREVENT + 1) #define REFRESH_EVENT (SDL_USEREVENT + 1)
#define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2 #define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2
#define MOUSE_GRAB_PADDING 10 #define MOUSE_GRAB_PADDING 5
SDL_HitTestResult HitTestCallback(SDL_Window *Window, const SDL_Point *Area, SDL_HitTestResult Render::HitTestCallback(SDL_Window *window,
void *Data) { const SDL_Point *area, void *data) {
int Width, Height; Render *render = (Render *)data;
SDL_GetWindowSize(Window, &Width, &Height);
if (Area->y < 30 && Area->x < 30) { int window_width, window_height;
SDL_GetWindowSize(window, &window_width, &window_height);
if (area->y < 30 && area->y > MOUSE_GRAB_PADDING &&
area->x < window_width - 120 && area->x > MOUSE_GRAB_PADDING) {
return SDL_HITTEST_DRAGGABLE; return SDL_HITTEST_DRAGGABLE;
} else { }
if (!render->streaming_) {
return SDL_HITTEST_NORMAL; return SDL_HITTEST_NORMAL;
} }
// if (Area->y < MOUSE_GRAB_PADDING) { if (area->y < MOUSE_GRAB_PADDING) {
// if (Area->x < MOUSE_GRAB_PADDING) { if (area->x < MOUSE_GRAB_PADDING) {
// return SDL_HITTEST_RESIZE_TOPLEFT; return SDL_HITTEST_RESIZE_TOPLEFT;
// } else if (Area->x > Width - MOUSE_GRAB_PADDING) { } else if (area->x > window_width - MOUSE_GRAB_PADDING) {
// return SDL_HITTEST_RESIZE_TOPRIGHT; return SDL_HITTEST_RESIZE_TOPRIGHT;
// } else { } else {
// return SDL_HITTEST_RESIZE_TOP; return SDL_HITTEST_RESIZE_TOP;
// } }
// } else if (Area->y > Height - MOUSE_GRAB_PADDING) { } else if (area->y > window_height - MOUSE_GRAB_PADDING) {
// if (Area->x < MOUSE_GRAB_PADDING) { if (area->x < MOUSE_GRAB_PADDING) {
// return SDL_HITTEST_RESIZE_BOTTOMLEFT; return SDL_HITTEST_RESIZE_BOTTOMLEFT;
// } else if (Area->x > Width - MOUSE_GRAB_PADDING) { } else if (area->x > window_width - MOUSE_GRAB_PADDING) {
// return SDL_HITTEST_RESIZE_BOTTOMRIGHT; return SDL_HITTEST_RESIZE_BOTTOMRIGHT;
// } else { } else {
// return SDL_HITTEST_RESIZE_BOTTOM; return SDL_HITTEST_RESIZE_BOTTOM;
// } }
// } else if (Area->x < MOUSE_GRAB_PADDING) { } else if (area->x < MOUSE_GRAB_PADDING) {
// return SDL_HITTEST_RESIZE_LEFT; return SDL_HITTEST_RESIZE_LEFT;
// } else if (Area->x > Width - MOUSE_GRAB_PADDING) { } else if (area->x > window_width - MOUSE_GRAB_PADDING) {
// return SDL_HITTEST_RESIZE_RIGHT; return SDL_HITTEST_RESIZE_RIGHT;
// } else if (Area->y < 70) { }
// return SDL_HITTEST_DRAGGABLE;
// }
// return SDL_HITTEST_DRAGGABLE; // SDL_HITTEST_NORMAL <- Windows behaviour return SDL_HITTEST_NORMAL;
} }
Render::Render() {} Render::Render() {}
@@ -260,7 +264,7 @@ int Render::Run() {
"Remote Desk", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, "Remote Desk", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
main_window_width_default_, main_window_height_default_, window_flags); main_window_width_default_, main_window_height_default_, window_flags);
SDL_SetWindowHitTest(main_window_, HitTestCallback, 0); SDL_SetWindowHitTest(main_window_, HitTestCallback, this);
main_renderer_ = SDL_CreateRenderer( main_renderer_ = SDL_CreateRenderer(
main_window_, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); main_window_, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
@@ -295,11 +299,11 @@ int Render::Run() {
want_in.callback = SdlCaptureAudioIn; want_in.callback = SdlCaptureAudioIn;
want_in.userdata = this; want_in.userdata = this;
input_dev_ = SDL_OpenAudioDevice(NULL, 1, &want_in, &have_in, 0); // input_dev_ = SDL_OpenAudioDevice(NULL, 1, &want_in, &have_in, 0);
if (input_dev_ == 0) { // if (input_dev_ == 0) {
SDL_Log("Failed to open input: %s", SDL_GetError()); // SDL_Log("Failed to open input: %s", SDL_GetError());
// return 1; // // return 1;
} // }
SDL_zero(want_out); SDL_zero(want_out);
want_out.freq = 48000; want_out.freq = 48000;
@@ -316,7 +320,7 @@ int Render::Run() {
// return 1; // return 1;
} }
SDL_PauseAudioDevice(input_dev_, 0); // SDL_PauseAudioDevice(input_dev_, 0);
SDL_PauseAudioDevice(output_dev_, 0); SDL_PauseAudioDevice(output_dev_, 0);
// Setup Dear ImGui context // Setup Dear ImGui context
@@ -339,6 +343,8 @@ 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),
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);
@@ -432,20 +438,20 @@ int Render::Run() {
ImGui_ImplSDL2_NewFrame(); ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
// ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
// ImVec4(1.0f, 1.0f, 1.0f, streaming_ ? 0 : 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetNextWindowSize( ImGui::SetNextWindowSize(
ImVec2(main_window_width_, ImVec2(main_window_width_,
streaming_ ? title_bar_height_ : main_window_height_default_), streaming_ ? title_bar_height_ + control_window_height_
: main_window_height_default_),
ImGuiCond_Always); ImGuiCond_Always);
ImGui::Begin("Render", nullptr, ImGui::Begin("Render", nullptr,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleVar(); ImGui::PopStyleVar();
// ImGui::PopStyleColor(); ImGui::PopStyleColor();
TitleBar(); TitleBar();
@@ -455,7 +461,7 @@ int Render::Run() {
SDL_SetWindowResizable(main_window_, SDL_TRUE); SDL_SetWindowResizable(main_window_, SDL_TRUE);
} }
// ControlWindow(); ControlWindow();
} else { } else {
if (resizable_) { if (resizable_) {
resizable_ = !resizable_; resizable_ = !resizable_;
@@ -489,23 +495,26 @@ int Render::Run() {
} else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { } else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
SDL_GetWindowSize(main_window_, &main_window_width_, SDL_GetWindowSize(main_window_, &main_window_width_,
&main_window_height_); &main_window_height_);
if (main_window_width_ * 9 < main_window_height_ * 16) {
int video_width = main_window_width_;
int video_height = main_window_height_ - title_bar_height_;
if (video_width * 9 < video_height * 16) {
stream_render_rect_.x = 0; stream_render_rect_.x = 0;
stream_render_rect_.y = stream_render_rect_.y =
abs(main_window_height_ - main_window_width_ * 9 / 16) / 2; abs(video_height - video_width * 9 / 16) / 2 + title_bar_height_;
stream_render_rect_.w = main_window_width_; stream_render_rect_.w = video_width;
stream_render_rect_.h = main_window_width_ * 9 / 16; stream_render_rect_.h = video_width * 9 / 16;
} else if (main_window_width_ * 9 > main_window_height_ * 16) { } else if (video_width * 9 > video_height * 16) {
stream_render_rect_.x = stream_render_rect_.x = abs(video_width - video_height * 16 / 9) / 2;
abs(main_window_width_ - main_window_height_ * 16 / 9) / 2; stream_render_rect_.y = title_bar_height_;
stream_render_rect_.y = 0; stream_render_rect_.w = video_height * 16 / 9;
stream_render_rect_.w = main_window_height_ * 16 / 9; stream_render_rect_.h = video_height;
stream_render_rect_.h = main_window_height_;
} else { } else {
stream_render_rect_.x = 0; stream_render_rect_.x = 0;
stream_render_rect_.y = 0; stream_render_rect_.y = title_bar_height_;
stream_render_rect_.w = main_window_width_; stream_render_rect_.w = video_width;
stream_render_rect_.h = main_window_height_; stream_render_rect_.h = video_height;
} }
} else if (event.type == SDL_WINDOWEVENT && } else if (event.type == SDL_WINDOWEVENT &&
event.window.event == SDL_WINDOWEVENT_CLOSE) { event.window.event == SDL_WINDOWEVENT_CLOSE) {
@@ -566,7 +575,7 @@ int Render::Run() {
} }
SDL_CloseAudioDevice(output_dev_); SDL_CloseAudioDevice(output_dev_);
SDL_CloseAudioDevice(input_dev_); // SDL_CloseAudioDevice(input_dev_);
ImGui_ImplSDLRenderer2_Shutdown(); ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL2_Shutdown();

View File

@@ -36,10 +36,9 @@ class Render {
int MainWindow(); int MainWindow();
int LocalWindow(); int LocalWindow();
int RemoteWindow(); int RemoteWindow();
int SettingButton(); int SettingWindow();
int ControlWindow(); int ControlWindow();
int ControlBar(); int ControlBar();
int MenuWindow();
int AboutWindow(); int AboutWindow();
int StatusBar(); int StatusBar();
int ConnectionStatusWindow(); int ConnectionStatusWindow();
@@ -64,6 +63,9 @@ class Render {
static void NetStatusReport(TraversalMode mode, const unsigned short send, static void NetStatusReport(TraversalMode mode, const unsigned short send,
const unsigned short receive, void *user_ptr); const unsigned short receive, void *user_ptr);
static SDL_HitTestResult HitTestCallback(SDL_Window *window,
const SDL_Point *area, void *data);
private: private:
int ProcessMouseKeyEven(SDL_Event &ev); int ProcessMouseKeyEven(SDL_Event &ev);
@@ -142,7 +144,6 @@ class Render {
int main_window_height_before_fullscreen_ = 720; int main_window_height_before_fullscreen_ = 720;
int main_window_width_before_maximized_ = 960; int main_window_width_before_maximized_ = 960;
int main_window_height_before_maximized_ = 570; int main_window_height_before_maximized_ = 570;
int menu_window_height_ = 30;
int control_window_min_width_ = 40; int control_window_min_width_ = 40;
int control_window_height_ = 40; int control_window_height_ = 40;
int local_window_width_ = 350; int local_window_width_ = 350;
@@ -182,7 +183,7 @@ class Render {
bool control_bar_button_pressed_ = false; bool control_bar_button_pressed_ = false;
bool fullscreen_button_pressed_ = false; bool fullscreen_button_pressed_ = false;
bool mouse_control_button_pressed_ = false; bool mouse_control_button_pressed_ = false;
bool settings_button_pressed_ = false; bool show_settings_window_ = false;
bool received_frame_ = false; bool received_frame_ = false;
bool is_create_connection_ = false; bool is_create_connection_ = false;
bool audio_buffer_fresh_ = false; bool audio_buffer_fresh_ = false;

View File

@@ -4,22 +4,8 @@
#include "rd_log.h" #include "rd_log.h"
#include "render.h" #include "render.h"
int Render::SettingButton() { int Render::SettingWindow() {
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(255, 255, 255, 1)); if (show_settings_window_) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
ImVec4(104.0 / 255, 171.0 / 255, 251.0 / 255, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
std::string gear = ICON_FA_GEAR;
if (ImGui::Button(gear.c_str(), ImVec2(40, 30))) {
settings_button_pressed_ = !settings_button_pressed_;
settings_window_pos_reset_ = true;
}
ImGui::PopStyleColor(4);
if (settings_button_pressed_) {
if (settings_window_pos_reset_) { if (settings_window_pos_reset_) {
const ImGuiViewport *viewport = ImGui::GetMainViewport(); const ImGuiViewport *viewport = ImGui::GetMainViewport();
if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) { if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) {
@@ -166,7 +152,7 @@ int Render::SettingButton() {
// OK // OK
if (ImGui::Button( if (ImGui::Button(
localization::ok[localization_language_index_].c_str())) { localization::ok[localization_language_index_].c_str())) {
settings_button_pressed_ = false; show_settings_window_ = false;
// Language // Language
if (language_button_value_ == 0) { if (language_button_value_ == 0) {
@@ -227,7 +213,7 @@ int Render::SettingButton() {
// Cancel // Cancel
if (ImGui::Button( if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) { localization::cancel[localization_language_index_].c_str())) {
settings_button_pressed_ = false; show_settings_window_ = false;
if (language_button_value_ != language_button_value_last_) { if (language_button_value_ != language_button_value_last_) {
language_button_value_ = language_button_value_last_; language_button_value_ = language_button_value_last_;
} }

View File

@@ -2,7 +2,7 @@
#include "render.h" #include "render.h"
int Render::StatusBar() { int Render::StatusBar() {
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(0, 0, 0, 1)); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
static bool a, b, c, d, e; static bool a, b, c, d, e;
ImGui::SetNextWindowPos( ImGui::SetNextWindowPos(
ImVec2(0, main_window_height_default_ - status_bar_height_ - 1), ImVec2(0, main_window_height_default_ - status_bar_height_ - 1),

View File

@@ -2,84 +2,77 @@
#include "localization.h" #include "localization.h"
#include "render.h" #include "render.h"
#define BUTTON_PADDING 36.0f
int Render::TitleBar() { int Render::TitleBar() {
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(0, 0, 0, 0.05f)); ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0);
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(1, 1, 1, 1.0f));
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetWindowFontScale(0.8f);
ImGui::BeginChild("TitleBar", ImVec2(main_window_width_, title_bar_height_), ImGui::BeginChild("TitleBar", ImVec2(main_window_width_, title_bar_height_),
ImGuiChildFlags_Border, ImGuiChildFlags_Border,
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::SetWindowFontScale(1.0f);
if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenuBar()) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); ImGui::SetCursorPosX(main_window_width_ - (streaming_
? BUTTON_PADDING * 4 - 3
ImGui::SetCursorPosX(60); : BUTTON_PADDING * 3 - 3));
if (streaming_) { ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0, 0, 0, 0.1f));
std::string mouse = ICON_FA_COMPUTER_MOUSE; ImGui::PushStyleColor(ImGuiCol_HeaderActive,
if (ImGui::Button(mouse.c_str(), ImVec2(30, 30))) { ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
if (mouse_control_button_label_ == if (ImGui::BeginMenu(ICON_FA_BARS)) {
localization::control_mouse[localization_language_index_] && ImGui::SetWindowFontScale(0.5f);
connection_established_) { if (ImGui::MenuItem(
mouse_control_button_pressed_ = true; localization::settings[localization_language_index_].c_str())) {
control_mouse_ = true; show_settings_window_ = true;
mouse_control_button_label_ =
localization::release_mouse[localization_language_index_];
} else {
control_mouse_ = false;
mouse_control_button_label_ =
localization::control_mouse[localization_language_index_];
}
mouse_control_button_pressed_ = !mouse_control_button_pressed_;
} }
if (ImGui::MenuItem(
ImGui::SameLine(); localization::about[localization_language_index_].c_str())) {
// Fullscreen show_about_window_ = true;
std::string fullscreen =
fullscreen_button_pressed_ ? ICON_FA_COMPRESS : ICON_FA_EXPAND;
if (ImGui::Button(fullscreen.c_str(), ImVec2(30, 30))) {
fullscreen_button_pressed_ = !fullscreen_button_pressed_;
if (fullscreen_button_pressed_) {
main_window_width_before_fullscreen_ = main_window_width_;
main_window_height_before_fullscreen_ = main_window_height_;
SDL_SetWindowFullscreen(main_window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
} else {
SDL_SetWindowFullscreen(main_window_, SDL_FALSE);
SDL_SetWindowSize(main_window_, main_window_width_before_fullscreen_,
main_window_height_before_fullscreen_);
main_window_width_ = main_window_width_before_fullscreen_;
main_window_height_ = main_window_height_before_fullscreen_;
}
} }
ImGui::SetWindowFontScale(1.0f);
ImGui::EndMenu();
}
ImGui::PopStyleColor(2);
{
SettingWindow();
AboutWindow();
} }
ImGui::SetCursorPosX(main_window_width_ - (streaming_ ? 90 : 60)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::SetCursorPosX(main_window_width_ - (streaming_
? BUTTON_PADDING * 3
: BUTTON_PADDING * 2));
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; std::string window_minimize_button = ICON_FA_MINUS;
if (ImGui::Button(window_minimize_button.c_str(), ImVec2(30, 30))) { if (ImGui::Button(window_minimize_button.c_str(),
ImVec2(BUTTON_PADDING, 30))) {
SDL_MinimizeWindow(main_window_); SDL_MinimizeWindow(main_window_);
} }
ImGui::PopStyleColor(2); ImGui::PopStyleColor(2);
if (streaming_) { if (streaming_) {
ImGui::SetCursorPosX(main_window_width_ - 60); ImGui::SetCursorPosX(main_window_width_ - BUTTON_PADDING * 2);
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));
if (window_maximized_) { if (window_maximized_) {
std::string window_restore_button = ICON_FA_WINDOW_RESTORE; std::string window_restore_button = ICON_FA_WINDOW_RESTORE;
if (ImGui::Button(window_restore_button.c_str(), ImVec2(30, 30))) { if (ImGui::Button(window_restore_button.c_str(),
ImVec2(BUTTON_PADDING, 30))) {
SDL_RestoreWindow(main_window_); SDL_RestoreWindow(main_window_);
window_maximized_ = !window_maximized_; window_maximized_ = !window_maximized_;
} }
} else { } else {
std::string window_maximize_button = ICON_FA_SQUARE; std::string window_maximize_button = ICON_FA_SQUARE_FULL;
if (ImGui::Button(window_maximize_button.c_str(), ImVec2(30, 30))) { if (ImGui::Button(window_maximize_button.c_str(),
SDL_GetWindowSize(main_window_, &main_window_width_before_maximized_, ImVec2(BUTTON_PADDING, 30))) {
&main_window_height_before_maximized_);
SDL_MaximizeWindow(main_window_); SDL_MaximizeWindow(main_window_);
window_maximized_ = !window_maximized_; window_maximized_ = !window_maximized_;
} }
@@ -87,11 +80,11 @@ int Render::TitleBar() {
ImGui::PopStyleColor(2); ImGui::PopStyleColor(2);
} }
ImGui::SetCursorPosX(main_window_width_ - 30); 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; std::string close_button = ICON_FA_XMARK;
if (ImGui::Button(close_button.c_str(), ImVec2(30, 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);
@@ -104,5 +97,6 @@ int Render::TitleBar() {
ImGui::EndChild(); ImGui::EndChild();
ImGui::PopStyleColor(2); ImGui::PopStyleColor(2);
ImGui::PopStyleVar();
return 0; return 0;
} }