# Khaotic Engine Reborn: font_class Class Reference

Loading...
Searching...
No Matches
font_class Class Reference

## Public Member Functions

| font_class (const font_class &)
bool | Initialize (ID3D11Device *, ID3D11DeviceContext *, int)
void | Shutdown ()
ID3D11ShaderResourceView * | GetTexture ()
void | BuildVertexArray (void *, char *, float, float)
int | GetSentencePixelLength (char *)
int | GetFontHeight ()

## Detailed Description

Definition at line 22 of file font_class.h.

## Constructor & Destructor Documentation

## font_class() [1/2]

font_class::font_class | ( |  | ) |

Definition at line 3 of file font_class.cpp.

{
m_Font = 0;
m_Texture = 0;
}

## font_class() [2/2]

font_class::font_class | ( | const font_class & | other | ) |

Definition at line 10 of file font_class.cpp.

{
}

## ~font_class()

font_class::~font_class | ( |  | ) |

Definition at line 15 of file font_class.cpp.

{
}

## Member Function Documentation

## BuildVertexArray()

void font_class::BuildVertexArray | ( | void * | vertices,
|  | char * | sentence,
|  | float | drawX,
|  | float | drawY )

Definition at line 178 of file font_class.cpp.

{
VertexType* vertexPtr;
int numLetters, index, i, letter;
// Coerce the input vertices into a VertexType structure.
vertexPtr = (VertexType*)vertices;
// Get the number of letters in the sentence.
numLetters = (int)strlen(sentence);
// Initialize the index to the vertex array.
index = 0;
// Draw each letter onto a quad.
for (i = 0; i < numLetters; i++)
{
letter = ((int)sentence[i]) - 32;
// If the letter is a space then just move over three pixels.
if (letter == 0)
{
drawX = drawX + m_spaceSize;
}
else
{
// First triangle in quad.
vertexPtr[index].position = XMFLOAT3(drawX, drawY, 0.0f); // Top left.
vertexPtr[index].texture = XMFLOAT2(m_Font[letter].left, 0.0f);
index++;
vertexPtr[index].position = XMFLOAT3((drawX + m_Font[letter].size), (drawY - m_fontHeight), 0.0f); // Bottom right.
vertexPtr[index].texture = XMFLOAT2(m_Font[letter].right, 1.0f);
index++;
vertexPtr[index].position = XMFLOAT3(drawX, (drawY - m_fontHeight), 0.0f); // Bottom left.
vertexPtr[index].texture = XMFLOAT2(m_Font[letter].left, 1.0f);
index++;
// Second triangle in quad.
vertexPtr[index].position = XMFLOAT3(drawX, drawY, 0.0f); // Top left.
vertexPtr[index].texture = XMFLOAT2(m_Font[letter].left, 0.0f);
index++;
vertexPtr[index].position = XMFLOAT3(drawX + m_Font[letter].size, drawY, 0.0f); // Top right.
vertexPtr[index].texture = XMFLOAT2(m_Font[letter].right, 0.0f);
index++;
vertexPtr[index].position = XMFLOAT3((drawX + m_Font[letter].size), (drawY - m_fontHeight), 0.0f); // Bottom right.
vertexPtr[index].texture = XMFLOAT2(m_Font[letter].right, 1.0f);
index++;
// Update the x location for drawing by the size of the letter and one pixel.
drawX = drawX + m_Font[letter].size + 1.0f;
}
}
return;
}

## GetFontHeight()

int font_class::GetFontHeight | ( |  | ) |

Definition at line 265 of file font_class.cpp.

{
return (int)m_fontHeight;
}

## GetSentencePixelLength()

int font_class::GetSentencePixelLength | ( | char * | sentence | ) |

Definition at line 239 of file font_class.cpp.

{
int pixelLength, numLetters, i, letter;
pixelLength = 0;
numLetters = (int)strlen(sentence);
for (i = 0; i < numLetters; i++)
{
letter = ((int)sentence[i]) - 32;
// If the letter is a space then count it as three pixels.
if (letter == 0)
{
pixelLength += m_spaceSize;
}
else
{
pixelLength += (m_Font[letter].size + 1);
}
}
return pixelLength;
}

## GetTexture()

ID3D11ShaderResourceView * font_class::GetTexture | ( |  | ) |

Definition at line 173 of file font_class.cpp.

{
return m_Texture->GetTexture();
}

## Initialize()

bool font_class::Initialize | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | int | fontChoice )

Definition at line 19 of file font_class.cpp.

{
Logger::Get().Log("Initializing font class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
char fontFilename[128];
char fontTextureFilename[128];
bool result;
// Choose one of the available fonts, and default to the first font otherwise.
switch (fontChoice)
{
case 0:
{
strcpy_s(fontFilename, "font01.txt");
strcpy_s(fontTextureFilename, "font01.tga");
m_fontHeight = 32.0f;
m_spaceSize = 3;
break;
}
default:
{
strcpy_s(fontFilename, "font01.txt");
strcpy_s(fontTextureFilename, "font01.tga");
m_fontHeight = 32.0f;
m_spaceSize = 3;
break;
}
}
// Load in the text file containing the font data.
result = LoadFontData(fontFilename);
if (!result)
{
Logger::Get().Log("Failed to load font data", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Load the texture that has the font characters on it.
result = LoadTexture(device, deviceContext, fontTextureFilename);
if (!result)
{
Logger::Get().Log("Failed to load font texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
Logger::Get().Log("Font class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}

## Shutdown()

void font_class::Shutdown | ( |  | ) |

Definition at line 69 of file font_class.cpp.

{
// Release the font texture.
ReleaseTexture();
// Release the font data.
ReleaseFontData();
return;
}

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

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