File indexing completed on 2024-05-12 05:46:45

0001 /*
0002  * Copyright (C) 2006 Dmitry Suzdalev <dimsuz@gmail.com>
0003  * Copyright (C) 2007 Tomasz Boczkowski <tboczkowski@onet.pl>
0004  *
0005  * This file is part of the KDE project "KBounce"
0006  *
0007  * This program is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This program is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public
0018  * License along with this program; if not, write to the Free Software
0019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0020  */
0021 
0022 #ifndef RENDERER_H
0023 #define RENDERER_H
0024 
0025 #include <QSvgRenderer>
0026 #include <KGameRenderer>
0027 
0028 #include <QSize>
0029 #include <QHash>
0030 #include <QPixmap>
0031 
0032 
0033 /**
0034  * Class for rendering elements of game SVG to QPixmap
0035  */
0036 
0037 class KBounceRenderer : public KGameRenderer
0038 {
0039     Q_OBJECT
0040     public:
0041         /**
0042          * Constructor.
0043          * @param fileName path to SVG containing game graphics
0044          */
0045         explicit KBounceRenderer();
0046         /**
0047          * Destructor.
0048          */
0049         ~KBounceRenderer() override;
0050         /**
0051          * Sets Background size and invalidates background cache
0052          */
0053         void setBackgroundSize(QSize size);
0054         /**
0055          * Renders background to QPixmap of size set by setBachgroundSize
0056          * Background pixmap is cached (setBackgroundSize() invalidates the cache)
0057          */
0058         QPixmap renderBackground();
0059         /**
0060          * Set s the path were custom background pictures are located.
0061          */
0062         void setCustomBackgroundPath(const QString &path);
0063         /**
0064          * Returns a random pixmap from the custom background path.
0065          * If no picture is located in this path the pixmap is null.
0066          */
0067         QPixmap getRandomBackgroundPixmap(const QString& path);
0068         bool loadNewBackgroundPixmap();
0069 
0070     private:
0071         QSvgRenderer m_svgRenderer;
0072         QSize m_backgroundSize;
0073         QPixmap m_cachedBackground;
0074         QPixmap m_randomBackground;
0075 
0076         QString m_customBackgroundPath;
0077         bool m_useRandomBackgrounds;
0078 };
0079 
0080 #endif //RENDERER_H
0081