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.

57 lines
1.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "logWidget.h"
  2. sdlLog::sdlLog(int x, int y, int width, int height, sdlCoreWidget * pWnd) :sdlCoreWidget(x, y, width, height, true, pWnd){
  3. m_nLines = 1 + height / SDL_DEFAULT_LOG_ROW_SIZE;
  4. m_nCurrentLine = 0;
  5. m_ppLines = (sdlLabel**)calloc( m_nLines, sizeof(sdlLabel*) );
  6. if(m_ppLines != NULL) memset( m_ppLines, 0, m_nLines * sizeof(sdlLabel*) );
  7. sdlGraphicElement::setType(GEL_PANEL);
  8. m_pGUI->registerGEL(this);
  9. };
  10. sdlLog::~sdlLog(){
  11. m_pGUI->removeGEL(this);
  12. if (m_ppLines != NULL){
  13. for (int index = 0; index < m_nLines; index++) delete(m_ppLines[index]);
  14. free(m_ppLines);
  15. };
  16. };
  17. void sdlLog::logMessage(const char *Msg){
  18. if (m_ppLines != NULL){
  19. if (m_nCurrentLine < m_nLines){
  20. m_ppLines[m_nCurrentLine] = new sdlLabel(
  21. NULL,
  22. 1,
  23. 1 + (m_nCurrentLine*SDL_DEFAULT_LOG_ROW_SIZE),
  24. m_sGeometry.w - 2,
  25. SDL_DEFAULT_LOG_ROW_SIZE,
  26. this,
  27. SDL_DEFAULT_LOG_FONT_SIZE
  28. );
  29. if( m_ppLines[m_nCurrentLine] != NULL ){
  30. m_ppLines[m_nCurrentLine]->setAlign(ALIGN_LEFT);
  31. m_ppLines[m_nCurrentLine]->setBgColor(0x34, 0x83, 0xae, 10);
  32. m_ppLines[m_nCurrentLine]->setColor(255, 255, 255);
  33. m_nCurrentLine++;
  34. };
  35. for (int index = m_nCurrentLine - 1; index > 0; index--){
  36. char tBuf[SDL_DEFAULT_TEXT_SIZE];
  37. memcpy(tBuf, m_ppLines[index - 1]->getText(), SDL_DEFAULT_TEXT_SIZE);
  38. m_ppLines[index]->setText(tBuf);
  39. };
  40. m_ppLines[0]->setText((CSTR)Msg);
  41. } else {
  42. for (int index = m_nLines - 1; index > 0; index-- ){
  43. char tBuf[SDL_DEFAULT_TEXT_SIZE];
  44. memcpy(tBuf, m_ppLines[index-1]->getText(), SDL_DEFAULT_TEXT_SIZE);
  45. m_ppLines[index]->setText(tBuf);
  46. };
  47. m_ppLines[0]->setText((CSTR)Msg);
  48. };
  49. };
  50. };
  51. void sdlLog::logMessage(CSTR Msg){
  52. logMessage((const char*)Msg);
  53. };