#include "pvr.h"

///
//
///
PVR::cGuiTextString::cGuiTextString()
{    
    m_sNumChars = 0;
    // todo:
    m_pCharacters = (cGuiChar**)malloc(2048 * sizeof(cGuiChar*));
}

///
//
///
PVR::cGuiTextString::~cGuiTextString()
{    
    Flush();    
    free (m_pCharacters);
}

///
// todo
///
void PVR::cGuiTextString::Add(uint16_t usCharacterId, int16_t sX, int16_t sY, int16_t sW, int16_t sH, PVR::cTexture *pTexture, float fR, float fG, float fB, int8_t layerOffset)
{    
    cGuiChar *pCharacter = new cGuiChar(usCharacterId, sX, sY, sW, sH, pTexture);
    pCharacter->m_fR = fR;
    pCharacter->m_fG = fG;
    pCharacter->m_fB = fB;
    pCharacter->m_cLayerOffset = layerOffset;
    m_pCharacters[m_sNumChars++] = pCharacter;       
}

///
void PVR::cGuiTextString::Add(uint16_t usCharacterId, int16_t sX, int16_t sY, int16_t sW, int16_t sH, PVR::cTexture *pTexture, uint32_t colour, int8_t layerOffset)
{    
    cGuiChar *pCharacter = new cGuiChar(usCharacterId, sX, sY, sW, sH, pTexture);
    pCharacter->m_ulColour = colour;  
    pCharacter->m_cLayerOffset = layerOffset;
    m_pCharacters[m_sNumChars++] = pCharacter;
}

///
//
///
void PVR::cGuiTextString::Print(int16_t sOffsetX, int16_t sOffsetY)
{    
    for (int16_t sIndex = 0; sIndex < m_sNumChars; sIndex++)
    {
        m_pCharacters[sIndex]->Print(sOffsetX, sOffsetY);
    }
}

///
//
///
void PVR::cGuiTextString::Flush()
{        
    for (int16_t index = 0; index < m_sNumChars; index++)
    {
        delete m_pCharacters[index];
    }
    m_sNumChars = 0;
}
