File indexing completed on 2024-09-08 06:47:18
0001 /* 0002 This file is part of Killbots. 0003 0004 SPDX-FileCopyrightText: 2007-2010 Parker Coates <coates@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "renderer.h" 0010 0011 #include "settings.h" 0012 0013 // KDEGames 0014 #include <KGameTheme> 0015 #include <KGameThemeProvider> 0016 0017 #include <QCursor> 0018 0019 static KGameThemeProvider *provider() 0020 { 0021 KGameThemeProvider *prov = new KGameThemeProvider; 0022 prov->discoverThemes( 0023 QStringLiteral("themes"), // theme file location 0024 QStringLiteral("robotkill") // default theme file name 0025 ); 0026 return prov; 0027 } 0028 0029 static Killbots::Renderer *r = nullptr; 0030 0031 Killbots::Renderer *Killbots::Renderer::self() 0032 { 0033 if (!r) { 0034 r = new Killbots::Renderer(); 0035 } 0036 return r; 0037 } 0038 0039 void Killbots::Renderer::cleanup() 0040 { 0041 delete r; 0042 r = nullptr; 0043 } 0044 0045 Killbots::Renderer::Renderer() 0046 : KGameRenderer(provider()) 0047 { 0048 } 0049 0050 QCursor Killbots::Renderer::cursorFromAction(int direction) 0051 { 0052 QString element = QStringLiteral("cursor%1").arg(direction); 0053 QPixmap pixmap = spritePixmap(element, QSize(42, 42)); 0054 return QCursor(pixmap); 0055 } 0056 0057 QColor Killbots::Renderer::textColor() 0058 { 0059 if (m_cachedTheme != theme()->identifier()) { 0060 m_textColor = spritePixmap(QStringLiteral("textcolor"), QSize(3, 3)).toImage().pixel(1, 1); 0061 m_cachedTheme = theme()->identifier(); 0062 } 0063 return m_textColor; 0064 } 0065 0066 qreal Killbots::Renderer::aspectRatio() 0067 { 0068 const QRectF tileRect = boundsOnSprite(QStringLiteral("cell")); 0069 return qBound<qreal>(0.3333, tileRect.width() / tileRect.height(), 3.0); 0070 }