mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 18:53:28 +01:00
Qt: gs_frame position updates
This commit is contained in:
parent
5a3c218239
commit
e557c962fb
@ -5,8 +5,8 @@
|
|||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
#include <QOffscreenSurface>
|
#include <QOffscreenSurface>
|
||||||
|
|
||||||
gl_gs_frame::gl_gs_frame(const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings)
|
gl_gs_frame::gl_gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings)
|
||||||
: gs_frame(geometry, appIcon, gui_settings)
|
: gs_frame(screen, geometry, appIcon, gui_settings)
|
||||||
{
|
{
|
||||||
setSurfaceType(QSurface::OpenGLSurface);
|
setSurfaceType(QSurface::OpenGLSurface);
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ private:
|
|||||||
GLContext *m_primary_context = nullptr;
|
GLContext *m_primary_context = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
gl_gs_frame(const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings);
|
explicit gl_gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings);
|
||||||
|
|
||||||
draw_context_t make_context() override;
|
draw_context_t make_context() override;
|
||||||
void set_current(draw_context_t context) override;
|
void set_current(draw_context_t context) override;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QScreen>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@ -51,8 +52,10 @@ extern atomic_t<bool> g_user_asked_for_frame_capture;
|
|||||||
|
|
||||||
constexpr auto qstr = QString::fromStdString;
|
constexpr auto qstr = QString::fromStdString;
|
||||||
|
|
||||||
gs_frame::gs_frame(const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings)
|
gs_frame::gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings)
|
||||||
: QWindow(), m_gui_settings(gui_settings)
|
: QWindow()
|
||||||
|
, m_initial_geometry(geometry)
|
||||||
|
, m_gui_settings(gui_settings)
|
||||||
{
|
{
|
||||||
m_disable_mouse = gui_settings->GetValue(gui::gs_disableMouse).toBool();
|
m_disable_mouse = gui_settings->GetValue(gui::gs_disableMouse).toBool();
|
||||||
m_disable_kb_hotkeys = gui_settings->GetValue(gui::gs_disableKbHotkeys).toBool();
|
m_disable_kb_hotkeys = gui_settings->GetValue(gui::gs_disableKbHotkeys).toBool();
|
||||||
@ -75,6 +78,7 @@ gs_frame::gs_frame(const QRect& geometry, const QIcon& appIcon, const std::share
|
|||||||
|
|
||||||
setMinimumWidth(160);
|
setMinimumWidth(160);
|
||||||
setMinimumHeight(90);
|
setMinimumHeight(90);
|
||||||
|
setScreen(screen);
|
||||||
setGeometry(geometry);
|
setGeometry(geometry);
|
||||||
setTitle(m_window_title);
|
setTitle(m_window_title);
|
||||||
setVisibility(Hidden);
|
setVisibility(Hidden);
|
||||||
@ -133,11 +137,11 @@ void gs_frame::paintEvent(QPaintEvent *event)
|
|||||||
void gs_frame::showEvent(QShowEvent *event)
|
void gs_frame::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
// we have to calculate new window positions, since the frame is only known once the window was created
|
// we have to calculate new window positions, since the frame is only known once the window was created
|
||||||
// the left and right margins are too big on my setup for some reason yet unknown, so we'll have to ignore them
|
const QRect available_geometry = screen()->availableGeometry();
|
||||||
const int x = geometry().left(); //std::max(geometry().left(), frameMargins().left());
|
QPoint pos = m_initial_geometry.topLeft();
|
||||||
const int y = std::max(geometry().top(), frameMargins().top());
|
pos.setX(std::clamp(pos.x(), available_geometry.left(), available_geometry.width() - frameGeometry().width()));
|
||||||
|
pos.setY(std::clamp(pos.y(), available_geometry.top(), available_geometry.height() - frameGeometry().height()));
|
||||||
setPosition(x, y);
|
setFramePosition(pos);
|
||||||
|
|
||||||
QWindow::showEvent(event);
|
QWindow::showEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ private:
|
|||||||
void UpdateProgress(int progress, bool disable = false);
|
void UpdateProgress(int progress, bool disable = false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QRect m_initial_geometry;
|
||||||
|
|
||||||
std::shared_ptr<gui_settings> m_gui_settings;
|
std::shared_ptr<gui_settings> m_gui_settings;
|
||||||
QTimer m_mousehide_timer;
|
QTimer m_mousehide_timer;
|
||||||
|
|
||||||
@ -48,7 +50,7 @@ private:
|
|||||||
bool m_flip_showed_frame = false;
|
bool m_flip_showed_frame = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
gs_frame(const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings);
|
explicit gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, const std::shared_ptr<gui_settings>& gui_settings);
|
||||||
~gs_frame();
|
~gs_frame();
|
||||||
|
|
||||||
draw_context_t make_context() override;
|
draw_context_t make_context() override;
|
||||||
|
@ -256,8 +256,9 @@ std::unique_ptr<gs_frame> gui_application::get_gs_frame()
|
|||||||
h = m_gui_settings->GetValue(gui::gs_height).toInt();
|
h = m_gui_settings->GetValue(gui::gs_height).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto screen_geometry = m_main_window ? m_main_window->geometry() : primaryScreen()->geometry();
|
const auto screen = m_main_window ? m_main_window->screen() : primaryScreen();
|
||||||
const auto frame_geometry = gui::utils::create_centered_window_geometry(screen_geometry, w, h);
|
const auto source_geometry = m_main_window ? m_main_window->geometry() : primaryScreen()->geometry();
|
||||||
|
const auto frame_geometry = gui::utils::create_centered_window_geometry(screen, source_geometry, w, h);
|
||||||
const auto app_icon = m_main_window ? m_main_window->GetAppIcon() : gui::utils::get_app_icon_from_path(Emu.GetBoot(), Emu.GetTitleID());
|
const auto app_icon = m_main_window ? m_main_window->GetAppIcon() : gui::utils::get_app_icon_from_path(Emu.GetBoot(), Emu.GetTitleID());
|
||||||
|
|
||||||
gs_frame* frame;
|
gs_frame* frame;
|
||||||
@ -266,13 +267,13 @@ std::unique_ptr<gs_frame> gui_application::get_gs_frame()
|
|||||||
{
|
{
|
||||||
case video_renderer::opengl:
|
case video_renderer::opengl:
|
||||||
{
|
{
|
||||||
frame = new gl_gs_frame(frame_geometry, app_icon, m_gui_settings);
|
frame = new gl_gs_frame(screen, frame_geometry, app_icon, m_gui_settings);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case video_renderer::null:
|
case video_renderer::null:
|
||||||
case video_renderer::vulkan:
|
case video_renderer::vulkan:
|
||||||
{
|
{
|
||||||
frame = new gs_frame(frame_geometry, app_icon, m_gui_settings);
|
frame = new gs_frame(screen, frame_geometry, app_icon, m_gui_settings);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: fmt::throw_exception("Invalid video renderer: %s", type);
|
default: fmt::throw_exception("Invalid video renderer: %s", type);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "Emu/System.h"
|
#include "Emu/System.h"
|
||||||
#include "Utilities/File.h"
|
#include "Utilities/File.h"
|
||||||
@ -18,29 +19,24 @@ namespace gui
|
|||||||
{
|
{
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
QRect create_centered_window_geometry(const QRect& origin, s32 width, s32 height)
|
QRect create_centered_window_geometry(const QScreen* screen, const QRect& origin, s32 width, s32 height)
|
||||||
{
|
{
|
||||||
|
ensure(screen);
|
||||||
|
|
||||||
// Get minimum virtual screen x & y for clamping the
|
// Get minimum virtual screen x & y for clamping the
|
||||||
// window x & y later while taking the width and height
|
// window x & y later while taking the width and height
|
||||||
// into account, so they don't go offscreen
|
// into account, so they don't go offscreen
|
||||||
s32 min_screen_x = INT32_MAX;
|
const QRect screen_geometry = screen->availableGeometry();
|
||||||
s32 max_screen_x = INT32_MIN;
|
const s32 min_screen_x = screen_geometry.x();
|
||||||
s32 min_screen_y = INT32_MAX;
|
const s32 max_screen_x = screen_geometry.x() + screen_geometry.width() - width;
|
||||||
s32 max_screen_y = INT32_MIN;
|
const s32 min_screen_y = screen_geometry.y();
|
||||||
for (auto screen : QApplication::screens())
|
const s32 max_screen_y = screen_geometry.y() + screen_geometry.height() - height;
|
||||||
{
|
|
||||||
auto screen_geometry = screen->availableGeometry();
|
|
||||||
min_screen_x = std::min(min_screen_x, screen_geometry.x());
|
|
||||||
max_screen_x = std::max(max_screen_x, screen_geometry.x() + screen_geometry.width() - width);
|
|
||||||
min_screen_y = std::min(min_screen_y, screen_geometry.y());
|
|
||||||
max_screen_y = std::max(max_screen_y, screen_geometry.y() + screen_geometry.height() - height);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 frame_x_raw = origin.left() + ((origin.width() - width) / 2);
|
const s32 frame_x_raw = origin.left() + ((origin.width() - width) / 2);
|
||||||
s32 frame_y_raw = origin.top() + ((origin.height() - height) / 2);
|
const s32 frame_y_raw = origin.top() + ((origin.height() - height) / 2);
|
||||||
|
|
||||||
s32 frame_x = std::clamp(frame_x_raw, min_screen_x, max_screen_x);
|
const s32 frame_x = std::clamp(frame_x_raw, min_screen_x, max_screen_x);
|
||||||
s32 frame_y = std::clamp(frame_y_raw, min_screen_y, max_screen_y);
|
const s32 frame_y = std::clamp(frame_y_raw, min_screen_y, max_screen_y);
|
||||||
|
|
||||||
return QRect(frame_x, frame_y, width, height);
|
return QRect(frame_x, frame_y, width, height);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace gui
|
|||||||
|
|
||||||
// Creates a frame geometry rectangle with given width height that's centered inside the origin,
|
// Creates a frame geometry rectangle with given width height that's centered inside the origin,
|
||||||
// while still considering screen boundaries.
|
// while still considering screen boundaries.
|
||||||
QRect create_centered_window_geometry(const QRect& origin, s32 width, s32 height);
|
QRect create_centered_window_geometry(const QScreen* screen, const QRect& origin, s32 width, s32 height);
|
||||||
|
|
||||||
// Returns a custom colored QPixmap based on another QPixmap.
|
// Returns a custom colored QPixmap based on another QPixmap.
|
||||||
// use colorize_all to repaint every opaque pixel with the chosen color
|
// use colorize_all to repaint every opaque pixel with the chosen color
|
||||||
|
Loading…
Reference in New Issue
Block a user