BsSplashScreen.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Utility/BsSplashScreen.h"
  4. #include "Utility/BsBuiltinEditorResources.h"
  5. #include "Utility/BsTimer.h"
  6. #include "CoreThread/BsCoreThread.h"
  7. #if BS_PLATFORM == BS_PLATFORM_WIN32
  8. #include "Private/Win32/BsWin32Platform.h"
  9. #include "Private/Win32/BsWin32Window.h"
  10. namespace bs
  11. {
  12. struct SplashScreen::Pimpl
  13. {
  14. Win32Window* window = nullptr;
  15. Timer timer;
  16. };
  17. // Note: Never freed, but that's fine
  18. SplashScreen::Pimpl* SplashScreen::m = bs_new<Pimpl>();
  19. void SplashScreen::show()
  20. {
  21. gCoreThread().queueCommand(&SplashScreen::create, CTQF_InternalQueue);
  22. }
  23. void SplashScreen::hide()
  24. {
  25. gCoreThread().queueCommand(&SplashScreen::destroy, CTQF_InternalQueue);
  26. }
  27. void SplashScreen::create()
  28. {
  29. if (m->window != nullptr)
  30. return;
  31. WINDOW_DESC windowDesc;
  32. windowDesc.allowResize = false;
  33. windowDesc.showBorder = false;
  34. windowDesc.showTitleBar = false;
  35. windowDesc.width = 543;
  36. windowDesc.height = 680;
  37. windowDesc.left = -1;
  38. windowDesc.top = -1;
  39. windowDesc.title = "Banshee Splash";
  40. windowDesc.toolWindow = true;
  41. windowDesc.alphaBlending = true;
  42. windowDesc.wndProc = Win32Platform::_win32WndProc;
  43. SPtr<PixelData> splashPixelData = BuiltinEditorResources::getSplashScreen();
  44. if (splashPixelData == nullptr)
  45. return;
  46. Vector<Color> pixels = splashPixelData->getColors();
  47. windowDesc.backgroundPixels = (Color*)pixels.data();
  48. windowDesc.backgroundWidth = splashPixelData->getWidth();
  49. windowDesc.backgroundHeight = splashPixelData->getHeight();
  50. m->window = bs_new<Win32Window>(windowDesc);
  51. m->timer.reset();
  52. }
  53. void SplashScreen::destroy()
  54. {
  55. if (m->window == nullptr)
  56. return;
  57. bs_delete(m->window);
  58. m->window = nullptr;
  59. }
  60. }
  61. #elif BS_PLATFORM == BS_PLATFORM_LINUX
  62. #include "Private/Linux/BsLinuxPlatform.h"
  63. #include "Private/Linux/BsLinuxWindow.h"
  64. #include "X11/Xutil.h"
  65. namespace bs
  66. {
  67. struct SplashScreen::Pimpl
  68. {
  69. LinuxWindow* window = nullptr;
  70. Timer timer;
  71. };
  72. // Note: Never freed, but that's fine
  73. SplashScreen::Pimpl* SplashScreen::m = bs_new<Pimpl>();
  74. void SplashScreen::show()
  75. {
  76. gCoreThread().queueCommand(&SplashScreen::create, CTQF_InternalQueue);
  77. }
  78. void SplashScreen::hide()
  79. {
  80. gCoreThread().queueCommand(&SplashScreen::destroy, CTQF_InternalQueue);
  81. }
  82. void SplashScreen::create()
  83. {
  84. if (m->window != nullptr)
  85. return;
  86. WINDOW_DESC windowDesc;
  87. windowDesc.width = 543;
  88. windowDesc.height = 680;
  89. windowDesc.x = -1;
  90. windowDesc.y = -1;
  91. windowDesc.title = "Banshee Splash";
  92. windowDesc.showDecorations = false;
  93. windowDesc.allowResize = false;
  94. windowDesc.hidden = false;
  95. SPtr<PixelData> splashPixelData = BuiltinEditorResources::getSplashScreen();
  96. if (splashPixelData == nullptr)
  97. return;
  98. windowDesc.background = splashPixelData;
  99. LinuxPlatform::lockX();
  100. ::Display* display = LinuxPlatform::getXDisplay();
  101. windowDesc.screen = (UINT32)XDefaultScreen(display);
  102. windowDesc.visualInfo.depth = XDefaultDepth(LinuxPlatform::getXDisplay(), windowDesc.screen);
  103. windowDesc.visualInfo.visual = XDefaultVisual(LinuxPlatform::getXDisplay(), windowDesc.screen);
  104. // Get a RGBA visual
  105. XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &windowDesc.visualInfo);
  106. m->window = bs_new<LinuxWindow>(windowDesc);
  107. LinuxPlatform::unlockX();
  108. m->timer.reset();
  109. }
  110. void SplashScreen::destroy()
  111. {
  112. if (m->window == nullptr)
  113. return;
  114. LinuxPlatform::lockX();
  115. bs_delete(m->window);
  116. LinuxPlatform::unlockX();
  117. m->window = nullptr;
  118. }
  119. }
  120. #else
  121. #include "Private/MacOS/BsMacOSWindow.h"
  122. namespace bs
  123. {
  124. struct SplashScreen::Pimpl
  125. {
  126. CocoaWindow* window = nullptr;
  127. Timer timer;
  128. };
  129. // Note: Never freed, but that's fine
  130. SplashScreen::Pimpl* SplashScreen::m = bs_new<Pimpl>();
  131. void SplashScreen::show()
  132. {
  133. SplashScreen::create();
  134. }
  135. void SplashScreen::hide()
  136. {
  137. SplashScreen::destroy();
  138. }
  139. void SplashScreen::create()
  140. {
  141. if (m->window != nullptr)
  142. return;
  143. WINDOW_DESC windowDesc;
  144. windowDesc.width = 543;
  145. windowDesc.height = 680;
  146. windowDesc.x = -1;
  147. windowDesc.y = -1;
  148. windowDesc.title = "Banshee Splash";
  149. windowDesc.showDecorations = false;
  150. windowDesc.allowResize = false;
  151. windowDesc.floating = true;
  152. SPtr<PixelData> splashPixelData = BuiltinEditorResources::getSplashScreen();
  153. if (splashPixelData == nullptr)
  154. return;
  155. windowDesc.background = splashPixelData;
  156. m->window = bs_new<CocoaWindow>(windowDesc);
  157. m->timer.reset();
  158. }
  159. void SplashScreen::destroy()
  160. {
  161. if (m->window == nullptr)
  162. return;
  163. bs_delete(m->window);
  164. m->window = nullptr;
  165. }
  166. }
  167. #endif