final ports and first fixes

This commit is contained in:
Geoffray Levasseur committed 2026-11-04 11:55:54 +01:00
1 parent 77690cbd96
commit 6f3556009a
23 files changed
+2302 -41

No files matched your search

+2 -3
View File
@@ -58,9 +58,8 @@ public:
};
// TGraphicSet equivalent: a sprite sheet (data) with its transparency mask
// (mask), plus a set of named item rectangles. Persisted as XML, though not
// in the same node layout as the original (custom WriteString/WriteInteger
// helper), so files are not binary-compatible with the original .grs format.
// (mask), plus a set of named item rectangles. Persisted as XML in the
// original .grs layout (each item field a child element).
class GraphicSet {
public:
GraphicSet() = default;
+2
View File
@@ -250,5 +250,7 @@ void paintLogo(Dpi::Canvas &canvas, int x, int y, QColor lightColor, QColor shad
// ScreenTools.pas's InitOrnament(): recolours the ornament sprite to the
// current texture's bevel colours (once).
void initOrnament();
// ScreenTools.pas's DarkenImage(): subtracts `change` from every colour channel (clamped at 0).
void darkenImage(Dpi::Bitmap &bitmap, int change);
} // namespace Cevo
+3 -1
View File
@@ -59,7 +59,9 @@ public:
private:
QImage *m_image = nullptr;
int m_x = 0;
int m_baseX = 0; // position of the pointer's origin in the image
int m_baseY = 0;
int m_x = 0; // current position, relative to the origin
int m_y = 0;
int m_width = 0;
int m_height = 0;
+38 -12
View File
@@ -86,14 +86,40 @@ void GraphicSet::loadFromFile(const QString &fileName)
QXmlStreamReader xml(&file);
while (!xml.atEnd()) {
xml.readNext();
if (xml.isStartElement() && xml.name() == QLatin1String("Item")) {
const QXmlStreamAttributes attrs = xml.attributes();
GraphicSetItem *newItem = addNew(attrs.value("Name").toString());
newItem->left = attrs.value("Left").toInt();
newItem->top = attrs.value("Top").toInt();
newItem->width = attrs.value("Width").toInt();
newItem->height = attrs.value("Height").toInt();
if (!xml.isStartElement() || xml.name() != QLatin1String("Item"))
continue;
// The original format stores each field as a child element (<Name>, <Left>, ...);
// attributes are accepted too.
const QXmlStreamAttributes attrs = xml.attributes();
QString name = attrs.value("Name").toString();
int left = attrs.value("Left").toInt();
int top = attrs.value("Top").toInt();
int width = attrs.value("Width").toInt();
int height = attrs.value("Height").toInt();
while (!xml.atEnd()) {
xml.readNext();
if (xml.isEndElement() && xml.name() == QLatin1String("Item"))
break;
if (!xml.isStartElement())
continue;
const QString field = xml.name().toString();
const QString text = xml.readElementText();
if (field == QLatin1String("Name"))
name = text;
else if (field == QLatin1String("Left"))
left = text.toInt();
else if (field == QLatin1String("Top"))
top = text.toInt();
else if (field == QLatin1String("Width"))
width = text.toInt();
else if (field == QLatin1String("Height"))
height = text.toInt();
}
GraphicSetItem *newItem = addNew(name);
newItem->left = left;
newItem->top = top;
newItem->width = width;
newItem->height = height;
}
}
@@ -110,11 +136,11 @@ void GraphicSet::saveToFile(const QString &fileName) const
xml.writeStartElement(QLatin1String("Items"));
for (GraphicSetItem *item : m_items) {
xml.writeStartElement(QLatin1String("Item"));
xml.writeAttribute(QLatin1String("Name"), item->name);
xml.writeAttribute(QLatin1String("Left"), QString::number(item->left));
xml.writeAttribute(QLatin1String("Top"), QString::number(item->top));
xml.writeAttribute(QLatin1String("Width"), QString::number(item->width));
xml.writeAttribute(QLatin1String("Height"), QString::number(item->height));
xml.writeTextElement(QLatin1String("Name"), item->name);
xml.writeTextElement(QLatin1String("Left"), QString::number(item->left));
xml.writeTextElement(QLatin1String("Top"), QString::number(item->top));
xml.writeTextElement(QLatin1String("Width"), QString::number(item->width));
xml.writeTextElement(QLatin1String("Height"), QString::number(item->height));
xml.writeEndElement();
}
xml.writeEndElement();
+13
View File
@@ -956,6 +956,19 @@ void paintLogo(Dpi::Canvas &canvas, int x, int y, QColor lightColor, QColor shad
canvas.copyRect(QRect(x, y, logo->width, logo->height), drawBuffer.canvas(), QRect(0, 0, logo->width, logo->height));
}
void darkenImage(Dpi::Bitmap &bitmap, int change)
{
QImage &image = bitmap.image();
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
const QRgb c = image.pixel(x, y);
image.setPixel(x, y,
qRgba(std::max(qRed(c) - change, 0), std::max(qGreen(c) - change, 0),
std::max(qBlue(c) - change, 0), qAlpha(c)));
}
}
}
namespace {
bool ornamentInitialized = false;
}
+8 -5
View File
@@ -31,13 +31,12 @@
namespace Dpi {
PixelPointer::PixelPointer(QImage *image, int baseX, int baseY)
: m_image(image)
: m_image(image), m_baseX(baseX), m_baseY(baseY)
{
if (m_image) {
m_width = m_image->width();
m_height = m_image->height();
}
setXY(baseX, baseY);
}
void PixelPointer::setXY(int x, int y)
@@ -64,30 +63,34 @@ void PixelPointer::previousPixel()
void PixelPointer::nextLine()
{
++m_y;
m_x = 0;
}
void PixelPointer::previousLine()
{
--m_y;
m_x = 0;
}
bool PixelPointer::posValid() const
{
return m_image && m_x >= 0 && m_x < m_width && m_y >= 0 && m_y < m_height;
const int x = m_baseX + m_x;
const int y = m_baseY + m_y;
return m_image && x >= 0 && x < m_width && y >= 0 && y < m_height;
}
QRgb PixelPointer::pixelARGB() const
{
if (!posValid())
return 0;
return reinterpret_cast<const QRgb *>(m_image->constScanLine(m_y))[m_x];
return reinterpret_cast<const QRgb *>(m_image->constScanLine(m_baseY + m_y))[m_baseX + m_x];
}
void PixelPointer::setPixelARGB(QRgb value)
{
if (!posValid())
return;
reinterpret_cast<QRgb *>(m_image->scanLine(m_y))[m_x] = value;
reinterpret_cast<QRgb *>(m_image->scanLine(m_baseY + m_y))[m_baseX + m_x] = value;
}
QRgb PixelPointer::pixelRGB() const