Subversion Repositories spk

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 cycrow 1
//#include "stdafx.h"
2
#include "RenderText.h"
3
 
4
#include "../Hook/MyDirect3DDevice9.h"
5
 
6
CRenderText::CRenderText ( int size ) : CRenderObject ()
7
{
8
	m_iSize = size;
9
	m_font = NULL;
10
	m_iX = m_iY = 0;
11
	m_iWidth = 520;
12
	m_iHeight = size;
13
	m_iAlign = DT_LEFT;
14
	m_bBreakLine = false;
15
 
16
	m_iColour[0] = 0;
17
	m_iColour[1] = 0;
18
	m_iColour[2] = 255;
19
}
20
 
21
CRenderText::~CRenderText ()
22
{
23
	if ( m_font )
24
		m_font->Release ();
25
	m_font = NULL;
26
}
27
 
28
bool CRenderText::CheckMouse ( int x, int y, int offsetx, int offsety )
29
{
30
	int iX = offsetx + m_iX;
31
	int iY = offsety + m_iY;
32
 
33
	if ( x < iX )
34
		return false;
35
	if ( y < iY )
36
		return false;
37
	if ( x > (iX + m_iWidth) )
38
		return false;
39
	if ( y > (iY + m_iHeight) )
40
		return false;
41
 
42
	return true;
43
}
44
 
45
 
46
void CRenderText::ParseSetting ( COverlay *overlay, CyString cmd, CyString rest, CyString section )
47
{
48
	cmd.ToUpper();
49
	if ( section == "ANIMATE" )
50
	{
51
		if ( cmd == "TEXT" )
52
		{
53
			SAnimateText *text = new SAnimateText;
54
			text->iStartTime = ConvertAnimationTime ( rest.GetToken ( ",", 1, 1 ) );
55
			text->sText = rest.GetToken ( ",", 2 );
56
			m_lAnimations.push_back ( text );
57
		}
58
		else if ( cmd == "COLOUR" )
59
		{
60
			SAnimateColour *c = new SAnimateColour;
61
			c->iStartTime = ConvertAnimationTime ( rest.GetToken ( ",", 1, 1 ) );
62
			c->iR = rest.GetToken ( ",", 2, 2 ).ConvertEquation();
63
			c->iG = rest.GetToken ( ",", 3, 3 ).ConvertEquation();
64
			c->iB = rest.GetToken ( ",", 4, 4 ).ConvertEquation();
65
			m_lAnimations.push_back ( c );
66
		}
67
		else
68
			CRenderObject::ParseSetting ( overlay, cmd, rest, section );
69
	}
70
	else if ( (section == "MOUSEOVER") || (section == "ONCLICK") )
71
	{
72
		if ( cmd == "APPEND" )
73
		{
74
			SMOTextAppend *c = new SMOTextAppend;
75
			c->sText = rest;
76
			AddMouseEvent ( section, c );
77
		}
78
		else if ( cmd == "PREPEND" )
79
		{
80
			SMOTextPrepend *c = new SMOTextPrepend;
81
			c->sText = rest;
82
			AddMouseEvent ( section, c );
83
		}
84
		else
85
			CRenderObject::ParseSetting ( overlay, cmd, rest, section );
86
	}
87
	else if ( section.Empty() )
88
	{
89
		if ( cmd == "LENGTH" )
90
			m_iWidth = rest.ConvertEquation();
91
		else if ( cmd == "FONT" )
92
			InitFont ( m_pDevice, TEXT(rest.c_str()), m_iSize );
93
		else if ( cmd == "ALIGN" )
94
		{
95
			rest.ToUpper();
96
			if ( rest == "CENTER" )
97
				m_iAlign = DT_CENTER;
98
			else if ( rest == "LEFT" )
99
				m_iAlign = DT_LEFT;
100
			else if ( rest == "RIGHT" )
101
				m_iAlign = DT_RIGHT;
102
		}
103
		else if ( (cmd == "SIZE") && (m_iSize == -1) )
104
			m_iSize = rest.ConvertEquation();
105
		else if ( cmd == "LINES" )
106
		{
107
			int l = rest.ConvertEquation();
108
			if ( l < 1 )
109
				l = 1;
110
			m_iHeight = m_iSize * l;
111
			if ( l > 1 )
112
				m_bBreakLine = true;
113
		}
114
		else if ( cmd == "COLOUR" )
115
		{
116
			m_iColour[0] = rest.GetToken ( ",", 1, 1 ).ConvertEquation();
117
			m_iColour[1] = rest.GetToken ( ",", 2, 2 ).ConvertEquation();
118
			m_iColour[2] = rest.GetToken ( ",", 3, 3 ).ConvertEquation();
119
		}
120
		else if ( cmd == "TEXT" )
121
			m_sText = rest;
122
		else
123
			CRenderObject::ParseSetting ( overlay, cmd, rest, section );
124
	}
125
	else
126
		CRenderObject::ParseSetting ( overlay, cmd, rest, section );
127
}
128
 
