window drawing bugfix

This commit is contained in:
Geoffray Levasseur committed 2026-11-04 14:05:01 +01:00
1 parent 6f3556009a
commit 19006fac6c
5 files changed
+36 -27

No files matched your search

+15 -3
View File
@@ -28,12 +28,15 @@
#include "Back.h"
#include "Dpi/DpiForms.h"
#include "Global.h"
#include <QFileInfo>
#include <QPainter>
#include <QScreen>
#include <algorithm>
namespace Cevo {
Background::Background(QWidget *parent) : QWidget(parent)
@@ -54,9 +57,9 @@ void Background::showEvent(QShowEvent *event)
void Background::updateInterface()
{
const QRect screenRect = Dpi::Screen::primaryMonitor().boundsRect();
if (fullScreen) {
if (QScreen *primaryScreen = screen())
setGeometry(primaryScreen->geometry());
setGeometry(screenRect);
showFullScreen();
if (!m_img) {
const QString fileName = getGraphicsDir() + QLatin1Char('/') + QStringLiteral("Background") + PngExt;
@@ -66,12 +69,21 @@ void Background::updateInterface()
update();
}
}
if (m_anchor) {
// Below the logo, with its bottom near the bottom of the screen.
const QPoint shift((screenRect.width() - std::min(screenRect.width(), 800)) * 3 / 8,
(screenRect.height() - std::min(screenRect.height(), 600)) / 3);
m_anchor->move(shift.x(), screenRect.height() - m_anchor->height() - shift.y());
}
} else {
// Dropped the original's wsNormal/wsFullScreen/wsNormal toggle - an
// LCL-specific refresh workaround, not needed with Qt.
showNormal();
if (m_anchor) {
setGeometry(m_anchor->x() - 8, m_anchor->y() - 8, m_anchor->width() + 16, m_anchor->height() + 16);
// A black frame around the anchor, centred on the screen.
const QSize frameSize = m_anchor->size() + QSize(16, 16);
setGeometry(QRect(screenRect.center() - QPoint(frameSize.width() / 2, frameSize.height() / 2), frameSize));
m_anchor->move(8, 8);
}
}
}
+14 -14
View File
@@ -115,13 +115,12 @@ QString incrementFileName(const QString &fileName)
} // namespace
StartDlg::StartDlg(DirectDlg *direct, QWidget *parent)
: BufferedDrawDlg(parent), m_direct(direct), ui(new Ui::StartDlg)
StartDlg::StartDlg(DirectDlg *direct, Background *background)
: BufferedDrawDlg(background), m_direct(direct), m_background(background), ui(new Ui::StartDlg)
{
ui->setupUi(this);
setMouseTracking(true);
setWindowFlag(Qt::WindowStaysOnTopHint, true);
m_background = std::make_unique<Background>();
// A child of the background window: it is always drawn above it, and is placed relative to it.
m_background->setAnchor(this);
titleHeight = 0;
@@ -282,14 +281,12 @@ StartDlg::StartDlg(DirectDlg *direct, QWidget *parent)
if (m_showTab == Tab::PreviousGame)
GameServer::previewMap(m_startLandMass); // avoid delay on first tab change
changeTab(m_showTab);
m_background->setEnabled(false);
updateMusic();
};
onHide = [this] {
m_diff0 = Database::difficulty[0];
m_listIndex[static_cast<std::size_t>(m_tab)] = ui->list->currentRow();
m_showTab = m_tab;
m_background->setEnabled(true);
const int formerIndex = m_listIndex[static_cast<std::size_t>(Tab::PreviousGame)];
m_lastGame = formerIndex >= 0 && formerIndex < m_formerGames.count() ? m_formerGames[formerIndex].nameOnly()
: QString();
@@ -300,7 +297,14 @@ StartDlg::StartDlg(DirectDlg *direct, QWidget *parent)
if (ui->list->count() > 0 && ui->list->currentItem())
ui->list->scrollToItem(ui->list->currentItem());
};
onClose = [this] { m_direct->close(); };
// Closing the start screen ends the application (the original's main form, DirectDlg, closes).
// DirectDlg is hidden by then and the start screen is only a child window, so closing them
// would not by itself make Qt quit.
onClose = [this] {
m_direct->close();
m_background->close();
QCoreApplication::quit();
};
}
StartDlg::~StartDlg()
@@ -374,11 +378,9 @@ void StartDlg::loadAiBrainsPictures()
void StartDlg::updateInterface()
{
const QRect screen = Dpi::Screen::primaryMonitor().boundsRect();
// The background window sizes itself and places this dialog.
m_background->updateInterface();
if (fullScreen) {
const QPoint shift((screen.width() - std::min(screen.width(), 800)) * 3 / 8,
(screen.height() - std::min(screen.height(), 600)) / 3);
move(screen.left() + shift.x(), screen.top() + screen.height() - height() - shift.y());
// Only the quit button area above the tab strip stays visible, as in the original window region.
QRegion region(0, 0, width(), height());
region -= QRegion(TabOffset + 4 * TabSize + 2, 0, width() - (TabOffset + 4 * TabSize + 2), TabHeight);
@@ -386,7 +388,6 @@ void StartDlg::updateInterface()
setMask(region);
} else {
clearMask();
centerToScreen();
}
}
@@ -754,7 +755,6 @@ void StartDlg::keyPressEvent(QKeyEvent *event)
if (KeyBindings::bFullScreen && KeyBindings::bFullScreen->test(shortcut)) {
fullScreen = !fullScreen;
updateInterface();
m_background->updateInterface();
activateWindow();
} else if (KeyBindings::bHelp && KeyBindings::bHelp->test(shortcut)) {
GameServer::directHelp(cStartHelp);
@@ -1106,7 +1106,7 @@ void StartDlg::renameClicked()
: QStringLiteral("TITLE_MAPNAME")));
const int row = ui->list->currentRow();
inputDlg.editInput()->setText(ui->list->item(row)->text());
inputDlg.centerToRect(geometry());
inputDlg.centerToRect(QRect(mapToGlobal(QPoint(0, 0)), size()));
inputDlg.showModal();
QString newName = inputDlg.editInput()->text();
while (GameServer::isAutoSaveFileName(newName))
+3 -3
View File
@@ -64,10 +64,10 @@ public:
enum class Tab { Main, Map, NewGame, PreviousGame };
enum class MainAction { Config, Manual, Credits, AIDev, Web, None };
explicit StartDlg(DirectDlg *direct, QWidget *parent = nullptr);
explicit StartDlg(DirectDlg *direct, Background *background);
~StartDlg() override;
Background *background() const { return m_background.get(); }
Background *background() const { return m_background; }
Languages &languages() { return m_languages; }
// Called by DirectDlg when a game ends or a map was edited.
@@ -163,7 +163,7 @@ private:
QString m_lastMap;
DirectDlg *m_direct;
std::unique_ptr<Background> m_background;
Background *m_background; // not owned: the dialog is its child window
Dpi::Bitmap m_emptyPicture;
MiniMap m_miniMap;
Languages m_languages;
+2 -7
View File
@@ -27,13 +27,10 @@
// knowledge of the CeCILL license and that you accept its terms.
#include "game/Direct.h"
#include "game/GameServer.h"
#include <QDebug>
#include "game/Global.h"
#include "game/Start.h"
#include <QApplication>
#include <QTimer>
#include <QLocale>
#include <QTranslator>
@@ -59,11 +56,9 @@ int main(int argc, char *argv[])
// DirectDlg (created first, as in the original) is the main window; it
// shows the start screen once the game engine is up.
Cevo::DirectDlg direct;
Cevo::StartDlg start(&direct);
Cevo::Background background; // declared before the start dialog, which is its child
Cevo::StartDlg start(&direct, &background);
direct.setStartDlg(&start);
direct.show();
QTimer::singleShot(2000, [] { for (int i = 0; i < Cevo::GameServer::brains.count(); ++i) qWarning() << "BRAIN" << i << Cevo::GameServer::brains[i].fileName << Cevo::GameServer::brains[i].name() << int(Cevo::GameServer::brains[i].kind) << Cevo::GameServer::brains[i].beginner; }); // TEMP-GRAB
QTimer::singleShot(2500, [&start] { start.grab().save(QStringLiteral("/tmp/start-shot.png")); }); // TEMP-GRAB
QTimer::singleShot(3000, [] { QCoreApplication::quit(); }); // TEMP-GRAB
return a.exec();
}
+2
View File
@@ -44,6 +44,8 @@ namespace Cevo {
DrawDlg::DrawDlg(QWidget *parent) : Dpi::Form(parent)
{
// The original's dialogs are borderless (BorderStyle = bsNone): they draw their own frame and title.
setWindowFlag(Qt::FramelessWindowHint, true);
QPalette pal = palette();
pal.setColor(QPalette::Window, Qt::black);
setPalette(pal);