diff --git a/widget/include/Cevo/CevoScreenTools.h b/widget/include/Cevo/CevoScreenTools.h index c22877b..5c69d33 100644 --- a/widget/include/Cevo/CevoScreenTools.h +++ b/widget/include/Cevo/CevoScreenTools.h @@ -47,6 +47,10 @@ class GraphicSetItem; // (e.g. ButtonA's $0000FF placeholder color) with this helper rather than // constructing QColor from the raw hex value directly. QColor colorFromDelphi(int value); +// Inverse of colorFromDelphi(): packs a QColor back into a Delphi/VCL +// $00BBGGRR int (needed whenever a QColor-valued field, e.g. a tribe's +// Color, must be passed to a raw-Delphi-int API like imageOpBCC()). +int colorToDelphi(const QColor &color); // Global display gamma correction setting, in percent (100 = no // correction) - ScreenTools.pas's `Gamma`. Call applyGammaToBitmap() diff --git a/widget/src/CevoScreenTools.cpp b/widget/src/CevoScreenTools.cpp index c9a32f1..eabe8c8 100644 --- a/widget/src/CevoScreenTools.cpp +++ b/widget/src/CevoScreenTools.cpp @@ -51,6 +51,11 @@ QColor colorFromDelphi(int value) return QColor(value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF); } +int colorToDelphi(const QColor &color) +{ + return color.red() | (color.green() << 8) | (color.blue() << 16); +} + int gamma = 100; GraphicSets grExt; QString graphicsDir; @@ -124,14 +129,22 @@ GraphicSet *loadGraphicSet(const QString &name, bool transparency) return result; result = &grExt.addNew(name); - const QString fileName = graphicsDir + QLatin1Char('/') + name; + const QString baseFileName = graphicsDir + QLatin1Char('/') + name; + // The original's LoadGraphicFile auto-appends ".png" when the name has + // no extension, but that is a by-value parameter so it does NOT affect + // the (possibly extension-less) base name used below for the .grs + // sidecar path - replicate both quirks exactly. + QString imageFileName = baseFileName; + if (QFileInfo(imageFileName).suffix().isEmpty()) + imageFileName += QLatin1String(".png"); // Do not apply gamma during file load as it would affect transparency colors too. - result->data.loadFromFile(fileName); + result->data.loadFromFile(imageFileName); if (result->data.width() == 0 || result->data.height() == 0) return nullptr; - const QString grsFileName = QFileInfo(fileName).path() + QLatin1Char('/') + - QFileInfo(fileName).completeBaseName() + QLatin1String(GraphicSetFileExt); + const QFileInfo baseInfo(baseFileName); + const QString grsFileName = baseInfo.path() + QLatin1Char('/') + + baseInfo.completeBaseName() + QLatin1String(GraphicSetFileExt); if (QFileInfo::exists(grsFileName)) result->loadFromFile(grsFileName);