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
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
1 /*
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
2 * GuiImage
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
3 */
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
4
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
5 #include "GuiImage.h"
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
6 #include "VertexTypes.h"
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
7
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
8 /*
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
9 * GuiImage
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
10 */
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
11 GuiImage::GuiImage() : pEffect(NULL), pVertexBuffer(NULL), pTexture(NULL)
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
12 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
13 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
14
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
15 /*
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
16 * Initialize
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
17 */
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
18 ErrorCode GuiImage::Initialize(ResourceManager* pManager)
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
19 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
20 pResourceManager = pManager;
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
21
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
22 ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
23 if(eCode == Error_Success)
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
24 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
25 eCode = pResourceManager->CreateVertexBuffer(6 * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
26 if(eCode == Error_Success)
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
27 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
28 eCode = SetupVertexBuffer();
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
29 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
30 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
31
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
32 return eCode;
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
33 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
34
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
35 /*
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
36 * Terminate
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
37 */
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
38 void GuiImage::Terminate()
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
39 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
40 if(pVertexBuffer)
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
41 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
42 pVertexBuffer->Release();
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
43 pVertexBuffer = NULL;
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
44 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
45 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
46
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
47 /*
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
48 * Update
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
49 */
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
50 void GuiImage::Update(float fElapsed)
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
51 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
52 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
53
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
54 /*
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
55 * Render
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
56 */
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
57 void GuiImage::Render(RenderContext& kContext, Camera& kCamera)
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
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
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
60 {
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
61 if(pTexture)
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
62 {
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
63 uint32 nPasses = 0;
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
64
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
65 const float fOffsetX = -0.5f * ScreenSizeX;
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
66 const float fOffsetY = +0.5f * ScreenSizeY;
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
67
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
68 const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
69
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
70 kContext.ApplyCameraToEffect(kCamera, pEffect);
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
71
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
72 D3DXMATRIX kScale;
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
73 D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f);
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
74
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
75 const D3DXVECTOR2& kLocation = GetPosition();
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
76
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
77 D3DXMATRIX kTranslate;
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
78 D3DXMatrixTranslation(&kTranslate, fOffsetX + kLocation.x + 0.5f, fOffsetY - kLocation.y + 0.5f, 0.0f);
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
79
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
80 D3DXMATRIX kWorldMatrix;
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
81 D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate);
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
82
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
83 pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
84 pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
85 pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
86
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
87 pEffect->SetTechnique(pEffect->GetTechnique(0));
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
88 pEffect->Begin(&nPasses, 0);
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
89 pEffect->BeginPass(0);
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
90
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
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
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
93 pEffect->EndPass();
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
94 pEffect->End();
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
95 }
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
96
23
a785b0aaf004 More work on the Gui system
koryspansel
parents: 21
diff changeset
97 GuiElement::Render(kContext, kCamera);
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
98 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
99 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
100
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
101 /*
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
102 * SetTexture
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
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
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
105 {
27
5656c8e382fc More Gui work; Remove some old files
koryspansel
parents: 26
diff changeset
106 pTexture = NULL;
18
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
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
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
122 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
123
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
124 /*
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
125 * SetupVertexBuffer
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
126 */
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
127 ErrorCode GuiImage::SetupVertexBuffer()
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
128 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
129 Vertex::Quad* pVertices = NULL;
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
130
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
131 HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
132 if(FAILED(hResult))
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
133 {
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
134 return Error_Fail;
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
135 }
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
136
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
137 pVertices[0] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
138 pVertices[1] = Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
139 pVertices[2] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
140 pVertices[3] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
141 pVertices[4] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
142 pVertices[5] = Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
143
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
144 pVertexBuffer->Unlock();
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
145
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
146 return Error_Success;
33cb6979ac51 More work on GUI system
koryspansel
parents:
diff changeset
147 }