Mercurial > LightClone
annotate LightClone/Source/GuiImage.cpp @ 27:5656c8e382fc
More Gui work; Remove some old files
author | koryspansel |
---|---|
date | Fri, 16 Sep 2011 18:21:36 -0700 |
parents | 3a63df04f3c0 |
children | 7ff46a00bcd3 |
rev | line source |
---|---|
18 | 1 /* |
2 * GuiImage | |
3 */ | |
4 | |
5 #include "GuiImage.h" | |
6 #include "VertexTypes.h" | |
7 | |
8 /* | |
9 * GuiImage | |
10 */ | |
11 GuiImage::GuiImage() : pEffect(NULL), pVertexBuffer(NULL), pTexture(NULL) | |
12 { | |
13 } | |
14 | |
15 /* | |
16 * Initialize | |
17 */ | |
18 ErrorCode GuiImage::Initialize(ResourceManager* pManager) | |
19 { | |
20 pResourceManager = pManager; | |
21 | |
22 ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect); | |
23 if(eCode == Error_Success) | |
24 { | |
25 eCode = pResourceManager->CreateVertexBuffer(6 * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer); | |
26 if(eCode == Error_Success) | |
27 { | |
28 eCode = SetupVertexBuffer(); | |
29 } | |
30 } | |
31 | |
32 return eCode; | |
33 } | |
34 | |
35 /* | |
36 * Terminate | |
37 */ | |
38 void GuiImage::Terminate() | |
39 { | |
40 if(pVertexBuffer) | |
41 { | |
42 pVertexBuffer->Release(); | |
43 pVertexBuffer = NULL; | |
44 } | |
45 } | |
46 | |
47 /* | |
48 * Update | |
49 */ | |
50 void GuiImage::Update(float fElapsed) | |
51 { | |
52 } | |
53 | |
54 /* | |
55 * Render | |
56 */ | |
57 void GuiImage::Render(RenderContext& kContext, Camera& kCamera) | |
58 { | |
26
3a63df04f3c0
Several Gui enhancements; Drag and drop should work; Added resource caching
koryspansel
parents:
23
diff
changeset
|
59 if(nFlags & GuiElementFlag_Visible) |
18 | 60 { |
23 | 61 if(pTexture) |
62 { | |
63 uint32 nPasses = 0; | |
18 | 64 |
23 | 65 const float fOffsetX = -0.5f * ScreenSizeX; |
66 const float fOffsetY = +0.5f * ScreenSizeY; | |
18 | 67 |
23 | 68 const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); |
69 | |
70 kContext.ApplyCameraToEffect(kCamera, pEffect); | |
18 | 71 |
23 | 72 D3DXMATRIX kScale; |
73 D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f); | |
18 | 74 |
23 | 75 const D3DXVECTOR2& kLocation = GetPosition(); |
18 | 76 |
23 | 77 D3DXMATRIX kTranslate; |
78 D3DXMatrixTranslation(&kTranslate, fOffsetX + kLocation.x + 0.5f, fOffsetY - kLocation.y + 0.5f, 0.0f); | |
18 | 79 |
23 | 80 D3DXMATRIX kWorldMatrix; |
81 D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate); | |
82 | |
83 pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix); | |
84 pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector); | |
85 pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture); | |
18 | 86 |
23 | 87 pEffect->SetTechnique(pEffect->GetTechnique(0)); |
88 pEffect->Begin(&nPasses, 0); | |
89 pEffect->BeginPass(0); | |
90 | |
91 kContext.DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace); | |
21
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
92 |
23 | 93 pEffect->EndPass(); |
94 pEffect->End(); | |
95 } | |
18 | 96 |
23 | 97 GuiElement::Render(kContext, kCamera); |
18 | 98 } |
99 } | |
100 | |
101 /* | |
102 * SetTexture | |
103 */ | |
21
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
104 ErrorCode GuiImage::SetTexture(const char* pName, bool bResize) |
18 | 105 { |
27 | 106 pTexture = NULL; |
18 | 107 |
21
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
108 ErrorCode eCode = pResourceManager->CreateTextureFromFile(pName, &pTexture); |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
109 if(eCode == Error_Success) |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
110 { |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
111 if(bResize) |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
112 { |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
113 D3DSURFACE_DESC kDescriptor; |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
114 pTexture->GetLevelDesc(0, &kDescriptor); |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
115 |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
116 kDimensions.x = (float)kDescriptor.Width; |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
117 kDimensions.y = (float)kDescriptor.Height; |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
118 } |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
119 } |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
120 |
b4dc5d674e22
Added GUI event system and some support data structures
koryspansel
parents:
18
diff
changeset
|
121 return eCode; |
18 | 122 } |
123 | |
124 /* | |
125 * SetupVertexBuffer | |
126 */ | |
127 ErrorCode GuiImage::SetupVertexBuffer() | |
128 { | |
129 Vertex::Quad* pVertices = NULL; | |
130 | |
131 HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); | |
132 if(FAILED(hResult)) | |
133 { | |
134 return Error_Fail; | |
135 } | |
136 | |
137 pVertices[0] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f); | |
138 pVertices[1] = Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f); | |
139 pVertices[2] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f); | |
140 pVertices[3] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f); | |
141 pVertices[4] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f); | |
142 pVertices[5] = Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f); | |
143 | |
144 pVertexBuffer->Unlock(); | |
145 | |
146 return Error_Success; | |
147 } |