User moves are now created by the entity.
[tagua/yd.git] / src / loader / theme.h
blob7b965a597a521365391601859de78c02daa151ed
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 LOADER__THEME_H
12 #define LOADER__THEME_H
14 #include <map>
15 #include <QPixmap>
16 #include <QObject>
17 #include "loader/context.h"
18 #include "luaapi/loader.h"
19 #include "themeinfo.h"
21 namespace Loader {
23 typedef std::map<QRect, QPixmap, ::LuaApi::RectLess> PixmapMap;
24 typedef boost::variant<QPixmap, PixmapMap> PixmapOrMap;
26 /**
27 * @class Theme <loader/theme.h>
28 * @brief A class that represents and caches all images loaded by a theme.
30 * This class will be created once for each lua-scripted theme, and will cache
31 * images loaded from that theme.
33 class Theme : public QObject {
34 Q_OBJECT
36 private:
37 ThemeInfo m_theme;
39 /** there will be one such class for each size, and i will store pixmaps and glyphs */
40 class SizeCache {
41 public:
42 typedef std::map<QString, PixmapOrMap> PixmapsCache;
43 typedef std::map<QString, Glyph> GlyphsCache;
44 int m_ref_count;
45 PixmapsCache m_pixmaps_cache;
46 GlyphsCache m_glyphs_cache;
48 SizeCache()
49 : m_ref_count(0) {}
52 typedef std::map<int, SizeCache> Cache;
54 Context m_context;
55 LuaApi::Loader m_lua_loader;
56 Cache m_cache;
58 static PixmapOrMap to_pixmap_map(const ::LuaApi::ImageOrMap& m);
60 private Q_SLOTS:
61 void onSettingsChanged();
63 public:
64 /** Constructor, created the class from a lua theme file */
65 Theme(const ThemeInfo& theme);
66 ~Theme();
68 /** References the size \a size, enabling you to get pixmaps of size \a size */
69 void refSize(int size);
71 /** Unreferences the size */
72 void unrefSize(int size);
74 /** Loads a value */
75 template<typename T>
76 T getValue(const QString& key, int size, const ::LuaApi::LuaValueMap* args = NULL);
79 } //end namespace loader
81 #endif //LOADER__THEME_H