Torque3D Documentation / _generateds / sdlSplashScreen.cpp

sdlSplashScreen.cpp

Engine/source/windowManager/sdl/sdlSplashScreen.cpp

More...

Public Variables

SDL_Surface *
SDL_Renderer *
SDL_Texture *
SDL_Window *

Detailed Description

Public Variables

SDL_Surface * gSplashImage 
SDL_Renderer * gSplashRenderer 
SDL_Texture * gSplashTexture 
SDL_Window * gSplashWindow 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "console/console.h"
 26#include "gfx/bitmap/gBitmap.h"
 27#include "SDL.h"
 28#include "windowManager/sdl/sdlWindow.h"
 29
 30static SDL_Window* gSplashWindow = nullptr;
 31static SDL_Surface* gSplashImage = nullptr;
 32static SDL_Texture* gSplashTexture = nullptr;
 33static SDL_Renderer* gSplashRenderer = nullptr;
 34
 35bool Platform::displaySplashWindow( String path )
 36{
 37   if(path.isEmpty())
 38      return false;
 39
 40   Torque::Path iconPath = Torque::Path(path);
 41
 42   if (iconPath.getExtension() == String("bmp"))
 43   {
 44      Con::errorf("Unable to use bmp format images for the splash screen. Please use a different format.");
 45      return false;
 46   }
 47
 48   Resource<GBitmap> img = GBitmap::load(iconPath);
 49   if (img != NULL)
 50   {
 51      U32 pitch;
 52      U32 width = img->getWidth();
 53      bool hasAlpha = img->getHasTransparency();
 54      U32 depth;
 55
 56      if (hasAlpha)
 57      {
 58         pitch = 4 * width;
 59         depth = 32;
 60      }
 61      else
 62      {
 63         pitch = 3 * width;
 64         depth = 24;
 65      }
 66
 67      Uint32 rmask, gmask, bmask, amask;
 68      if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
 69      {
 70         S32 shift = hasAlpha ? 8 : 0;
 71         rmask = 0xff000000 >> shift;
 72         gmask = 0x00ff0000 >> shift;
 73         bmask = 0x0000ff00 >> shift;
 74         amask = 0x000000ff >> shift;
 75      }
 76      else
 77      {
 78         rmask = 0x000000ff;
 79         gmask = 0x0000ff00;
 80         bmask = 0x00ff0000;
 81         amask = hasAlpha ? 0xff000000 : 0;
 82      }
 83
 84      gSplashImage = SDL_CreateRGBSurfaceFrom(img->getAddress(0, 0), img->getWidth(), img->getHeight(), depth, pitch, rmask, gmask, bmask, amask);
 85   }
 86
 87   //now the pop-up window
 88   if (gSplashImage)
 89   {
 90      gSplashWindow = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
 91         gSplashImage->w, gSplashImage->h, SDL_WINDOW_BORDERLESS | SDL_WINDOW_SHOWN);
 92
 93      gSplashRenderer = SDL_CreateRenderer(gSplashWindow, -1, SDL_RENDERER_ACCELERATED);
 94
 95      gSplashTexture = SDL_CreateTextureFromSurface(gSplashRenderer, gSplashImage);
 96
 97      SDL_RenderCopy(gSplashRenderer, gSplashTexture, NULL, NULL);
 98
 99      SDL_RenderPresent(gSplashRenderer);
100   }
101
102   return true;
103}
104
105bool Platform::closeSplashWindow()
106{
107   if (gSplashTexture != nullptr)
108   {
109      SDL_DestroyTexture(gSplashTexture);
110      gSplashTexture = nullptr;
111   }
112   if (gSplashImage != nullptr)
113   {
114      SDL_FreeSurface(gSplashImage);
115      gSplashImage = nullptr;
116   }
117   if (gSplashRenderer != nullptr)
118   {
119      SDL_DestroyRenderer(gSplashRenderer);
120      gSplashRenderer = nullptr;
121   }
122   if (gSplashWindow != nullptr)
123   {
124      SDL_DestroyWindow(gSplashWindow);
125      gSplashWindow = nullptr;
126   }
127
128   return true;
129}
130