qt: Add fullscreen status icons support and option
This commit is contained in:
@@ -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]));
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user