From aa8a1c7de01b846bc6a273105b357cdcb4f8671f Mon Sep 17 00:00:00 2001 From: Sacha Date: Thu, 13 Dec 2012 16:38:33 +1000 Subject: [PATCH] Symbian support. Add new Qt frontend. Can be used by any platform. Currently used by Symbian. --- base/QtMain.cpp | 58 +++++++++++++++++++++++++++++++++ base/QtMain.h | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 base/QtMain.cpp create mode 100644 base/QtMain.h diff --git a/base/QtMain.cpp b/base/QtMain.cpp new file mode 100644 index 0000000000..64acc52bd6 --- /dev/null +++ b/base/QtMain.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012 Sacha Refshauge + * + */ +// Qt implementation of the framework. +// Currently supports: Symbian + +#include +#include +#include +#include + +#ifdef __SYMBIAN32__ +#include +#endif +#include "QtMain.h" + +void LaunchBrowser(const char *url) +{ + QDesktopServices::openUrl(QUrl(url)); +} + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + // Lock orientation to landscape on Symbian +#ifdef __SYMBIAN32__ + QT_TRAP_THROWING(dynamic_cast(CEikonEnv::Static()->AppUi())->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape)); +#endif + net::Init(); + QSize res = QApplication::desktop()->screenGeometry().size(); + if (res.width() < res.height()) + res.transpose(); + pixel_xres = res.width(); + pixel_yres = res.height(); + // Calculate DPI from TWIPS on Symbian +#ifdef __SYMBIAN32__ + TSize sizeTwips = CEikonEnv::Static()->ScreenDevice()->SizeInTwips(); + float dpi = sqrt((float)(pixel_xres*pixel_xres + pixel_yres*pixel_yres)) + / (sqrt((float)(sizeTwips.iHeight*sizeTwips.iHeight + sizeTwips.iWidth*sizeTwips.iWidth)) / KTwipsPerInch); + float dpi_scale = dpi / 170.0f; +#endif + dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale); + NativeInit(argc, (const char **)argv, +#ifdef __SYMBIAN32__ + "E:/PPSSPP/", "E:", "BADCOFFEE"); +#else + "./","/tmp","BADCOFFEE"); +#endif + MainUI w; + w.resize(pixel_xres, pixel_yres); + w.showFullScreen(); + int ret = a.exec(); + NativeShutdown(); + net::Shutdown(); + return ret; +} + diff --git a/base/QtMain.h b/base/QtMain.h new file mode 100644 index 0000000000..96365208ff --- /dev/null +++ b/base/QtMain.h @@ -0,0 +1,87 @@ +#ifndef SYMBIANMAIN_H +#define SYMBIANMAIN_H + +#include +#include + +#include +#include + +#include "base/display.h" +#include "base/logging.h" +#include "base/timeutil.h" +#include "gfx_es2/glsl_program.h" +#include "file/zip_read.h" +#include "input/input_state.h" +#include "base/NativeApp.h" +#include "net/resolve.h" +#include "display.h" + +class MainUI : public QGLWidget +{ + Q_OBJECT +public: + explicit MainUI(float scale, QWidget *parent = 0): + QGLWidget(parent), dpi_scale(scale) + { + setAttribute(Qt::WA_AcceptTouchEvents); + } + ~MainUI() { + NativeShutdownGraphics(); + } + +protected: + bool event(QEvent *e) + { + QList touchPoints; + switch(e->type()) + { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + touchPoints = static_cast(e)->touchPoints(); + foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) { + switch (touchPoint.state()) { + case Qt::TouchPointStationary: + break; + case Qt::TouchPointPressed: + case Qt::TouchPointReleased: + input_state.pointer_down[touchPoint.id()] = (touchPoint.state() == Qt::TouchPointPressed); + case Qt::TouchPointMoved: + input_state.pointer_x[touchPoint.id()] = touchPoint.pos().x() * dpi_scale; + input_state.pointer_y[touchPoint.id()] = touchPoint.pos().y() * dpi_scale; + break; + default: + break; + } + } + break; + default: + return QWidget::event(e); + } + e->accept(); + return true; + } + + void initializeGL() + { + NativeInitGraphics(); + } + + void paintGL() + { + UpdateInputState(&input_state); + NativeUpdate(input_state); + EndInputState(&input_state); + NativeRender(); + + update(); + } + +private: + InputState input_state; + float dpi_scale; +}; + +#endif +