window drawing bugfix
This commit is contained in:
1 parent
6f3556009a
commit
19006fac6c
5 files changed
+36
-27
No files matched your search
+15
-3
@@ -28,12 +28,15 @@
|
|||||||
|
|
||||||
#include "Back.h"
|
#include "Back.h"
|
||||||
|
|
||||||
|
#include "Dpi/DpiForms.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Cevo {
|
namespace Cevo {
|
||||||
|
|
||||||
Background::Background(QWidget *parent) : QWidget(parent)
|
Background::Background(QWidget *parent) : QWidget(parent)
|
||||||
@@ -54,9 +57,9 @@ void Background::showEvent(QShowEvent *event)
|
|||||||
|
|
||||||
void Background::updateInterface()
|
void Background::updateInterface()
|
||||||
{
|
{
|
||||||
|
const QRect screenRect = Dpi::Screen::primaryMonitor().boundsRect();
|
||||||
if (fullScreen) {
|
if (fullScreen) {
|
||||||
if (QScreen *primaryScreen = screen())
|
setGeometry(screenRect);
|
||||||
setGeometry(primaryScreen->geometry());
|
|
||||||
showFullScreen();
|
showFullScreen();
|
||||||
if (!m_img) {
|
if (!m_img) {
|
||||||
const QString fileName = getGraphicsDir() + QLatin1Char('/') + QStringLiteral("Background") + PngExt;
|
const QString fileName = getGraphicsDir() + QLatin1Char('/') + QStringLiteral("Background") + PngExt;
|
||||||
@@ -66,12 +69,21 @@ void Background::updateInterface()
|
|||||||
update();
|
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 {
|
} else {
|
||||||
// Dropped the original's wsNormal/wsFullScreen/wsNormal toggle - an
|
// Dropped the original's wsNormal/wsFullScreen/wsNormal toggle - an
|
||||||
// LCL-specific refresh workaround, not needed with Qt.
|
// LCL-specific refresh workaround, not needed with Qt.
|
||||||
showNormal();
|
showNormal();
|
||||||
if (m_anchor) {
|
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
@@ -115,13 +115,12 @@ QString incrementFileName(const QString &fileName)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
StartDlg::StartDlg(DirectDlg *direct, QWidget *parent)
|
StartDlg::StartDlg(DirectDlg *direct, Background *background)
|
||||||
: BufferedDrawDlg(parent), m_direct(direct), ui(new Ui::StartDlg)
|
: BufferedDrawDlg(background), m_direct(direct), m_background(background), ui(new Ui::StartDlg)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setWindowFlag(Qt::WindowStaysOnTopHint, true);
|
// A child of the background window: it is always drawn above it, and is placed relative to it.
|
||||||
m_background = std::make_unique<Background>();
|
|
||||||
m_background->setAnchor(this);
|
m_background->setAnchor(this);
|
||||||
|
|
||||||
titleHeight = 0;
|
titleHeight = 0;
|
||||||
@@ -282,14 +281,12 @@ StartDlg::StartDlg(DirectDlg *direct, QWidget *parent)
|
|||||||
if (m_showTab == Tab::PreviousGame)
|
if (m_showTab == Tab::PreviousGame)
|
||||||
GameServer::previewMap(m_startLandMass); // avoid delay on first tab change
|
GameServer::previewMap(m_startLandMass); // avoid delay on first tab change
|
||||||
changeTab(m_showTab);
|
changeTab(m_showTab);
|
||||||
m_background->setEnabled(false);
|
|
||||||
updateMusic();
|
updateMusic();
|
||||||
};
|
};
|
||||||
onHide = [this] {
|
onHide = [this] {
|
||||||
m_diff0 = Database::difficulty[0];
|
m_diff0 = Database::difficulty[0];
|
||||||
m_listIndex[static_cast<std::size_t>(m_tab)] = ui->list->currentRow();
|
m_listIndex[static_cast<std::size_t>(m_tab)] = ui->list->currentRow();
|
||||||
m_showTab = m_tab;
|
m_showTab = m_tab;
|
||||||
m_background->setEnabled(true);
|
|
||||||
const int formerIndex = m_listIndex[static_cast<std::size_t>(Tab::PreviousGame)];
|
const int formerIndex = m_listIndex[static_cast<std::size_t>(Tab::PreviousGame)];
|
||||||
m_lastGame = formerIndex >= 0 && formerIndex < m_formerGames.count() ? m_formerGames[formerIndex].nameOnly()
|
m_lastGame = formerIndex >= 0 && formerIndex < m_formerGames.count() ? m_formerGames[formerIndex].nameOnly()
|
||||||
: QString();
|
: QString();
|
||||||
@@ -300,7 +297,14 @@ StartDlg::StartDlg(DirectDlg *direct, QWidget *parent)
|
|||||||
if (ui->list->count() > 0 && ui->list->currentItem())
|
if (ui->list->count() > 0 && ui->list->currentItem())
|
||||||
ui->list->scrollToItem(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()
|
StartDlg::~StartDlg()
|
||||||
@@ -374,11 +378,9 @@ void StartDlg::loadAiBrainsPictures()
|
|||||||
|
|
||||||
void StartDlg::updateInterface()
|
void StartDlg::updateInterface()
|
||||||
{
|
{
|
||||||
const QRect screen = Dpi::Screen::primaryMonitor().boundsRect();
|
// The background window sizes itself and places this dialog.
|
||||||
|
m_background->updateInterface();
|
||||||
if (fullScreen) {
|
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.
|
// Only the quit button area above the tab strip stays visible, as in the original window region.
|
||||||
QRegion region(0, 0, width(), height());
|
QRegion region(0, 0, width(), height());
|
||||||
region -= QRegion(TabOffset + 4 * TabSize + 2, 0, width() - (TabOffset + 4 * TabSize + 2), TabHeight);
|
region -= QRegion(TabOffset + 4 * TabSize + 2, 0, width() - (TabOffset + 4 * TabSize + 2), TabHeight);
|
||||||
@@ -386,7 +388,6 @@ void StartDlg::updateInterface()
|
|||||||
setMask(region);
|
setMask(region);
|
||||||
} else {
|
} else {
|
||||||
clearMask();
|
clearMask();
|
||||||
centerToScreen();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,7 +755,6 @@ void StartDlg::keyPressEvent(QKeyEvent *event)
|
|||||||
if (KeyBindings::bFullScreen && KeyBindings::bFullScreen->test(shortcut)) {
|
if (KeyBindings::bFullScreen && KeyBindings::bFullScreen->test(shortcut)) {
|
||||||
fullScreen = !fullScreen;
|
fullScreen = !fullScreen;
|
||||||
updateInterface();
|
updateInterface();
|
||||||
m_background->updateInterface();
|
|
||||||
activateWindow();
|
activateWindow();
|
||||||
} else if (KeyBindings::bHelp && KeyBindings::bHelp->test(shortcut)) {
|
} else if (KeyBindings::bHelp && KeyBindings::bHelp->test(shortcut)) {
|
||||||
GameServer::directHelp(cStartHelp);
|
GameServer::directHelp(cStartHelp);
|
||||||
@@ -1106,7 +1106,7 @@ void StartDlg::renameClicked()
|
|||||||
: QStringLiteral("TITLE_MAPNAME")));
|
: QStringLiteral("TITLE_MAPNAME")));
|
||||||
const int row = ui->list->currentRow();
|
const int row = ui->list->currentRow();
|
||||||
inputDlg.editInput()->setText(ui->list->item(row)->text());
|
inputDlg.editInput()->setText(ui->list->item(row)->text());
|
||||||
inputDlg.centerToRect(geometry());
|
inputDlg.centerToRect(QRect(mapToGlobal(QPoint(0, 0)), size()));
|
||||||
inputDlg.showModal();
|
inputDlg.showModal();
|
||||||
QString newName = inputDlg.editInput()->text();
|
QString newName = inputDlg.editInput()->text();
|
||||||
while (GameServer::isAutoSaveFileName(newName))
|
while (GameServer::isAutoSaveFileName(newName))
|
||||||
|
|||||||
+3
-3
@@ -64,10 +64,10 @@ public:
|
|||||||
enum class Tab { Main, Map, NewGame, PreviousGame };
|
enum class Tab { Main, Map, NewGame, PreviousGame };
|
||||||
enum class MainAction { Config, Manual, Credits, AIDev, Web, None };
|
enum class MainAction { Config, Manual, Credits, AIDev, Web, None };
|
||||||
|
|
||||||
explicit StartDlg(DirectDlg *direct, QWidget *parent = nullptr);
|
explicit StartDlg(DirectDlg *direct, Background *background);
|
||||||
~StartDlg() override;
|
~StartDlg() override;
|
||||||
|
|
||||||
Background *background() const { return m_background.get(); }
|
Background *background() const { return m_background; }
|
||||||
Languages &languages() { return m_languages; }
|
Languages &languages() { return m_languages; }
|
||||||
|
|
||||||
// Called by DirectDlg when a game ends or a map was edited.
|
// Called by DirectDlg when a game ends or a map was edited.
|
||||||
@@ -163,7 +163,7 @@ private:
|
|||||||
QString m_lastMap;
|
QString m_lastMap;
|
||||||
|
|
||||||
DirectDlg *m_direct;
|
DirectDlg *m_direct;
|
||||||
std::unique_ptr<Background> m_background;
|
Background *m_background; // not owned: the dialog is its child window
|
||||||
Dpi::Bitmap m_emptyPicture;
|
Dpi::Bitmap m_emptyPicture;
|
||||||
MiniMap m_miniMap;
|
MiniMap m_miniMap;
|
||||||
Languages m_languages;
|
Languages m_languages;
|
||||||
|
|||||||
@@ -27,13 +27,10 @@
|
|||||||
// knowledge of the CeCILL license and that you accept its terms.
|
// knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
#include "game/Direct.h"
|
#include "game/Direct.h"
|
||||||
#include "game/GameServer.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include "game/Global.h"
|
#include "game/Global.h"
|
||||||
#include "game/Start.h"
|
#include "game/Start.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTimer>
|
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
@@ -59,11 +56,9 @@ int main(int argc, char *argv[])
|
|||||||
// DirectDlg (created first, as in the original) is the main window; it
|
// DirectDlg (created first, as in the original) is the main window; it
|
||||||
// shows the start screen once the game engine is up.
|
// shows the start screen once the game engine is up.
|
||||||
Cevo::DirectDlg direct;
|
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.setStartDlg(&start);
|
||||||
direct.show();
|
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();
|
return a.exec();
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,8 @@ namespace Cevo {
|
|||||||
|
|
||||||
DrawDlg::DrawDlg(QWidget *parent) : Dpi::Form(parent)
|
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();
|
QPalette pal = palette();
|
||||||
pal.setColor(QPalette::Window, Qt::black);
|
pal.setColor(QPalette::Window, Qt::black);
|
||||||
setPalette(pal);
|
setPalette(pal);
|
||||||
|
|||||||
Reference in new issue
Block a user