Add support for --screenrotate

This commit is contained in:
Tomas Jakobsson 2018-01-18 18:30:00 +01:00
parent d9ce6e8f6e
commit e2fc3b325c
4 changed files with 85 additions and 5 deletions

View file

@ -70,6 +70,17 @@ bool parseArgs(int argc, char* argv[])
i += 2; // skip the argument value i += 2; // skip the argument value
Settings::getInstance()->setInt("ScreenOffsetX", x); Settings::getInstance()->setInt("ScreenOffsetX", x);
Settings::getInstance()->setInt("ScreenOffsetY", y); Settings::getInstance()->setInt("ScreenOffsetY", y);
}else if (strcmp(argv[i], "--screenrotate") == 0)
{
if (i >= argc - 1)
{
std::cerr << "Invalid screenrotate supplied.";
return false;
}
int rotate = atoi(argv[i + 1]);
++i; // skip the argument value
Settings::getInstance()->setInt("ScreenRotate", rotate);
}else if(strcmp(argv[i], "--gamelist-only") == 0) }else if(strcmp(argv[i], "--gamelist-only") == 0)
{ {
Settings::getInstance()->setBool("ParseGamelistOnly", true); Settings::getInstance()->setBool("ParseGamelistOnly", true);

View file

@ -24,6 +24,7 @@ namespace Renderer
unsigned int getScreenHeight(); unsigned int getScreenHeight();
unsigned int getScreenOffsetX(); unsigned int getScreenOffsetX();
unsigned int getScreenOffsetY(); unsigned int getScreenOffsetY();
unsigned int getScreenRotate();
void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount); void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount);

View file

@ -69,7 +69,13 @@ namespace Renderer {
box.h = 0; box.h = 0;
clipStack.push(box); clipStack.push(box);
glScissor(box.x, box.y, box.w, box.h); switch(Renderer::getScreenRotate())
{
case 0: { glScissor(box.x, box.y, box.w, box.h); } break;
case 1: { glScissor(box.y, Renderer::getScreenWidth() - box.x - box.w, box.h, box.w); } break;
case 2: { glScissor(Renderer::getScreenWidth() - box.x - box.w, Renderer::getScreenHeight() - box.y - box.h, box.w, box.h); } break;
case 3: { glScissor(Renderer::getScreenHeight() - box.y - box.h, box.x, box.h, box.w); } break;
}
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
} }
@ -87,7 +93,13 @@ namespace Renderer {
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
}else{ }else{
const ClipRect& top = clipStack.top(); const ClipRect& top = clipStack.top();
glScissor(top.x, top.y, top.w, top.h); switch(Renderer::getScreenRotate())
{
case 0: { glScissor(top.x, top.y, top.w, top.h); } break;
case 1: { glScissor(top.y, Renderer::getScreenWidth() - top.x - top.w, top.h, top.w); } break;
case 2: { glScissor(Renderer::getScreenWidth() - top.x - top.w, Renderer::getScreenHeight() - top.y - top.h, top.w, top.h); } break;
case 3: { glScissor(Renderer::getScreenHeight() - top.y - top.h, top.x, top.h, top.w); } break;
}
} }
} }

View file

