summaryrefslogtreecommitdiff
path: root/hammer/dummytexture.cpp
blob: 644db739e2656cd4dc9fd6562cbbeb61ec403343 (plain) (blame)
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Implementation of IEditorTexture interface for placeholder textures.
//			Placeholder textures are used for textures that are referenced in
//			the map file but not found in storage.
//
//=============================================================================//

#include "stdafx.h"
#include <process.h>
#include <afxtempl.h>
#include <io.h>
#include <sys\stat.h>
#include <fcntl.h>
#include "DummyTexture.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>


//-----------------------------------------------------------------------------
// Purpose: Constructor.
//-----------------------------------------------------------------------------
CDummyTexture::CDummyTexture(const char *pszName, TEXTUREFORMAT eFormat)
{
	if (pszName != NULL)
	{
		strcpy(m_szName, pszName);
	}
	else
	{
		strcpy(m_szName, "Missing texture");
	}

	m_eTextureFormat = eFormat;
}


//-----------------------------------------------------------------------------
// Purpose: Destructor.
//-----------------------------------------------------------------------------
CDummyTexture::~CDummyTexture()
{
}


//-----------------------------------------------------------------------------
// Purpose: Returns an empty string, since we have no source file.
//-----------------------------------------------------------------------------
const char *CDummyTexture::GetFileName() const
{
	static char *pszEmpty = "";
	return(pszEmpty);
}


//-----------------------------------------------------------------------------
// Purpose: Returns a string of comma delimited keywords associated with this
//			material.
// Input  : pszKeywords - Buffer to receive keywords, NULL to query string length.
// Output : Returns the number of characters in the keyword string.
//-----------------------------------------------------------------------------
int CDummyTexture::GetKeywords(char *pszKeywords) const
{
	if (pszKeywords != NULL)
	{
		*pszKeywords = '\0';
	}

	return(0);
}


//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pszName - 
// Output : 
//-----------------------------------------------------------------------------
// dvs: move into a common place for CWADTexture & CDummyTexture
int CDummyTexture::GetShortName(char *pszName) const
{
	char szBuf[MAX_PATH];

	if (pszName == NULL)
	{
		pszName = szBuf;
	}

	if (m_eTextureFormat == tfWAL)
	{
		const char *psz = strstr(m_szName, "textures");
		if (psz == NULL)
		{
			psz = m_szName;
		}
		else
		{
			psz += strlen("textures\\");
		}

		strcpy(pszName, psz);

		// remove extension
		char *pszExtension = strstr(pszName, ".wal");
		if (pszExtension)
		{
			*pszExtension = 0;
		}
	}
	else
	{
		strcpy(pszName, m_szName);
	}

	return(strlen(pszName));
}


//-----------------------------------------------------------------------------
// Purpose: If the buffer pointer passed in is not NULL, copies the image data
//			in RGB format to the buffer
// Input  : pImageRGB - Pointer to buffer that receives the image data. If the
//				pointer is NULL, no data is copied, only the data size is returned.
// Output : Returns a the size of the RGB image in bytes.
//-----------------------------------------------------------------------------
int CDummyTexture::GetImageDataRGB( void *pImageRGB )
{
	return(0);
}


//-----------------------------------------------------------------------------
// Purpose: If the buffer pointer passed in is not NULL, copies the image data
//			in RGBA format to the buffer
// Input  : pImageRGBA - Pointer to buffer that receives the image data. If the
//				pointer is NULL, no data is copied, only the data size is returned.
// Output : Returns a the size of the RGBA image in bytes.
//-----------------------------------------------------------------------------
int CDummyTexture::GetImageDataRGBA( void *pImageRGBA )
{
	return(0);
}


//-----------------------------------------------------------------------------
// Purpose: 
// Input  : size - 
//-----------------------------------------------------------------------------
void CDummyTexture::GetSize( SIZE &size ) const
{
	size.cx = 0;
	size.cy = 0;
}


//-----------------------------------------------------------------------------
// Purpose: Renders "No Image" into a device context as a placeholder for the
//			missing texture.
// Input  : pDC - 
//			rect - 
//			iFontHeight - 
//			dwFlags - 
//-----------------------------------------------------------------------------
void CDummyTexture::Draw(CDC *pDC, RECT &rect, int iFontHeight, int iIconHeight, DrawTexData_t &DrawTexData)
{
	CFont *pOldFont = (CFont *)pDC->SelectStockObject(ANSI_VAR_FONT);
	COLORREF crText = pDC->SetTextColor(RGB(0xff, 0xff, 0xff));
	COLORREF crBack = pDC->SetBkColor(RGB(0, 0, 0));

	pDC->FillRect(&rect, CBrush::FromHandle(HBRUSH(GetStockObject(BLACK_BRUSH))));
	pDC->TextOut(rect.left + 2, rect.top + 2, "No Image", 8);

	pDC->SelectObject(pOldFont);
	pDC->SetTextColor(crText);
	pDC->SetBkColor(crBack);
}


//-----------------------------------------------------------------------------
// Purpose: Loads this texture from disk if it is not already loaded.
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CDummyTexture::Load( void )
{
	return(true);
}