qt: Add fullscreen status icons support and option
This commit is contained in:
@@ -521,6 +521,7 @@ load_general(void)
|
||||
|
||||
rctrl_is_lalt = config_get_int(cat, "rctrl_is_lalt", 0);
|
||||
update_icons = config_get_int(cat, "update_icons", 1);
|
||||
status_icons_fullscreen = !!config_get_int(cat, "status_icons_fullscreen", 0);
|
||||
|
||||
window_remember = config_get_int(cat, "window_remember", 0);
|
||||
if (window_remember || (vid_resize & 2)) {
|
||||
@@ -2294,6 +2295,11 @@ save_general(void)
|
||||
else
|
||||
config_delete_var(cat, "enable_discord");
|
||||
|
||||
if (status_icons_fullscreen)
|
||||
config_set_int(cat, "status_icons_fullscreen", status_icons_fullscreen);
|
||||
else
|
||||
config_delete_var(cat, "status_icons_fullscreen");
|
||||
|
||||
if (video_framerate != -1)
|
||||
config_set_int(cat, "video_gl_framerate", video_framerate);
|
||||
else
|
||||
|
||||
@@ -88,6 +88,7 @@ extern int infocus;
|
||||
extern char emu_version[200]; /* version ID string */
|
||||
extern int rctrl_is_lalt;
|
||||
extern int update_icons;
|
||||
extern int status_icons_fullscreen;
|
||||
|
||||
extern int unscaled_size_x, /* current unscaled size X */
|
||||
unscaled_size_y; /* current unscaled size Y */
|
||||
|
||||
@@ -86,6 +86,7 @@ void HardwareRenderer::initializeGL()
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" gl_FragColor = texture2D(texture, texc.st).bgra;\n"
|
||||
" gl_FragColor.a = 1.0;\n"
|
||||
"}\n";
|
||||
QString fsrccore =
|
||||
"uniform sampler2D texture;\n"
|
||||
@@ -94,6 +95,7 @@ void HardwareRenderer::initializeGL()
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" FragColor = texture2D(texture, texc.st).bgra;\n"
|
||||
" FragColor.a = 1.0;\n"
|
||||
"}\n";
|
||||
if (m_context->isOpenGLES() && m_context->format().version() >= qMakePair(3, 0))
|
||||
{
|
||||
@@ -135,6 +137,22 @@ void HardwareRenderer::initializeGL()
|
||||
glClearColor(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
void HardwareRenderer::paintOverGL()
|
||||
{
|
||||
// Context switching is needed to make use of QPainter to draw status bar icons in fullscreen.
|
||||
// Especially since it seems to be impossible to use QPainter on externally-created OpenGL contexts.
|
||||
if (video_fullscreen && status_icons_fullscreen)
|
||||
{
|
||||
m_context->makeCurrent(nullptr);
|
||||
makeCurrent();
|
||||
QPainter painter(this);
|
||||
drawStatusBarIcons(&painter);
|
||||
painter.end();
|
||||
doneCurrent();
|
||||
m_context->makeCurrent(this);
|
||||
}
|
||||
}
|
||||
|
||||
void HardwareRenderer::paintGL() {
|
||||
m_context->makeCurrent(this);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
void resizeGL(int w, int h) override;
|
||||
void initializeGL() override;
|
||||
void paintGL() override;
|
||||
void paintOverGL() override;
|
||||
std::vector<std::tuple<uint8_t*, std::atomic_flag*>> getBuffers() override;
|
||||
HardwareRenderer(QWidget* parent = nullptr, RenderType rtype = RenderType::OpenGL)
|
||||
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent->windowHandle()), QOpenGLFunctions()
|
||||
|
||||
@@ -225,6 +225,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->actionHide_tool_bar->setChecked(hide_tool_bar);
|
||||
ui->actionUpdate_status_bar_icons->setChecked(update_icons);
|
||||
ui->actionEnable_Discord_integration->setChecked(enable_discord);
|
||||
ui->actionShow_status_icons_in_fullscreen->setChecked(status_icons_fullscreen);
|
||||
|
||||
#if defined Q_OS_WINDOWS || defined Q_OS_MACOS
|
||||
/* Make the option visible only if ANGLE is loaded. */
|
||||
@@ -1614,3 +1615,10 @@ void MainWindow::changeEvent(QEvent* event)
|
||||
#endif
|
||||
QWidget::changeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionShow_status_icons_in_fullscreen_triggered()
|
||||
{
|
||||
status_icons_fullscreen = !status_icons_fullscreen;
|
||||
ui->actionShow_status_icons_in_fullscreen->setChecked(status_icons_fullscreen);
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,8 @@ private slots:
|
||||
|
||||
void on_actionEnable_Discord_integration_triggered(bool checked);
|
||||
|
||||
void on_actionShow_status_icons_in_fullscreen_triggered();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void keyReleaseEvent(QKeyEvent* event) override;
|
||||
|
||||
@@ -149,6 +149,7 @@
|
||||
</widget>
|
||||
<addaction name="actionHide_tool_bar"/>
|
||||
<addaction name="actionHide_status_bar"/>
|
||||
<addaction name="actionShow_status_icons_in_fullscreen"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionResizable_window"/>
|
||||
<addaction name="actionRemember_size_and_position"/>
|
||||
@@ -697,6 +698,14 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShow_status_icons_in_fullscreen">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show status icons in fullscreen</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
||||
@@ -17,17 +17,25 @@
|
||||
|
||||
#include "qt_renderercommon.hpp"
|
||||
#include "qt_mainwindow.hpp"
|
||||
#include "qt_machinestatus.hpp"
|
||||
#include "ui_qt_mainwindow.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QWidget>
|
||||
#include <QEvent>
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
#include <QStatusBar>
|
||||
#include <QLayout>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
extern "C" {
|
||||
#include <86box/86box.h>
|
||||
#include <86box/plat.h>
|
||||
#include <86box/video.h>
|
||||
|
||||
int status_icons_fullscreen = 0;
|
||||
}
|
||||
|
||||
RendererCommon::RendererCommon() = default;
|
||||
@@ -101,6 +109,44 @@ void RendererCommon::onResize(int width, int height) {
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCommon::drawStatusBarIcons(QPainter* painter)
|
||||
{
|
||||
uint32_t x = 0;
|
||||
auto prevcompositionMode = painter->compositionMode();
|
||||
painter->setCompositionMode(QPainter::CompositionMode::CompositionMode_SourceOver);
|
||||
for (int i = 0; i < main_window->ui->statusbar->children().count(); i++)
|
||||
{
|
||||
QLabel* label = qobject_cast<QLabel*>(main_window->ui->statusbar->children()[i]);
|
||||
if (label)
|
||||
{
|
||||
auto pixmap = label->pixmap(Qt::ReturnByValue);
|
||||
if (!pixmap.isNull())
|
||||
{
|
||||
painter->setBrush(QColor(0, 0, 0, 255));
|
||||
painter->fillRect(x, painter->device()->height() - pixmap.height() - 4, pixmap.width(), pixmap.height() + 4, QColor(0, 0, 0, 127));
|
||||
painter->drawPixmap(x, painter->device()->height() - pixmap.height(), pixmap);
|
||||
x += pixmap.width();
|
||||
if (i <= main_window->ui->statusbar->children().count() - 3)
|
||||
{
|
||||
painter->fillRect(x, painter->device()->height() - pixmap.height() - 4, main_window->ui->statusbar->layout()->spacing(), pixmap.height() + 4, QColor(0, 0, 0, 127));
|
||||
x += main_window->ui->statusbar->layout()->spacing();
|
||||
}
|
||||
else painter->fillRect(x, painter->device()->height() - pixmap.height() - 4, 4, pixmap.height() + 4, QColor(0, 0, 0, 127));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (main_window->status->getMessage().isEmpty() == false)
|
||||
{
|
||||
auto curStatusMsg = main_window->status->getMessage();
|
||||
auto textSize = painter->fontMetrics().size(Qt::TextSingleLine, curStatusMsg);
|
||||
painter->setPen(QColor(0, 0, 0, 127));
|
||||
painter->fillRect(painter->device()->width() - textSize.width(), painter->device()->height() - textSize.height(), textSize.width(), textSize.height(), QColor(0, 0, 0, 127));
|
||||
painter->setPen(QColor(255, 255, 255, 255));
|
||||
painter->drawText(QRectF(painter->device()->width() - textSize.width(), painter->device()->height() - textSize.height(), textSize.width(), textSize.height()), Qt::TextSingleLine, curStatusMsg);
|
||||
}
|
||||
painter->setCompositionMode(prevcompositionMode);
|
||||
}
|
||||
|
||||
bool RendererCommon::eventDelegate(QEvent *event, bool& result)
|
||||
{
|
||||
switch (event->type())
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
virtual std::vector<std::tuple<uint8_t*, std::atomic_flag*>> getBuffers() = 0;
|
||||
protected:
|
||||
bool eventDelegate(QEvent* event, bool& result);
|
||||
void drawStatusBarIcons(QPainter* painter);
|
||||
|
||||
QRect source, destination;
|
||||
QWidget* parentWidget{nullptr};
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
extern "C" {
|
||||
#include <86box/86box.h>
|
||||
#include <86box/plat.h>
|
||||
#include <86box/video.h>
|
||||
}
|
||||
|
||||
@@ -83,6 +84,7 @@ void SoftwareRenderer::onPaint(QPaintDevice* device) {
|
||||
#endif
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Plus);
|
||||
painter.drawImage(destination, *images[cur_image], source);
|
||||
if (video_fullscreen && status_icons_fullscreen) drawStatusBarIcons(&painter);
|
||||
}
|
||||
|
||||
std::vector<std::tuple<uint8_t*, std::atomic_flag*>> SoftwareRenderer::getBuffers()
|
||||
|
||||
@@ -48,6 +48,7 @@ extern wchar_t sdl_win_title[512];
|
||||
plat_joystick_t plat_joystick_state[MAX_PLAT_JOYSTICKS];
|
||||
joystick_t joystick_state[MAX_JOYSTICKS];
|
||||
int joysticks_present;
|
||||
int status_icons_fullscreen = 0; /* unused. */
|
||||
SDL_mutex *blitmtx;
|
||||
SDL_threadID eventthread;
|
||||
static int exit_event = 0;
|
||||
|
||||
@@ -67,6 +67,7 @@ int fixed_size_x = 0, fixed_size_y = 0;
|
||||
int kbd_req_capture = 0;
|
||||
int hide_status_bar = 0;
|
||||
int hide_tool_bar = 0;
|
||||
int status_icons_fullscreen = 0; /* unused. */
|
||||
int dpi = 96;
|
||||
|
||||
extern char openfilestring[512];
|
||||
|
||||
Reference in New Issue
Block a user