129
void CRenderText::render ( MyDirect3DDevice9 *device, int x, int y, LPD3DXSPRITE sprite )
130
{
131
	// set size of text
132
	RECT rct;
133
	rct.left = m_iX + x;
134
	rct.right = rct.left + m_iWidth;
135
	rct.top = m_iY + y;
136
	rct.bottom = rct.top + m_iHeight;
137
 
138
	// set the colour for the text
139
	short *c = m_iColour;
140
	CyString text = m_sText;
141
 
142
	CLinkList<SMouseOver> *mouseList = NULL;
143
 
144
	for ( int i = 0; i < 2; i++ )
145
	{
146
		mouseList = NULL;
147
		if ( (i == 1) && (m_bClicked) )
148
			mouseList = &m_lMouseClick;
149
		else if ( (i == 0) && (m_bMouseOver) )
150
			mouseList = &m_lMouseOver;
151
 
152
		if ( mouseList )
153
		{
154
			for ( SMouseOver *mo = mouseList->First(); mo; mo = mouseList->Next() )
155
			{
156
				if ( mo->iType == MO_COLOUR )
157
					c = ((SMOColour *)mo)->iColour;
158
				else if ( mo->iType == MO_TEXTAPPEND )
159
					text += ((SMOTextAppend *)mo)->sText;
160
				else if ( mo->iType == MO_TEXTPREPEND )
161
					text = ((SMOTextPrepend *)mo)->sText + text;
162
			}
163
		}
164
	}
165
 
166
	if ( text.IsIn("$") )
167
		text = ParseVaribles ( text, &m_lVaribles );
168
 
169
	D3DCOLOR fontColor = D3DCOLOR_ARGB ( m_iAlpha, c[0], c[1], c[2] );
170
 
171
	// set the alignment
172
	int align = m_iAlign;
173
	if ( m_bBreakLine )
174
		align += DT_WORDBREAK;
175
 
176
	// set the transformation position
177
	D3DXMATRIX mat;
178
	D3DXMatrixIdentity ( &mat );
179
	sprite->SetTransform ( &mat );
180
 
181
	// draw the text
182
	m_font->DrawText( sprite, text.c_str(), -1, &rct, align, fontColor );	
183
}
184
 
185
void CRenderText::InitFont ( MyDirect3DDevice9 *device, LPCTSTR fontStr, int size )
186
{
187
	D3DXCreateFont( device, size, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, fontStr, &m_font );
188
	m_iHeight = size;
189
}
190
 
191
 
192
void CRenderText::StartAnimation ( SAnimate *anim )
193
{
194
	if ( anim->iType == ANIM_CHANGETEXT )
195
	{
196
		SAnimateText *text = (SAnimateText *)anim;
197
		m_sText = text->sText;
198
		EndAnimation ( anim );
199
	}
200
	else if ( anim->iType == ANIM_CHANGECOLOUR )
201
	{
202
		SAnimateColour *colour = (SAnimateColour *)anim;
203
		m_iColour[0] = colour->iR;
204
		m_iColour[1] = colour->iG;
205
		m_iColour[2] = colour->iB;
206
		EndAnimation ( anim );
207
	}
208
	else
209
		CRenderObject::StartAnimation ( anim );
210
}
211
 
212
/*
213
###############################################################
214
########                Render Text Header            #########
215
###############################################################
216
*/
217
 
218
CRenderTextHeader::CRenderTextHeader ( MyDirect3DDevice9 *device, LPCTSTR fontStr, CyString header ) : CRenderText ()
219
{
220
	InitFont ( device, fontStr, 50 );
221
	m_iAlign = DT_CENTER;
222
	m_sText = header;
223
}
224
 
225
CRenderTextNormal::CRenderTextNormal ( MyDirect3DDevice9 *device, LPCTSTR fontStr, CyString header ) : CRenderText ()
226
{
227
	InitFont ( device, fontStr, 20 );
228
	m_iAlign = DT_CENTER | DT_WORDBREAK;
229
	m_sText = header;
230
}