Add more assertions.
[tagua/yd.git] / src / pixmaploader.h
blobe0cdf865da8f66cab872d2d21287788df0cc736a
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
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 PIXMAPLOADER_H
12 #define PIXMAPLOADER_H
14 #include <QPixmap>
15 #include <QString>
16 #include <QHash>
17 #include "loader/theme.h"
18 #include "themeinfo.h"
20 /**
21 * @class PixmapLoader <pixmaploader.h>
22 * @brief The simple pixmap loading facility.
24 * This is the utility class used by the interface to load pixmap from resource ids.
25 * It acts simply as a wrapper around PixmapLoader::ThemeLoader, making it possible to
26 * use it in a simple and afficient way.
28 * Note that pixmaps will not be all of the specified size, the size is only the base size.
30 class PixmapLoader {
31 private:
32 class ThemeLoader;
33 typedef QHash<ThemeInfo, ThemeLoader*> ThemeLoadersCache;
35 /** static cache of the loaders, there should be only one for each (theme,variant) pair */
36 static ThemeLoadersCache& loaders();
38 /** the current loader, or NULL */
39 ThemeLoader *m_loader;
41 /** the current size */
42 int m_size;
44 /** the current theme */
45 ThemeInfo m_theme;
47 /** internal, clears references to the currently used loader, if any. */
48 void flush();
50 /** internal, gets or creates a loader good for the current
51 (theme,variant) pair and refs the size */
52 void initialize();
54 public:
55 /** constructor */
56 PixmapLoader();
57 ~PixmapLoader();
59 /** set the theme */
60 void setTheme(const ThemeInfo& theme);
62 /** set the base size of the pixmaps. Note that returned pixmaps's size can be different.
63 * For instance, if the size is 100 the "background" generated by the
64 * chess variant will be 200x200 (and it will be tiled on the Board)
66 void setSize(int s);
68 /** looks up a string id (for instance a predefined id, like "background" or "highlighting") */
69 // QPixmap operator()(const QString& id);
70 QPixmap getPixmap(const QString& id);
72 QPixmap piecePixmap(const QString& id, bool flipped = false);
74 /** returns a value */
75 template<typename T>
76 T getValue(const QString& id, const ::LuaApi::LuaValueMap* args = NULL, bool allow_nil = false);
78 /** returns a static value (not depending on the size) */
79 template<typename T>
80 T getStaticValue(const QString& id, const ::LuaApi::LuaValueMap* args = NULL, bool allow_nil = false);
83 #endif // PIXMAPLOADER_H