LoadingState.cxx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "LoadingState.hxx"
  2. #include "AssetManager.hxx"
  3. void LoadingState::update(GameStateManager& gsm, std::chrono::milliseconds const delta_time)
  4. {
  5. (void) gsm;
  6. (void) delta_time;
  7. }
  8. void LoadingState::render(SDLRenderer& renderer)
  9. {
  10. SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  11. SDL_RenderClear(renderer);
  12. static int const BAR_MARGIN = 30;
  13. static int const BAR_HEIGHT = 50;
  14. int w, h;
  15. SDL_GetRendererOutputSize(renderer, &w, &h);
  16. float progress = AssetManager::instance().get_progress();
  17. SDL_Rect const outer_rect = {
  18. .x=BAR_MARGIN,
  19. .y=h-BAR_MARGIN-BAR_HEIGHT,
  20. .w=w-(BAR_MARGIN*2),
  21. .h=BAR_HEIGHT
  22. };
  23. SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
  24. SDL_RenderFillRect(renderer, &outer_rect);
  25. SDL_Rect const inner_rect = {
  26. .x=BAR_MARGIN+2,
  27. .y=h-BAR_MARGIN-BAR_HEIGHT+2,
  28. .w=w-(BAR_MARGIN*2)-4,
  29. .h=BAR_HEIGHT-4
  30. };
  31. SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  32. SDL_RenderFillRect(renderer, &inner_rect);
  33. SDL_Rect const progress_rect = {
  34. .x=BAR_MARGIN+4,
  35. .y=h-BAR_MARGIN-BAR_HEIGHT+4,
  36. .w=static_cast<int>(std::lerp(0, w-(BAR_MARGIN*2)-8, progress)),
  37. .h=BAR_HEIGHT-8
  38. };
  39. SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
  40. SDL_RenderFillRect(renderer, &progress_rect);
  41. SDL_RenderPresent(renderer);
  42. }