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.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "progressBar.h"
  2. sdlProgressBar::sdlProgressBar(int x, int y, int width, int height, sdlCoreWidget * pWnd) :sdlCoreWidget(x, y, width, height, pWnd){
  3. m_pStatusProvider = NULL;
  4. m_pLabel = NULL;
  5. };
  6. sdlProgressBar::~sdlProgressBar(){
  7. };
  8. void sdlProgressBar::draw(SDL_Renderer *pRenderer){
  9. m_mStatusProtecter.lock();
  10. if( m_pStatusProvider ){
  11. SDL_Rect r;
  12. char tBuff[256];
  13. uint8_t bStatus;
  14. bStatus = m_pStatusProvider->getStatus(tBuff);
  15. if (tBuff[0]!=(char)0)setText(tBuff);
  16. if (bStatus > 0){
  17. SDL_SetRenderDrawColor(pRenderer, m_sColorStyle.activeSelector.r, m_sColorStyle.activeSelector.g, m_sColorStyle.activeSelector.b, m_sColorStyle.activeSelector.a);
  18. if (bStatus < 100){
  19. r.x = 1; r.y = 1; r.w = ( m_sRect.w * bStatus ) / 100 -2; r.h = m_sRect.h - 2;
  20. } else {
  21. r.x = 1; r.y = 1; r.w = m_sRect.w - 2; r.h = m_sRect.h - 2;
  22. };
  23. //SDL_RenderDrawRect(pRenderer, &r);
  24. SDL_RenderFillRect(pRenderer, &r);
  25. if (m_pLabel != NULL) m_pLabel->render(pRenderer);
  26. //SDL_SetRenderDrawColor(pRenderer, m_sColorStyle.borderBODY.r, m_sColorStyle.borderBODY.g, m_sColorStyle.borderBODY.b, m_sColorStyle.borderBODY.a);
  27. //r.x = 0; r.y = 0; r.w = m_sRect.w; r.h = m_sRect.h;
  28. //SDL_RenderDrawRect(pRenderer, &r);
  29. };
  30. };
  31. m_mStatusProtecter.unlock();
  32. };
  33. void sdlProgressBar::dispatch(SDL_Event *pEvt){
  34. if (pEvt->type == SDL_MOUSEMOTION || pEvt->type == SDL_MOUSEBUTTONDOWN || pEvt->type == SDL_MOUSEBUTTONUP){
  35. //Get mouse position
  36. int x, y;
  37. SDL_GetMouseState(&x, &y);
  38. };
  39. };
  40. void sdlProgressBar::attachStatusProvider(basicStatusProvider *tPtr){
  41. m_mStatusProtecter.lock();
  42. m_pStatusProvider = tPtr;
  43. m_mStatusProtecter.unlock();
  44. };
  45. void sdlProgressBar::setText(CSTR tPtr){
  46. if (m_pLabel == NULL){
  47. m_pLabel = new sdlLabel( 1, 1, m_sRect.w - 2, m_sRect.h - 2, this, 12 );
  48. };
  49. if (m_pLabel != NULL){
  50. m_pLabel->setText(tPtr);
  51. };
  52. };