]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/itextures.h
Remove <gtk/gtk.h> from gtkutil/entry.h
[xonotic/netradiant.git] / include / itextures.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_ITEXTURES_H )
23 #define INCLUDED_ITEXTURES_H
24
25 #include "iimage.h"
26 #include "generic/constant.h"
27
28 struct qtexture_t;
29
30 class LoadImageCallback
31 {
32 typedef Image* ( *LoadFunc )( void* environment, const char* name );
33 public:
34 void* m_environment;
35 LoadFunc m_func;
36
37 LoadImageCallback( void* environment, LoadFunc func ) : m_environment( environment ), m_func( func ){
38 }
39 Image* loadImage( const char* name ) const {
40         return m_func( m_environment, name );
41 }
42 };
43
44 inline bool operator==( const LoadImageCallback& self, const LoadImageCallback& other ){
45         return self.m_environment == other.m_environment && self.m_func == other.m_func;
46 }
47 inline bool operator<( const LoadImageCallback& self, const LoadImageCallback& other ){
48         return self.m_environment < other.m_environment ||
49                    ( !( other.m_environment < self.m_environment ) && self.m_func < other.m_func );
50 }
51
52 class TexturesCacheObserver
53 {
54 public:
55 virtual void unrealise() = 0;
56 virtual void realise() = 0;
57 };
58
59 class TexturesCache
60 {
61 public:
62 INTEGER_CONSTANT( Version, 1 );
63 STRING_CONSTANT( Name, "textures" );
64 virtual LoadImageCallback defaultLoader() const = 0;
65 virtual Image* loadImage( const char* name ) = 0;
66 virtual qtexture_t* capture( const char* name ) = 0;
67 virtual qtexture_t* capture( const LoadImageCallback& load, const char* name ) = 0;
68 virtual void release( qtexture_t* texture ) = 0;
69 virtual void attach( TexturesCacheObserver& observer ) = 0;
70 virtual void detach( TexturesCacheObserver& observer ) = 0;
71 };
72
73 #include "modulesystem.h"
74
75 template<typename Type>
76 class GlobalModule;
77 typedef GlobalModule<TexturesCache> GlobalTexturesModule;
78
79 template<typename Type>
80 class GlobalModuleRef;
81 typedef GlobalModuleRef<TexturesCache> GlobalTexturesModuleRef;
82
83 inline TexturesCache& GlobalTexturesCache(){
84         return GlobalTexturesModule::getTable();
85 }
86
87 #endif