Subversion Repositories spk

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 cycrow 1
//#include "stdafx.h"
2
#include "RenderTexture.h"
3
 
4
#include "../Hook/MyDirect3DDevice9.h"
5
 
6
CRenderTexture::CRenderTexture ( MyDirect3DDevice9 *device ) : CRenderObject ()
7
{
8
	m_texture = NULL;
9
}
10
 
11
CRenderTexture::~CRenderTexture ()
12
{
13
	if ( m_texture )
14
		m_texture->Release ();
15
}
16
 
17
void CRenderTexture::OpenTextureFile ( CyString filename )
18
{
19
	D3DXCreateTextureFromFile ( m_pDevice, filename.c_str(), &m_texture );
20
}
21
 
22
void CRenderTexture::ParseSetting ( COverlay *overlay, CyString cmd, CyString rest, CyString section )
23
{
24
	if ( (section == "MOUSEOVER") || (section == "ONCLICK") )
25
	{
26
		if ( cmd == "FRAME" )
27
		{
28
			SMOFrame *c = new SMOFrame;
29
			c->iFrame = rest.ToInt();
30
			AddMouseEvent ( section, c );
31
		}
32
		else if ( cmd == "ANIMATION" )
33
		{
34
			SMOAnimation *c = new SMOAnimation;
35
			c->iAnimation = rest.ToInt();
36
			AddMouseEvent ( section, c );
37
		}
38
		else
39
			CRenderObject::ParseSetting ( overlay, cmd, rest, section );
40
	}
41
	else if ( section.Empty() )
42
	{
43
		if ( cmd == "FILE" )
44
			OpenTextureFile ( rest );
45
		else
46
			CRenderObject::ParseSetting ( overlay, cmd, rest, section );
47
	}
48
	else
49
		CRenderObject::ParseSetting ( overlay, cmd, rest, section );
50
}
51
 
52
void CRenderTexture::render ( MyDirect3DDevice9 *device, int x, int y, LPD3DXSPRITE sprite )
53
{
54
	if ( !m_texture )
55
		return;
56
 
57
	D3DXMATRIX mat;
58
	// render top left corner
59
	D3DXMatrixTransformation2D ( &mat, NULL, 0.0, &D3DXVECTOR2(1, 1), NULL, 0, &D3DXVECTOR2 ( (float)(x + m_iX), (float)(y + m_iY)) );
60
	sprite->SetTransform(&mat);
61
 
62
	short *c = m_iColour;
63
 
64
	LPDIRECT3DTEXTURE9  texture = m_texture;
65
	if ( m_bMouseOver )
66
	{
67
		for ( SMouseOver *mo = m_lMouseOver.First(); mo; mo = m_lMouseOver.Next() )
68
		{
69
			if ( mo->iType == MO_COLOUR )
70
				c = ((SMOColour *)mo)->iColour;
71
			else if ( mo->iType == MO_TEXTURE )
72
				texture = ((SMOTexture *)mo)->pTexture;
73
		}		
74
	}
75
 
76
	D3DCOLOR color = D3DCOLOR_RGBA ( c[0], c[1], c[2], m_iAlpha );
77
	sprite->Draw ( texture, NULL, NULL, NULL, color );
78
}
79
 
80
bool CRenderTexture::CheckMouse ( int x, int y, int offsetx, int offsety )
81
{
82
	if ( !m_texture )
83
		return false;
84
 
85
	int iX = offsetx + m_iX;
86
	int iY = offsety + m_iY;
87
 
88
	D3DSURFACE_DESC desc;
89
	m_texture->GetLevelDesc ( 0, &desc );
90
 
91
	if ( x < iX )
92
		return false;
93
	if ( y < iY )
94
		return false;
95
	if ( x > (iX + (long)desc.Width) )
96
		return false;
97
	if ( y > (iY + (long)desc.Height) )
98
		return false;
99
 
100
	return true;
101
}