mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
* [Icons] Migrate UI glyphs to palette-token SVGs Runtime inversion is not a theming system: it rotates hue, breaks duotone art and mishandles alpha, and a QPixmap snapshot cannot follow a palette change. Redraw the top-level UI glyph set on a 24x24 grid with `currentColor` as the paint token, drop Inkscape/Sodipodi cruft, and delete the icons whose metaphor was duplicated (cogwheel/gear -> settings, scale_balanced -> scales, update.png -> reload). Load the glyphs through `loadThemedIcon` so the engine resolves the token from the palette on every request, and let `themePixmap` use the same resolution for one-shot pixmaps. `loadColorAdjustedPixmap` is gone; every caller now keeps a QIcon, which `SettingsButtonWidget::setButtonIcon` accepts instead of a QPixmap. Content art (mana, counters, countries) keeps its authored colors. Add a render test covering aspect ratio, palette flips, icon modes and high-DPI pixmaps. * [Tests] Keep the icon render test QApplication alive until exit Creating it as a function-local static tears it down before Qt's library statics at exit, and libQt6Network then runs QObject destructors against freed memory — a SEGV the sanitizer leg reports after the tests have already passed. Leak the application instead, the usual pattern for a test binary. * [Icons] Render lock and dropdown glyphs through the icon engine Both generators rendered the sentinel SVG to a fixed height x height pixmap at DPR 1. The pre-migration path rendered larger and let QIcon scale it, so on a 2x display the games-list lock (13px) and the banner dropdown arrow (24px) came back crisp; the new path hands the widget a DPR-1 bitmap that gets upscaled and blurred. - The games list asks the themed engine for `icons/lock` directly, so the item view paints it at the device pixel ratio and the lock also follows HighlightedText on a selected row. - The dropdown goes through `loadThemedIcon(...).pixmap(size, dpr)`, which keeps the glyph's aspect ratio and renders at the requested ratio. - LockPixmapGenerator has no consumer left, so it and its cache are gone. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
161 lines
4.3 KiB
C++
161 lines
4.3 KiB
C++
/**
|
|
* @file pixel_map_generator.h
|
|
* @ingroup UI
|
|
*/
|
|
//! \todo Document this file.
|
|
|
|
#ifndef PIXMAPGENERATOR_H
|
|
#define PIXMAPGENERATOR_H
|
|
|
|
#include "libcockatrice/protocol/pb/serverinfo_user.pb.h"
|
|
|
|
#include <QHash>
|
|
#include <QIcon>
|
|
#include <QLoggingCategory>
|
|
#include <QMap>
|
|
#include <QPixmap>
|
|
#include <QString>
|
|
#include <QStringView>
|
|
#include <libcockatrice/network/server/remote/user_level.h>
|
|
#include <optional>
|
|
|
|
class QSize;
|
|
|
|
inline Q_LOGGING_CATEGORY(PixelMapGeneratorLog, "pixel_map_generator");
|
|
|
|
class PhasePixmapGenerator
|
|
{
|
|
private:
|
|
static QMap<QString, QPixmap> pmCache;
|
|
|
|
public:
|
|
static QPixmap generatePixmap(int size, QString name);
|
|
static void clear()
|
|
{
|
|
pmCache.clear();
|
|
}
|
|
};
|
|
|
|
class CounterPixmapGenerator
|
|
{
|
|
private:
|
|
static QMap<QString, QPixmap> pmCache;
|
|
|
|
public:
|
|
static QPixmap generatePixmap(int size, QString name, bool highlight);
|
|
static void clear()
|
|
{
|
|
pmCache.clear();
|
|
}
|
|
};
|
|
|
|
class PingPixmapGenerator
|
|
{
|
|
private:
|
|
static QMap<int, QPixmap> pmCache;
|
|
|
|
public:
|
|
static QPixmap generatePixmap(int size, int value, int max);
|
|
static void clear()
|
|
{
|
|
pmCache.clear();
|
|
}
|
|
};
|
|
|
|
class CountryPixmapGenerator
|
|
{
|
|
private:
|
|
static QMap<QString, QPixmap> pmCache;
|
|
|
|
public:
|
|
static QPixmap generatePixmap(int height, const QString &countryCode);
|
|
static void clear()
|
|
{
|
|
pmCache.clear();
|
|
}
|
|
};
|
|
|
|
class UserLevelPixmapGenerator
|
|
{
|
|
private:
|
|
static QMap<QString, QIcon> iconCache;
|
|
|
|
static QIcon generateIconDefault(int height, UserLevelFlags userLevel, bool isBuddy, const QString &privLevel);
|
|
static QIcon generateIconWithColorOverride(int height,
|
|
bool isBuddy,
|
|
const UserLevelFlags &userLevelFlags,
|
|
const QString &privLevel,
|
|
const std::optional<QString> &colorLeft,
|
|
const std::optional<QString> &colorRight);
|
|
|
|
public:
|
|
static QPixmap generatePixmap(int height,
|
|
UserLevelFlags userLevel,
|
|
ServerInfo_User::PawnColorsOverride pawnColors,
|
|
bool isBuddy,
|
|
const QString &privLevel);
|
|
|
|
static QIcon generateIcon(int minHeight,
|
|
UserLevelFlags userLevel,
|
|
ServerInfo_User::PawnColorsOverride pawnColors,
|
|
bool isBuddy,
|
|
const QString &privLevel);
|
|
static void clear()
|
|
{
|
|
iconCache.clear();
|
|
}
|
|
};
|
|
|
|
class DropdownIconPixmapGenerator
|
|
{
|
|
private:
|
|
static QMap<QString, QPixmap> pmCache;
|
|
|
|
public:
|
|
static QPixmap generatePixmap(int height, bool expanded);
|
|
static void clear()
|
|
{
|
|
pmCache.clear();
|
|
}
|
|
};
|
|
|
|
class ManaSymbolPixmapGenerator
|
|
{
|
|
private:
|
|
static QHash<QString, QPixmap> masterCache;
|
|
static QHash<QString, QPixmap> scaledCache;
|
|
|
|
/**
|
|
* @brief Renders \a symbol once at a fixed moderate size, so repeated scalings never
|
|
* re-rasterize the source file (SVG sources can be very expensive to rasterize).
|
|
*/
|
|
static const QPixmap &masterIcon(const QString &symbol);
|
|
|
|
public:
|
|
/**
|
|
* @brief Returns a smooth-scaled rendering of the given mana symbol icon.
|
|
*
|
|
* Results are shared between all callers via a process-wide cache keyed by symbol
|
|
* and size, so scaling work is done once per distinct combination instead of once
|
|
* per widget creation or resize.
|
|
*/
|
|
static QPixmap generatePixmap(const QString &symbol, const QSize &size);
|
|
static void clear()
|
|
{
|
|
masterCache.clear();
|
|
scaledCache.clear();
|
|
}
|
|
};
|
|
|
|
// Returns a "theme:" asset (with no file extension in prefix), preferring the
|
|
// scheme-qualified variant (prefix-dark / prefix-light, resolved via
|
|
// ThemeManager::assetPath) and falling back to the plain asset. Token-driven
|
|
// SVGs resolve their `currentColor` sentinel from the palette. Use for
|
|
// scheme-sensitive pixmaps like backgrounds, the card back, and the app logo.
|
|
QPixmap themePixmap(QStringView prefix);
|
|
|
|
// Clears every PixmapGenerator's static cache so scheme variants are
|
|
// re-resolved when the active theme or color scheme changes.
|
|
void clearPixmapGeneratorCaches();
|
|
|
|
#endif
|