# Khaotic Engine Reborn: text_class Class Reference

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.

{
m_vertexBuffer = 0;
m_indexBuffer = 0;
}

## text_class() [2/2]

text_class::text_class | ( | const text_class & | other | ) |

Definition at line 11 of file text_class.cpp.

{
}

## ~text_class()

text_class::~text_class | ( |  | ) |

Definition at line 16 of file text_class.cpp.

{
}

## Member Function Documentation

## GetIndexCount()

int text_class::GetIndexCount | ( |  | ) |

Definition at line 59 of file text_class.cpp.

{
return m_indexCount;
}

## GetPixelColor()

XMFLOAT4 text_class::GetPixelColor | ( |  | ) |

Definition at line 247 of file text_class.cpp.

{
return m_pixelColor;
}

## 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.

{
bool result;
// Store the screen width and height.
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
// Store the maximum length of the sentence.
m_maxLength = maxLength;
// Initalize the sentence.
result = InitializeBuffers(device, deviceContext, Font, text, positionX, positionY, red, green, blue);
if (!result)
{
return false;
}
return true;
}

## Render()

void text_class::Render | ( | ID3D11DeviceContext * | deviceContext | ) |

Definition at line 51 of file text_class.cpp.

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

## Shutdown()

void text_class::Shutdown | ( |  | ) |

Definition at line 43 of file text_class.cpp.

{
// Release the vertex and index buffers.
ShutdownBuffers();
return;
}

## 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.

{
int numLetters;
VertexType* vertices;
float drawX, drawY;
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;
VertexType* verticesPtr;
// Store the color of the sentence.
m_pixelColor = XMFLOAT4(red, green, blue, 1.0f);
// Get the number of letters in the sentence.
numLetters = (int)strlen(text);
// Check for possible buffer overflow.
if (numLetters > m_maxLength)
{
return false;
}
// Create the vertex array.
vertices = new VertexType[m_vertexCount];
// Initialize vertex array to zeros at first.
memset(vertices, 0, (sizeof(VertexType) * m_vertexCount));
// Calculate the X and Y pixel position on the screen to start drawing to.
drawX = (float)(((m_screenWidth / 2) * -1) + positionX);
drawY = (float)((m_screenHeight / 2) - positionY);
// Use the font class to build the vertex array from the sentence text and sentence draw location.
Font->BuildVertexArray((void*)vertices, text, drawX, drawY);
// Lock the vertex buffer so it can be written to.
result = deviceContext->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return false;
}
// Get a pointer to the data in the vertex buffer.
verticesPtr = (VertexType*)mappedResource.pData;
// Copy the data into the vertex buffer.
memcpy(verticesPtr, (void*)vertices, (sizeof(VertexType) * m_vertexCount));
// Unlock the vertex buffer.
deviceContext->Unmap(m_vertexBuffer, 0);
// Release the vertex array as it is no longer needed.
delete[] vertices;
vertices = 0;
return true;
}

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

- enginecustom/src/inc/system/text_class.h
- enginecustom/src/src/system/text_class.cpp