auto save/load geometry for wx GUI #94
* Add support to save/load geometry options for GUI window. * Refactor code to use wxWidgets functions to get window geometry. * Call update_opts() from ::OnSize and ::OnMove functions.
This commit is contained in:
parent
36fbf71527
commit
944c263e7f
|
@ -109,8 +109,10 @@ enum named_opts
|
||||||
OPT_SYNCHRONIZE,
|
OPT_SYNCHRONIZE,
|
||||||
OPT_THREAD_PRIORITY,
|
OPT_THREAD_PRIORITY,
|
||||||
OPT_VIDEO_OPTION,
|
OPT_VIDEO_OPTION,
|
||||||
|
OPT_WINDOW_HEIGHT,
|
||||||
OPT_WINDOW_POSITION_X,
|
OPT_WINDOW_POSITION_X,
|
||||||
OPT_WINDOW_POSITION_Y,
|
OPT_WINDOW_POSITION_Y,
|
||||||
|
OPT_WINDOW_WIDTH,
|
||||||
OPT_SPEEDUP_THROTTLE,
|
OPT_SPEEDUP_THROTTLE,
|
||||||
OPT_SPEEDUP_FRAME_SKIP
|
OPT_SPEEDUP_FRAME_SKIP
|
||||||
};
|
};
|
||||||
|
@ -239,8 +241,10 @@ int useBiosFileGBC;
|
||||||
int videoOption;
|
int videoOption;
|
||||||
int vsync;
|
int vsync;
|
||||||
int wasPaused = 0;
|
int wasPaused = 0;
|
||||||
|
uint32_t windowHeight;
|
||||||
int windowPositionX;
|
int windowPositionX;
|
||||||
int windowPositionY;
|
int windowPositionY;
|
||||||
|
uint32_t windowWidth;
|
||||||
int winFlashSize;
|
int winFlashSize;
|
||||||
int winGbBorderOn;
|
int winGbBorderOn;
|
||||||
int winGbPrinterEnabled;
|
int winGbPrinterEnabled;
|
||||||
|
@ -394,8 +398,10 @@ struct option argOptions[] = {
|
||||||
{ "video-option", required_argument, 0, OPT_VIDEO_OPTION },
|
{ "video-option", required_argument, 0, OPT_VIDEO_OPTION },
|
||||||
{ "vsync", no_argument, &vsync, 1 },
|
{ "vsync", no_argument, &vsync, 1 },
|
||||||
{ "win-gb-printer-enabled", no_argument, &winGbPrinterEnabled, 1 },
|
{ "win-gb-printer-enabled", no_argument, &winGbPrinterEnabled, 1 },
|
||||||
|
{ "window-height", required_argument, 0, OPT_WINDOW_HEIGHT },
|
||||||
{ "window-position-x", required_argument, 0, OPT_WINDOW_POSITION_X },
|
{ "window-position-x", required_argument, 0, OPT_WINDOW_POSITION_X },
|
||||||
{ "window-position-y", required_argument, 0, OPT_WINDOW_POSITION_Y },
|
{ "window-position-y", required_argument, 0, OPT_WINDOW_POSITION_Y },
|
||||||
|
{ "window-width", required_argument, 0, OPT_WINDOW_WIDTH },
|
||||||
|
|
||||||
|
|
||||||
{ NULL, no_argument, NULL, 0 }
|
{ NULL, no_argument, NULL, 0 }
|
||||||
|
@ -547,8 +553,10 @@ void LoadConfig()
|
||||||
useBiosFileGBC = ReadPref("useBiosGBC", 0);
|
useBiosFileGBC = ReadPref("useBiosGBC", 0);
|
||||||
videoOption = ReadPref("video", 2); // VIDEO_3X = 2
|
videoOption = ReadPref("video", 2); // VIDEO_3X = 2
|
||||||
vsync = ReadPref("vsync", false);
|
vsync = ReadPref("vsync", false);
|
||||||
windowPositionX = ReadPref("windowX", 0);
|
windowHeight = ReadPref("windowHeight", 0);
|
||||||
windowPositionY = ReadPref("windowY", 0);
|
windowPositionX = ReadPref("windowX", -1);
|
||||||
|
windowPositionY = ReadPref("windowY", -1);
|
||||||
|
windowWidth = ReadPref("windowWidth", 0);
|
||||||
winFlashSize = ReadPref("flashSize", 0x10000);
|
winFlashSize = ReadPref("flashSize", 0x10000);
|
||||||
winGbBorderOn = ReadPref("borderOn", 0);
|
winGbBorderOn = ReadPref("borderOn", 0);
|
||||||
winGbPrinterEnabled = ReadPref("gbPrinter", 0);
|
winGbPrinterEnabled = ReadPref("gbPrinter", 0);
|
||||||
|
@ -1333,6 +1341,20 @@ int ReadOpts(int argc, char ** argv)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPT_WINDOW_HEIGHT:
|
||||||
|
// --window-height
|
||||||
|
if (optarg) {
|
||||||
|
windowHeight = atoi(optarg);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OPT_WINDOW_WIDTH:
|
||||||
|
// --window-width
|
||||||
|
if (optarg) {
|
||||||
|
windowWidth = atoi(optarg);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case OPT_DOTCODE_FILE_NAME_LOAD:
|
case OPT_DOTCODE_FILE_NAME_LOAD:
|
||||||
// --dotcode-file-name-load
|
// --dotcode-file-name-load
|
||||||
loadDotCodeFile = optarg;
|
loadDotCodeFile = optarg;
|
||||||
|
|
|
@ -132,8 +132,10 @@ extern int useBiosFileGBC;
|
||||||
extern int videoOption;
|
extern int videoOption;
|
||||||
extern int vsync;
|
extern int vsync;
|
||||||
extern int wasPaused;
|
extern int wasPaused;
|
||||||
|
extern uint32_t windowHeight;
|
||||||
extern int windowPositionX;
|
extern int windowPositionX;
|
||||||
extern int windowPositionY;
|
extern int windowPositionY;
|
||||||
|
extern uint32_t windowWidth;
|
||||||
extern int winFlashSize;
|
extern int winFlashSize;
|
||||||
extern int winGbBorderOn;
|
extern int winGbBorderOn;
|
||||||
extern int winGbPrinterEnabled;
|
extern int winGbPrinterEnabled;
|
||||||
|
|
|
@ -239,7 +239,6 @@ opt_desc opts[] = {
|
||||||
INTOPT("preferences/fsFrequency", "", wxTRANSLATE("Fullscreen mode frequency (0 = any)"), fsFrequency, 0, 999),
|
INTOPT("preferences/fsFrequency", "", wxTRANSLATE("Fullscreen mode frequency (0 = any)"), fsFrequency, 0, 999),
|
||||||
INTOPT("preferences/fsHeight", "", wxTRANSLATE("Fullscreen mode height (0 = desktop)"), fsHeight, 0, 99999),
|
INTOPT("preferences/fsHeight", "", wxTRANSLATE("Fullscreen mode height (0 = desktop)"), fsHeight, 0, 99999),
|
||||||
INTOPT("preferences/fsWidth", "", wxTRANSLATE("Fullscreen mode width (0 = desktop)"), fsWidth, 0, 99999),
|
INTOPT("preferences/fsWidth", "", wxTRANSLATE("Fullscreen mode width (0 = desktop)"), fsWidth, 0, 99999),
|
||||||
INTOPT("preferences/fullScreen", "Fullscreen", wxTRANSLATE("Enter fullscreen mode at startup"), fullScreen, 0, 1),
|
|
||||||
INTOPT("preferences/gbPaletteOption", "", wxTRANSLATE("The palette to use"), gbPaletteOption, 0, 2),
|
INTOPT("preferences/gbPaletteOption", "", wxTRANSLATE("The palette to use"), gbPaletteOption, 0, 2),
|
||||||
INTOPT("preferences/gbPrinter", "Printer", wxTRANSLATE("Enable printer emulation"), winGbPrinterEnabled, 0, 1),
|
INTOPT("preferences/gbPrinter", "Printer", wxTRANSLATE("Enable printer emulation"), winGbPrinterEnabled, 0, 1),
|
||||||
INTOPT("preferences/gdbBreakOnLoad", "DebugGDBBreakOnLoad", wxTRANSLATE("Break into GDB after loading the game."), gdbBreakOnLoad, 0, 1),
|
INTOPT("preferences/gdbBreakOnLoad", "DebugGDBBreakOnLoad", wxTRANSLATE("Break into GDB after loading the game."), gdbBreakOnLoad, 0, 1),
|
||||||
|
@ -264,8 +263,14 @@ opt_desc opts[] = {
|
||||||
INTOPT("preferences/useBiosGBC", "BootRomGBC", wxTRANSLATE("Use the specified BIOS file for GBC"), useBiosFileGBC, 0, 1),
|
INTOPT("preferences/useBiosGBC", "BootRomGBC", wxTRANSLATE("Use the specified BIOS file for GBC"), useBiosFileGBC, 0, 1),
|
||||||
INTOPT("preferences/vsync", "VSync", wxTRANSLATE("Wait for vertical sync"), vsync, 0, 1),
|
INTOPT("preferences/vsync", "VSync", wxTRANSLATE("Wait for vertical sync"), vsync, 0, 1),
|
||||||
|
|
||||||
/// Sound
|
/// Geometry
|
||||||
|
INTOPT("geometry/fullScreen", "Fullscreen", wxTRANSLATE("Enter fullscreen mode at startup"), fullScreen, 0, 1),
|
||||||
|
UINTOPT("geometry/windowHeight", "Height", wxTRANSLATE("Window height at startup"), windowHeight, 0, 99999),
|
||||||
|
UINTOPT("geometry/windowWidth", "Width", wxTRANSLATE("Window width at startup"), windowWidth, 0, 99999),
|
||||||
|
INTOPT("geometry/windowX", "X", wxTRANSLATE("Window axis X position at startup"), windowPositionX, -1, 99999),
|
||||||
|
INTOPT("geometry/windowY", "Y", wxTRANSLATE("Window axis Y position at startup"), windowPositionY, -1, 99999),
|
||||||
|
|
||||||
|
/// Sound
|
||||||
ENUMOPT("Sound/AudioAPI", "", wxTRANSLATE("Sound API; if unsupported, default API will be used"), gopts.audio_api, wxTRANSLATE("sdl|openal|directsound|xaudio2|faudio")),
|
ENUMOPT("Sound/AudioAPI", "", wxTRANSLATE("Sound API; if unsupported, default API will be used"), gopts.audio_api, wxTRANSLATE("sdl|openal|directsound|xaudio2|faudio")),
|
||||||
STROPT("Sound/AudioDevice", "", wxTRANSLATE("Device ID of chosen audio device for chosen driver"), gopts.audio_dev),
|
STROPT("Sound/AudioDevice", "", wxTRANSLATE("Device ID of chosen audio device for chosen driver"), gopts.audio_dev),
|
||||||
INTOPT("Sound/Buffers", "", wxTRANSLATE("Number of sound buffers"), gopts.audio_buffers, 2, 10),
|
INTOPT("Sound/Buffers", "", wxTRANSLATE("Number of sound buffers"), gopts.audio_buffers, 2, 10),
|
||||||
|
|
|
@ -398,6 +398,11 @@ bool wxvbamApp::OnInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the main window
|
// create the main window
|
||||||
|
int x = windowPositionX;
|
||||||
|
int y = windowPositionX;
|
||||||
|
int width = windowWidth;
|
||||||
|
int height = windowHeight;
|
||||||
|
int isFullscreen = fullScreen;
|
||||||
frame = wxDynamicCast(xr->LoadFrame(NULL, wxT("MainFrame")), MainFrame);
|
frame = wxDynamicCast(xr->LoadFrame(NULL, wxT("MainFrame")), MainFrame);
|
||||||
|
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
|
@ -409,6 +414,11 @@ bool wxvbamApp::OnInit()
|
||||||
if (!frame->BindControls())
|
if (!frame->BindControls())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (x >= 0 && y >= 0 && width > 0 && height > 0)
|
||||||
|
frame->SetSize(x, y, width, height);
|
||||||
|
|
||||||
|
if (isFullscreen && wxGetApp().pending_load != wxEmptyString)
|
||||||
|
frame->ShowFullScreen(isFullscreen);
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -633,6 +643,9 @@ EVT_ACTIVATE(MainFrame::OnActivate)
|
||||||
// requires DragAcceptFiles(true); even then may not do anything
|
// requires DragAcceptFiles(true); even then may not do anything
|
||||||
EVT_DROP_FILES(MainFrame::OnDropFile)
|
EVT_DROP_FILES(MainFrame::OnDropFile)
|
||||||
|
|
||||||
|
// for window geometry
|
||||||
|
EVT_MOVE(MainFrame::OnMove)
|
||||||
|
EVT_SIZE(MainFrame::OnSize)
|
||||||
// pause game if menu pops up
|
// pause game if menu pops up
|
||||||
//
|
//
|
||||||
// This is a feature most people don't like, and it causes problems with
|
// This is a feature most people don't like, and it causes problems with
|
||||||
|
@ -688,6 +701,39 @@ void MainFrame::OnMenu(wxContextMenuEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainFrame::OnMove(wxMoveEvent& event)
|
||||||
|
{
|
||||||
|
wxRect pos = GetRect();
|
||||||
|
int x = pos.GetX(), y = pos.GetY();
|
||||||
|
if (x >= 0 && y >= 0 && !IsFullScreen())
|
||||||
|
{
|
||||||
|
windowPositionX = x;
|
||||||
|
windowPositionY = y;
|
||||||
|
update_opts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainFrame::OnSize(wxSizeEvent& event)
|
||||||
|
{
|
||||||
|
wxFrame::OnSize(event);
|
||||||
|
wxRect pos = GetRect();
|
||||||
|
int height = pos.GetHeight(), width = pos.GetWidth();
|
||||||
|
int x = pos.GetX(), y = pos.GetY();
|
||||||
|
bool isFullscreen = IsFullScreen();
|
||||||
|
if (height > 0 && width > 0 && !isFullscreen)
|
||||||
|
{
|
||||||
|
windowHeight = height;
|
||||||
|
windowWidth = width;
|
||||||
|
}
|
||||||
|
if (x >= 0 && y >= 0 && !isFullscreen)
|
||||||
|
{
|
||||||
|
windowPositionX = x;
|
||||||
|
windowPositionY = y;
|
||||||
|
}
|
||||||
|
fullScreen = isFullscreen;
|
||||||
|
update_opts();
|
||||||
|
}
|
||||||
|
|
||||||
wxString MainFrame::GetGamePath(wxString path)
|
wxString MainFrame::GetGamePath(wxString path)
|
||||||
{
|
{
|
||||||
wxString game_path = path;
|
wxString game_path = path;
|
||||||
|
|
|
@ -356,6 +356,9 @@ private:
|
||||||
void OnDropFile(wxDropFilesEvent&);
|
void OnDropFile(wxDropFilesEvent&);
|
||||||
// pop up menu in fullscreen mode
|
// pop up menu in fullscreen mode
|
||||||
void OnMenu(wxContextMenuEvent&);
|
void OnMenu(wxContextMenuEvent&);
|
||||||
|
// window geometry
|
||||||
|
void OnMove(wxMoveEvent& event);
|
||||||
|
void OnSize(wxSizeEvent& event);
|
||||||
// Load a named wxDialog from the XRC file
|
// Load a named wxDialog from the XRC file
|
||||||
wxDialog* LoadXRCDialog(const char* name);
|
wxDialog* LoadXRCDialog(const char* name);
|
||||||
// Load a named wxDialog from the XRC file
|
// Load a named wxDialog from the XRC file
|
||||||
|
|
Loading…
Reference in New Issue