Permalink
Browse files

Merge pull request #6718 from spycrab/qt_freelook

Qt: Implement "Free look"
  • Loading branch information...
stenzek committed Apr 29, 2018
2 parents e51cf88 + bc51c34 commit 1c9b64ff02ef1f2f6c46631aab5eb30ecdad63b6
Showing with 32 additions and 0 deletions.
  1. +27 −0 Source/Core/DolphinQt2/RenderWidget.cpp
  2. +5 −0 Source/Core/DolphinQt2/RenderWidget.h
@@ -6,12 +6,16 @@
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPalette>
#include <QScreen>
#include <QTimer>
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoConfig.h"
#include "DolphinQt2/Host.h"
#include "DolphinQt2/RenderWidget.h"
#include "DolphinQt2/Settings.h"
@@ -120,6 +124,10 @@ bool RenderWidget::event(QEvent* event)
break;
}
case QEvent::MouseMove:
if (g_Config.bFreeLook)
OnFreeLookMouseMove(static_cast<QMouseEvent*>(event));
// [[fallthrough]]
case QEvent::MouseButtonPress:
if (!Settings::Instance().GetHideCursor() && isActiveWindow())
{
@@ -162,3 +170,22 @@ bool RenderWidget::event(QEvent* event)
}
return QWidget::event(event);
}
void RenderWidget::OnFreeLookMouseMove(QMouseEvent* event)
{
if (event->buttons() & Qt::MidButton)
{
// Mouse Move
VertexShaderManager::TranslateView((event->x() - m_last_mouse[0]) / 50.0f,
(event->y() - m_last_mouse[1]) / 50.0f);
}
else if (event->buttons() & Qt::RightButton)
{
// Mouse Look
VertexShaderManager::RotateView((event->x() - m_last_mouse[0]) / 200.0f,
(event->y() - m_last_mouse[1]) / 200.0f);
}
m_last_mouse[0] = event->x();
m_last_mouse[1] = event->y();
}
@@ -4,9 +4,12 @@
#pragma once
#include <array>
#include <QEvent>
#include <QWidget>
class QMouseEvent;
class QTimer;
class RenderWidget final : public QWidget
@@ -31,7 +34,9 @@ class RenderWidget final : public QWidget
void OnHideCursorChanged();
void OnKeepOnTopChanged(bool top);
void SetFillBackground(bool fill);
void OnFreeLookMouseMove(QMouseEvent* event);
static constexpr int MOUSE_HIDE_DELAY = 3000;
QTimer* m_mouse_timer;
std::array<float, 2> m_last_mouse{};
};

0 comments on commit 1c9b64f

Please sign in to comment.