BsSplashScreen.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "BsSplashScreen.h"
  2. #include "BsBuiltinResources.h"
  3. #include "BsTimer.h"
  4. #if BS_PLATFORM == BS_PLATFORM_WIN32
  5. #include "Win32/BsWin32Window.h"
  6. namespace BansheeEngine
  7. {
  8. struct SplashScreen::Pimpl
  9. {
  10. Win32Window* window = nullptr;
  11. Timer timer;
  12. };
  13. // Note: Never freed, but that's fine
  14. SplashScreen::Pimpl* SplashScreen::m = bs_new<Pimpl>();
  15. const UINT32 SplashScreen::SPLASH_SCREEN_DURATION_MS = 2000;
  16. void SplashScreen::show()
  17. {
  18. if (m->window != nullptr)
  19. return;
  20. WINDOW_DESC windowDesc;
  21. windowDesc.border = WindowBorder::None;
  22. windowDesc.width = 600;
  23. windowDesc.height = 662;
  24. windowDesc.left = -1;
  25. windowDesc.top = -1;
  26. windowDesc.title = "Banshee Splash";
  27. windowDesc.toolWindow = true;
  28. windowDesc.alphaBlending = true;
  29. PixelDataPtr splashPixelData = BuiltinResources::getSplashScreen();
  30. if (splashPixelData == nullptr)
  31. return;
  32. windowDesc.background = splashPixelData;
  33. m->window = bs_new<Win32Window>(windowDesc);
  34. m->timer.reset();
  35. }
  36. void SplashScreen::hide()
  37. {
  38. if (m->window == nullptr)
  39. return;
  40. UINT32 currentTime = m->timer.getMilliseconds();
  41. if (currentTime < SPLASH_SCREEN_DURATION_MS)
  42. BS_THREAD_SLEEP(SPLASH_SCREEN_DURATION_MS - currentTime);
  43. bs_delete(m->window);
  44. m->window = nullptr;
  45. }
  46. }
  47. #else
  48. static_assert("Missing SplashScreen implementation.");
  49. #endif