From da58a8f5c5c8e8364cb97fa8203d51811038f42f Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Wed, 9 Feb 2022 16:37:05 -0300 Subject: [PATCH 1/4] Added docked mode or handheld mode detector. Added docked mode or handheld mode detector. --- .vscode/settings.json | 11 ++++++++++- include/gui.h | 2 +- source/gui.cpp | 9 +++++++++ source/main.cpp | 28 +++++++++++++++++++++++++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cefb299..4d3ff03 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,15 @@ { "files.associations": { "xstring": "cpp", - "string": "cpp" + "string": "cpp", + "array": "cpp", + "format": "cpp", + "initializer_list": "cpp", + "list": "cpp", + "regex": "cpp", + "type_traits": "cpp", + "vector": "cpp", + "xtree": "cpp", + "xutility": "cpp" } } \ No newline at end of file diff --git a/include/gui.h b/include/gui.h index ac27c27..910ac60 100644 --- a/include/gui.h +++ b/include/gui.h @@ -214,7 +214,7 @@ extern USBMounter *usbmounter; #ifdef NXMP_ENIGMASUPPORT extern Enigma2 *enigma2; #endif - +extern bool isHandheld; extern uint32_t wakeup_on_mpv_render_update; extern uint32_t wakeup_on_mpv_events; diff --git a/source/gui.cpp b/source/gui.cpp index ab35d09..8cd557b 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -991,6 +991,15 @@ namespace GUI { changeFontTheme(); dochangethemefont = false; } + + #ifdef NXMP_SWITCH + //get if console is docked + AppletOperationMode stus=appletGetOperationMode(); + if (stus == AppletOperationMode_Handheld) + {isHandheld=true;} + if (stus == AppletOperationMode_Console) + {isHandheld=false;} + #endif } diff --git a/source/main.cpp b/source/main.cpp index e019b42..b6710f4 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -46,6 +46,11 @@ using namespace c2d; #endif +#define handheldWidth 1280 +#define handheldHeight 720 +#define dockedWidth 1920 +#define dockedHeight 1080 + static bool init(); SDL_Window *window; @@ -103,9 +108,11 @@ float themefontsmall; ImFont* fontSmall; +bool isHandheld=true; + shaderMania* shadermania = nullptr; -const GLuint WIDTH = 1280, HEIGHT = 720; +GLuint WIDTH = handheldWidth, HEIGHT = handheldWidth; std::string nxmpTitle = std::string("NXMP v") + std::to_string(VERSION_MAJOR) + std::string(".") + std::to_string(VERSION_MINOR) + std::string(".") + std::to_string(VERSION_MICRO); @@ -142,7 +149,19 @@ void deinitTextures(){ static bool init() { - bool success = true; + #ifdef NXMP_SWITCH + //get if console is docked + AppletOperationMode stus=appletGetOperationMode(); + if (stus == AppletOperationMode_Handheld) + {printf("Handheld Mode\n"); + isHandheld=true;} + if (stus == AppletOperationMode_Console) + {printf("Docked Mode\n"); + isHandheld=false;} + #endif + + + bool success = true; SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "no"); if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0 ){ @@ -154,7 +173,10 @@ static bool init() { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - + if (isHandheld == true) + {WIDTH = handheldWidth; HEIGHT = handheldHeight;} + else + {WIDTH = dockedWidth; HEIGHT = dockedHeight;} window = SDL_CreateWindow( "[glad] GL with SDL", SDL_WINDOWPOS_CENTERED, From 4d53444d40cb42181be43379a79574de4a3e6f94 Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Wed, 9 Feb 2022 16:45:14 -0300 Subject: [PATCH 2/4] Rewrite state of Switch --- source/gui.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/gui.cpp b/source/gui.cpp index 8cd557b..38cd864 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -993,12 +993,20 @@ namespace GUI { } #ifdef NXMP_SWITCH - //get if console is docked + //rewrite switch state AppletOperationMode stus=appletGetOperationMode(); if (stus == AppletOperationMode_Handheld) - {isHandheld=true;} + { + if (isHandheld == false) + {isHandheld=true; + printf("changed to Handheld Mode.\n"); + } + } if (stus == AppletOperationMode_Console) - {isHandheld=false;} + { if (isHandheld == true) + {isHandheld=false; + printf("changed to Docked Mode.\n");} + } #endif } From f39800ca9152ecef7ae46eebbfe55943c341c5ce Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Wed, 9 Feb 2022 16:51:07 -0300 Subject: [PATCH 3/4] Window Size Changer --- include/gui.h | 4 ++++ source/gui.cpp | 5 ++++- source/main.cpp | 5 ----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/gui.h b/include/gui.h index 910ac60..57d8cc8 100644 --- a/include/gui.h +++ b/include/gui.h @@ -46,6 +46,10 @@ #include "shaderMania.h" #include "themes.h" +#define handheldWidth 1280 +#define handheldHeight 720 +#define dockedWidth 1920 +#define dockedHeight 1080 enum MENU_STATES { MENU_STATE_HOME, diff --git a/source/gui.cpp b/source/gui.cpp index 38cd864..b77e5c9 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -1000,12 +1000,15 @@ namespace GUI { if (isHandheld == false) {isHandheld=true; printf("changed to Handheld Mode.\n"); + SDL_SetWindowSize(window, handheldWidth, handheldHeight); } } if (stus == AppletOperationMode_Console) { if (isHandheld == true) {isHandheld=false; - printf("changed to Docked Mode.\n");} + printf("changed to Docked Mode.\n"); + SDL_SetWindowSize(window, dockedWidth, dockedHeight); + } } #endif diff --git a/source/main.cpp b/source/main.cpp index b6710f4..dad45fe 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -46,11 +46,6 @@ using namespace c2d; #endif -#define handheldWidth 1280 -#define handheldHeight 720 -#define dockedWidth 1920 -#define dockedHeight 1080 - static bool init(); SDL_Window *window; From 4c7faae832aa27a5ac72756f3e96dd8bb59e49ba Mon Sep 17 00:00:00 2001 From: Angel Xex Date: Wed, 9 Feb 2022 18:46:17 -0300 Subject: [PATCH 4/4] NXMP Docked Mode (1080p) Work in progress --- include/apppopups.h | 7 ++++++- include/appwindows.h | 8 ++++++-- include/gui.h | 5 ++++- include/playerwindows.h | 24 +++++++++++++++--------- source/UI/playerWindows.cpp | 14 +++++++------- source/gui.cpp | 10 ++++++++-- source/main.cpp | 22 +++++++++++++++------- 7 files changed, 61 insertions(+), 29 deletions(-) diff --git a/include/apppopups.h b/include/apppopups.h index 5127999..f8de677 100644 --- a/include/apppopups.h +++ b/include/apppopups.h @@ -3,11 +3,16 @@ #include "imgui.h" +extern int newResW; +extern int newResH; +extern float multiplyRes; +extern bool isHandheld; + namespace Popups { inline void SetupPopup(const char *id) { ImGui::OpenPopup(id); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15)); - ImGui::SetNextWindowPos(ImVec2(640.0f, 360.0f), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + ImGui::SetNextWindowPos(ImVec2(640.0f*multiplyRes, 360.0f*multiplyRes), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); }; inline void ExitPopup(void) { diff --git a/include/appwindows.h b/include/appwindows.h index 930ec7c..7516a89 100644 --- a/include/appwindows.h +++ b/include/appwindows.h @@ -4,18 +4,22 @@ #include "imgui.h" #include "platforms.h" +extern int newResW; +extern int newResH; +extern float multiplyRes; +extern bool isHandheld; namespace Windows { inline void SetupMainWindow(void) { ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f), ImGuiCond_Once); - ImGui::SetNextWindowSize(ImVec2(1280.0f, 720.0f), ImGuiCond_Once); + ImGui::SetNextWindowSize(ImVec2(1280.0f*multiplyRes, 720.0f*multiplyRes), ImGuiCond_Once); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); }; inline void SetupWindow(void) { ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f), ImGuiCond_Once); - ImGui::SetNextWindowSize(ImVec2(1280.0f, 720.0f), ImGuiCond_Once); + ImGui::SetNextWindowSize(ImVec2(1280.0f*multiplyRes, 720.0f*multiplyRes), ImGuiCond_Once); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); }; diff --git a/include/gui.h b/include/gui.h index 57d8cc8..4e8f9f8 100644 --- a/include/gui.h +++ b/include/gui.h @@ -218,7 +218,6 @@ extern USBMounter *usbmounter; #ifdef NXMP_ENIGMASUPPORT extern Enigma2 *enigma2; #endif -extern bool isHandheld; extern uint32_t wakeup_on_mpv_render_update; extern uint32_t wakeup_on_mpv_events; @@ -240,6 +239,10 @@ extern Playlist *playlist; extern SysIcons nxmpicons; +extern int newResW; +extern int newResH; +extern float multiplyRes; +extern bool isHandheld; /* extern Tex SdCardTexture; extern Tex UsbTexture; diff --git a/include/playerwindows.h b/include/playerwindows.h index 2c9ad10..cdf14c5 100644 --- a/include/playerwindows.h +++ b/include/playerwindows.h @@ -4,19 +4,22 @@ #include "imgui.h" #include "gui.h" - +extern int newResW; +extern int newResH; +extern float multiplyRes; +extern bool isHandheld; namespace playerWindows{ inline void SetupCacheWindow(void){ - ImGui::SetNextWindowPos(ImVec2(10.0f, 600.0f), ImGuiCond_Once); - ImGui::SetNextWindowSize(ImVec2(250.0f, 80.0f), ImGuiCond_Once); + ImGui::SetNextWindowPos(ImVec2(10.0f*multiplyRes, 600.0f*multiplyRes), ImGuiCond_Once); + ImGui::SetNextWindowSize(ImVec2(250.0f*multiplyRes, 80.0f*multiplyRes), ImGuiCond_Once); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); } inline void SetupVolumeWindow(void){ - ImGui::SetNextWindowPos(ImVec2(10.0f, 10.0f), ImGuiCond_Once); - ImGui::SetNextWindowSize(ImVec2(200.0f, 50.0f), ImGuiCond_Once); + ImGui::SetNextWindowPos(ImVec2(10.0f*multiplyRes, 10.0f*multiplyRes), ImGuiCond_Once); + ImGui::SetNextWindowSize(ImVec2(200.0f*multiplyRes, 50.0f*multiplyRes), ImGuiCond_Once); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); @@ -24,8 +27,11 @@ namespace playerWindows{ static float rightmenuposX = 1280.0f; inline void SetupRightWindow(void) { + if(isHandheld == true) ImGui::SetNextWindowPos(ImVec2(rightmenuposX, 0.0f), ImGuiCond_Always); - ImGui::SetNextWindowSize(ImVec2(200.0f, 720.0f), ImGuiCond_Once); + else + ImGui::SetNextWindowPos(ImVec2((rightmenuposX*multiplyRes)+100, 0.0f), ImGuiCond_Always); + ImGui::SetNextWindowSize(ImVec2(200.0f, 720.0f*multiplyRes), ImGuiCond_Once); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); @@ -41,14 +47,14 @@ namespace playerWindows{ inline void SetupAudioPlayerWindow(void) { ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f), ImGuiCond_Once); - ImGui::SetNextWindowSize(ImVec2(1280.0f, 720.0f), ImGuiCond_Once); + ImGui::SetNextWindowSize(ImVec2(1280.0f*multiplyRes, 720.0f*multiplyRes), ImGuiCond_Once); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); }; inline void SetupPlayerControlsWindow(void) { - ImGui::SetNextWindowPos(ImVec2(0.0f, 620.0f), ImGuiCond_Once); - ImGui::SetNextWindowSize(ImVec2(1280.0f, 720.0f), ImGuiCond_Once); + ImGui::SetNextWindowPos(ImVec2(0.0f, 620.0f*multiplyRes), ImGuiCond_Once); + ImGui::SetNextWindowSize(ImVec2(1280.0f*multiplyRes, 720.0f*multiplyRes), ImGuiCond_Once); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0,0.0,0.0,0.5)); diff --git a/source/UI/playerWindows.cpp b/source/UI/playerWindows.cpp index 55722b1..a235b72 100644 --- a/source/UI/playerWindows.cpp +++ b/source/UI/playerWindows.cpp @@ -58,7 +58,7 @@ namespace playerWindows{ std::vector topmenu = {"Tracks","Chapters","Aspect Ratio","Image","Audio","Subtitle","ShaderMania"}; if (ImGui::Begin("Right Menu Home", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { ImGui::SetNextWindowFocus(); - if (ImGui::BeginListBox("Right Menu Home List",ImVec2(1280.0f, 720.0f))){ + if (ImGui::BeginListBox("Right Menu Home List",ImVec2(1280.0f*multiplyRes, 720.0f*multiplyRes))){ for (unsigned int n = 0; n < topmenu.size(); n++){ static int selected = -1; if (ImGui::Selectable(topmenu[n].c_str(), selected == n)){ @@ -103,7 +103,7 @@ namespace playerWindows{ std::vector topmenu = {"Video","Audio","Sub"}; if (ImGui::Begin("Right Menu Tracks", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { ImGui::SetNextWindowFocus(); - if (ImGui::BeginListBox("Tracks Menu",ImVec2(1280.0f, 720.0f))){ + if (ImGui::BeginListBox("Tracks Menu",ImVec2(1280.0f*multiplyRes, 720.0f*multiplyRes))){ for (unsigned int n = 0; n < topmenu.size(); n++){ static int selected = -1; if (ImGui::Selectable(topmenu[n].c_str(), selected == n)){ @@ -132,7 +132,7 @@ namespace playerWindows{ playerWindows::SetupRightWindow(); if (ImGui::Begin("Right Menu Tracks Video", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { ImGui::SetNextWindowFocus(); - if (ImGui::BeginListBox("Video Tracks Menu",ImVec2(1280.0f, 720.0f))){ + if (ImGui::BeginListBox("Video Tracks Menu",ImVec2(1280.0f*multiplyRes, 720.0f*multiplyRes))){ if(libmpv->getFileInfo() != nullptr){ for (unsigned int n = 0; n < libmpv->getFileInfo()->videos.size(); n++){ static int selected = -1; @@ -160,7 +160,7 @@ namespace playerWindows{ playerWindows::SetupRightWindow(); if (ImGui::Begin("Right Menu Tracks Audio", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { ImGui::SetNextWindowFocus(); - if (ImGui::BeginListBox("Audio Tracks Menu",ImVec2(200.0f, 720.0f))){ + if (ImGui::BeginListBox("Audio Tracks Menu",ImVec2(200.0f, 720.0f*multiplyRes))){ if(libmpv->getFileInfo() != nullptr){ for (unsigned int n = 0; n < libmpv->getFileInfo()->audios.size(); n++){ std::string itemid = "##" + std::to_string(n); @@ -195,7 +195,7 @@ namespace playerWindows{ playerWindows::SetupRightWindow(); if (ImGui::Begin("Right Menu Tracks Subs", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { ImGui::SetNextWindowFocus(); - if (ImGui::BeginListBox("Sub Tracks Menu",ImVec2(200.0f, 720.0f))){ + if (ImGui::BeginListBox("Sub Tracks Menu",ImVec2(200.0f, 720.0f*multiplyRes))){ if(libmpv->getFileInfo() != nullptr){ for (unsigned int n = 0; n < libmpv->getFileInfo()->subtitles.size(); n++){ static int selected = -1; @@ -231,7 +231,7 @@ namespace playerWindows{ std::vector topmenu = {"Video","Audio","Sub"}; if (ImGui::Begin("Right Menu Chapters", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { ImGui::SetNextWindowFocus(); - if (ImGui::BeginListBox("Chapter Menu",ImVec2(200.0f, 720.0f))){ + if (ImGui::BeginListBox("Chapter Menu",ImVec2(200.0f, 720.0f*multiplyRes))){ if(libmpv->getFileInfo() != nullptr){ for (unsigned int n = 0; n < libmpv->getFileInfo()->chapters.size(); n++){ static int selected = -1; @@ -333,7 +333,7 @@ namespace playerWindows{ std::vector topmenu = {"Default","16:9","16:10","4:3","Custom Ratio"}; if (ImGui::Begin("Right Menu ARatio", nullptr, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar)) { ImGui::SetNextWindowFocus(); - if (ImGui::BeginListBox("Aspect Ratio",ImVec2(200.0f, 720.0f))){ + if (ImGui::BeginListBox("Aspect Ratio",ImVec2(200.0f, 720.0f*multiplyRes))){ for (unsigned int n = 0; n < topmenu.size(); n++){ static int selected = -1; if (ImGui::Selectable(topmenu[n].c_str(), selected == n)){ diff --git a/source/gui.cpp b/source/gui.cpp index b77e5c9..7584e57 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -1000,14 +1000,20 @@ namespace GUI { if (isHandheld == false) {isHandheld=true; printf("changed to Handheld Mode.\n"); - SDL_SetWindowSize(window, handheldWidth, handheldHeight); + newResW = handheldWidth; + newResH = handheldHeight; + multiplyRes = 1.0f; + SDL_SetWindowSize(window, newResW, newResH); } } if (stus == AppletOperationMode_Console) { if (isHandheld == true) {isHandheld=false; printf("changed to Docked Mode.\n"); - SDL_SetWindowSize(window, dockedWidth, dockedHeight); + newResW = dockedWidth; + newResH = dockedHeight; + multiplyRes = 1.5f; + SDL_SetWindowSize(window, newResW, newResH); } } #endif diff --git a/source/main.cpp b/source/main.cpp index dad45fe..40edb93 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -104,7 +104,9 @@ float themefontsmall; ImFont* fontSmall; bool isHandheld=true; - +int newResW = 1280; +int newResH = 720; +float multiplyRes = 1.0f; shaderMania* shadermania = nullptr; GLuint WIDTH = handheldWidth, HEIGHT = handheldWidth; @@ -149,10 +151,18 @@ static bool init() { AppletOperationMode stus=appletGetOperationMode(); if (stus == AppletOperationMode_Handheld) {printf("Handheld Mode\n"); - isHandheld=true;} + isHandheld=true; + newResW = handheldWidth; + newResH = handheldHeight; + multiplyRes = 1.0f; + } if (stus == AppletOperationMode_Console) {printf("Docked Mode\n"); - isHandheld=false;} + isHandheld=false; + newResW = dockedWidth; + newResH = dockedHeight; + multiplyRes = 1.5f; + } #endif @@ -168,10 +178,8 @@ static bool init() { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - if (isHandheld == true) - {WIDTH = handheldWidth; HEIGHT = handheldHeight;} - else - {WIDTH = dockedWidth; HEIGHT = dockedHeight;} + + WIDTH = newResW; HEIGHT = newResH; window = SDL_CreateWindow( "[glad] GL with SDL", SDL_WINDOWPOS_CENTERED,