From e3421032047c49d6a95b54b777fc07ddf7f8b409 Mon Sep 17 00:00:00 2001 From: Xawotihs Date: Sun, 10 Oct 2010 21:58:02 +0000 Subject: [PATCH] Added support for left mouse click and zoom buttons --- JGE/src/Qtmain.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/JGE/src/Qtmain.cpp b/JGE/src/Qtmain.cpp index 71f566405..aaa728937 100644 --- a/JGE/src/Qtmain.cpp +++ b/JGE/src/Qtmain.cpp @@ -1,6 +1,13 @@ #define GL_GLEXT_PROTOTYPES #include #include + +#ifdef Q_WS_MAEMO_5 +#include +#include +#include +#endif //Q_WS_MAEMO_5 + #include "../include/JGE.h" #include "../include/JTypes.h" #include "../include/JApp.h" @@ -39,6 +46,34 @@ protected: void wheelEvent(QWheelEvent *event); +#ifdef Q_WS_MAEMO_5 + void grabZoomKeys(bool grab) + { + if (!winId()) { + qWarning("Can't grab keys unless we have a window id"); + return; + } + + unsigned long val = (grab) ? 1 : 0; + Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); + if (!atom) { + qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM. This example will only work " + "on a Maemo 5 device!"); + return; + } + + XChangeProperty (QX11Info::display(), + winId(), + atom, + XA_INTEGER, + 32, + PropModeReplace, + reinterpret_cast(&val), + 1); + } +#endif //Q_WS_MAEMO_5 + + protected: QPoint lastPos; @@ -132,6 +167,7 @@ JGEQtRenderer::JGEQtRenderer(QWidget *parent) #ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_Maemo5AutoOrientation); setAttribute(Qt::WA_Maemo5NonComposited); + grabZoomKeys(true); #endif setAttribute(Qt::WA_AcceptTouchEvents); grabGesture(Qt::PanGesture); @@ -222,6 +258,46 @@ void JGEQtRenderer::timerEvent( QTimerEvent* ) updateGL(); } +void JGEQtRenderer::mousePressEvent(QMouseEvent *event) +{ + if(event->button() == Qt::LeftButton) + { + lastPos = event->pos(); + // this is intended to convert window coordinate into game coordinate. + // this is correct only if the game and window have the same aspect ratio, otherwise, it's just wrong + g_engine->LeftClicked((lastPos.x()*SCREEN_WIDTH)/actualWidth, (lastPos.y()*SCREEN_HEIGHT)/actualHeight); + event->accept(); + } + else + { + QGLWidget::mousePressEvent(event); + } +} + +void JGEQtRenderer::mouseReleaseEvent(QMouseEvent *event) +{ + if(event->button() == Qt::LeftButton) + { + QGLWidget::mouseReleaseEvent(event); + } + else if(event->button() == Qt::RightButton) + { /* next phase please */ + g_engine->HoldKey_NoRepeat(JGE_BTN_PREV); + event->accept(); + } + else if(event->button() == Qt::MidButton) + { /* interrupt please */ + g_engine->HoldKey_NoRepeat(JGE_BTN_SEC); + event->accept(); + } + else + { + QGLWidget::mouseReleaseEvent(event); + } +} + + +/* void JGEQtRenderer::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) @@ -276,7 +352,7 @@ void JGEQtRenderer::mouseReleaseEvent(QMouseEvent *event) QGLWidget::mouseReleaseEvent(event); } } - +*/ void JGEQtRenderer::mouseDoubleClickEvent(QMouseEvent *event) { @@ -319,11 +395,24 @@ void JGEQtRenderer::wheelEvent(QWheelEvent *event) void JGEQtRenderer::keyPressEvent(QKeyEvent *event) { - if(event->key() == Qt::Key_F) + switch(event->key()) { +#ifdef Q_WS_MAEMO_5 + case Qt::Key_F7: + /* interrupt please */ + g_engine->HoldKey_NoRepeat(JGE_BTN_SEC); + break; + case Qt::Key_F8: + /* next phase please */ + g_engine->HoldKey_NoRepeat(JGE_BTN_PREV); + break; +#endif // Q_WS_MAEMO_5 + case Qt::Key_F: JGEToggleFullscreen(); + break; + default: + g_engine->HoldKey_NoRepeat((LocalKeySym)event->key()); } - g_engine->HoldKey_NoRepeat((LocalKeySym)event->key()); event->accept(); QWidget::keyPressEvent(event); return; @@ -374,5 +463,6 @@ int main(int argc, char* argv[]) // Shutdown DestroyGame(); + return 0; }