Implementation for menu bar

This commit is contained in:
dijunkun
2024-06-27 17:36:13 +08:00
parent 8076e7f662
commit ad6f2c2c70
14 changed files with 40847 additions and 132 deletions

View File

@@ -1,4 +1,4 @@
/*
/*
* @Author: DI JUNKUN
* @Date: 2024-05-29
* Copyright (c) 2024 by DI JUNKUN, All Rights Reserved.
@@ -10,38 +10,40 @@
#include <vector>
namespace localization {
static std::vector<std::string> tabbar = {u8"菜单", "Menu"};
static std::vector<std::string> menu = {u8"菜单", "Menu"};
static std::vector<std::string> local_id = {u8"本机ID", "Local ID"};
static std::vector<std::string> password = {u8"密码", "Password"};
static std::vector<std::string> max_password_len = {u8"最大6个字符",
static std::vector<std::string> local_desktop = {u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Local Desktop"};
static std::vector<std::string> local_id = {u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID", "Local ID"};
static std::vector<std::string> password = {u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Password"};
static std::vector<std::string> max_password_len = {u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>6<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>",
"Max 6 chars"};
static std::vector<std::string> remote_id = {u8"对端ID", "Remote ID"};
static std::vector<std::string> connect = {u8"连接", "Connect"};
static std::vector<std::string> disconnect = {u8"断开连接", "Disconnect"};
static std::vector<std::string> fullscreen = {u8" 全屏", " Fullscreen"};
static std::vector<std::string> exit_fullscreen = {u8" 退出全屏",
static std::vector<std::string> remote_desktop = {u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"Control Remote Desktop"};
static std::vector<std::string> remote_id = {u8"<EFBFBD>Զ<EFBFBD>ID", "Remote ID"};
static std::vector<std::string> connect = {u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Connect"};
static std::vector<std::string> disconnect = {u8"<EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Disconnect"};
static std::vector<std::string> fullscreen = {u8" ȫ<><C8AB>", " Fullscreen"};
static std::vector<std::string> exit_fullscreen = {u8" <20>˳<EFBFBD>ȫ<EFBFBD><C8AB>",
" Exit fullscreen"};
static std::vector<std::string> control_mouse = {u8" 控制", " Control"};
static std::vector<std::string> release_mouse = {u8" 释放", " Release"};
static std::vector<std::string> settings = {u8" 设置", " Settings"};
static std::vector<std::string> language = {u8"语言:", "Language:"};
static std::vector<std::string> language_zh = {u8"中文", "Chinese"};
static std::vector<std::string> language_en = {u8"英文", "English"};
static std::vector<std::string> video_quality = {u8"视频质量:",
static std::vector<std::string> control_mouse = {u8" <EFBFBD><EFBFBD><EFBFBD><EFBFBD>", " Control"};
static std::vector<std::string> release_mouse = {u8" <EFBFBD>ͷ<EFBFBD>", " Release"};
static std::vector<std::string> settings = {u8" <EFBFBD><EFBFBD><EFBFBD><EFBFBD>", " Settings"};
static std::vector<std::string> language = {u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:", "Language:"};
static std::vector<std::string> language_zh = {u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Chinese"};
static std::vector<std::string> language_en = {u8"Ӣ<EFBFBD><EFBFBD>", "English"};
static std::vector<std::string> video_quality = {u8"<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:",
"Video Quality:"};
static std::vector<std::string> video_quality_high = {u8"", "High"};
static std::vector<std::string> video_quality_medium = {u8"", "Medium"};
static std::vector<std::string> video_quality_low = {u8"", "Low"};
static std::vector<std::string> video_encode_format = {u8"视频编码格式:",
static std::vector<std::string> video_quality_high = {u8"<EFBFBD><EFBFBD>", "High"};
static std::vector<std::string> video_quality_medium = {u8"<EFBFBD><EFBFBD>", "Medium"};
static std::vector<std::string> video_quality_low = {u8"<EFBFBD><EFBFBD>", "Low"};
static std::vector<std::string> video_encode_format = {u8"<EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ:",
"Video Encode Format:"};
static std::vector<std::string> av1 = {u8"AV1", "AV1"};
static std::vector<std::string> h264 = {u8"H.264", "H.264"};
static std::vector<std::string> enable_hardware_video_codec = {
u8"启用硬件编解码器:", "Enable Hardware Video Codec:"};
u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:", "Enable Hardware Video Codec:"};
static std::vector<std::string> ok = {u8"确认", "OK"};
static std::vector<std::string> cancel = {u8"取消", "Cancel"};
static std::vector<std::string> ok = {u8"ȷ<EFBFBD><EFBFBD>", "OK"};
static std::vector<std::string> cancel = {u8"ȡ<EFBFBD><EFBFBD>", "Cancel"};
} // namespace localization

View File

@@ -1,3 +1,5 @@
#include "render.h"
#include <fstream>
#include <iostream>
#include <string>
@@ -7,7 +9,6 @@
#include "localization.h"
#include "log.h"
#include "platform.h"
#include "render.h"
#include "screen_capturer_factory.h"
// Refresh Event
@@ -338,14 +339,12 @@ int Render::Run() {
if (!connection_established_) {
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::Begin(localization::menu[localization_language_index_].c_str(),
nullptr,
ImGui::Begin("MainWindow", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove);
} else {
// ImGui::SetNextWindowCollapsed(true, ImGuiCond_Once);
ImGui::Begin(localization::menu[localization_language_index_].c_str(),
nullptr, ImGuiWindowFlags_None);
ImGui::Begin("MainWindow", nullptr, ImGuiWindowFlags_None);
}
{

View 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;
}

View 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;
}

View File

@@ -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;
}

View File

@@ -7,6 +7,8 @@ int Render::MainWindow() {
ImGui::Begin("Render", nullptr,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);
MenuWindow();
LocalWindow();
RemoteWindow();

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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_);

View File

@@ -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;

View File

@@ -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;
}