mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Use fix ratio to render frame in window
This commit is contained in:
@@ -6,7 +6,7 @@ int Render::MenuWindow() {
|
|||||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||||
ImGui::BeginChild("MenuWindow",
|
ImGui::BeginChild("MenuWindow",
|
||||||
ImVec2(main_window_width_, menu_window_height_),
|
ImVec2(main_window_width_, menu_window_height_),
|
||||||
ImGuiChildFlags_Border);
|
ImGuiChildFlags_Border, ImGuiWindowFlags_NoScrollbar);
|
||||||
|
|
||||||
if (ImGui::BeginMenuBar()) {
|
if (ImGui::BeginMenuBar()) {
|
||||||
if (ImGui::BeginMenu("Menu")) {
|
if (ImGui::BeginMenu("Menu")) {
|
||||||
|
|||||||
@@ -187,8 +187,8 @@ int Render::Run() {
|
|||||||
// Create main window with SDL_Renderer graphics context
|
// Create main window with SDL_Renderer graphics context
|
||||||
SDL_WindowFlags window_flags =
|
SDL_WindowFlags window_flags =
|
||||||
(SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE);
|
(SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE);
|
||||||
main_window_ = SDL_CreateWindow("Remote Desk", SDL_WINDOWPOS_CENTERED,
|
main_window_ = SDL_CreateWindow("Remote Desk", SDL_WINDOWPOS_UNDEFINED,
|
||||||
SDL_WINDOWPOS_CENTERED, main_window_width_,
|
SDL_WINDOWPOS_UNDEFINED, main_window_width_,
|
||||||
main_window_height_, window_flags);
|
main_window_height_, window_flags);
|
||||||
|
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
@@ -203,30 +203,20 @@ int Render::Run() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto scaling for the render frame
|
||||||
|
SDL_RenderSetLogicalSize(sdl_renderer_, main_window_width_,
|
||||||
|
main_window_height_);
|
||||||
|
|
||||||
pixformat_ = SDL_PIXELFORMAT_NV12;
|
pixformat_ = SDL_PIXELFORMAT_NV12;
|
||||||
|
|
||||||
// sdl_texture_ =
|
sdl_texture_ =
|
||||||
// SDL_CreateTexture(sdl_renderer_, pixformat_,
|
SDL_CreateTexture(sdl_renderer_, pixformat_, SDL_TEXTUREACCESS_STREAMING,
|
||||||
// SDL_TEXTUREACCESS_STREAMING,
|
texture_width_, texture_height_);
|
||||||
// texture_width_, texture_height_);
|
|
||||||
|
|
||||||
// video_window_ =
|
sdl_rect_.x = 0;
|
||||||
// SDL_CreateWindow("Video", SDL_WINDOWPOS_CENTERED,
|
sdl_rect_.y = 0;
|
||||||
// SDL_WINDOWPOS_CENTERED,
|
sdl_rect_.w = main_window_width_;
|
||||||
// main_window_width_, main_window_height_,
|
sdl_rect_.h = main_window_height_;
|
||||||
// window_flags);
|
|
||||||
|
|
||||||
// video_renderer_ = SDL_CreateRenderer(
|
|
||||||
// video_window_, -1, SDL_RENDERER_PRESENTVSYNC |
|
|
||||||
// SDL_RENDERER_ACCELERATED);
|
|
||||||
// if (video_renderer_ == nullptr) {
|
|
||||||
// SDL_Log("Error creating SDL_Renderer!");
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// video_texture_ = SDL_CreateTexture(video_renderer_, pixformat_,
|
|
||||||
// SDL_TEXTUREACCESS_STREAMING,
|
|
||||||
// texture_width_, texture_height_);
|
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
// Setup Dear ImGui context
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
@@ -347,7 +337,9 @@ int Render::Run() {
|
|||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
if (!connection_established_ || !received_frame_) {
|
||||||
MainWindow();
|
MainWindow();
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
@@ -355,35 +347,29 @@ int Render::Run() {
|
|||||||
if (event.type == SDL_QUIT) {
|
if (event.type == SDL_QUIT) {
|
||||||
exit_ = true;
|
exit_ = true;
|
||||||
} else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
} else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
||||||
int window_w_last = main_window_width_;
|
|
||||||
int window_h_last = main_window_height_;
|
|
||||||
|
|
||||||
SDL_GetWindowSize(main_window_, &main_window_width_,
|
SDL_GetWindowSize(main_window_, &main_window_width_,
|
||||||
&main_window_height_);
|
&main_window_height_);
|
||||||
|
|
||||||
// int w_change_ratio = abs(main_window_width_ - window_w_last) / 16;
|
sdl_rect_.x = 0;
|
||||||
// int h_change_ratio = abs(main_window_height_ - window_h_last) / 9;
|
sdl_rect_.y = 0;
|
||||||
|
if (main_window_width_ * 9 / 16 > main_window_height_) {
|
||||||
|
sdl_rect_.w = main_window_height_ * 16 / 9;
|
||||||
|
sdl_rect_.h = main_window_height_;
|
||||||
|
} else {
|
||||||
|
sdl_rect_.w = main_window_width_;
|
||||||
|
sdl_rect_.h = main_window_width_ * 9 / 16;
|
||||||
|
}
|
||||||
|
|
||||||
// if (w_change_ratio > h_change_ratio) {
|
main_window_width_last_ = main_window_width_;
|
||||||
// main_window_height_ = main_window_width_ * 9 / 16;
|
main_window_height_last_ = main_window_height_;
|
||||||
// } else {
|
|
||||||
// main_window_width_ = main_window_height_ * 16 / 9;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// SDL_SetWindowSize(main_window_, main_window_width_,
|
|
||||||
// main_window_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 &&
|
||||||
event.window.windowID == SDL_GetWindowID(main_window_)) {
|
event.window.windowID == SDL_GetWindowID(main_window_)) {
|
||||||
exit_ = true;
|
exit_ = true;
|
||||||
} else if (event.type == REFRESH_EVENT) {
|
} else if (event.type == REFRESH_EVENT) {
|
||||||
sdl_rect_.x = 0;
|
if (sdl_texture_)
|
||||||
sdl_rect_.y = 0;
|
SDL_UpdateTexture(sdl_texture_, NULL, dst_buffer_, 1280);
|
||||||
sdl_rect_.w = main_window_width_;
|
|
||||||
sdl_rect_.h = main_window_height_;
|
|
||||||
|
|
||||||
if (video_texture_)
|
|
||||||
SDL_UpdateTexture(video_texture_, NULL, dst_buffer_, 1280);
|
|
||||||
} else {
|
} else {
|
||||||
if (connection_established_) {
|
if (connection_established_) {
|
||||||
ProcessMouseKeyEven(event);
|
ProcessMouseKeyEven(event);
|
||||||
@@ -395,17 +381,10 @@ int Render::Run() {
|
|||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
SDL_RenderSetScale(sdl_renderer_, io.DisplayFramebufferScale.x,
|
SDL_RenderSetScale(sdl_renderer_, io.DisplayFramebufferScale.x,
|
||||||
io.DisplayFramebufferScale.y);
|
io.DisplayFramebufferScale.y);
|
||||||
// SDL_SetRenderDrawColor(sdl_renderer_, 255, 255, 255, 255);
|
|
||||||
SDL_RenderClear(sdl_renderer_);
|
SDL_RenderClear(sdl_renderer_);
|
||||||
|
if (connection_established_ && received_frame_) {
|
||||||
if (video_renderer_) {
|
SDL_RenderCopy(sdl_renderer_, sdl_texture_, NULL, &sdl_rect_);
|
||||||
SDL_RenderCopy(video_renderer_, video_texture_, NULL, &sdl_rect_);
|
SDL_RenderPresent(sdl_renderer_);
|
||||||
|
|
||||||
if (!connection_established_ || !received_frame_) {
|
|
||||||
SDL_RenderClear(video_renderer_);
|
|
||||||
SDL_SetRenderDrawColor(video_renderer_, 255, 255, 255, 255);
|
|
||||||
}
|
|
||||||
SDL_RenderPresent(video_renderer_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|||||||
@@ -108,8 +108,10 @@ class Render {
|
|||||||
private:
|
private:
|
||||||
int screen_width_ = 1280;
|
int screen_width_ = 1280;
|
||||||
int screen_height_ = 720;
|
int screen_height_ = 720;
|
||||||
int main_window_width_ = 1280;
|
int main_window_width_ = 960;
|
||||||
int main_window_height_ = 720;
|
int main_window_height_ = 540;
|
||||||
|
int main_window_width_last_ = 960;
|
||||||
|
int main_window_height_last_ = 540;
|
||||||
int main_window_width_before_fullscreen_ = 1280;
|
int main_window_width_before_fullscreen_ = 1280;
|
||||||
int main_window_height_before_fullscreen_ = 720;
|
int main_window_height_before_fullscreen_ = 720;
|
||||||
int menu_window_height_ = 40;
|
int menu_window_height_ = 40;
|
||||||
|
|||||||
@@ -172,35 +172,6 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) {
|
|||||||
render->start_screen_capture_ = true;
|
render->start_screen_capture_ = true;
|
||||||
render->start_mouse_control_ = true;
|
render->start_mouse_control_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!render->video_window_created_) {
|
|
||||||
SDL_WindowFlags window_flags =
|
|
||||||
(SDL_WindowFlags)(SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE);
|
|
||||||
|
|
||||||
render->sdl_texture_ =
|
|
||||||
SDL_CreateTexture(render->sdl_renderer_, render->pixformat_,
|
|
||||||
SDL_TEXTUREACCESS_STREAMING, render->texture_width_,
|
|
||||||
render->texture_height_);
|
|
||||||
|
|
||||||
render->video_window_ =
|
|
||||||
SDL_CreateWindow("Video", SDL_WINDOWPOS_CENTERED,
|
|
||||||
SDL_WINDOWPOS_CENTERED, render->main_window_width_,
|
|
||||||
render->main_window_height_, window_flags);
|
|
||||||
|
|
||||||
render->video_renderer_ = SDL_CreateRenderer(
|
|
||||||
render->video_window_, -1,
|
|
||||||
SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
|
||||||
if (render->video_renderer_ == nullptr) {
|
|
||||||
SDL_Log("Error creating SDL_Renderer!");
|
|
||||||
}
|
|
||||||
|
|
||||||
render->video_texture_ =
|
|
||||||
SDL_CreateTexture(render->video_renderer_, render->pixformat_,
|
|
||||||
SDL_TEXTUREACCESS_STREAMING, render->texture_width_,
|
|
||||||
render->texture_height_);
|
|
||||||
render->video_window_created_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (ConnectionStatus::Disconnected == status) {
|
} else if (ConnectionStatus::Disconnected == status) {
|
||||||
render->connection_status_str_ = "Disconnected";
|
render->connection_status_str_ = "Disconnected";
|
||||||
} else if (ConnectionStatus::Failed == status) {
|
} else if (ConnectionStatus::Failed == status) {
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
/*
|
|
||||||
* @Author: DI JUNKUN
|
|
||||||
* @Date: 2024-06-17
|
|
||||||
* Copyright (c) 2024 by DI JUNKUN, All Rights Reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _SUB_WINDOW_H_
|
|
||||||
#define _SUB_WINDOW_H_
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user