-
Notifications
You must be signed in to change notification settings - Fork 1
/
UIWrappers.cpp
191 lines (167 loc) · 4.92 KB
/
UIWrappers.cpp
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
187
188
189
190
191
#include "UIWrappers.h"
Surface::Surface()
{
// this->SetDevice(pDevice);
this->SetSurface(NULL);
//m_BackBuffer = new Surface(pDevice);
m_SourceRect = NULL;
}
Surface::~Surface()
{
delete m_BackBuffer;
if (m_Surface != NULL)
m_Surface->Release();
}
HRESULT Surface::CreateSurface(UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool)
{
return Device->CreateOffscreenPlainSurface(Width, Height, Format, Pool, &m_Surface, NULL);
}
HRESULT Surface::LoadFromFile(LPSTR Path)
{
HRESULT Result = E_FAIL;
ZeroMemory(&Info, sizeof(D3DXIMAGE_INFO));
if (SUCCEEDED(D3DXGetImageInfoFromFile(Path, &Info)))
{
Result = CreateSurface(Info.Width, Info.Height, Info.Format, D3DPOOL_SYSTEMMEM);
}
if (Result == S_OK)
{
Result = D3DXLoadSurfaceFromFile(m_Surface, NULL, NULL, Path, NULL, D3DX_FILTER_NONE, 0, NULL);
}
else
Result = E_FAIL;
return Result;
}
HRESULT Surface::MakeBackBuffer(void)
{
if (Device)
{
SafeRelease(m_BackBuffer->m_Surface);
D3D::Release(m_BackBuffer->m_Surface);
return Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_BackBuffer->m_Surface);
}
return E_NOTIMPL;
}
HRESULT Surface::UpdateSurface(Surface * Source, RECT * pSourceRect, int x, int y)
{
m_SourceRect = pSourceRect;
if ((Device) && (Source))
{
POINT Point;
Point.x = x;
Point.y = y;
return Device->UpdateSurface(Source->GetSurface(), pSourceRect, m_Surface, &Point);
}
else
return E_FAIL;
}
HRESULT Surface::CopySurface(IDirect3DSurface9 * CopyTo, RECT CopyFromRect, int x, int y)
{
if ((Device) && (CopyTo))
{
POINT l_Point;
l_Point.x = x;
l_Point.y = y;
return Device->UpdateSurface(m_Surface, &CopyFromRect, CopyTo, &l_Point);
}
return E_FAIL;
}
void Surface::Render(void)
{
m_BackBuffer->UpdateSurface(this, m_SourceRect, 0, 0);
}
///---------------------------------------------------------------------------------Texture wrapper-----------------------------------------------------------------------
Texture::Texture()
{
D3DXVECTOR2 Vec;
D3DXVECTOR2 VecS ;
Vec.x = 0;
Vec.y = 0;
VecS.x = 1;
VecS.y = 1;
// SetDevice(pDevice);
SetTexture(NULL);
SetRotation(0.0f);
SetRotationCenter(Vec);
SetScaling(VecS);
SetTranslation(Vec);
m_Info;
}
Texture::Texture(LPSTR Path, D3DXVECTOR2 RotationCenter, FLOAT Rotation, D3DXVECTOR2 Translation, D3DXVECTOR2 Scaling)
{
// SetDevice(pDevice);
LoadFromFile(Path);
InitTexture( RotationCenter, Rotation, Translation, Scaling);
}
void Texture::InitTexture( D3DXVECTOR2 RotationCenter, FLOAT Rotation, D3DXVECTOR2 Translation, D3DXVECTOR2 Scaling)
{
SetRotation(Rotation);
SetRotationCenter(RotationCenter);
SetScaling(Scaling);
SetTranslation(Translation);
}
Texture::~Texture()
{
if (m_Texture != NULL)
SafeRelease(m_Texture);
}
HRESULT Texture::LoadFromFile(LPSTR Path)
{
if (m_Texture != NULL)
m_Texture->Release();
if (SUCCEEDED(D3DXGetImageInfoFromFile(Path, &m_Info)))
{
m_SrcRect.top = 0;
m_SrcRect.left = 0;
m_SrcRect.bottom = m_Info.Height;
m_SrcRect.right = m_Info.Width;
return D3DXCreateTextureFromFileEx(Device, Path, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2,
D3DX_DEFAULT, 0, m_Info.Format, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &m_Texture);
}
return E_FAIL;
}
///----------------------------------------------------------------------Sprite Wrapper-------------------------------------------------------------------------------
Sprite::Sprite()
{
// SetDevice(pDevice);
D3DXCreateSprite(Device, &m_Sprite);
}
Sprite::~Sprite()
{
if (m_Sprite != NULL)
SafeRelease(m_Sprite);
}
HRESULT Sprite::DrawTexture(Texture* Tex, D3DXVECTOR2 Pos)
{
if ((Tex->GetTexture() != NULL) && (m_Sprite != NULL))
{
D3DXMATRIX Mat;
D3DXMatrixTransformation2D(&Mat, NULL, 0, &Tex->GetScaling(), &Tex->GetRotationCenter(), Tex->GetRotation(), &Pos);
m_Sprite->Begin(D3DXSPRITE_ALPHABLEND);
m_Sprite->SetTransform(&Mat);
HRESULT Result = m_Sprite->Draw(Tex->GetTexture(), &Tex->GetRect(), NULL, NULL, 0xFFFFFFFF);
m_Sprite->End();
return Result;
}
else
return E_FAIL;
}
HRESULT Sprite::DrawBackground(Texture* Tex)
{
if ((Tex->GetTexture() != NULL) && (m_Sprite != NULL))
{
D3DXMATRIX Mat;
D3DXVECTOR2 m_scale;
ZeroMemory(&m_scale, sizeof(D3DXVECTOR2));
m_scale.x = (FLOAT(Tex->GetRect().right)/ FLOAT(Tex->GetWidth()));
m_scale.y = (FLOAT(Tex->GetRect().bottom)/ FLOAT(Tex->GetHeight()));
D3DXMatrixTransformation2D(&Mat, NULL, 0, &m_scale, &Tex->GetRotationCenter(), Tex->GetRotation(), &Tex->GetTranslation());
m_Sprite->Begin(D3DXSPRITE_ALPHABLEND);
m_Sprite->SetTransform(&Mat);
HRESULT Result = m_Sprite->Draw(Tex->GetTexture(), NULL, NULL, NULL, 0xFFFFFFFF);
m_Sprite->End();
return Result;
}
else
return E_FAIL;
}