Fixed mouse input with retina display
This commit is contained in:
@@ -136,6 +136,8 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int lastPosx(){ return m_lastPos.x()*devicePixelRatio();}
|
||||||
|
int lastPosy(){ return m_lastPos.y()*devicePixelRatio();}
|
||||||
void timerEvent( QTimerEvent* );
|
void timerEvent( QTimerEvent* );
|
||||||
void doAndEnqueue(JButton action) {
|
void doAndEnqueue(JButton action) {
|
||||||
m_engine->HoldKey_NoRepeat(action);
|
m_engine->HoldKey_NoRepeat(action);
|
||||||
@@ -154,6 +156,7 @@ private:
|
|||||||
int m_timerId;
|
int m_timerId;
|
||||||
bool m_active;
|
bool m_active;
|
||||||
QRect m_viewPort;
|
QRect m_viewPort;
|
||||||
|
QPoint m_lastPos;
|
||||||
#ifdef QT_WIDGET
|
#ifdef QT_WIDGET
|
||||||
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
||||||
int mMouseDownX;
|
int mMouseDownX;
|
||||||
|
|||||||
@@ -418,29 +418,29 @@ void WagicCore::mousePressEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
if(event->button() == Qt::LeftButton)
|
if(event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
QPoint lastPos = event->pos();
|
m_lastPos = event->pos();
|
||||||
// this is intended to convert window coordinate into game coordinate.
|
// 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
|
// this is correct only if the game and window have the same aspect ratio, otherwise, it's just wrong
|
||||||
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
||||||
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
|
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
|
||||||
|
|
||||||
if (lastPos.y() >= m_viewPort.top() &&
|
if (lastPosy() >= m_viewPort.top() &&
|
||||||
lastPos.y() <= m_viewPort.bottom() &&
|
lastPosy() <= m_viewPort.bottom() &&
|
||||||
lastPos.x() <= m_viewPort.right() &&
|
lastPosx() <= m_viewPort.right() &&
|
||||||
lastPos.x() >= m_viewPort.left()) {
|
lastPosx() >= m_viewPort.left()) {
|
||||||
m_engine->LeftClicked(
|
m_engine->LeftClicked(
|
||||||
((lastPos.x()-m_viewPort.left())*SCREEN_WIDTH)/actualWidth,
|
((lastPosx()-m_viewPort.left())*SCREEN_WIDTH)/actualWidth,
|
||||||
((lastPos.y()-m_viewPort.top())*SCREEN_HEIGHT)/actualHeight);
|
((lastPosy()-m_viewPort.top())*SCREEN_HEIGHT)/actualHeight);
|
||||||
#if (!defined Q_WS_MAEMO_5) && (!defined MEEGO_EDITION_HARMATTAN) && (!defined Q_WS_ANDROID)
|
#if (!defined Q_WS_MAEMO_5) && (!defined MEEGO_EDITION_HARMATTAN) && (!defined Q_WS_ANDROID)
|
||||||
m_engine->HoldKey_NoRepeat(JGE_BTN_OK);
|
m_engine->HoldKey_NoRepeat(JGE_BTN_OK);
|
||||||
#else
|
#else
|
||||||
mMouseDownX = lastPos.x();
|
mMouseDownX = lastPosx();
|
||||||
mMouseDownY = lastPos.y();
|
mMouseDownY = lastPosy();
|
||||||
mLastFingerDownTime = g_startTimer.elapsed();
|
mLastFingerDownTime = g_startTimer.elapsed();
|
||||||
#endif
|
#endif
|
||||||
} else if(lastPos.y()<m_viewPort.top()) {
|
} else if(lastPosy()<m_viewPort.top()) {
|
||||||
m_engine->HoldKey_NoRepeat(JGE_BTN_MENU);
|
m_engine->HoldKey_NoRepeat(JGE_BTN_MENU);
|
||||||
} else if(lastPos.y()>m_viewPort.bottom()) {
|
} else if(lastPosy()>m_viewPort.bottom()) {
|
||||||
m_engine->HoldKey_NoRepeat(JGE_BTN_NEXT);
|
m_engine->HoldKey_NoRepeat(JGE_BTN_NEXT);
|
||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
@@ -465,33 +465,33 @@ void WagicCore::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
if(event->button() == Qt::LeftButton)
|
if(event->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
QPoint lastPos = event->pos();
|
m_lastPos = event->pos();
|
||||||
|
|
||||||
if (lastPos.y() >= m_viewPort.top() &&
|
if (lastPosy() >= m_viewPort.top() &&
|
||||||
lastPos.y() <= m_viewPort.bottom() &&
|
lastPosy() <= m_viewPort.bottom() &&
|
||||||
lastPos.x() <= m_viewPort.right() &&
|
lastPosx() <= m_viewPort.right() &&
|
||||||
lastPos.x() >= m_viewPort.left()) {
|
lastPosx() >= m_viewPort.left()) {
|
||||||
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
#if (defined Q_WS_MAEMO_5) || (defined MEEGO_EDITION_HARMATTAN) || (defined Q_WS_ANDROID)
|
||||||
if(g_startTimer.elapsed() - mLastFingerDownTime <= kTapEventTimeout )
|
if(g_startTimer.elapsed() - mLastFingerDownTime <= kTapEventTimeout )
|
||||||
{
|
{
|
||||||
if(abs(mMouseDownX - lastPos.x()) < kHitzonePliancy &&
|
if(abs(mMouseDownX - lastPosx()) < kHitzonePliancy &&
|
||||||
abs(mMouseDownY - lastPos.y()) < kHitzonePliancy)
|
abs(mMouseDownY - lastPosy()) < kHitzonePliancy)
|
||||||
{
|
{
|
||||||
m_engine->HoldKey_NoRepeat(JGE_BTN_OK);
|
m_engine->HoldKey_NoRepeat(JGE_BTN_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (g_startTimer.elapsed() - mLastFingerDownTime >= kSwipeEventMinDuration)
|
else if (g_startTimer.elapsed() - mLastFingerDownTime >= kSwipeEventMinDuration)
|
||||||
{ // Let's swipe
|
{ // Let's swipe
|
||||||
m_engine->Scroll(lastPos.x()-mMouseDownX, lastPos.y()-mMouseDownY);
|
m_engine->Scroll(lastPosx()-mMouseDownX, lastPosy()-mMouseDownY);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
//#if (!defined Q_WS_MAEMO_5) && (!defined MEEGO_EDITION_HARMATTAN)
|
//#if (!defined Q_WS_MAEMO_5) && (!defined MEEGO_EDITION_HARMATTAN)
|
||||||
m_engine->ReleaseKey(JGE_BTN_OK);
|
m_engine->ReleaseKey(JGE_BTN_OK);
|
||||||
#endif
|
#endif
|
||||||
m_engine->ReleaseKey(JGE_BTN_MENU);
|
m_engine->ReleaseKey(JGE_BTN_MENU);
|
||||||
} else if(lastPos.y() < m_viewPort.top()) {
|
} else if(lastPosy() < m_viewPort.top()) {
|
||||||
m_engine->ReleaseKey(JGE_BTN_MENU);
|
m_engine->ReleaseKey(JGE_BTN_MENU);
|
||||||
} else if(lastPos.y() > m_viewPort.bottom()) {
|
} else if(lastPosy() > m_viewPort.bottom()) {
|
||||||
m_engine->ReleaseKey(JGE_BTN_NEXT);
|
m_engine->ReleaseKey(JGE_BTN_NEXT);
|
||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
@@ -517,15 +517,15 @@ void WagicCore::mouseMoveEvent(QMouseEvent *event)
|
|||||||
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
int actualWidth = (int) JRenderer::GetInstance()->GetActualWidth();
|
||||||
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
|
int actualHeight = (int) JRenderer::GetInstance()->GetActualHeight();
|
||||||
|
|
||||||
QPoint lastPos = event->pos();
|
m_lastPos = event->pos();
|
||||||
|
|
||||||
if (lastPos.y() >= m_viewPort.top() &&
|
if (lastPosy() >= m_viewPort.top() &&
|
||||||
lastPos.y() <= m_viewPort.bottom() &&
|
lastPosy() <= m_viewPort.bottom() &&
|
||||||
lastPos.x() <= m_viewPort.right() &&
|
lastPosx() <= m_viewPort.right() &&
|
||||||
lastPos.x() >= m_viewPort.left()) {
|
lastPosx() >= m_viewPort.left()) {
|
||||||
m_engine->LeftClicked(
|
m_engine->LeftClicked(
|
||||||
((lastPos.x()-m_viewPort.left())*SCREEN_WIDTH)/actualWidth,
|
((lastPosx()-m_viewPort.left())*SCREEN_WIDTH)/actualWidth,
|
||||||
((lastPos.y()-m_viewPort.top())*SCREEN_HEIGHT)/actualHeight);
|
((lastPosy()-m_viewPort.top())*SCREEN_HEIGHT)/actualHeight);
|
||||||
event->accept();
|
event->accept();
|
||||||
} else {
|
} else {
|
||||||
super::mouseMoveEvent(event);
|
super::mouseMoveEvent(event);
|
||||||
|
|||||||
Reference in New Issue
Block a user