qt: Add fullscreen status icons support and option

This commit is contained in:
Cacodemon345
2022-02-16 01:09:11 +06:00
parent ba7befbbca
commit c577aa85f2
12 changed files with 106 additions and 10 deletions

View File

@@ -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

View File

@@ -75,7 +75,7 @@ extern "C" {
/* Global variables residing in the platform module. */
extern int dopause, /* system is paused */
mouse_capture; /* mouse is captured in app */
mouse_capture; /* mouse is captured in app */
extern atomic_flag_t doresize; /* screen resize requested */
extern volatile int is_quit; /* system exit requested */
@@ -88,9 +88,10 @@ 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 */
unscaled_size_y; /* current unscaled size Y */
extern int kbd_req_capture, hide_status_bar, hide_tool_bar;

View File

@@ -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);
@@ -200,7 +218,7 @@ void HardwareRenderer::onBlit(int buf_idx, int x, int y, int w, int h) {
void HardwareRenderer::resizeEvent(QResizeEvent *event) {
onResize(width(), height());
QOpenGLWindow::resizeEvent(event);
}
@@ -214,7 +232,7 @@ bool HardwareRenderer::event(QEvent *event)
std::vector<std::tuple<uint8_t*, std::atomic_flag*>> HardwareRenderer::getBuffers()
{
std::vector<std::tuple<uint8_t*, std::atomic_flag*>> buffers;
buffers.push_back(std::make_tuple(imagebufs[0].get(), &buf_usage[0]));
buffers.push_back(std::make_tuple(imagebufs[1].get(), &buf_usage[1]));

View File

@@ -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()

View File

@@ -132,7 +132,7 @@ MainWindow::MainWindow(QWidget *parent) :
return;
}
if (!hide_tool_bar)
#ifdef _WIN32
#ifdef _WIN32
toolbar_label->setText(title);
#else
{
@@ -187,12 +187,12 @@ MainWindow::MainWindow(QWidget *parent) :
connect(this, &MainWindow::resizeContents, this, [this](int w, int h) {
if (!QApplication::platformName().contains("eglfs") && vid_resize == 0) {
w = qRound(w / (!dpi_scale ? util::screenOfWidget(this)->devicePixelRatio() : 1.));
int modifiedHeight = qRound(h / (!dpi_scale ? util::screenOfWidget(this)->devicePixelRatio() : 1.))
+ menuBar()->height()
+ (statusBar()->height() * !hide_status_bar)
+ (ui->toolBar->height() * !hide_tool_bar);
ui->stackedWidget->resize(w, h);
setFixedSize(w, modifiedHeight);
}
@@ -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);
}

View File

@@ -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;
@@ -124,7 +126,7 @@ private:
Ui::MainWindow *ui;
std::unique_ptr<MachineStatus> status;
std::shared_ptr<MediaMenu> mm;
/* If main window should send keyboard input */
bool send_keyboard_input = true;
bool shownonce = false;

View File

@@ -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>

View File

@@ -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())

View File

@@ -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};

View File

@@ -24,6 +24,7 @@
extern "C" {
#include <86box/86box.h>
#include <86box/plat.h>
#include <86box/video.h>
}
@@ -53,7 +54,7 @@ void SoftwareRenderer::onBlit(int buf_idx, int x, int y, int w, int h) {
cur_image = buf_idx;
buf_usage[(buf_idx + 1) % 2].clear();
source.setRect(x, y, w, h),
update();
}
@@ -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()

View File

@@ -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;
@@ -1272,4 +1273,4 @@ void endblit()
void
ui_sb_mt32lcd(char* str)
{
}
}

View File

@@ -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];