2016-06-09 20:18:08 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2019-02-22 10:07:32 -05:00
|
|
|
* Copyright (C) 2016-2019 - Brad Parker
|
2016-06-09 20:18:08 +02:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-04-30 14:33:05 -04:00
|
|
|
#include <QApplication>
|
2018-05-05 22:57:29 -04:00
|
|
|
#include <QAbstractEventDispatcher>
|
2016-06-10 08:38:27 +02:00
|
|
|
|
2019-01-13 21:56:16 -08:00
|
|
|
#ifndef CXX_BUILD
|
2018-04-30 14:33:05 -04:00
|
|
|
extern "C" {
|
2019-01-13 21:56:16 -08:00
|
|
|
#endif
|
|
|
|
|
2016-06-09 20:18:08 +02:00
|
|
|
#include "../../ui_companion_driver.h"
|
2018-04-30 14:33:05 -04:00
|
|
|
#include "../../../retroarch.h"
|
|
|
|
#include "../../../verbosity.h"
|
|
|
|
#include "../../../version.h"
|
|
|
|
#include "../../../frontend/frontend.h"
|
|
|
|
#include "../../../tasks/tasks_internal.h"
|
|
|
|
#include <retro_timers.h>
|
2018-08-27 17:56:53 -04:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
2019-01-13 21:56:16 -08:00
|
|
|
|
|
|
|
#ifndef CXX_BUILD
|
2018-04-30 14:33:05 -04:00
|
|
|
}
|
2019-01-13 21:56:16 -08:00
|
|
|
#endif
|
2018-04-30 14:33:05 -04:00
|
|
|
|
|
|
|
#include "../ui_qt.h"
|
|
|
|
|
2020-06-04 14:41:28 +02:00
|
|
|
static AppHandler *app_handler;
|
2018-04-30 14:33:05 -04:00
|
|
|
static ui_application_qt_t ui_application;
|
|
|
|
|
2018-09-22 12:14:18 -03:00
|
|
|
/* ARGB 16x16 */
|
2018-04-30 14:33:05 -04:00
|
|
|
static const unsigned retroarch_qt_icon_data[] = {
|
2018-09-22 12:14:18 -03:00
|
|
|
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,
|
|
|
|
0x00000000,0x00000000,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0x00000000,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xfff2f2f2,0xff333333,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xff333333,0xfff2f2f2,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xff333333,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xff333333,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xff333333,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xfff2f2f2,0xff333333,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xfff2f2f2,0xff333333,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0x00000000,0x00000000,
|
|
|
|
0x00000000,0x00000000,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0xff333333,0x00000000,0x00000000,0x00000000,
|
|
|
|
0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
|
2018-04-30 14:33:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
AppHandler::AppHandler(QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
2016-06-09 20:18:08 +02:00
|
|
|
|
2018-04-30 14:33:05 -04:00
|
|
|
AppHandler::~AppHandler()
|
2016-06-09 20:18:08 +02:00
|
|
|
{
|
2018-04-30 14:33:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppHandler::exit()
|
|
|
|
{
|
2019-07-11 02:18:21 +02:00
|
|
|
ui_application_qt.exiting = true;
|
2018-05-01 17:47:12 -04:00
|
|
|
|
|
|
|
if (qApp)
|
|
|
|
qApp->closeAllWindows();
|
2018-04-30 14:33:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AppHandler::isExiting() const
|
|
|
|
{
|
2019-07-11 02:18:21 +02:00
|
|
|
return ui_application_qt.exiting;
|
2018-04-30 14:33:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppHandler::onLastWindowClosed()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* ui_application_qt_initialize(void)
|
|
|
|
{
|
2020-06-04 14:41:28 +02:00
|
|
|
/* These must last for the lifetime of the QApplication */
|
|
|
|
static int app_argc = 1;
|
|
|
|
static char app_name[] = "retroarch";
|
|
|
|
static char *app_argv[] = { app_name, NULL };
|
|
|
|
|
|
|
|
app_handler = new AppHandler();
|
2018-04-30 14:33:05 -04:00
|
|
|
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
|
|
|
|
/* HiDpi supported since Qt 5.6 */
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QApplication::setStyle("fusion");
|
|
|
|
|
|
|
|
ui_application.app = new QApplication(app_argc, app_argv);
|
|
|
|
ui_application.app->setOrganizationName("libretro");
|
|
|
|
ui_application.app->setApplicationName("RetroArch");
|
|
|
|
ui_application.app->setApplicationVersion(PACKAGE_VERSION);
|
2020-06-04 14:41:28 +02:00
|
|
|
ui_application.app->connect(ui_application.app, SIGNAL(lastWindowClosed()),
|
|
|
|
app_handler, SLOT(onLastWindowClosed()));
|
2018-04-30 14:33:05 -04:00
|
|
|
|
2018-08-27 17:56:53 -04:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
#endif
|
2018-04-30 14:33:05 -04:00
|
|
|
{
|
|
|
|
/* Can't declare the pixmap at the top, because: "QPixmap: Must construct a QGuiApplication before a QPixmap" */
|
|
|
|
QImage iconImage(16, 16, QImage::Format_ARGB32);
|
|
|
|
QPixmap iconPixmap;
|
|
|
|
unsigned char *bits = iconImage.bits();
|
|
|
|
|
|
|
|
memcpy(bits, retroarch_qt_icon_data, 16 * 16 * sizeof(unsigned));
|
|
|
|
|
|
|
|
iconPixmap = QPixmap::fromImage(iconImage);
|
|
|
|
|
|
|
|
ui_application.app->setWindowIcon(QIcon(iconPixmap));
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ui_application;
|
2016-06-09 20:18:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_application_qt_process_events(void)
|
|
|
|
{
|
2019-07-17 22:08:11 +02:00
|
|
|
QAbstractEventDispatcher *dispatcher = QApplication::eventDispatcher();
|
|
|
|
if (dispatcher && dispatcher->hasPendingEvents())
|
2018-05-05 22:57:29 -04:00
|
|
|
QApplication::processEvents();
|
2016-06-09 20:18:08 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 14:33:05 -04:00
|
|
|
static void ui_application_qt_quit(void)
|
|
|
|
{
|
2020-06-04 14:41:28 +02:00
|
|
|
if (app_handler)
|
|
|
|
app_handler->exit();
|
2018-04-30 14:33:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_MAIN
|
2019-01-13 21:56:16 -08:00
|
|
|
#if defined(__cplusplus) && !defined(CXX_BUILD)
|
2018-04-30 14:33:05 -04:00
|
|
|
extern "C"
|
|
|
|
#endif
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return rarch_main(argc, argv, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ui_application_t ui_application_qt = {
|
2016-06-09 20:18:08 +02:00
|
|
|
ui_application_qt_initialize,
|
|
|
|
ui_application_qt_process_events,
|
2018-04-30 14:33:05 -04:00
|
|
|
ui_application_qt_quit,
|
2019-07-11 02:18:21 +02:00
|
|
|
false,
|
2016-06-09 20:18:08 +02:00
|
|
|
"qt"
|
|
|
|
};
|