diff --git a/src/single_window/connection_status_window.cpp b/src/single_window/connection_status_window.cpp index 6beb806..57aa110 100644 --- a/src/single_window/connection_status_window.cpp +++ b/src/single_window/connection_status_window.cpp @@ -17,7 +17,6 @@ int Render::ConnectionStatusWindow() { ImGui::SetNextWindowSize(ImVec2(connection_status_window_width_, connection_status_window_height_)); - ImGui::SetWindowFontScale(0.5f); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0)); @@ -30,7 +29,6 @@ int Render::ConnectionStatusWindow() { ImGuiWindowFlags_NoSavedSettings); ImGui::PopStyleVar(2); ImGui::PopStyleColor(); - ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(0.5f); std::string text; @@ -130,10 +128,8 @@ int Render::ConnectionStatusWindow() { ImGui::Text("%s", text.c_str()); ImGui::SetWindowFontScale(1.0f); - ImGui::SetWindowFontScale(0.5f); ImGui::End(); ImGui::PopStyleVar(); - ImGui::SetWindowFontScale(1.0f); } return 0; } \ No newline at end of file diff --git a/src/single_window/control_window.cpp b/src/single_window/control_window.cpp index 7288a94..3220bf5 100644 --- a/src/single_window/control_window.cpp +++ b/src/single_window/control_window.cpp @@ -3,7 +3,7 @@ int Render::ControlWindow() { ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); static bool a, b, c, d, e; - ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); + ImGui::SetNextWindowPos(ImVec2(0, 0 + title_bar_height_), ImGuiCond_Always); ImGui::SetWindowFontScale(0.5f); auto time_duration = ImGui::GetTime() - control_bar_button_pressed_time_; diff --git a/src/single_window/local_peer_window.cpp b/src/single_window/local_peer_window.cpp index 29b80b0..3839b9b 100644 --- a/src/single_window/local_peer_window.cpp +++ b/src/single_window/local_peer_window.cpp @@ -7,18 +7,19 @@ #include "render.h" int Render::LocalWindow() { - ImGui::SetNextWindowPos(ImVec2(0, menu_window_height_), ImGuiCond_Always); + ImGui::SetNextWindowPos(ImVec2(0, menu_window_height_ + title_bar_height_), + ImGuiCond_Always); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - ImGui::BeginChild( - "LocalDesktopWindow", - ImVec2(local_window_width_, - main_window_height_ - menu_window_height_ - status_bar_height_), - ImGuiChildFlags_Border, - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | - ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | - ImGuiWindowFlags_NoBringToFrontOnFocus); + ImGui::BeginChild("LocalDesktopWindow", + ImVec2(local_window_width_, + main_window_height_default_ - title_bar_height_ - + menu_window_height_ - status_bar_height_), + ImGuiChildFlags_Border, + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | + ImGuiWindowFlags_NoBringToFrontOnFocus); ImGui::PopStyleColor(); ImGui::SetWindowFontScale(1.0f); diff --git a/src/single_window/main_window.cpp b/src/single_window/main_window.cpp index 445ed50..a4ab8e2 100644 --- a/src/single_window/main_window.cpp +++ b/src/single_window/main_window.cpp @@ -2,9 +2,9 @@ int Render::MainWindow() { ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); - ImGui::SetNextWindowSize(ImVec2(main_window_width_, main_window_height_), - ImGuiCond_Always); - + ImGui::SetNextWindowSize( + ImVec2(main_window_width_default_, main_window_height_default_), + ImGuiCond_Always); MenuWindow(); LocalWindow(); RemoteWindow(); diff --git a/src/single_window/menu_window.cpp b/src/single_window/menu_window.cpp index 76612b5..45325a2 100644 --- a/src/single_window/menu_window.cpp +++ b/src/single_window/menu_window.cpp @@ -7,7 +7,7 @@ int Render::MenuWindow() { ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(255, 255, 255, 1)); static bool a, b, c, d, e; - ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); + ImGui::SetNextWindowPos(ImVec2(0, 0 + title_bar_height_), ImGuiCond_Always); ImGui::SetWindowFontScale(0.8f); ImGui::BeginChild( "MenuWindow", ImVec2(main_window_width_, menu_window_height_), diff --git a/src/single_window/remote_peer_window.cpp b/src/single_window/remote_peer_window.cpp index ef68f2f..34fd89c 100644 --- a/src/single_window/remote_peer_window.cpp +++ b/src/single_window/remote_peer_window.cpp @@ -5,19 +5,20 @@ #include "render.h" int Render::RemoteWindow() { - ImGui::SetNextWindowPos(ImVec2(local_window_width_ - 1, menu_window_height_), - ImGuiCond_Always); + ImGui::SetNextWindowPos( + ImVec2(local_window_width_ - 1, menu_window_height_ + title_bar_height_), + ImGuiCond_Always); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - ImGui::BeginChild( - "RemoteDesktopWindow", - ImVec2(main_window_width_ - local_window_width_ + 1, - main_window_height_ - menu_window_height_ - status_bar_height_), - ImGuiChildFlags_Border, - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | - ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | - ImGuiWindowFlags_NoBringToFrontOnFocus); + ImGui::BeginChild("RemoteDesktopWindow", + ImVec2(main_window_width_ - local_window_width_ + 1, + main_window_height_default_ - title_bar_height_ - + menu_window_height_ - status_bar_height_), + ImGuiChildFlags_Border, + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | + ImGuiWindowFlags_NoBringToFrontOnFocus); ImGui::PopStyleColor(); ImGui::SetWindowFontScale(1.0f); diff --git a/src/single_window/render.cpp b/src/single_window/render.cpp index 7174923..b28ded2 100644 --- a/src/single_window/render.cpp +++ b/src/single_window/render.cpp @@ -18,6 +18,46 @@ #define REFRESH_EVENT (SDL_USEREVENT + 1) #define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2 +#define MOUSE_GRAB_PADDING 10 + +SDL_HitTestResult HitTestCallback(SDL_Window *Window, const SDL_Point *Area, + void *Data) { + int Width, Height; + SDL_GetWindowSize(Window, &Width, &Height); + + if (Area->y < 30 && Area->x < 30) { + return SDL_HITTEST_DRAGGABLE; + } else { + return SDL_HITTEST_NORMAL; + } + + // if (Area->y < MOUSE_GRAB_PADDING) { + // if (Area->x < MOUSE_GRAB_PADDING) { + // return SDL_HITTEST_RESIZE_TOPLEFT; + // } else if (Area->x > Width - MOUSE_GRAB_PADDING) { + // return SDL_HITTEST_RESIZE_TOPRIGHT; + // } else { + // return SDL_HITTEST_RESIZE_TOP; + // } + // } else if (Area->y > Height - MOUSE_GRAB_PADDING) { + // if (Area->x < MOUSE_GRAB_PADDING) { + // return SDL_HITTEST_RESIZE_BOTTOMLEFT; + // } else if (Area->x > Width - MOUSE_GRAB_PADDING) { + // return SDL_HITTEST_RESIZE_BOTTOMRIGHT; + // } else { + // return SDL_HITTEST_RESIZE_BOTTOM; + // } + // } else if (Area->x < MOUSE_GRAB_PADDING) { + // return SDL_HITTEST_RESIZE_LEFT; + // } else if (Area->x > Width - MOUSE_GRAB_PADDING) { + // return SDL_HITTEST_RESIZE_RIGHT; + // } else if (Area->y < 70) { + // return SDL_HITTEST_DRAGGABLE; + // } + + // return SDL_HITTEST_DRAGGABLE; // SDL_HITTEST_NORMAL <- Windows behaviour +} + Render::Render() {} Render::~Render() {} @@ -213,17 +253,15 @@ int Render::Run() { return -1; } - // From 2.0.18: Enable native IME. -#ifdef SDL_HINT_IME_SHOW_UI - SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1"); -#endif - // Create main window with SDL_Renderer graphics context - SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI); + SDL_WindowFlags window_flags = + (SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS); main_window_ = SDL_CreateWindow( "Remote Desk", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, main_window_width_default_, main_window_height_default_, window_flags); + SDL_SetWindowHitTest(main_window_, HitTestCallback, 0); + main_renderer_ = SDL_CreateRenderer( main_window_, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); if (main_renderer_ == nullptr) { @@ -238,7 +276,7 @@ int Render::Run() { texture_width_, texture_height_); 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_.h = main_window_height_; @@ -394,26 +432,30 @@ int Render::Run() { ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - ImGui::PushStyleColor(ImGuiCol_WindowBg, - ImVec4(1.0f, 1.0f, 1.0f, streaming_ ? 0 : 1.0f)); + // ImGui::PushStyleColor(ImGuiCol_WindowBg, + // ImVec4(1.0f, 1.0f, 1.0f, streaming_ ? 0 : 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); ImGui::SetNextWindowSize( ImVec2(main_window_width_, - streaming_ ? control_window_height_ : main_window_height_), + streaming_ ? title_bar_height_ : main_window_height_default_), ImGuiCond_Always); ImGui::Begin("Render", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar); + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | + ImGuiWindowFlags_NoBringToFrontOnFocus); ImGui::PopStyleVar(); - ImGui::PopStyleColor(); + // ImGui::PopStyleColor(); + + TitleBar(); + if (streaming_ && is_client_mode_) { if (!resizable_) { resizable_ = !resizable_; SDL_SetWindowResizable(main_window_, SDL_TRUE); } - ControlWindow(); + // ControlWindow(); } else { if (resizable_) { resizable_ = !resizable_; @@ -491,7 +533,7 @@ int Render::Run() { &stream_render_rect_); } - ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData()); + ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), main_renderer_); SDL_RenderPresent(main_renderer_); // frame_count_++; diff --git a/src/single_window/render.h b/src/single_window/render.h index dbc9bc8..faa986f 100644 --- a/src/single_window/render.h +++ b/src/single_window/render.h @@ -32,6 +32,7 @@ class Render { private: int CreateStreamRenderWindow(); + int TitleBar(); int MainWindow(); int LocalWindow(); int RemoteWindow(); @@ -61,7 +62,7 @@ class Render { static void OnConnectionStatusCb(ConnectionStatus status, void *user_data); static void NetStatusReport(TraversalMode mode, const unsigned short send, - const unsigned short receive, void *user_ptr); + const unsigned short receive, void *user_ptr); private: int ProcessMouseKeyEven(SDL_Event &ev); @@ -123,10 +124,12 @@ class Render { bool is_client_mode_ = false; private: + int title_bar_width_ = 960; + int title_bar_height_ = 30; int screen_width_ = 1280; int screen_height_ = 720; int main_window_width_default_ = 960; - int main_window_height_default_ = 540; + int main_window_height_default_ = 570; int main_window_width_ = 960; int main_window_height_ = 540; int main_window_width_last_ = 960; @@ -137,6 +140,8 @@ class Render { int stream_window_height_last_ = 720; int main_window_width_before_fullscreen_ = 1280; int main_window_height_before_fullscreen_ = 720; + int main_window_width_before_maximized_ = 960; + int main_window_height_before_maximized_ = 570; int menu_window_height_ = 30; int control_window_min_width_ = 40; int control_window_height_ = 40; @@ -190,6 +195,7 @@ class Render { bool streaming_ = false; bool show_about_window_ = false; bool show_connection_status_window_ = false; + bool window_maximized_ = false; double copy_start_time_ = 0; double regenerate_password_start_time_ = 0; @@ -207,6 +213,7 @@ class Render { std::string signal_status_str_ = ""; std::string connection_status_str_ = ""; bool signal_connected_ = false; + bool p2p_mode_ = true; private: PeerPtr *peer_ = nullptr; diff --git a/src/single_window/status_bar.cpp b/src/single_window/status_bar.cpp index a186cdd..d3690dc 100644 --- a/src/single_window/status_bar.cpp +++ b/src/single_window/status_bar.cpp @@ -5,7 +5,7 @@ int Render::StatusBar() { ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(0, 0, 0, 1)); static bool a, b, c, d, e; ImGui::SetNextWindowPos( - ImVec2(0, main_window_height_ - status_bar_height_ - 1), + ImVec2(0, main_window_height_default_ - status_bar_height_ - 1), ImGuiCond_Always); ImGui::BeginChild( @@ -15,17 +15,17 @@ int Render::StatusBar() { ImDrawList* draw_list = ImGui::GetWindowDrawList(); draw_list->AddCircleFilled( - ImVec2(15, main_window_height_ - status_bar_height_ + 9.0f), 5, + ImVec2(15, main_window_height_default_ - status_bar_height_ + 9.0f), 5, ImColor(signal_connected_ ? 0.0f : 1.0f, signal_connected_ ? 1.0f : 0.0f, 0.0f), 100); draw_list->AddCircle( - ImVec2(15, main_window_height_ - status_bar_height_ + 10.0f), 6, + ImVec2(15, main_window_height_default_ - status_bar_height_ + 10.0f), 6, ImColor(1.0f, 1.0f, 1.0f), 100); ImGui::SetWindowFontScale(0.5f); draw_list->AddText( - ImVec2(25, main_window_height_ - status_bar_height_ + 3.0f), + ImVec2(25, main_window_height_default_ - status_bar_height_ + 3.0f), ImColor(0.0f, 0.0f, 0.0f), signal_connected_ ? localization::signal_connected[localization_language_index_].c_str() diff --git a/src/single_window/title_bar.cpp b/src/single_window/title_bar.cpp new file mode 100644 index 0000000..b4567db --- /dev/null +++ b/src/single_window/title_bar.cpp @@ -0,0 +1,108 @@ +#include "IconsFontAwesome6.h" +#include "localization.h" +#include "render.h" + +int Render::TitleBar() { + ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(0, 0, 0, 0.05f)); + ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); + ImGui::BeginChild("TitleBar", ImVec2(main_window_width_, title_bar_height_), + ImGuiChildFlags_Border, + ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration | + ImGuiWindowFlags_NoBringToFrontOnFocus); + + ImGui::SetWindowFontScale(1.0f); + if (ImGui::BeginMenuBar()) { + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); + + ImGui::SetCursorPosX(60); + if (streaming_) { + std::string mouse = ICON_FA_COMPUTER_MOUSE; + if (ImGui::Button(mouse.c_str(), ImVec2(30, 30))) { + if (mouse_control_button_label_ == + localization::control_mouse[localization_language_index_] && + connection_established_) { + mouse_control_button_pressed_ = true; + control_mouse_ = 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_; + } + + ImGui::SameLine(); + // Fullscreen + 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::SetCursorPosX(main_window_width_ - (streaming_ ? 90 : 60)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0.1f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, + ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); + std::string window_minimize_button = ICON_FA_MINUS; + if (ImGui::Button(window_minimize_button.c_str(), ImVec2(30, 30))) { + SDL_MinimizeWindow(main_window_); + } + ImGui::PopStyleColor(2); + + if (streaming_) { + ImGui::SetCursorPosX(main_window_width_ - 60); + 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_) { + std::string window_restore_button = ICON_FA_WINDOW_RESTORE; + if (ImGui::Button(window_restore_button.c_str(), ImVec2(30, 30))) { + SDL_RestoreWindow(main_window_); + window_maximized_ = !window_maximized_; + } + } else { + std::string window_maximize_button = ICON_FA_SQUARE; + if (ImGui::Button(window_maximize_button.c_str(), ImVec2(30, 30))) { + SDL_GetWindowSize(main_window_, &main_window_width_before_maximized_, + &main_window_height_before_maximized_); + SDL_MaximizeWindow(main_window_); + window_maximized_ = !window_maximized_; + } + } + ImGui::PopStyleColor(2); + } + + ImGui::SetCursorPosX(main_window_width_ - 30); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0, 0, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0, 0, 0.5f)); + std::string close_button = ICON_FA_XMARK; + if (ImGui::Button(close_button.c_str(), ImVec2(30, 30))) { + SDL_Event event; + event.type = SDL_QUIT; + SDL_PushEvent(&event); + } + ImGui::PopStyleColor(2); + + ImGui::PopStyleColor(1); + } + ImGui::SetWindowFontScale(1.0f); + + ImGui::EndChild(); + ImGui::PopStyleColor(2); + return 0; +} \ No newline at end of file diff --git a/thirdparty/projectx b/thirdparty/projectx index 5417972..66fc4d3 160000 --- a/thirdparty/projectx +++ b/thirdparty/projectx @@ -1 +1 @@ -Subproject commit 54179722e5628835f389664d498cf8cb1444ca9e +Subproject commit 66fc4d3f9537ea87d1dadcce6bd48611d2a470bf diff --git a/xmake.lua b/xmake.lua index f404ed7..7d699f1 100644 --- a/xmake.lua +++ b/xmake.lua @@ -18,7 +18,7 @@ if is_mode("debug") then end add_requires("spdlog 1.14.1", {system = false}) -add_requires("imgui 1.90.6", {configs = {sdl2 = true, sdl2_renderer = true}}) +add_requires("imgui v1.91.0", {configs = {sdl2 = true, sdl2_renderer = true}}) add_requires("libyuv") if is_os("windows") then