mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-17 22:55:38 +00:00
Merge pull request #348 from tomaz82/rotateScreen
Add support for --screenrotate
This commit is contained in:
commit
5f062ff9bc
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,21 @@ namespace Renderer {
|
||||||
//glScissor starts at the bottom left of the window
|
//glScissor starts at the bottom left of the window
|
||||||
//so (0, 0, 1, 1) is the bottom left pixel
|
//so (0, 0, 1, 1) is the bottom left pixel
|
||||||
//everything else uses y+ = down, so flip it to be consistent
|
//everything else uses y+ = down, so flip it to be consistent
|
||||||
//also take screen height and offset into account
|
switch(Renderer::getScreenRotate())
|
||||||
box.x = Renderer::getScreenOffsetX() + box.x;
|
{
|
||||||
box.y = Renderer::getWindowHeight() - Renderer::getScreenOffsetY() - box.y - box.h;
|
case 0: { box = ClipRect(box.x, Renderer::getWindowHeight() - (box.y + box.h), box.w, box.h); } break;
|
||||||
|
case 1: { box = ClipRect(Renderer::getScreenHeight() - (box.y + box.h), Renderer::getWindowWidth() - (box.x + box.w), box.h, box.w); } break;
|
||||||
|
case 2: { box = ClipRect(Renderer::getScreenWidth() - (box.x + box.w), Renderer::getWindowHeight() - Renderer::getScreenHeight() + box.y, box.w, box.h); } break;
|
||||||
|
case 3: { box = ClipRect(box.y, Renderer::getWindowWidth() - Renderer::getScreenWidth() + box.x, box.h, box.w); } break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(Renderer::getScreenRotate())
|
||||||
|
{
|
||||||
|
case 0: { box.x += Renderer::getScreenOffsetX(); box.y -= Renderer::getScreenOffsetY(); } break;
|
||||||
|
case 1: { box.x += Renderer::getScreenOffsetY(); box.y -= Renderer::getScreenOffsetX(); } break;
|
||||||
|
case 2: { box.x += Renderer::getScreenOffsetX(); box.y -= Renderer::getScreenOffsetY(); } break;
|
||||||
|
case 3: { box.x += Renderer::getScreenOffsetY(); box.y -= Renderer::getScreenOffsetX(); } break;
|
||||||
|
}
|
||||||
|
|
||||||
//make sure the box fits within clipStack.top(), and clip further accordingly
|
//make sure the box fits within clipStack.top(), and clip further accordingly
|
||||||
if(clipStack.size())
|
if(clipStack.size())
|
||||||
|
@ -69,6 +81,7 @@ namespace Renderer {
|
||||||
box.h = 0;
|
box.h = 0;
|
||||||
|
|
||||||
clipStack.push(box);
|
clipStack.push(box);
|
||||||
|
|
||||||
glScissor(box.x, box.y, box.w, box.h);
|
glScissor(box.x, box.y, box.w, box.h);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ std::vector<const char*> settings_dont_save {
|
||||||
{ "ScreenWidth" },
|
{ "ScreenWidth" },
|
||||||
{ "ScreenHeight" },
|
{ "ScreenHeight" },
|
||||||
{ "ScreenOffsetX" },
|
{ "ScreenOffsetX" },
|
||||||
{ "ScreenOffsetY" }
|
{ "ScreenOffsetY" },
|
||||||
|
{ "ScreenRotate" }
|
||||||
};
|
};
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
|
@ -140,6 +141,7 @@ void Settings::setDefaults()
|
||||||
mIntMap["ScreenHeight"] = 0;
|
mIntMap["ScreenHeight"] = 0;
|
||||||
mIntMap["ScreenOffsetX"] = 0;
|
mIntMap["ScreenOffsetX"] = 0;
|
||||||
mIntMap["ScreenOffsetY"] = 0;
|
mIntMap["ScreenOffsetY"] = 0;
|
||||||
|
mIntMap["ScreenRotate"] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "utils/StringUtil.h"
|
#include "utils/StringUtil.h"
|
||||||
#include "AudioManager.h"
|
#include "AudioManager.h"
|
||||||
|
#include "Renderer.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <wait.h>
|
#include <wait.h>
|
||||||
|
@ -93,14 +94,68 @@ void VideoPlayerComponent::startVideo()
|
||||||
|
|
||||||
// Find out the pixel position of the video view and build a command line for
|
// Find out the pixel position of the video view and build a command line for
|
||||||
// omxplayer to position it in the right place
|
// omxplayer to position it in the right place
|
||||||
char buf[32];
|
char buf1[32];
|
||||||
|
char buf2[32];
|
||||||
float x = mPosition.x() - (mOrigin.x() * mSize.x());
|
float x = mPosition.x() - (mOrigin.x() * mSize.x());
|
||||||
float y = mPosition.y() - (mOrigin.y() * mSize.y());
|
float y = mPosition.y() - (mOrigin.y() * mSize.y());
|
||||||
sprintf(buf, "%d,%d,%d,%d", (int)x, (int)y, (int)(x + mSize.x()), (int)(y + mSize.y()));
|
|
||||||
|
// fix x and y
|
||||||
|
switch(Renderer::getScreenRotate())
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
const int x1 = (int)(Renderer::getScreenOffsetX() + x);
|
||||||
|
const int y1 = (int)(Renderer::getScreenOffsetY() + y);
|
||||||
|
const int x2 = (int)(x1 + mSize.x());
|
||||||
|
const int y2 = (int)(y1 + mSize.y());
|
||||||
|
sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
const int x1 = (int)(Renderer::getScreenOffsetY() + Renderer::getScreenHeight() - y - mSize.y());
|
||||||
|
const int y1 = (int)(Renderer::getScreenOffsetX() + x);
|
||||||
|
const int x2 = (int)(x1 + mSize.y());
|
||||||
|
const int y2 = (int)(y1 + mSize.x());
|
||||||
|
sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
const int x1 = (int)(Renderer::getScreenOffsetX() + Renderer::getScreenWidth() - x - mSize.x());
|
||||||
|
const int y1 = (int)(Renderer::getScreenOffsetY() + Renderer::getScreenHeight() - y - mSize.y());
|
||||||
|
const int x2 = (int)(x1 + mSize.x());
|
||||||
|
const int y2 = (int)(y1 + mSize.y());
|
||||||
|
sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
const int x1 = (int)(Renderer::getScreenOffsetY() + y);
|
||||||
|
const int y1 = (int)(Renderer::getScreenOffsetX() + Renderer::getScreenWidth() - x - mSize.x());
|
||||||
|
const int x2 = (int)(x1 + mSize.y());
|
||||||
|
const int y2 = (int)(y1 + mSize.x());
|
||||||
|
sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// rotate the video
|
||||||
|
switch(Renderer::getScreenRotate())
|
||||||
|
{
|
||||||
|
case 0: { sprintf(buf2, "%d", (int) 0); } break;
|
||||||
|
case 1: { sprintf(buf2, "%d", (int) 90); } break;
|
||||||
|
case 2: { sprintf(buf2, "%d", (int)180); } break;
|
||||||
|
case 3: { sprintf(buf2, "%d", (int)270); } break;
|
||||||
|
}
|
||||||
|
|
||||||
// We need to specify the layer of 10000 or above to ensure the video is displayed on top
|
// We need to specify the layer of 10000 or above to ensure the video is displayed on top
|
||||||
// of our SDL display
|
// of our SDL display
|
||||||
|
|
||||||
const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "-o", "both","--win", buf, "--no-ghost-box", "", "", "", "", NULL };
|
const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "-o", "both","--win", buf1, "--orientation", buf2, "", "", "", "", NULL };
|
||||||
|
|
||||||
// check if we want to mute the audio
|
// check if we want to mute the audio
|
||||||
if (!Settings::getInstance()->getBool("VideoAudio") || (float)VolumeControl::getInstance()->getVolume() == 0)
|
if (!Settings::getInstance()->getBool("VideoAudio") || (float)VolumeControl::getInstance()->getVolume() == 0)
|
||||||
|
@ -128,14 +183,14 @@ void VideoPlayerComponent::startVideo()
|
||||||
if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never")
|
if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never")
|
||||||
{
|
{
|
||||||
// if we have chosen to render subtitles
|
// if we have chosen to render subtitles
|
||||||
argv[13] = "--subtitles";
|
argv[15] = "--subtitles";
|
||||||
argv[14] = subtitlePath.c_str();
|
argv[16] = subtitlePath.c_str();
|
||||||
argv[15] = mPlayingVideoPath.c_str();
|
argv[17] = mPlayingVideoPath.c_str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if we have chosen NOT to render subtitles in the screensaver
|
// if we have chosen NOT to render subtitles in the screensaver
|
||||||
argv[13] = mPlayingVideoPath.c_str();
|
argv[15] = mPlayingVideoPath.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -145,7 +200,7 @@ void VideoPlayerComponent::startVideo()
|
||||||
{
|
{
|
||||||
argv[6] = "stretch";
|
argv[6] = "stretch";
|
||||||
}
|
}
|
||||||
argv[13] = mPlayingVideoPath.c_str();
|
argv[15] = mPlayingVideoPath.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
argv[10] = Settings::getInstance()->getString("OMXAudioDev").c_str();
|
argv[10] = Settings::getInstance()->getString("OMXAudioDev").c_str();
|
||||||
|
|
Loading…
Reference in a new issue