Khaotic Engine Reborn
Loading...
Searching...
No Matches
text_class Class Reference

Public Member Functions

 text_class (const text_class &)
 
bool Initialize (ID3D11Device *, ID3D11DeviceContext *, int, int, int, font_class *, char *, int, int, float, float, float)
 
void Shutdown ()
 
void Render (ID3D11DeviceContext *)
 
int GetIndexCount ()
 
bool UpdateText (ID3D11DeviceContext *, font_class *, char *, int, int, float, float, float)
 
XMFLOAT4 GetPixelColor ()
 

Detailed Description

Definition at line 12 of file text_class.h.

Constructor & Destructor Documentation

◆ text_class() [1/2]

text_class::text_class ( )

Definition at line 4 of file text_class.cpp.

5{
6 m_vertexBuffer = 0;
7 m_indexBuffer = 0;
8}

◆ text_class() [2/2]

text_class::text_class ( const text_class & other)

Definition at line 11 of file text_class.cpp.

12{
13}

◆ ~text_class()

text_class::~text_class ( )

Definition at line 16 of file text_class.cpp.

17{
18}

Member Function Documentation

◆ GetIndexCount()

int text_class::GetIndexCount ( )

Definition at line 59 of file text_class.cpp.

60{
61 return m_indexCount;
62}

◆ GetPixelColor()

XMFLOAT4 text_class::GetPixelColor ( )

Definition at line 247 of file text_class.cpp.

248{
249 return m_pixelColor;
250}

◆ Initialize()

bool text_class::Initialize ( ID3D11Device * device,
ID3D11DeviceContext * deviceContext,
int screenWidth,
int screenHeight,
int maxLength,
font_class * Font,
char * text,
int positionX,
int positionY,
float red,
float green,
float blue )

Definition at line 20 of file text_class.cpp.

22{
23 bool result;
24
25
26 // Store the screen width and height.
27 m_screenWidth = screenWidth;
28 m_screenHeight = screenHeight;
29
30 // Store the maximum length of the sentence.
31 m_maxLength = maxLength;
32
33 // Initalize the sentence.
34 result = InitializeBuffers(device, deviceContext, Font, text, positionX, positionY, red, green, blue);
35 if (!result)
36 {
37 return false;
38 }
39
40 return true;
41}

◆ Render()

void text_class::Render ( ID3D11DeviceContext * deviceContext)

Definition at line 51 of file text_class.cpp.

52{
53 // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
54 RenderBuffers(deviceContext);
55
56 return;
57}

◆ Shutdown()

void text_class::Shutdown ( )

Definition at line 43 of file text_class.cpp.

44{
45 // Release the vertex and index buffers.
46 ShutdownBuffers();
47
48 return;
49}

◆ UpdateText()

bool text_class::UpdateText ( ID3D11DeviceContext * deviceContext,
font_class * Font,
char * text,
int positionX,
int positionY,
float red,
float green,
float blue )

Definition at line 169 of file text_class.cpp.

170{
171 int numLetters;
172 VertexType* vertices;
173 float drawX, drawY;
174 HRESULT result;
175 D3D11_MAPPED_SUBRESOURCE mappedResource;
176 VertexType* verticesPtr;
177
178 // Store the color of the sentence.
179 m_pixelColor = XMFLOAT4(red, green, blue, 1.0f);
180
181 // Get the number of letters in the sentence.
182 numLetters = (int)strlen(text);
183
184 // Check for possible buffer overflow.
185 if (numLetters > m_maxLength)
186 {
187 return false;
188 }
189
190 // Create the vertex array.
191 vertices = new VertexType[m_vertexCount];
192
193 // Initialize vertex array to zeros at first.
194 memset(vertices, 0, (sizeof(VertexType) * m_vertexCount));
195
196 // Calculate the X and Y pixel position on the screen to start drawing to.
197 drawX = (float)(((m_screenWidth / 2) * -1) + positionX);
198 drawY = (float)((m_screenHeight / 2) - positionY);
199
200 // Use the font class to build the vertex array from the sentence text and sentence draw location.
201 Font->BuildVertexArray((void*)vertices, text, drawX, drawY);
202
203 // Lock the vertex buffer so it can be written to.
204 result = deviceContext->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
205 if (FAILED(result))
206 {
207 return false;
208 }
209
210 // Get a pointer to the data in the vertex buffer.
211 verticesPtr = (VertexType*)mappedResource.pData;
212
213 // Copy the data into the vertex buffer.
214 memcpy(verticesPtr, (void*)vertices, (sizeof(VertexType) * m_vertexCount));
215
216 // Unlock the vertex buffer.
217 deviceContext->Unmap(m_vertexBuffer, 0);
218
219 // Release the vertex array as it is no longer needed.
220 delete[] vertices;
221 vertices = 0;
222
223 return true;
224}

The documentation for this class was generated from the following files: