Merge pull request #40 from audetto/geometry
Save load SDL2 window position.
This commit is contained in:
commit
783cf233a5
12 changed files with 91 additions and 17 deletions
|
@ -189,6 +189,7 @@ namespace common2
|
|||
|
||||
if (vm.count("geometry"))
|
||||
{
|
||||
options.geometry.empty = false;
|
||||
parseGeometry(vm["geometry"].as<std::string>(), options.geometry);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace common2
|
|||
|
||||
struct Geometry
|
||||
{
|
||||
bool empty = true;
|
||||
int width;
|
||||
int height;
|
||||
int x;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "StdAfx.h"
|
||||
#include "frontends/common2/utils.h"
|
||||
#include "frontends/common2/programoptions.h"
|
||||
|
||||
#include "linux/network/uthernet2.h"
|
||||
|
||||
|
@ -24,6 +25,7 @@
|
|||
#include "SaveState.h"
|
||||
#include "RGBMonitor.h"
|
||||
#include "Riff.h"
|
||||
#include "Registry.h"
|
||||
#include "Utilities.h"
|
||||
#include "Interface.h"
|
||||
#include "Debugger/Debug.h"
|
||||
|
@ -133,4 +135,42 @@ namespace common2
|
|||
RiffFinishWriteFile();
|
||||
}
|
||||
|
||||
void loadGeometryFromRegistry(const std::string §ion, Geometry & geometry)
|
||||
{
|
||||
if (geometry.empty) // otherwise it was user provided
|
||||
{
|
||||
const std::string path = section + "\\geometry";
|
||||
const auto loadValue = [&path](const char * name, int & dest)
|
||||
{
|
||||
DWORD value;
|
||||
if (RegLoadValue(path.c_str(), name, TRUE, &value))
|
||||
{
|
||||
// DWORD and int have the same size
|
||||
// but if they did not, this would be necessary
|
||||
typedef std::make_signed<DWORD>::type signed_t;
|
||||
dest = static_cast<signed_t>(value);
|
||||
}
|
||||
};
|
||||
|
||||
loadValue("width", geometry.width);
|
||||
loadValue("height", geometry.height);
|
||||
loadValue("x", geometry.x);
|
||||
loadValue("y", geometry.y);
|
||||
}
|
||||
}
|
||||
|
||||
void saveGeometryToRegistry(const std::string §ion, const Geometry & geometry)
|
||||
{
|
||||
const std::string path = section + "\\geometry";
|
||||
const auto saveValue = [&path](const char * name, const int source)
|
||||
{
|
||||
// this seems to already do the right thing for negative numbers
|
||||
RegSaveValue(path.c_str(), name, TRUE, source);
|
||||
};
|
||||
saveValue("width", geometry.width);
|
||||
saveValue("height", geometry.height);
|
||||
saveValue("x", geometry.x);
|
||||
saveValue("y", geometry.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
namespace common2
|
||||
{
|
||||
struct Geometry;
|
||||
|
||||
void setSnapshotFilename(const std::string & filename, const bool load);
|
||||
|
||||
|
@ -11,4 +12,6 @@ namespace common2
|
|||
void InitialiseEmulator();
|
||||
void DestroyEmulator();
|
||||
|
||||
void loadGeometryFromRegistry(const std::string §ion, Geometry & geometry);
|
||||
void saveGeometryToRegistry(const std::string §ion, const Geometry & geometry);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace ra2
|
|||
unsigned Game::ourInputDevices[MAX_PADS] = {RETRO_DEVICE_NONE};
|
||||
|
||||
Game::Game()
|
||||
: myLogger(true)
|
||||
: myLoggerContext(true)
|
||||
, myFrame(new ra2::RetroFrame())
|
||||
, mySpeed(true)
|
||||
, myButtonStates(RETRO_DEVICE_ID_JOYPAD_R3 + 1)
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace ra2
|
|||
static retro_usec_t ourFrameTime;
|
||||
|
||||
private:
|
||||
const Logger myLogger;
|
||||
const LoggerContext myLoggerContext;
|
||||
const std::shared_ptr<RetroFrame> myFrame;
|
||||
|
||||
common2::Speed mySpeed; // fixed speed
|
||||
|
|
|
@ -145,12 +145,12 @@ namespace
|
|||
if (!run)
|
||||
return 1;
|
||||
|
||||
const Logger logger(options.log);
|
||||
const std::shared_ptr<Registry> registry = CreateFileRegistry(options);
|
||||
const LoggerContext loggerContext(options.log);
|
||||
const RegistryContext registryContet(CreateFileRegistry(options));
|
||||
const std::shared_ptr<na2::EvDevPaddle> paddle(new na2::EvDevPaddle(options.paddleDeviceName));
|
||||
const std::shared_ptr<na2::NFrame> frame(new na2::NFrame(paddle));
|
||||
|
||||
const Initialisation init(registry, frame, paddle);
|
||||
const Initialisation init(frame, paddle);
|
||||
applyOptions(options);
|
||||
frame->Initialize();
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ void run_sdl(int argc, const char * argv [])
|
|||
const int sw = video.GetFrameBufferBorderlessWidth();
|
||||
const int sh = video.GetFrameBufferBorderlessHeight();
|
||||
|
||||
options.geometry.empty = true;
|
||||
options.geometry.width = sw * 2;
|
||||
options.geometry.height = sh * 2;
|
||||
options.geometry.x = SDL_WINDOWPOS_UNDEFINED;
|
||||
|
@ -76,8 +77,10 @@ void run_sdl(int argc, const char * argv [])
|
|||
if (!run)
|
||||
return;
|
||||
|
||||
const Logger logger(options.log);
|
||||
const std::shared_ptr<Registry> registry = CreateFileRegistry(options);
|
||||
const LoggerContext logger(options.log);
|
||||
const RegistryContext registryContext(CreateFileRegistry(options));
|
||||
|
||||
common2::loadGeometryFromRegistry("sa2", options.geometry);
|
||||
|
||||
std::shared_ptr<sa2::SDLFrame> frame;
|
||||
if (options.imgui)
|
||||
|
@ -90,7 +93,7 @@ void run_sdl(int argc, const char * argv [])
|
|||
}
|
||||
|
||||
std::shared_ptr<Paddle> paddle(new sa2::Gamepad(0));
|
||||
const Initialisation init(registry, frame, paddle);
|
||||
const Initialisation init(frame, paddle);
|
||||
applyOptions(options);
|
||||
frame->Initialize();
|
||||
|
||||
|
|
|
@ -136,6 +136,18 @@ namespace sa2
|
|||
{
|
||||
}
|
||||
|
||||
void SDLFrame::Destroy()
|
||||
{
|
||||
if (!myFullscreen)
|
||||
{
|
||||
common2::Geometry geometry;
|
||||
SDL_GetWindowPosition(myWindow.get(), &geometry.x, &geometry.y);
|
||||
SDL_GetWindowSize(myWindow.get(), &geometry.width, &geometry.height);
|
||||
saveGeometryToRegistry("sa2", geometry);
|
||||
}
|
||||
common2::CommonFrame::Destroy();
|
||||
}
|
||||
|
||||
void SDLFrame::setGLSwapInterval(const int interval)
|
||||
{
|
||||
const int current = SDL_GL_GetSwapInterval();
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace sa2
|
|||
SDLFrame(const common2::EmulatorOptions & options);
|
||||
|
||||
void Initialize() override;
|
||||
void Destroy() override;
|
||||
|
||||
void FrameRefreshStatus(int drawflags) override;
|
||||
int FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType) override;
|
||||
|
|
|
@ -37,12 +37,10 @@ Video& GetVideo()
|
|||
}
|
||||
|
||||
Initialisation::Initialisation(
|
||||
const std::shared_ptr<Registry> & registry,
|
||||
const std::shared_ptr<FrameBase> & frame,
|
||||
const std::shared_ptr<Paddle> & paddle
|
||||
)
|
||||
{
|
||||
Registry::instance = registry;
|
||||
SetFrame(frame);
|
||||
Paddle::instance = paddle;
|
||||
}
|
||||
|
@ -53,7 +51,6 @@ Initialisation::~Initialisation()
|
|||
SetFrame(std::shared_ptr<FrameBase>());
|
||||
|
||||
Paddle::instance.reset();
|
||||
Registry::instance.reset();
|
||||
|
||||
CloseHandle(g_hCustomRomF8);
|
||||
g_hCustomRomF8 = INVALID_HANDLE_VALUE;
|
||||
|
@ -61,7 +58,7 @@ Initialisation::~Initialisation()
|
|||
g_hCustomRom = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
Logger::Logger(const bool log)
|
||||
LoggerContext::LoggerContext(const bool log)
|
||||
{
|
||||
if (log)
|
||||
{
|
||||
|
@ -69,7 +66,17 @@ Logger::Logger(const bool log)
|
|||
}
|
||||
}
|
||||
|
||||
Logger::~Logger()
|
||||
LoggerContext::~LoggerContext()
|
||||
{
|
||||
LogDone();
|
||||
}
|
||||
|
||||
RegistryContext::RegistryContext(const std::shared_ptr<Registry> & registry)
|
||||
{
|
||||
Registry::instance = registry;
|
||||
}
|
||||
|
||||
RegistryContext::~RegistryContext()
|
||||
{
|
||||
Registry::instance.reset();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ class Initialisation
|
|||
{
|
||||
public:
|
||||
Initialisation(
|
||||
const std::shared_ptr<Registry> & registry,
|
||||
const std::shared_ptr<FrameBase> & frame,
|
||||
const std::shared_ptr<Paddle> & paddle
|
||||
);
|
||||
|
@ -21,9 +20,16 @@ public:
|
|||
};
|
||||
|
||||
// RAII around LogInit / LogDone.
|
||||
class Logger
|
||||
class LoggerContext
|
||||
{
|
||||
public:
|
||||
Logger(const bool log);
|
||||
~Logger();
|
||||
LoggerContext(const bool log);
|
||||
~LoggerContext();
|
||||
};
|
||||
|
||||
class RegistryContext
|
||||
{
|
||||
public:
|
||||
RegistryContext(const std::shared_ptr<Registry> & registry);
|
||||
~RegistryContext();
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue