diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 16301cd88..62321c749 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -29,7 +29,7 @@ namespace fs = boost::filesystem; bool scrape_cmdline = false; -bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height) +bool parseArgs(int argc, char* argv[]) { for(int i = 1; i < argc; i++) { @@ -41,9 +41,37 @@ bool parseArgs(int argc, char* argv[], unsigned int* width, unsigned int* height return false; } - *width = atoi(argv[i + 1]); - *height = atoi(argv[i + 2]); + int width = atoi(argv[i + 1]); + int height = atoi(argv[i + 2]); i += 2; // skip the argument value + Settings::getInstance()->setInt("WindowWidth", width); + Settings::getInstance()->setInt("WindowHeight", height); + }else if(strcmp(argv[i], "--screensize") == 0) + { + if(i >= argc - 2) + { + std::cerr << "Invalid screensize supplied."; + return false; + } + + int width = atoi(argv[i + 1]); + int height = atoi(argv[i + 2]); + i += 2; // skip the argument value + Settings::getInstance()->setInt("ScreenWidth", width); + Settings::getInstance()->setInt("ScreenHeight", height); + }else if(strcmp(argv[i], "--screenoffset") == 0) + { + if(i >= argc - 2) + { + std::cerr << "Invalid screenoffset supplied."; + return false; + } + + int x = atoi(argv[i + 1]); + int y = atoi(argv[i + 2]); + i += 2; // skip the argument value + Settings::getInstance()->setInt("ScreenOffsetX", x); + Settings::getInstance()->setInt("ScreenOffsetY", y); }else if(strcmp(argv[i], "--gamelist-only") == 0) { Settings::getInstance()->setBool("ParseGamelistOnly", true); @@ -182,13 +210,10 @@ int main(int argc, char* argv[]) { srand((unsigned int)time(NULL)); - unsigned int width = 0; - unsigned int height = 0; - std::locale::global(std::locale("C")); boost::filesystem::path::imbue(std::locale()); - if(!parseArgs(argc, argv, &width, &height)) + if(!parseArgs(argc, argv)) return 0; // only show the console on Windows if HideConsole is false @@ -250,7 +275,7 @@ int main(int argc, char* argv[]) if(!scrape_cmdline) { - if(!window.init(width, height)) + if(!window.init()) { LOG(LogError) << "Window failed to initialize!"; return 1; diff --git a/es-core/src/Renderer.h b/es-core/src/Renderer.h index 3a84ba360..6114163d6 100644 --- a/es-core/src/Renderer.h +++ b/es-core/src/Renderer.h @@ -15,11 +15,15 @@ class Transform4x4f; //Renderer_init_*.cpp has platform-specific renderer initialziation/deinitialziation code. (e.g. the Raspberry Pi sets up dispmanx/OpenGL ES) namespace Renderer { - bool init(int w, int h); + bool init(); void deinit(); + unsigned int getWindowWidth(); + unsigned int getWindowHeight(); unsigned int getScreenWidth(); unsigned int getScreenHeight(); + unsigned int getScreenOffsetX(); + unsigned int getScreenOffsetY(); void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount); diff --git a/es-core/src/Renderer_draw_gl.cpp b/es-core/src/Renderer_draw_gl.cpp index bbadb841e..9ed671a2b 100644 --- a/es-core/src/Renderer_draw_gl.cpp +++ b/es-core/src/Renderer_draw_gl.cpp @@ -45,8 +45,9 @@ namespace Renderer { //glScissor starts at the bottom left of the window //so (0, 0, 1, 1) is the bottom left pixel //everything else uses y+ = down, so flip it to be consistent - //rect.pos.y = Renderer::getScreenHeight() - rect.pos.y - rect.size.y; - box.y = Renderer::getScreenHeight() - box.y - box.h; + //also take screen height and offset into account + box.x = Renderer::getScreenOffsetX() + box.x; + box.y = Renderer::getWindowHeight() - Renderer::getScreenOffsetY() - box.y - box.h; //make sure the box fits within clipStack.top(), and clip further accordingly if(clipStack.size()) diff --git a/es-core/src/Renderer_init_sdlgl.cpp b/es-core/src/Renderer_init_sdlgl.cpp index 328267c95..b8fb9136e 100644 --- a/es-core/src/Renderer_init_sdlgl.cpp +++ b/es-core/src/Renderer_init_sdlgl.cpp @@ -14,11 +14,19 @@ namespace Renderer { static bool initialCursorState; - unsigned int display_width = 0; - unsigned int display_height = 0; + unsigned int windowWidth = 0; + unsigned int windowHeight = 0; + unsigned int screenWidth = 0; + unsigned int screenHeight = 0; + unsigned int screenOffsetX = 0; + unsigned int screenOffsetY = 0; - unsigned int getScreenWidth() { return display_width; } - unsigned int getScreenHeight() { return display_height; } + unsigned int getWindowWidth() { return windowWidth; } + unsigned int getWindowHeight() { return windowHeight; } + unsigned int getScreenWidth() { return screenWidth; } + unsigned int getScreenHeight() { return screenHeight; } + unsigned int getScreenOffsetX() { return screenOffsetX; } + unsigned int getScreenOffsetY() { return screenOffsetY; } SDL_Window* sdlWindow = NULL; SDL_GLContext sdlContext = NULL; @@ -52,14 +60,16 @@ namespace Renderer SDL_DisplayMode dispMode; SDL_GetDesktopDisplayMode(0, &dispMode); - if(display_width == 0) - display_width = dispMode.w; - if(display_height == 0) - display_height = dispMode.h; + windowWidth = Settings::getInstance()->getInt("WindowWidth") ? Settings::getInstance()->getInt("WindowWidth") : dispMode.w; + windowHeight = Settings::getInstance()->getInt("WindowHeight") ? Settings::getInstance()->getInt("WindowHeight") : dispMode.h; + screenWidth = Settings::getInstance()->getInt("ScreenWidth") ? Settings::getInstance()->getInt("ScreenWidth") : windowWidth; + screenHeight = Settings::getInstance()->getInt("ScreenHeight") ? Settings::getInstance()->getInt("ScreenHeight") : windowHeight; + screenOffsetX = Settings::getInstance()->getInt("ScreenOffsetX") ? Settings::getInstance()->getInt("ScreenOffsetX") : 0; + screenOffsetY = Settings::getInstance()->getInt("ScreenOffsetY") ? Settings::getInstance()->getInt("ScreenOffsetY") : 0; sdlWindow = SDL_CreateWindow("EmulationStation", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - display_width, display_height, + windowWidth, windowHeight, SDL_WINDOW_OPENGL | (Settings::getInstance()->getBool("Windowed") ? 0 : SDL_WINDOW_FULLSCREEN)); if(sdlWindow == NULL) @@ -113,12 +123,6 @@ namespace Renderer return true; } - void swapBuffers() - { - SDL_GL_SwapWindow(sdlWindow); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - } - void destroySurface() { SDL_GL_DeleteContext(sdlContext); @@ -133,22 +137,15 @@ namespace Renderer SDL_Quit(); } - bool init(int w, int h) + bool init() { - if(w) - display_width = w; - if(h) - display_height = h; - - bool createdSurface = createSurface(); - - if(!createdSurface) + if(!createSurface()) return false; - glViewport(0, 0, display_width, display_height); - + //gotta flip y since y=0 is at the bottom + glViewport(screenOffsetX, windowHeight - screenHeight - screenOffsetY, screenWidth, screenHeight); glMatrixMode(GL_PROJECTION); - glOrtho(0, display_width, display_height, 0, -1.0, 1.0); + glOrtho(0, screenWidth, screenHeight, 0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); @@ -159,4 +156,10 @@ namespace Renderer { destroySurface(); } + + void swapBuffers() + { + SDL_GL_SwapWindow(sdlWindow); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } }; diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 42d138bfc..75bf095cd 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -20,7 +20,13 @@ std::vector settings_dont_save { { "ShowExit" }, { "SplashScreen" }, { "VSync" }, - { "Windowed" } + { "Windowed" }, + { "WindowWidth" }, + { "WindowHeight" }, + { "ScreenWidth" }, + { "ScreenHeight" }, + { "ScreenOffsetX" }, + { "ScreenOffsetY" } }; Settings::Settings() @@ -127,6 +133,13 @@ void Settings::setDefaults() mBoolMap["ForceKiosk"] = false; mBoolMap["ForceKid"] = false; mBoolMap["hideQuitMenuOnKidUI"] = false; + + mIntMap["WindowWidth"] = 0; + mIntMap["WindowHeight"] = 0; + mIntMap["ScreenWidth"] = 0; + mIntMap["ScreenHeight"] = 0; + mIntMap["ScreenOffsetX"] = 0; + mIntMap["ScreenOffsetY"] = 0; } template diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index a5a056f12..bc4267e8b 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -65,9 +65,9 @@ GuiComponent* Window::peekGui() return mGuiStack.back(); } -bool Window::init(unsigned int width, unsigned int height) +bool Window::init() { - if(!Renderer::init(width, height)) + if(!Renderer::init()) { LOG(LogError) << "Renderer failed to initialize!"; return false; diff --git a/es-core/src/Window.h b/es-core/src/Window.h index c14a28c4c..0cc6009d0 100644 --- a/es-core/src/Window.h +++ b/es-core/src/Window.h @@ -54,7 +54,7 @@ public: void update(int deltaTime); void render(); - bool init(unsigned int width = 0, unsigned int height = 0); + bool init(); void deinit(); void normalizeNextUpdate();