HostDisplay: Track mouse position
This commit is contained in:
parent
2502afc3f6
commit
1000cb30a9
|
@ -33,6 +33,15 @@ public:
|
|||
ALWAYS_INLINE s32 GetWindowWidth() const { return m_window_width; }
|
||||
ALWAYS_INLINE s32 GetWindowHeight() const { return m_window_height; }
|
||||
|
||||
// Position is relative to the top-left corner of the window.
|
||||
ALWAYS_INLINE s32 GetMousePositionX() const { return m_mouse_position_x; }
|
||||
ALWAYS_INLINE s32 GetMousePositionY() const { return m_mouse_position_y; }
|
||||
ALWAYS_INLINE void SetMousePosition(s32 x, s32 y)
|
||||
{
|
||||
m_mouse_position_x = x;
|
||||
m_mouse_position_y = y;
|
||||
}
|
||||
|
||||
virtual RenderAPI GetRenderAPI() const = 0;
|
||||
virtual void* GetRenderDevice() const = 0;
|
||||
virtual void* GetRenderContext() const = 0;
|
||||
|
@ -122,6 +131,9 @@ protected:
|
|||
s32 m_window_width = 0;
|
||||
s32 m_window_height = 0;
|
||||
|
||||
s32 m_mouse_position_x = 0;
|
||||
s32 m_mouse_position_y = 0;
|
||||
|
||||
s32 m_display_width = 0;
|
||||
s32 m_display_height = 0;
|
||||
s32 m_display_active_left = 0;
|
||||
|
|
|
@ -18,6 +18,7 @@ QtDisplayWidget::QtDisplayWidget(QWidget* parent) : QWidget(parent)
|
|||
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||
setAttribute(Qt::WA_PaintOnScreen, true);
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
QtDisplayWidget::~QtDisplayWidget() = default;
|
||||
|
@ -58,18 +59,27 @@ bool QtDisplayWidget::event(QEvent* event)
|
|||
case QEvent::KeyPress:
|
||||
case QEvent::KeyRelease:
|
||||
{
|
||||
QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
|
||||
const QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
|
||||
if (!key_event->isAutoRepeat())
|
||||
emit windowKeyEvent(QtUtils::KeyEventToInt(key_event), event->type() == QEvent::KeyPress);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case QEvent::MouseMove:
|
||||
{
|
||||
const qreal dpr = devicePixelRatioFromScreen();
|
||||
const QMouseEvent* mouse_event = static_cast<QMouseEvent*>(event);
|
||||
emit windowMouseMoveEvent(static_cast<int>(static_cast<double>(mouse_event->x()) * dpr),
|
||||
static_cast<int>(static_cast<double>(mouse_event->y()) * dpr));
|
||||
return true;
|
||||
}
|
||||
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
const u32 button_index = CountTrailingZeros(static_cast<u32>(static_cast<const QMouseEvent*>(event)->button()));
|
||||
emit windowMouseEvent(static_cast<int>(button_index + 1u), event->type() == QEvent::MouseButtonPress);
|
||||
emit windowMouseButtonEvent(static_cast<int>(button_index + 1u), event->type() == QEvent::MouseButtonPress);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ Q_SIGNALS:
|
|||
void windowRestoredEvent();
|
||||
void windowClosedEvent();
|
||||
void windowKeyEvent(int key_code, bool pressed);
|
||||
void windowMouseEvent(int button, bool pressed);
|
||||
void windowMouseMoveEvent(int x, int y);
|
||||
void windowMouseButtonEvent(int button, bool pressed);
|
||||
|
||||
protected:
|
||||
bool event(QEvent* event) override;
|
||||
|
|
|
@ -220,7 +220,13 @@ void QtHostInterface::onDisplayWindowKeyEvent(int key, bool pressed)
|
|||
HandleHostKeyEvent(key, pressed);
|
||||
}
|
||||
|
||||
void QtHostInterface::onDisplayWindowMouseEvent(int button, bool pressed)
|
||||
void QtHostInterface::onDisplayWindowMouseMoveEvent(int x, int y)
|
||||
{
|
||||
DebugAssert(isOnWorkerThread());
|
||||
m_display->SetMousePosition(x, y);
|
||||
}
|
||||
|
||||
void QtHostInterface::onDisplayWindowMouseButtonEvent(int button, bool pressed)
|
||||
{
|
||||
DebugAssert(isOnWorkerThread());
|
||||
HandleHostMouseEvent(button, pressed);
|
||||
|
@ -322,7 +328,8 @@ void QtHostInterface::connectDisplaySignals()
|
|||
connect(widget, &QtDisplayWidget::windowClosedEvent, this, &QtHostInterface::powerOffSystem,
|
||||
Qt::BlockingQueuedConnection);
|
||||
connect(widget, &QtDisplayWidget::windowKeyEvent, this, &QtHostInterface::onDisplayWindowKeyEvent);
|
||||
connect(widget, &QtDisplayWidget::windowMouseEvent, this, &QtHostInterface::onDisplayWindowMouseEvent);
|
||||
connect(widget, &QtDisplayWidget::windowMouseMoveEvent, this, &QtHostInterface::onDisplayWindowMouseMoveEvent);
|
||||
connect(widget, &QtDisplayWidget::windowMouseButtonEvent, this, &QtHostInterface::onDisplayWindowMouseButtonEvent);
|
||||
}
|
||||
|
||||
void QtHostInterface::disconnectDisplaySignals()
|
||||
|
|
|
@ -104,7 +104,8 @@ public Q_SLOTS:
|
|||
void updateInputMap();
|
||||
void applyInputProfile(const QString& profile_path);
|
||||
void onDisplayWindowKeyEvent(int key, bool pressed);
|
||||
void onDisplayWindowMouseEvent(int button, bool pressed);
|
||||
void onDisplayWindowMouseMoveEvent(int x, int y);
|
||||
void onDisplayWindowMouseButtonEvent(int button, bool pressed);
|
||||
void bootSystem(const SystemBootParameters& params);
|
||||
void resumeSystemFromState(const QString& filename, bool boot_on_failure);
|
||||
void powerOffSystem();
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
#include "frontend-common/sdl_controller_interface.h"
|
||||
#include "imgui_impl_sdl.h"
|
||||
#include "opengl_host_display.h"
|
||||
#include "sdl_key_names.h"
|
||||
#include "scmversion/scmversion.h"
|
||||
#include "sdl_key_names.h"
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <imgui.h>
|
||||
|
@ -481,6 +481,12 @@ void SDLHostInterface::HandleSDLEvent(const SDL_Event* event)
|
|||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
m_display->SetMousePosition(event->motion.x, event->motion.y);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue