mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] enable movement for control bar
This commit is contained in:
@@ -33,20 +33,14 @@ int Render::ControlBar() {
|
|||||||
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_;
|
||||||
if (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);
|
SDL_SetWindowFullscreen(main_window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
} else {
|
} else {
|
||||||
SDL_SetWindowFullscreen(main_window_, SDL_FALSE);
|
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::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetCursorPosX(main_window_width_ - 35);
|
ImGui::SetCursorPosX(control_window_max_width_ - 35);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string control_bar =
|
std::string control_bar =
|
||||||
|
|||||||
@@ -1,25 +1,38 @@
|
|||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
||||||
int Render::ControlWindow() {
|
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, title_bar_height_ + 2), ImGuiCond_Always);
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
|
||||||
|
|
||||||
auto time_duration = ImGui::GetTime() - control_bar_button_pressed_time_;
|
auto time_duration = ImGui::GetTime() - control_bar_button_pressed_time_;
|
||||||
auto control_window_width =
|
auto control_window_width =
|
||||||
!control_bar_button_pressed_
|
!control_bar_button_pressed_
|
||||||
? time_duration < 0.25f
|
? time_duration < 0.25f
|
||||||
? main_window_width_ -
|
? control_window_max_width_ -
|
||||||
(main_window_width_ - control_window_min_width_) * 4 *
|
(control_window_max_width_ - control_window_min_width_) *
|
||||||
time_duration
|
4 * time_duration
|
||||||
: control_window_min_width_
|
: control_window_min_width_
|
||||||
: time_duration < 0.25f
|
: time_duration < 0.25f
|
||||||
? control_window_min_width_ +
|
? control_window_min_width_ +
|
||||||
(main_window_width_ - control_window_min_width_) * 4 *
|
(control_window_max_width_ - control_window_min_width_) * 4 *
|
||||||
time_duration
|
time_duration
|
||||||
: main_window_width_;
|
: control_window_max_width_;
|
||||||
ImGui::BeginChild("ControlWindow",
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
|
||||||
|
// ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
|
||||||
|
// ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0);
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once);
|
||||||
|
ImGui::SetNextWindowSize(
|
||||||
|
ImVec2(control_window_width + 10, control_window_height_ + 10),
|
||||||
|
ImGuiCond_Always);
|
||||||
|
ImGui::Begin("ControlWindow", nullptr,
|
||||||
|
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
||||||
|
ImGuiWindowFlags_NoScrollbar |
|
||||||
|
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
static bool a, b, c, d, e;
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once);
|
||||||
|
ImGui::SetWindowFontScale(0.5f);
|
||||||
|
|
||||||
|
ImGui::BeginChild("ControlBar",
|
||||||
ImVec2(control_window_width, control_window_height_),
|
ImVec2(control_window_width, control_window_height_),
|
||||||
ImGuiChildFlags_Border, ImGuiWindowFlags_NoDecoration);
|
ImGuiChildFlags_Border, ImGuiWindowFlags_NoDecoration);
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
ImGui::SetWindowFontScale(1.0f);
|
||||||
@@ -29,5 +42,9 @@ int Render::ControlWindow() {
|
|||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
// ImGui::PopStyleVar();
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -438,12 +438,14 @@ int Render::Run() {
|
|||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
|
ImGui::PushStyleColor(
|
||||||
|
ImGuiCol_WindowBg,
|
||||||
|
ImVec4(1.0f, 1.0f, 1.0f, fullscreen_button_pressed_ ? 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_ + control_window_height_
|
streaming_ ? (fullscreen_button_pressed_ ? 0 : title_bar_height_)
|
||||||
: main_window_height_default_),
|
: main_window_height_default_),
|
||||||
ImGuiCond_Always);
|
ImGuiCond_Always);
|
||||||
ImGui::Begin("Render", nullptr,
|
ImGui::Begin("Render", nullptr,
|
||||||
@@ -453,7 +455,9 @@ int Render::Run() {
|
|||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
TitleBar();
|
if (!fullscreen_button_pressed_) {
|
||||||
|
TitleBar();
|
||||||
|
}
|
||||||
|
|
||||||
if (streaming_ && is_client_mode_) {
|
if (streaming_ && is_client_mode_) {
|
||||||
if (!resizable_) {
|
if (!resizable_) {
|
||||||
@@ -536,8 +540,8 @@ int Render::Run() {
|
|||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
|
SDL_RenderClear(main_renderer_);
|
||||||
if (connection_established_ && received_frame_ && streaming_) {
|
if (connection_established_ && received_frame_ && streaming_) {
|
||||||
SDL_RenderClear(main_renderer_);
|
|
||||||
SDL_RenderCopy(main_renderer_, stream_texture_, NULL,
|
SDL_RenderCopy(main_renderer_, stream_texture_, NULL,
|
||||||
&stream_render_rect_);
|
&stream_render_rect_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,11 +140,10 @@ class Render {
|
|||||||
int stream_window_height_ = 720;
|
int stream_window_height_ = 720;
|
||||||
int stream_window_width_last_ = 1280;
|
int stream_window_width_last_ = 1280;
|
||||||
int stream_window_height_last_ = 720;
|
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_width_before_maximized_ = 960;
|
||||||
int main_window_height_before_maximized_ = 570;
|
int main_window_height_before_maximized_ = 570;
|
||||||
int control_window_min_width_ = 40;
|
int control_window_min_width_ = 40;
|
||||||
|
int control_window_max_width_ = 150;
|
||||||
int control_window_height_ = 40;
|
int control_window_height_ = 40;
|
||||||
int local_window_width_ = 350;
|
int local_window_width_ = 350;
|
||||||
int status_bar_height_ = 20;
|
int status_bar_height_ = 20;
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
#define BUTTON_PADDING 36.0f
|
#define BUTTON_PADDING 36.0f
|
||||||
|
|
||||||
int Render::TitleBar() {
|
int Render::TitleBar() {
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0);
|
// ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1);
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(1, 1, 1, 1.0f));
|
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(1, 1, 1, 0.0f));
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||||
ImGui::SetWindowFontScale(0.8f);
|
ImGui::SetWindowFontScale(0.8f);
|
||||||
ImGui::BeginChild("TitleBar", ImVec2(main_window_width_, title_bar_height_),
|
ImGui::BeginChild("TitleBar", ImVec2(main_window_width_, title_bar_height_),
|
||||||
@@ -97,6 +97,6 @@ int Render::TitleBar() {
|
|||||||
|
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::PopStyleColor(2);
|
ImGui::PopStyleColor(2);
|
||||||
ImGui::PopStyleVar();
|
// ImGui::PopStyleVar();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user