mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Implementation for menu bar
This commit is contained in:
48
src/single_window/control_bar.cpp
Normal file
48
src/single_window/control_bar.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "layout_style.h"
|
||||
#include "localization.h"
|
||||
#include "log.h"
|
||||
#include "render.h"
|
||||
|
||||
int Render::ControlBar() {
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
// Mouse control
|
||||
std::string mouse = ICON_FA_COMPUTER_MOUSE;
|
||||
if (ImGui::Button(mouse.c_str(), ImVec2(25, 25))) {
|
||||
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(25, 25))) {
|
||||
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_;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
18
src/single_window/control_window.cpp
Normal file
18
src/single_window/control_window.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "render.h"
|
||||
|
||||
int Render::ControlWindow() {
|
||||
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(0, 0, 0, 0));
|
||||
static bool a, b, c, d, e;
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||
ImGui::BeginChild("ControlWindow",
|
||||
ImVec2(main_window_width_, menu_window_height_),
|
||||
ImGuiChildFlags_Border, ImGuiWindowFlags_NoScrollbar);
|
||||
|
||||
ControlBar();
|
||||
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::EndChild();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -4,37 +4,27 @@
|
||||
#include "render.h"
|
||||
|
||||
int Render::LocalWindow() {
|
||||
// if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) {
|
||||
// ImGui::SetNextWindowSize(ImVec2(MENU_WINDOW_WIDTH_CN + 50,
|
||||
// main_window_height_ -
|
||||
// menu_window_height_));
|
||||
// } else {
|
||||
// ImGui::SetNextWindowSize(
|
||||
// ImVec2(MENU_WINDOW_WIDTH_EN, MENU_WINDOW_HEIGHT_EN));
|
||||
// }
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(0, menu_window_height_), ImGuiCond_Always);
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(255, 255, 255, 1));
|
||||
ImGui::BeginChild(
|
||||
u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>main",
|
||||
"LocalDesktopWindow",
|
||||
ImVec2(local_window_width_, main_window_height_ - menu_window_height_),
|
||||
ImGuiChildFlags_Border,
|
||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar);
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
ImGui::Text(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::Text(
|
||||
localization::local_desktop[localization_language_index_].c_str());
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
{
|
||||
// local
|
||||
// ImGui::SetNextWindowSize(ImVec2(300, 180));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
|
||||
// ImGui::SetNextWindowPos(ImVec2(0, 50), ImGuiCond_Always);
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0.05));
|
||||
ImGui::BeginChild(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1", ImVec2(330, 180), ImGuiChildFlags_Border);
|
||||
ImGui::BeginChild("LocalDesktopWindow_1", ImVec2(330, 180),
|
||||
ImGuiChildFlags_Border);
|
||||
{
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
|
||||
ImGui::Text(localization::local_id[localization_language_index_].c_str());
|
||||
|
||||
ImGui::Spacing();
|
||||
@@ -107,6 +97,7 @@ int Render::LocalWindow() {
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -7,6 +7,8 @@ int Render::MainWindow() {
|
||||
ImGui::Begin("Render", nullptr,
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);
|
||||
|
||||
MenuWindow();
|
||||
LocalWindow();
|
||||
RemoteWindow();
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "render.h"
|
||||
|
||||
int Render::MenuWindow() {
|
||||
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(255, 255, 255, 1));
|
||||
static bool a, b, c, d, e;
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||
ImGui::BeginChild("MenuWindow",
|
||||
ImVec2(main_window_width_, menu_window_height_),
|
||||
ImGuiChildFlags_Border, ImGuiWindowFlags_NoScrollbar);
|
||||
|
||||
ImGuiChildFlags_Border, ImGuiWindowFlags_MenuBar);
|
||||
if (ImGui::BeginMenuBar()) {
|
||||
if (ImGui::BeginMenu("Menu")) {
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
ImGui::SetWindowFontScale(0.8f);
|
||||
if (ImGui::BeginMenu(ICON_FA_BARS, true)) {
|
||||
ImGui::SetWindowFontScale(0.7f);
|
||||
ImGui::MenuItem("Auto-resizing window", NULL, &a);
|
||||
ImGui::MenuItem("Constrained-resizing window", NULL, &b);
|
||||
ImGui::MenuItem("Fullscreen window", NULL, &c);
|
||||
@@ -19,11 +20,12 @@ int Render::MenuWindow() {
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
SettingWindow();
|
||||
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::Dummy(ImVec2(main_window_width_ - 97, 0));
|
||||
|
||||
SettingButton();
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::EndChild();
|
||||
|
||||
|
||||
@@ -5,36 +5,28 @@
|
||||
#include "render.h"
|
||||
|
||||
int Render::RemoteWindow() {
|
||||
// if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) {
|
||||
// ImGui::SetNextWindowSize(
|
||||
// ImVec2(main_window_width_ - MENU_WINDOW_WIDTH_CN,
|
||||
// main_window_height_ - menu_window_height_));
|
||||
// } else {
|
||||
// ImGui::SetNextWindowSize(
|
||||
// ImVec2(MENU_WINDOW_WIDTH_EN, MENU_WINDOW_HEIGHT_EN));
|
||||
// }
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(local_window_width_, menu_window_height_),
|
||||
ImGui::SetNextWindowPos(ImVec2(local_window_width_ - 1, menu_window_height_),
|
||||
ImGuiCond_Always);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(255, 255, 255, 1));
|
||||
ImGui::BeginChild(
|
||||
"test",
|
||||
"RemoteDesktopWindow",
|
||||
ImVec2(main_window_width_ - local_window_width_, main_window_height_),
|
||||
ImGuiChildFlags_Border,
|
||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar);
|
||||
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
ImGui::Text(u8"Զ<EFBFBD>̿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::Text(
|
||||
localization::remote_desktop[localization_language_index_].c_str());
|
||||
|
||||
ImGui::Spacing();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
|
||||
ImGui::BeginChild(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>2", ImVec2(330, 180), ImGuiChildFlags_Border);
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0.09));
|
||||
ImGui::BeginChild("RemoteDesktopWindow_1", ImVec2(330, 180),
|
||||
ImGuiChildFlags_Border);
|
||||
{
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
|
||||
ImGui::Text(localization::remote_id[localization_language_index_].c_str());
|
||||
|
||||
ImGui::Spacing();
|
||||
@@ -76,7 +68,9 @@ int Render::RemoteWindow() {
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "device_controller_factory.h"
|
||||
#include "fa-regular-400.h"
|
||||
#include "fa-solid-900.h"
|
||||
#include "layout_style.h"
|
||||
#include "localization.h"
|
||||
#include "log.h"
|
||||
@@ -204,10 +206,6 @@ int Render::Run() {
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
texture_width_, texture_height_);
|
||||
|
||||
// Auto scaling for the render frame
|
||||
// SDL_RenderSetLogicalSize(main_renderer_, main_window_width_,
|
||||
// main_window_height_);
|
||||
|
||||
stream_render_rect_.x = 0;
|
||||
stream_render_rect_.y = 0;
|
||||
stream_render_rect_.w = main_window_width_;
|
||||
@@ -229,14 +227,14 @@ int Render::Run() {
|
||||
ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
if (config_center_.GetLanguage() == ConfigCenter::LANGUAGE::CHINESE) {
|
||||
// Load Fonts
|
||||
// Load Fonts
|
||||
#ifdef _WIN32
|
||||
std::string default_font_path = "c:/windows/fonts/simhei.ttf";
|
||||
std::string default_font_path = "fonts/OPPOSans-Regular.ttf";
|
||||
// std::string default_font_path = "c:/windows/fonts/simhei.ttf";
|
||||
std::ifstream font_path_f(default_font_path.c_str());
|
||||
std::string font_path =
|
||||
font_path_f.good() ? "c:/windows/fonts/simhei.ttf" : "";
|
||||
std::string font_path = font_path_f.good() ? default_font_path : "";
|
||||
if (!font_path.empty()) {
|
||||
io.Fonts->AddFontFromFileTTF(font_path.c_str(), 30.0f, NULL,
|
||||
io.Fonts->AddFontFromFileTTF(font_path.c_str(), 32.0f, NULL,
|
||||
io.Fonts->GetGlyphRangesChineseFull());
|
||||
}
|
||||
#elif __APPLE__
|
||||
@@ -259,8 +257,9 @@ int Render::Run() {
|
||||
config.GlyphMinAdvanceX =
|
||||
13.0f; // Use if you want to make the icon monospaced
|
||||
static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
|
||||
io.Fonts->AddFontFromFileTTF("fonts/fa-solid-900.ttf", 30.0f, &config,
|
||||
icon_ranges);
|
||||
io.Fonts->AddFontFromMemoryTTF(fa_solid_900_ttf, sizeof(fa_solid_900_ttf),
|
||||
30.0f, &config, icon_ranges);
|
||||
|
||||
io.Fonts->Build();
|
||||
|
||||
// Setup Dear ImGui style
|
||||
@@ -349,7 +348,7 @@ int Render::Run() {
|
||||
if (!streaming_) {
|
||||
MainWindow();
|
||||
} else {
|
||||
MenuWindow();
|
||||
ControlWindow();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
@@ -466,7 +465,6 @@ int Render::Run() {
|
||||
|
||||
ImGui_ImplSDLRenderer2_Shutdown();
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
SDL_DestroyRenderer(main_renderer_);
|
||||
SDL_DestroyWindow(main_window_);
|
||||
|
||||
@@ -32,10 +32,12 @@ class Render {
|
||||
private:
|
||||
int CreateStreamRenderWindow();
|
||||
int MainWindow();
|
||||
int MenuWindow();
|
||||
int LocalWindow();
|
||||
int RemoteWindow();
|
||||
int SettingWindow();
|
||||
int SettingButton();
|
||||
int ControlWindow();
|
||||
int ControlBar();
|
||||
int MenuWindow();
|
||||
|
||||
public:
|
||||
static void OnReceiveVideoBufferCb(const char *data, size_t size,
|
||||
@@ -119,7 +121,7 @@ class Render {
|
||||
int stream_window_height_last_ = 720;
|
||||
int main_window_width_before_fullscreen_ = 1280;
|
||||
int main_window_height_before_fullscreen_ = 720;
|
||||
int menu_window_height_ = 40;
|
||||
int menu_window_height_ = 30;
|
||||
int local_window_width_ = 350;
|
||||
|
||||
int texture_width_ = 1280;
|
||||
|
||||
@@ -4,53 +4,20 @@
|
||||
#include "log.h"
|
||||
#include "render.h"
|
||||
|
||||
int Render::SettingWindow() {
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
// Mouse control
|
||||
std::string mouse = ICON_FA_COMPUTER_MOUSE;
|
||||
if (ImGui::Button(mouse.c_str(), ImVec2(25, 25))) {
|
||||
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(25, 25))) {
|
||||
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::SameLine();
|
||||
int Render::SettingButton() {
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(255, 255, 255, 1));
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 1, 0.4));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
|
||||
ImGui::SetWindowFontScale(0.8f);
|
||||
// ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||
|
||||
std::string gear = ICON_FA_GEAR;
|
||||
if (ImGui::Button(gear.c_str(), ImVec2(25, 25))) {
|
||||
if (ImGui::Button(gear.c_str(), ImVec2(40, 35))) {
|
||||
settings_button_pressed_ = !settings_button_pressed_;
|
||||
settings_window_pos_reset_ = true;
|
||||
}
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
if (settings_button_pressed_) {
|
||||
if (settings_window_pos_reset_) {
|
||||
@@ -82,7 +49,7 @@ int Render::SettingWindow() {
|
||||
settings_window_pos_reset_ = false;
|
||||
}
|
||||
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
// ImGui::SetWindowFontScale(0.5f);
|
||||
// Settings
|
||||
ImGui::Begin(localization::settings[localization_language_index_].c_str(),
|
||||
nullptr,
|
||||
@@ -272,5 +239,7 @@ int Render::SettingWindow() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user