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.

58 lines
1.7 KiB

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