You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.7 KiB

#include "logWidget.h"
sdlLog::sdlLog(int x, int y, int width, int height, sdlCoreWidget * pWnd) :sdlCoreWidget(x, y, width, height, pWnd){
m_nLines = height / SDL_DEFAULT_LOG_ROW_SIZE;
m_nCurrentLine = 0;
m_ppLines = (sdlLabel**)calloc( m_nLines, sizeof(sdlLabel*) );
memset( m_ppLines, 0, m_nLines * sizeof(sdlLabel*) );
};
sdlLog::~sdlLog(){
if (m_ppLines != NULL){
for (int index = 0; index < m_nLines; index++) delete(m_ppLines[index]);
free(m_ppLines);
};
};
void sdlLog::logMessage(const char *Msg){
if (m_ppLines != NULL){
//m_mProtector.lock();
if (m_nCurrentLine < m_nLines){
m_ppLines[m_nCurrentLine] = new sdlLabel(
1,
1 + (m_nCurrentLine*SDL_DEFAULT_LOG_ROW_SIZE),
m_sRect.w - 2,
SDL_DEFAULT_LOG_ROW_SIZE,
this,
SDL_DEFAULT_LOG_FONT_SIZE
);
if( m_ppLines[m_nCurrentLine] != NULL ){
m_ppLines[m_nCurrentLine]->setAlign(ALIGN_LEFT);
m_nCurrentLine++;
};
for (int index = m_nCurrentLine - 1; index > 0; index--){
char tBuf[SDL_DEFAULT_TEXT_SIZE];
memcpy(tBuf, m_ppLines[index - 1]->getText(), SDL_DEFAULT_TEXT_SIZE);
m_ppLines[index]->setText(tBuf);
};
m_ppLines[0]->setText((CSTR)Msg);
} else {
for (int index = m_nLines - 1; index > 0; index-- ){
char tBuf[SDL_DEFAULT_TEXT_SIZE];
memcpy(tBuf, m_ppLines[index-1]->getText(), SDL_DEFAULT_TEXT_SIZE);
m_ppLines[index]->setText(tBuf);
};
m_ppLines[0]->setText((CSTR)Msg);
};
//m_mProtector.unlock();
};
};
void sdlLog::logMessage(CSTR Msg){
logMessage((const char*)Msg);
};
void sdlLog::draw(SDL_Renderer *pRenderer){
for (int index = 0; index < m_nLines; index++){
if (m_ppLines[index] != NULL) m_ppLines[index]->render(pRenderer);
};
};