Tyro/src/TyroApp.cpp

135 lines
2.6 KiB
C++
Raw Normal View History

/**
* Main application file
*/
2015-03-30 14:50:10 -04:00
2015-07-07 10:01:17 -04:00
#include "src/wx_common.h"
#include "src/widgets/widget.h"
2015-04-22 10:09:43 -04:00
#include <wx/app.h>
#include <wx/sysopt.h>
#include <wx/vidmode.h>
2015-07-07 10:01:17 -04:00
#include "src/widgets/MainFrame.h"
// All the ugly globals
wxConfigBase *Glob_config = nullptr;
LangConfig *Glob_lang_config = nullptr;
ThemeConfig *Glob_theme_config = nullptr;
MainFrame *Glob_main_frame = nullptr;
TyroMenu *Glob_menu_bar = nullptr;
wxStatusBar *Glob_status_bar = nullptr;
/**
* Class with main method
*/
class TyroApp : public wxApp
2015-03-30 14:50:10 -04:00
{
public:
/**
* Start the event loop and create the main window
*
* @return bool
*/
bool OnInit() final
{
2019-05-14 16:23:47 -04:00
TyroApp::SetSystemOptions();
2015-05-15 16:55:18 -04:00
this->SetAppName(APP_NAME);
this->SetVendorName(APP_VENDOR);
2015-05-15 16:55:18 -04:00
// Initialize globals
Glob_config = wxConfigBase::Get();
Glob_lang_config = new LangConfig();
Glob_theme_config = new ThemeConfig();
2015-05-15 16:55:18 -04:00
Glob_menu_bar = new TyroMenu();
2019-05-16 15:21:32 -04:00
Glob_main_frame = new MainFrame(nullptr, APP_NAME, CalculateWindowSize());
2015-05-15 16:55:18 -04:00
// Setup Main Window
Glob_main_frame->Layout();
Glob_main_frame->CenterOnScreen();
Glob_main_frame->Show(true);
2015-05-19 12:12:12 -04:00
// Open passed files
if (this->param_count > 0)
2015-05-19 12:12:12 -04:00
{
Glob_main_frame->OpenFiles(files);
}
2015-05-15 16:55:18 -04:00
SetTopWindow(Glob_main_frame);
return true;
}
/**
* Exit handler
2019-03-20 16:49:25 -04:00
*
* @return int
*/
int OnExit() final
{
2019-06-18 11:22:49 -04:00
wxLogDebug("Closing App...");
2015-05-15 16:55:18 -04:00
// Deallocate config object
2019-06-18 11:22:49 -04:00
wxLogDebug("Deleting wxConfigBase");
2019-03-20 16:49:25 -04:00
delete wxConfigBase::Set((wxConfigBase *) nullptr);
2015-05-15 16:55:18 -04:00
return close(true);
}
/**
* Set up Command Line options
*
* @param wxCmdLineParser& parser
* @return void
*/
void OnInitCmdLine(wxCmdLineParser &parser) final
2015-05-15 16:55:18 -04:00
{
parser.SetDesc(Glob_cmdLineDesc);
2015-05-15 16:55:18 -04:00
// Set - as parameter delimeter, so raw file paths can be used
parser.SetSwitchChars("-");
}
/**
* Handler for command line options
*
* @param wxCmdLineParser& parser
* @return bool
*/
bool OnCmdLineParsed(wxCmdLineParser &parser) final
2015-05-15 16:55:18 -04:00
{
// Get un-named parameters
this->param_count = parser.GetParamCount();
2015-05-15 16:55:18 -04:00
wxLogDebug("%i Parameters", this->param_count);
2015-05-15 16:55:18 -04:00
for (auto i = 0; i < this->param_count; i++)
2015-05-15 16:55:18 -04:00
{
this->files.Add(parser.GetParam(i));
2015-05-15 16:55:18 -04:00
}
return true;
}
private:
// app loading variables
wxArrayString files;
size_t param_count = 0;
/**
* Toolkit-specific settings
2019-05-16 15:21:32 -04:00
*/
2019-05-14 16:23:47 -04:00
void static SetSystemOptions()
{
#ifdef __WXMAC__
wxSystemOptions::SetOption("osx.openfiledialog.always-show-types", 1);
#endif
#ifdef __WXMSW__
wxSystemOptions::SetOption("msw.remap", 0);
wxSystemOptions::SetOption("msw.display.directdraw", 1);
#endif
}
};
2015-03-30 16:01:24 -04:00
// Set up the main method and event loop
2019-05-17 16:19:42 -04:00
wxIMPLEMENT_APP(TyroApp);