Continued refactoring.
[tagua/yd.git] / src / spriteloader.h
blob82563fc87438e31e06b92f9938a3c98b15c4d6eb
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef SPRITELOADER_H
12 #define SPRITELOADER_H
14 #include <QPixmap>
15 #include <QString>
16 #include "loader/theme.h"
18 /**
19 * @class SpriteLoader <spriteloader.h>
20 * @brief The simple pixmap loading facility.
22 * This is the utility class used by the interface to load pixmap from resource ids.
23 * It acts simply as a wrapper around PixmapLoader::Loader, making it possible to
24 * use it in a simple and afficient way.
26 * Note that pixmaps will not be all of the specified size, the size is only the base size.
28 class SpriteLoader {
29 private:
30 class Loader;
31 class LoadersCache;
33 /** static cache of the loaders, there should be only one for each (theme,variant) pair */
34 static LoadersCache loaders;
36 /** the current loader, or NULL */
37 Loader *m_loader;
39 /** the current size */
40 int m_size;
42 /** the current theme */
43 QString m_base;
45 /** internal, clears references to the currently used loader, if any. */
46 void flush();
48 /** internal, gets or creates a loader good for the current
49 (theme,variant) pair and refs the size */
50 void initialize();
52 public:
53 /** constructor */
54 SpriteLoader();
55 ~SpriteLoader();
57 /** set the theme path */
58 void setBasePath(const QString& base);
60 /** set the base size of the pixmaps. Note that returned pixmaps's size can be different.
61 * For instance, if the size is 100 the "background" generated by the
62 * chess variant will be 200x200 (and it will be tiled on the Board)
64 void setSize(int s);
66 /** looks up a string id (for instance a predefined id, like "background" or "highlighting") */
67 QPixmap operator()(const QString& id);
69 /** looks up a string id (for instance a predefined id, like "background" or "highlighting") */
70 ::Loader::PixmapOrMap getPixmapMap(const QString& id);
72 /** looks up a font + char */
73 ::Loader::Glyph getGlyph(const QString& id);
76 #endif // SPRITELOADER_H