ppsspp/base/QtMain.cpp

162 lines
3.9 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2012 Sacha Refshauge
*
*/
// Qt 4.7+ / 5.0+ implementation of the framework.
// Currently supports: Symbian, Blackberry, Meego, Linux, Windows, Mac OSX
2013-10-18 19:21:44 +00:00
#include <QApplication>
#include <QUrl>
2013-02-19 14:18:13 +00:00
#include <QDir>
#include <QDesktopWidget>
#include <QDesktopServices>
2013-10-18 19:21:44 +00:00
#include <QLocale>
#include <QThread>
#ifdef __SYMBIAN32__
#include <e32std.h>
2013-04-17 14:22:38 +00:00
#include <QSystemScreenSaver>
#include <QFeedbackHapticsEffect>
#include "SymbianMediaKeys.h"
#endif
#ifdef QT_HAS_SDL
#include "SDL/SDLJoystick.h"
#endif
#include "QtMain.h"
2013-04-01 12:42:40 +00:00
InputState* input_state;
std::string System_GetProperty(SystemProperty prop) {
switch (prop) {
case SYSPROP_NAME:
#ifdef __SYMBIAN32__
return "Qt:Symbian";
#elif defined(BLACKBERRY)
2013-11-26 06:38:00 +00:00
return "Qt:Blackberry";
#elif defined(MEEGO_EDITION_HARMATTAN)
return "Qt:Meego";
2014-01-05 00:53:47 +00:00
#elif defined(MAEMO)
return "Qt:Maemo";
2013-10-19 19:03:31 +00:00
#elif defined(Q_OS_LINUX)
return "Qt:Linux";
#elif defined(_WIN32)
return "Qt:Windows";
#elif defined(Q_OS_MAC)
return "Qt:Mac";
#else
return "Qt";
#endif
case SYSPROP_LANGREGION:
return QLocale::system().name().toStdString();
default:
return "";
}
}
2013-12-04 17:12:57 +00:00
void System_SendMessage(const char *command, const char *parameter) {
// Log?
}
bool System_InputBoxGetString(char *title, const char *defaultValue, char *outValue, size_t outLength)
{
QString text = emugl->InputBoxGetQString(QString(title), QString(defaultValue));
if (text.isEmpty())
return false;
strcpy(outValue, text.toStdString().c_str());
return true;
}
void Vibrate(int length_ms) {
if (length_ms == -1 || length_ms == -3)
length_ms = 50;
else if (length_ms == -2)
length_ms = 25;
// Symbian only for now
#if defined(__SYMBIAN32__)
QFeedbackHapticsEffect effect;
effect.setIntensity(0.8);
effect.setDuration(length_ms);
effect.start();
#endif
}
void LaunchBrowser(const char *url)
{
QDesktopServices::openUrl(QUrl(url));
}
2012-12-13 07:05:12 +00:00
float CalculateDPIScale()
{
2013-04-06 14:34:46 +00:00
// Sane default rather than check DPI
2012-12-13 07:05:12 +00:00
#ifdef __SYMBIAN32__
return 1.4f;
#elif defined(USING_GLES2)
2012-12-16 09:47:51 +00:00
return 1.2f;
#else
return 1.0f;
2012-12-13 07:05:12 +00:00
#endif
}
#ifndef QT_HAS_SDL
Q_DECL_EXPORT
#endif
int main(int argc, char *argv[])
{
2014-01-05 00:53:47 +00:00
#if defined(Q_OS_LINUX) && !defined(MAEMO)
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
#endif
QApplication a(argc, argv);
QSize res = QApplication::desktop()->screenGeometry().size();
if (res.width() < res.height())
res.transpose();
pixel_xres = res.width();
pixel_yres = res.height();
2013-08-20 10:30:03 +00:00
g_dpi_scale = CalculateDPIScale();
dp_xres = (int)(pixel_xres * g_dpi_scale); dp_yres = (int)(pixel_yres * g_dpi_scale);
2012-12-13 07:05:12 +00:00
net::Init();
#ifdef __SYMBIAN32__
2013-10-19 21:36:55 +00:00
const char *savegame_dir = "E:/PPSSPP/";
2013-10-20 05:36:04 +00:00
const char *assets_dir = "E:/PPSSPP/";
#elif defined(BLACKBERRY)
2013-10-19 21:36:55 +00:00
const char *savegame_dir = "/accounts/1000/shared/misc/";
const char *assets_dir = "app/native/assets/";
2014-01-05 00:53:47 +00:00
#elif defined(MEEGO_EDITION_HARMATTAN) || defined(MAEMO)
2013-10-19 21:36:55 +00:00
const char *savegame_dir = "/home/user/MyDocs/PPSSPP/";
const char *assets_dir = "/opt/PPSSPP/";
#else
2013-10-19 21:36:55 +00:00
const char *savegame_dir = "./";
const char *assets_dir = "./";
#endif
2013-07-08 00:04:20 +00:00
NativeInit(argc, (const char **)argv, savegame_dir, assets_dir, "BADCOFFEE");
#ifdef USING_GLES2
2013-12-08 11:09:24 +00:00
emugl = new MainUI();
emugl->resize(pixel_xres, pixel_yres);
emugl->showFullScreen();
#endif
2013-04-21 06:36:05 +00:00
#ifdef __SYMBIAN32__
// Set RunFast hardware mode for VFPv2.
User::SetFloatingPointMode(EFpModeRunFast);
// Disable screensaver
2013-12-08 11:09:24 +00:00
QScopedPointer<QSystemScreenSaver> ssObject(new QSystemScreenSaver(emugl));
2013-04-21 06:36:05 +00:00
ssObject->setScreenSaverInhibit();
2013-12-08 11:09:24 +00:00
QScopedPointer<SymbianMediaKeys> mediakeys(new SymbianMediaKeys());
2013-04-21 06:36:05 +00:00
#endif
2012-12-16 09:47:51 +00:00
2013-12-08 11:09:24 +00:00
QScopedPointer<QThread> thread(new QThread);
QScopedPointer<MainAudio> audio(new MainAudio());
audio->moveToThread(thread.data());
QObject::connect(thread.data(), SIGNAL(started()), audio.data(), SLOT(run()));
thread->start();
2012-12-16 09:47:51 +00:00
#ifdef QT_HAS_SDL
SDLJoystick joy(true);
joy.startEventLoop();
#endif
int ret = a.exec();
2013-10-26 09:51:29 +00:00
thread->quit();
NativeShutdown();
net::Shutdown();
return ret;
}