@ -20,6 +20,7 @@ namespace Renderer
unsigned int screenHeight = 0; unsigned int screenHeight = 0;
unsigned int screenOffsetX = 0; unsigned int screenOffsetX = 0;
unsigned int screenOffsetY = 0; unsigned int screenOffsetY = 0;
unsigned int screenRotate = 0;
unsigned int getWindowWidth() { return windowWidth; } unsigned int getWindowWidth() { return windowWidth; }
unsigned int getWindowHeight() { return windowHeight; } unsigned int getWindowHeight() { return windowHeight; }
@ -27,6 +28,7 @@ namespace Renderer
unsigned int getScreenHeight() { return screenHeight; } unsigned int getScreenHeight() { return screenHeight; }
unsigned int getScreenOffsetX() { return screenOffsetX; } unsigned int getScreenOffsetX() { return screenOffsetX; }
unsigned int getScreenOffsetY() { return screenOffsetY; } unsigned int getScreenOffsetY() { return screenOffsetY; }
unsigned int getScreenRotate() { return screenRotate; }
SDL_Window* sdlWindow = NULL; SDL_Window* sdlWindow = NULL;
SDL_GLContext sdlContext = NULL; SDL_GLContext sdlContext = NULL;
@ -66,6 +68,7 @@ namespace Renderer
screenHeight = Settings::getInstance()->getInt("ScreenHeight") ? Settings::getInstance()->getInt("ScreenHeight") : windowHeight; screenHeight = Settings::getInstance()->getInt("ScreenHeight") ? Settings::getInstance()->getInt("ScreenHeight") : windowHeight;
screenOffsetX = Settings::getInstance()->getInt("ScreenOffsetX") ? Settings::getInstance()->getInt("ScreenOffsetX") : 0; screenOffsetX = Settings::getInstance()->getInt("ScreenOffsetX") ? Settings::getInstance()->getInt("ScreenOffsetX") : 0;
screenOffsetY = Settings::getInstance()->getInt("ScreenOffsetY") ? Settings::getInstance()->getInt("ScreenOffsetY") : 0; screenOffsetY = Settings::getInstance()->getInt("ScreenOffsetY") ? Settings::getInstance()->getInt("ScreenOffsetY") : 0;
screenRotate = Settings::getInstance()->getInt("ScreenRotate") ? Settings::getInstance()->getInt("ScreenRotate") : 0;
sdlWindow = SDL_CreateWindow("EmulationStation", sdlWindow = SDL_CreateWindow("EmulationStation",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
@ -80,6 +83,21 @@ namespace Renderer
LOG(LogInfo) << "Created window successfully."; LOG(LogInfo) << "Created window successfully.";
//support screen rotation
if((screenRotate == 1) || (screenRotate == 3))
{
int temp;
temp = windowWidth;
windowWidth = windowHeight;
windowHeight = temp;
temp = screenWidth;
screenWidth = screenHeight;
screenHeight = temp;
temp = screenOffsetX;
screenOffsetX = screenOffsetY;
screenOffsetY = temp;
}
//set an icon for the window //set an icon for the window
size_t width = 0; size_t width = 0;
size_t height = 0; size_t height = 0;
@ -143,9 +161,47 @@ namespace Renderer
return false; return false;
//gotta flip y since y=0 is at the bottom //gotta flip y since y=0 is at the bottom
switch(screenRotate)
{
case 0:
{
glViewport(screenOffsetX, windowHeight - screenHeight - screenOffsetY, screenWidth, screenHeight); glViewport(screenOffsetX, windowHeight - screenHeight - screenOffsetY, screenWidth, screenHeight);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glOrtho(0, screenWidth, screenHeight, 0, -1.0, 1.0); glOrtho(0, screenWidth, screenHeight, 0, -1.0, 1.0);
}
break;
case 1:
{
glViewport(screenOffsetY, windowWidth - screenWidth - screenOffsetX, screenHeight, screenWidth);
glMatrixMode(GL_PROJECTION);
glOrtho(0, screenHeight, screenWidth, 0, -1.0, 1.0);
glRotatef(90, 0, 0, 1);
glTranslatef(0, screenHeight * -1.0f, 0);
}
break;
case 2:
{
glViewport(screenOffsetX, windowHeight - screenHeight - screenOffsetY, screenWidth, screenHeight);
glMatrixMode(GL_PROJECTION);
glOrtho(0, screenWidth, screenHeight, 0, -1.0, 1.0);
glRotatef(180, 0, 0, 1);
glTranslatef(screenWidth * -1.0f, screenHeight * -1.0f, 0);
}
break;
case 3:
{
glViewport(screenOffsetY, windowWidth - screenWidth - screenOffsetX, screenHeight, screenWidth);
glMatrixMode(GL_PROJECTION);
glOrtho(0, screenHeight, screenWidth, 0, -1.0, 1.0);
glRotatef(270, 0, 0, 1);
glTranslatef(screenWidth * -1.0f, 0, 0);
}
break;
}
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);