all repos — mgba @ f6755a6e1b7b0cf2b944cd8ca842746f11d6bf82

mGBA Game Boy Advance Emulator

src/platform/qt/main.cpp (view raw)

  1/* Copyright (c) 2013-2014 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6
  7// This must be defined before anything else is included.
  8#define SDL_MAIN_HANDLED
  9
 10#include "ConfigController.h"
 11#include "GBAApp.h"
 12#include "Window.h"
 13
 14#include <mgba/core/version.h>
 15#include <mgba/gba/interface.h>
 16
 17#include <QLibraryInfo>
 18#include <QTranslator>
 19
 20#ifdef BUILD_GLES2
 21#include <QSurfaceFormat>
 22#endif
 23
 24#ifdef QT_STATIC
 25#include <QtPlugin>
 26#ifdef Q_OS_WIN
 27Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
 28Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin);
 29#ifdef BUILD_QT_MULTIMEDIA
 30Q_IMPORT_PLUGIN(QWindowsAudioPlugin);
 31Q_IMPORT_PLUGIN(DSServicePlugin);
 32#endif
 33#elif defined(Q_OS_MAC)
 34Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
 35#ifdef BUILD_QT_MULTIMEDIA
 36Q_IMPORT_PLUGIN(CoreAudioPlugin);
 37Q_IMPORT_PLUGIN(AVFServicePlugin);
 38#endif
 39#endif
 40#endif
 41
 42using namespace QGBA;
 43
 44int main(int argc, char* argv[]) {
 45#ifdef BUILD_SDL
 46#if SDL_VERSION_ATLEAST(2, 0, 0) // CPP does not shortcut function lookup
 47	SDL_SetMainReady();
 48#endif
 49#endif
 50
 51	ConfigController configController;
 52
 53	QLocale locale;
 54	if (!configController.getQtOption("language").isNull()) {
 55		locale = QLocale(configController.getQtOption("language").toString());
 56		QLocale::setDefault(locale);
 57	}
 58
 59	mArguments args;
 60	mGraphicsOpts graphicsOpts;
 61	mSubParser subparser;
 62	initParserForGraphics(&subparser, &graphicsOpts);
 63	bool loaded = configController.parseArguments(&args, argc, argv, &subparser);
 64	if (loaded && args.showHelp) {
 65		usage(argv[0], subparser.usage);
 66		return 0;
 67	}
 68
 69	QApplication::setApplicationName(projectName);
 70	QApplication::setApplicationVersion(projectVersion);
 71	QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
 72
 73#ifdef BUILD_GLES2
 74	QSurfaceFormat format;
 75	format.setVersion(3, 0);
 76	QSurfaceFormat::setDefaultFormat(format);
 77#endif
 78
 79	GBAApp application(argc, argv, &configController);
 80
 81#ifndef Q_OS_MAC
 82	QApplication::setWindowIcon(QIcon(":/res/mgba-1024.png"));
 83#endif
 84
 85	QTranslator qtTranslator;
 86	qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
 87	application.installTranslator(&qtTranslator);
 88
 89#ifdef QT_STATIC
 90	QTranslator qtStaticTranslator;
 91	qtStaticTranslator.load(locale, "qtbase", "_", ":/translations/");
 92	application.installTranslator(&qtStaticTranslator);
 93#endif
 94
 95	QTranslator langTranslator;
 96	langTranslator.load(locale, binaryName, "-", ":/translations/");
 97	application.installTranslator(&langTranslator);
 98
 99	Window* w = application.newWindow();
100	if (loaded) {
101		w->argumentsPassed(&args);
102	} else {
103		w->loadConfig();
104	}
105	freeArguments(&args);
106
107	if (graphicsOpts.multiplier) {
108		w->resizeFrame(QSize(GBA_VIDEO_HORIZONTAL_PIXELS * graphicsOpts.multiplier, GBA_VIDEO_VERTICAL_PIXELS * graphicsOpts.multiplier));
109	}
110	if (graphicsOpts.fullscreen) {
111		w->enterFullScreen();
112	}
113
114	w->show();
115
116	return application.exec();
117}
118
119#ifdef _WIN32
120#include <mgba-util/string.h>
121#include <vector>
122
123extern "C"
124int wmain(int argc, wchar_t* argv[]) {
125	std::vector<char*> argv8;
126	for (int i = 0; i < argc; ++i) {
127		argv8.push_back(utf16to8(reinterpret_cast<uint16_t*>(argv[i]), wcslen(argv[i]) * 2));
128	}
129	int ret = main(argc, argv8.data());
130	for (char* ptr : argv8) {
131		free(ptr);
132	}
133	return ret;
134}
135#endif