summaryrefslogtreecommitdiff
path: root/hammer/texturewindow.h
blob: 9db7acb404bcd997be99957b929408f22a8d54ae (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef TEXTUREWINDOW_H
#define TEXTUREWINDOW_H
#ifdef _WIN32
#pragma once
#endif

#include "IEditorTexture.h"
#include "utlvector.h"


struct TextureWindowTex_t
{
	IEditorTexture *pTex;
	int nUsageCount;
};


class TextureWindowTexList : public CUtlVector<TextureWindowTex_t>
{
public:

	inline int Find(IEditorTexture *pTex)
	{
		for (int i = 0; i < Count(); i++)
		{
			if (Element(i).pTex == pTex)
			{
				return i;
			}
		}	

		return -1;
	}
};


class CTextureWindow : public CWnd
{
public:
	CTextureWindow();
	virtual ~CTextureWindow();

	void Create(CWnd *pParentWnd, RECT& rect);

	struct TWENUMPOS
	{
		IEditorTexture *pTex;
		RECT texrect;
		int cur_x, cur_y;
		RECT clientrect;
		int largest_y;
		int iTexIndex;
		int nUsageCount;		// The number of times this texture is used in the map. Only set in "Used Textures Only" mode.
	};

	enum
	{
		TYPEFILTER_OPAQUE = 0x1,
		TYPEFILTER_TRANSLUCENT = 0x2,
		TYPEFILTER_SELFILLUM = 0x4,
		TYPEFILTER_ENVMASK = 0x8,

		TYPEFILTER_ALL = (TYPEFILTER_OPAQUE|TYPEFILTER_TRANSLUCENT|TYPEFILTER_SELFILLUM|TYPEFILTER_ENVMASK),
	};

	void EnableUpdate(bool bEnable);
	void UpdateScrollSizes();
	BOOL EnumTexturePositions(TWENUMPOS *pTE, BOOL bStart = FALSE);
	void SetDisplaySize(int iSize);
	void HighlightCurTexture(CDC *pDC = NULL);
	void SetNameFilter(LPCTSTR pszFilter);
	void SetKeywords(const char *pszKeywords);
	void SetTextureFormat(TEXTUREFORMAT eTextureFormat);
	void SelectTexture(LPCTSTR pszTexture, BOOL bAllowRedraw = TRUE);
	void SetSpecificList(TextureWindowTexList *pList);
	void SetTypeFilter( int filter, bool enable );
	void ShowErrors( bool enable )	{ m_bShowErrors = true; }

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTextureWindow)
	//}}AFX_VIRTUAL

	char szCurTexture[128];

protected:

	bool MatchKeywords(const char *pszSearch, char **pszKeyword, int nKeywords);

	int total_x;
	int total_y;
	int iDisplaySize;
	int iTexNameCharWidth;
	BOOL bFirstPaint;
	CFont TexFont;
	TextureWindowTexList *m_pSpecificList;
	CRect rectHighlight;
	int	m_nTypeFilter;

	char m_szFilter[128];			// Name filter, space, comma, or semicolon delimited.
	int m_nFilters;					// The number of names that were parsed out of the name filter.
	char *m_Filters[64];			// The individual name filters.

	char m_szKeywords[128];			// Keyword filter, space, comma, or semicolon delimited.
	int m_nKeywords;				// The number of keywords that were parsed out of the name filter.
	char *m_Keyword[64];			// The individual keywords.

	bool m_bEnableUpdate;			// Locks GUI updates to control repaints.
	bool m_bShowErrors;

	TEXTUREFORMAT m_eTextureFormat;

	//{{AFX_MSG(CTextureWindow)
	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};


#endif // TEXTUREWINDOW_H