initial port for Cevo game in C++ (libs)

This commit is contained in:
Geoffray Levasseur committed 2026-10-22 17:20:45 +02:00
commit 8436242032
375 files changed
+46282

No files matched your search

+168
View File
@@ -0,0 +1,168 @@
#include "Cevo/CevoDrawDlg.h"
#include "Cevo/CevoArea.h"
#include "Cevo/CevoButtonBase.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPainter>
#include <QRegion>
namespace Cevo {
DrawDlg::DrawDlg(QWidget *parent) : Dpi::Form(parent)
{
QPalette pal = palette();
pal.setColor(QPalette::Window, Qt::black);
setPalette(pal);
setAutoFillBackground(true);
}
void DrawDlg::mousePressEvent(QMouseEvent *event)
{
const QPoint pos = event->pos();
if (rect().contains(pos) && pos.y() < titleHeight) {
m_moveMousePos = mapToGlobal(event->pos());
m_moveFormPos = QPoint(x(), y());
m_moveActive = true;
} else {
m_moveActive = false;
}
}
void DrawDlg::mouseMoveEvent(QMouseEvent *event)
{
if (m_moveActive) {
const QPoint delta = mapToGlobal(event->pos()) - m_moveMousePos;
move(m_moveFormPos + delta);
}
}
void DrawDlg::mouseReleaseEvent(QMouseEvent *)
{
m_moveActive = false;
}
void DrawDlg::leaveEvent(QEvent *)
{
m_moveActive = false;
}
void DrawDlg::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape)
close();
else
QWidget::keyPressEvent(event);
}
void DrawDlg::smartInvalidate()
{
QRegion region(rect());
const auto children = findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly);
for (QWidget *child : children) {
if (!qobject_cast<Area *>(child) && child->isVisible())
region -= QRegion(child->geometry());
}
update(region);
}
void DrawDlg::centerToScreen()
{
centerToScreen(width(), height());
}
void DrawDlg::centerToScreen(int w, int h)
{
const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor();
setGeometry(monitor.left() + (monitor.width() - w) / 2,
monitor.top() + (monitor.height() - h) / 2, w, h);
}
// ---- BaseMessgDlg ----
BaseMessgDlg::BaseMessgDlg(QWidget *parent) : DrawDlg(parent)
{
titleHeight = Dpi::Screen::height();
}
void BaseMessgDlg::paintEvent(QPaintEvent *)
{
QPainter painter(this);
Dpi::Canvas canvas;
canvas.bind(&painter);
paintBackground(canvas, 3 + Border, 3 + Border, width() - (6 + 2 * Border), height() - (6 + 2 * Border),
width(), height());
for (int i = 0; i <= Border; ++i)
frame(canvas, i, i, width() - 1 - i, height() - 1 - i, Qt::black, Qt::black);
if (MainTexture) {
frame(canvas, Border + 1, Border + 1, width() - (2 + Border), height() - (2 + Border),
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
frame(canvas, 2 + Border, 2 + Border, width() - (3 + Border), height() - (3 + Border),
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
}
splitText(false);
if (MainTexture) {
const auto children = findChildren<ButtonBase *>(QString(), Qt::FindDirectChildrenOnly);
for (ButtonBase *button : children) {
if (button->isVisible())
btnFrame(canvas, button->geometry(), *MainTexture);
}
}
canvas.unbind();
}
void BaseMessgDlg::splitText(bool preview)
{
// Best-effort port of the 1-indexed Pascal word-wrap logic below; wraps
// messageText at word boundaries (or '\' line breaks) to fit within
// (width() - 56) px per line.
if (!MainTexture)
return;
int start = 0;
int linesCount = 0;
QPixmap dummy(1, 1);
QPainter painter(&dummy);
Dpi::Canvas canvas;
canvas.bind(&painter);
while (start < messageText.length()) {
int stop = start;
while (stop < messageText.length() - 1 && messageText.at(stop) != QLatin1Char('\\') &&
biColorTextWidth(canvas, messageText.mid(start, stop - start + 1)) < width() - 56)
++stop;
if (stop != messageText.length() - 1) {
int ordinaryStop = stop;
while (ordinaryStop > start && messageText.at(ordinaryStop) != QLatin1Char(' ') &&
messageText.at(ordinaryStop) != QLatin1Char('\\'))
--ordinaryStop;
if ((ordinaryStop - start) * 2 >= stop - start)
stop = ordinaryStop - 1;
}
if (!preview) {
const QString s = messageText.mid(start, stop - start + 1);
loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2,
19 + Border + topSpace + linesCount * MessageLineSpacing, s);
}
start = stop + 2;
++linesCount;
}
canvas.unbind();
if (preview)
lines = linesCount;
}
void BaseMessgDlg::correctHeight()
{
const int newHeight = 72 + Border + topSpace + lines * MessageLineSpacing;
const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor();
const int newTop = monitor.top() + (monitor.height() - newHeight) / 2;
setGeometry(x(), newTop, width(), newHeight);
const auto children = findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly);
for (QWidget *child : children)
child->move(child->x(), newHeight - (34 + Border));
}
} // namespace Cevo