File: setupdisplay_generic.cpp

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (168 lines) | stat: -rw-r--r-- 4,419 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
	$Id: setupdisplay_generic.cpp,v 1.14 2001/11/30 11:05:19 mbn Exp $

	------------------------------------------------------------------------
	ClanLib, the platform independent game SDK.

	This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
	version 2. See COPYING for details.

	For a total list of contributers see CREDITS.

	------------------------------------------------------------------------
*/
#include "Core/precomp.h"

#include <cstdlib>
#include "Display/Display/Generic/resource_surface_generic.h"
#include "Display/Font/resource_font_generic.h"
#include "API/Core/Resources/resourceoptions.h"
#include "API/Core/Resources/resource_manager.h"
#include "API/Core/Resources/resourcetype.h"
#include "API/Display/SurfaceProviders/provider_pcx.h"
#include "API/Display/SurfaceProviders/provider_bmp.h"
#include "API/Display/SurfaceProviders/provider_targa.h"
#include "API/Display/Display/res_surface.h"

#include "setupdisplay_generic.h"

/////////////////////////////////////////////////////////////////////////////
// Resource support: (sorry for the messy code)

static class CL_PCX_ResourceSource : public CL_ResourceSource_Surface
{
public:
	virtual const char *get_name() { return "pcx"; }

	virtual bool can_create(
		std::string ext,
		CL_ResourceOptions &options)
	{
		if (ext == ".pcx") return true;
		if (options.exists("pcx")) return true;
		
		return false;
	}
	
	virtual CL_SurfaceProvider *create(
		CL_Resource &resource,
		CL_ResourceOptions &options,
		CL_ResourceManager &parent)
	{
		CL_InputSourceProvider *provider =
			parent.get_resource_provider();

		return new CL_PCXProvider(resource.get_location().c_str(), provider);
	}

	virtual CL_SurfaceProvider *create(
		const std::string &filename)
	{
		return new CL_PCXProvider(filename.c_str(), NULL);
	}

} *pcx_resource_source = NULL;

static class CL_BMP_ResourceSource : public CL_ResourceSource_Surface
{
public:
	virtual const char *get_name() { return "bmp"; }

	virtual bool can_create(
		std::string ext,
		CL_ResourceOptions &options)
	{
		if (ext == ".bmp") return true;
		if (options.exists("bmp")) return true;
		
		return false;
	}
	
	virtual CL_SurfaceProvider *create(
		CL_Resource &resource,
		CL_ResourceOptions &options,
		CL_ResourceManager &parent)
	{
		CL_InputSourceProvider *provider =
			parent.get_resource_provider();

		return new CL_BMPProvider(resource.get_location().c_str(), provider);
	}

	virtual CL_SurfaceProvider *create(
		const std::string &filename)
	{
		return new CL_BMPProvider(filename.c_str(), NULL);
	}

} *bmp_resource_source = NULL;

static class CL_Targa_ResourceSource : public CL_ResourceSource_Surface
{
public:
	virtual const char *get_name() { return "tga"; }

	virtual bool can_create(
		std::string ext,
		CL_ResourceOptions &options)
	{
		if (ext == ".tga") return true;
		if (options.exists("tga")) return true;

		return false;
	}

	virtual CL_SurfaceProvider *create(
		CL_Resource &resource,
		CL_ResourceOptions &options,
		CL_ResourceManager &parent)
	{
		CL_InputSourceProvider *provider =
			parent.get_resource_provider();

		return new CL_TargaProvider(resource.get_location().c_str(), provider);
	}

	virtual CL_SurfaceProvider *create(
		const std::string &filename)
	{
		return new CL_TargaProvider(filename.c_str(), NULL);
	}

} *targa_resource_source = NULL;

/////////////////////////////////////////////////////////////////////////////
// CL_SetupDisplay_Generic initialization:

static CL_RegisterResourceType<CL_ResourceData_Surface> *restype_surface = NULL;
static CL_RegisterResourceType<CL_ResourceData_Font> *restype_font = NULL;

void CL_SetupDisplay_Generic::init()
{
	restype_surface = new CL_RegisterResourceType<CL_ResourceData_Surface>("surface");
	restype_font = new CL_RegisterResourceType<CL_ResourceData_Font>("font");

	pcx_resource_source = new CL_PCX_ResourceSource;
	bmp_resource_source = new CL_BMP_ResourceSource;
	targa_resource_source = new CL_Targa_ResourceSource;
}

/////////////////////////////////////////////////////////////////////////////
// CL_SetupDisplay_Generic deinitialization:

void CL_SetupDisplay_Generic::deinit()
{
	delete pcx_resource_source;
	delete bmp_resource_source;
	delete targa_resource_source;

	pcx_resource_source = NULL;
	bmp_resource_source = NULL;
	targa_resource_source = NULL;

	delete restype_surface;
	delete restype_font;

	restype_surface = NULL;
	restype_font = NULL;
}