Extend geometry arg to WxH(+X+Y).
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
07900d5c38
commit
3e5a6aa520
5 changed files with 38 additions and 13 deletions
|
@ -19,14 +19,23 @@ namespace po = boost::program_options;
|
|||
namespace
|
||||
{
|
||||
|
||||
std::pair<int, int> parseSize(const std::string & s)
|
||||
void parseGeometry(const std::string & s, Geometry & geometry)
|
||||
{
|
||||
std::smatch m;
|
||||
if (std::regex_match(s, m, std::regex("^(\\d+)x(\\d+)$")))
|
||||
if (std::regex_match(s, m, std::regex("^(\\d+)x(\\d+)(\\+(\\d+)\\+(\\d+))?$")))
|
||||
{
|
||||
const int width = std::stoi(m.str(1));
|
||||
const int height = std::stoi(m.str(2));
|
||||
return std::make_pair(width, height);
|
||||
const size_t groups = m.size();
|
||||
if (groups == 6)
|
||||
{
|
||||
geometry.width = std::stoi(m.str(1));
|
||||
geometry.height = std::stoi(m.str(2));
|
||||
if (!m.str(3).empty())
|
||||
{
|
||||
geometry.x = std::stoi(m.str(4));
|
||||
geometry.y = std::stoi(m.str(5));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Invalid sizes: " + s);
|
||||
}
|
||||
|
@ -87,7 +96,7 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit
|
|||
("sdl-driver", po::value<int>()->default_value(options.sdlDriver), "SDL driver")
|
||||
("gl-swap", po::value<int>()->default_value(options.glSwapInterval), "SDL_GL_SwapInterval")
|
||||
("imgui", "Render with Dear ImGui")
|
||||
("size", po::value<std::string>(), "WxH")
|
||||
("geometry", po::value<std::string>(), "WxH(+X+Y)")
|
||||
;
|
||||
desc.add(sdlDesc);
|
||||
|
||||
|
@ -161,9 +170,9 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit
|
|||
options.paddleDeviceName = vm["device-name"].as<std::string>();
|
||||
}
|
||||
|
||||
if (vm.count("size"))
|
||||
if (vm.count("geometry"))
|
||||
{
|
||||
options.size = parseSize(vm["size"].as<std::string>());
|
||||
parseGeometry(vm["geometry"].as<std::string>(), options.geometry);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
struct Geometry
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
|
||||
struct EmulatorOptions
|
||||
{
|
||||
std::string disk1;
|
||||
|
@ -37,7 +46,7 @@ struct EmulatorOptions
|
|||
|
||||
int sdlDriver = -1; // default = -1 to let SDL choose
|
||||
bool imgui = false; // use imgui renderer
|
||||
std::pair<int, int> size; // width x height
|
||||
Geometry geometry; // must be initialised with defaults
|
||||
int glSwapInterval = 1; // SDL_GL_SetSwapInterval
|
||||
|
||||
std::vector<std::string> registryOptions;
|
||||
|
|
|
@ -47,8 +47,10 @@ SDLImGuiFrame::SDLImGuiFrame(const EmulatorOptions & options)
|
|||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||
|
||||
SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, options.size.first, options.size.second, windowFlags), SDL_DestroyWindow);
|
||||
const SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
const Geometry & geometry = options.geometry;
|
||||
|
||||
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, windowFlags), SDL_DestroyWindow);
|
||||
if (!myWindow)
|
||||
{
|
||||
throw std::runtime_error(SDL_GetError());
|
||||
|
|
|
@ -83,7 +83,10 @@ void run_sdl(int argc, const char * argv [])
|
|||
const int sw = video.GetFrameBufferBorderlessWidth();
|
||||
const int sh = video.GetFrameBufferBorderlessHeight();
|
||||
|
||||
options.size = std::make_pair(sw, sh);
|
||||
options.geometry.width = sw;
|
||||
options.geometry.height = sh;
|
||||
options.geometry.x = SDL_WINDOWPOS_UNDEFINED;
|
||||
options.geometry.y = SDL_WINDOWPOS_UNDEFINED;
|
||||
options.memclear = g_nMemoryClearType;
|
||||
const bool run = getEmulatorOptions(argc, argv, "SDL2", options);
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
|
||||
SDLRendererFrame::SDLRendererFrame(const EmulatorOptions & options)
|
||||
{
|
||||
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, options.size.first, options.size.second, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE), SDL_DestroyWindow);
|
||||
const Geometry & geometry = options.geometry;
|
||||
|
||||
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, SDL_WINDOW_RESIZABLE), SDL_DestroyWindow);
|
||||
if (!myWindow)
|
||||
{
|
||||
throw std::runtime_error(SDL_GetError());
|
||||
|
|
Loading…
Add table
Reference in a new issue