Skip to content

Commit

Permalink
Merge pull request #6718 from spycrab/qt_freelook
Browse files Browse the repository at this point in the history
Qt: Implement "Free look"
  • Loading branch information
stenzek committed Apr 29, 2018
2 parents e51cf88 + bc51c34 commit 1c9b64f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Source/Core/DolphinQt2/RenderWidget.cpp
Expand Up @@ -6,12 +6,16 @@
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QGuiApplication> #include <QGuiApplication>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMouseEvent>
#include <QPalette> #include <QPalette>
#include <QScreen> #include <QScreen>
#include <QTimer> #include <QTimer>


#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoConfig.h"

#include "DolphinQt2/Host.h" #include "DolphinQt2/Host.h"
#include "DolphinQt2/RenderWidget.h" #include "DolphinQt2/RenderWidget.h"
#include "DolphinQt2/Settings.h" #include "DolphinQt2/Settings.h"
Expand Down Expand Up @@ -120,6 +124,10 @@ bool RenderWidget::event(QEvent* event)
break; break;
} }
case QEvent::MouseMove: case QEvent::MouseMove:
if (g_Config.bFreeLook)
OnFreeLookMouseMove(static_cast<QMouseEvent*>(event));

// [[fallthrough]]
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
if (!Settings::Instance().GetHideCursor() && isActiveWindow()) if (!Settings::Instance().GetHideCursor() && isActiveWindow())
{ {
Expand Down Expand Up @@ -162,3 +170,22 @@ bool RenderWidget::event(QEvent* event)
} }
return QWidget::event(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();
}
5 changes: 5 additions & 0 deletions Source/Core/DolphinQt2/RenderWidget.h
Expand Up @@ -4,9 +4,12 @@


#pragma once #pragma once


#include <array>

#include <QEvent> #include <QEvent>
#include <QWidget> #include <QWidget>


class QMouseEvent;
class QTimer; class QTimer;


class RenderWidget final : public QWidget class RenderWidget final : public QWidget
Expand All @@ -31,7 +34,9 @@ class RenderWidget final : public QWidget
void OnHideCursorChanged(); void OnHideCursorChanged();
void OnKeepOnTopChanged(bool top); void OnKeepOnTopChanged(bool top);
void SetFillBackground(bool fill); void SetFillBackground(bool fill);
void OnFreeLookMouseMove(QMouseEvent* event);


static constexpr int MOUSE_HIDE_DELAY = 3000; static constexpr int MOUSE_HIDE_DELAY = 3000;
QTimer* m_mouse_timer; QTimer* m_mouse_timer;
std::array<float, 2> m_last_mouse{};
}; };

0 comments on commit 1c9b64f

Please sign in to comment.