Skip to content
Hapax edited this page Jul 5, 2016 · 2 revisions

Slide Splash

Introduction

Slide Splash is designed to simplify the opening section of a game/application. It takes control of a window and animates a slideshow within in; the window's events are processed by Slide Splash.

The main ("Standard") Slide Splash animates the slideshow in the window you pass to it while taking over control over the duration. The window ("Window") addition to Slide Splash is a wrapper over a window and Slide Splash that creates the window you choose and displays the slideshow in that window. This allows a temporary, dedicated window for the slideshow (similar to some applications' splash screens). This window is close when the slideshow is finished. However, it can be re-opened by starting the slideshow again (as long as the Slide Splash object exists).

Inputs

Some input options can be set in Slide Splash:

  • skip key - pressing this key skips the entire slideshow and returns true,
  • close key - pressing this key skips the entire slideshow and returns false,
  • slide key - pressing this key skips the slide,
  • slide mouse button - pressing a mouse button skips the slide. Upon completion of the slideshow, Slide Splash returns true unless a close was requested (via the chosen key or the window was closed).
    Each slide has its own slide key and slide mouse button. This makes it possible to only skip certain slides and also make it possible to only skip a particular slide using a specific key, for example.

A key is an sf::Keyboard::Key. The key can be any of the values available. The value "Unknown" is used in Slide Splash to represent "no key", which indicates that a key cannot be used for that task. The value "KeyCount" is used in Slide Splash to represent "any key", which indicates that any key can be used for that task. Any other value indicates that only that key alone can be used for that task.

Standard

Declaration

SlideSplash slideSplash(window)
creates a slideSplash that will use the provided sf::RenderWindow for the slideshow. The window must be provided.

Slide

A Slide struct type is used in Slide Splash (within the SlideSplash class) to represent each slide in the slideshow.

Members:

  • texture
    sf::Texture - holds the image used for the slide

  • delay
    sf::Time - amount of time that the slide is shown

  • transition
    sf::Time - amount of time taken by the slide's transition (as it appears)

  • key
    sf::Keyboard::Key - key that will skip this slide

  • mouseButton
    bool - allows a mouse button to skip this slide

  • sizing
    SlideSplash::Sizing - an enum class that can be one of two values: SlideSplash::Sizing::Stretch or SlideSplash::Sizing::Zoom. If sizing is set to "stretch", the image is stretched to fit the window, ignoring and possibly distorting its aspect ratio. If sizing is set to "zoom", the image is scaled larger to fill the window, keeping its aspect ratio but possibly losing parts of the image.

Slides

The SlideSplash object has a vector of Slides available publicly. This allows you to set up your slide directly. However, to help simplifying the loading of images, SlideSplash provides methods to load them.

Methods

  • play()
    starts the slideshow. This method returns only when the slideshow has ended. The return value from this method is true unless the window was requested to be closed.

  • addImage(std::string filename)
    adds a new slide (to the end if one or more already exist) and loads the image at the filename given, which is stored in the newly created slide.

  • addImages(std::vector<std::string> filenames)
    adds a new slide for each of the filenames in the vector and loads the image at the filename, which is stored in the slide.

  • setBackgroundColor(color)
    sets the background colour of the slideshow (visible at the beginning and end of the slideshow unless the first transition is instant) to the provided sf::Color.

  • setSkipKey(key)
    allows the sf::Keyboard::Key provided to skip the entire slideshow.

  • setCloseKey(key)
    allows the sf::Keyboard::Key provided to request window closure.

Window

Since this is a wrapper for SlideSplash, it includes all of the methods available above (in Standard) as it just passes on the parameters so they will not be listed again here. For more information on those methods (addImage, addImages, setBackgroundColor, setSkipKey and setCloseKey), see above. The methods that are listed here are exclusive to the SlideSplash Window wrapper. Also, the Slide type will not be described again here.

Declaration

SlideSplashWindow slideSplashWindow(size, name, style)
creates a SlideSplashWindow, which includes a window of size, name and style matching the parameters and a SlideSplash that is used to show the slideshow on that window. size is an sf::Vector2u, name is an std::string and style is an sf::Uint32, which is used for values of sf::Style. All parameters have defaults: size is (0, 0), name is "" and style is sf::Style::None.

Methods

  • setSize(size)
    sets the size that the window will be during the slideshow to the provided sf::Vector2u.

  • setName(name)
    sets the name that the window will have during the slideshow to the provided std::string.

  • setStyle(style)
    sets the style that the window will use during the slideshow to the provided sf::Uint32. It should be values from the enum, sf::Style, which can be orred together.

  • getSlides()
    returns a reference to the vector of Slides that will be used for the slideshow. This allows direct access to the Slides. Manipulating these slides will affect the actual slides used.

Simple Example (Standard)

#include <SFML/Graphics.hpp>
#include <SlideSplash.hpp>
int main()
{
    sf::RenderWindow window(sf::VideoMode(960, 540), "Slide Splash");
    const std::vector<std::string> filenames
    {
        "images/landscape-1436382_1920.jpg",
        "images/cat-1455468_1920.jpg",
        "images/mountain-1209533_1920.jpg",
        "images/binary-1282366_1920.jpg",
        "images/piano-1396970_1920.jpg",
        "images/adler-62588_1920.jpg",
        "images/street-1209401_1920.jpg",
        "images/tiger-165039_1280.jpg",
        "images/sea-1209607_1920.jpg"
    };
    SlideSplash slideSplash(window);
    if (!slideSplash.addImages(filenames))
        return EXIT_FAILURE;
    slideSplash.play();
    return EXIT_SUCCESS;
}

Simple Example (Window)

#include <SFML/Graphics.hpp>
#include <SlideSplashWindow.hpp>
int main()
{
    const std::vector<std::string> filenames
    {
        "images/landscape-1436382_1920.jpg",
        "images/cat-1455468_1920.jpg",
        "images/mountain-1209533_1920.jpg",
        "images/binary-1282366_1920.jpg",
        "images/piano-1396970_1920.jpg",
        "images/adler-62588_1920.jpg",
        "images/street-1209401_1920.jpg",
        "images/tiger-165039_1280.jpg",
        "images/sea-1209607_1920.jpg"
    };
    SlideSplashWindow slideSplashWindow({ 960, 540 }, "Slide Splash Window", sf::Style::None);
    if (!slideSplashWindow.addImages(filenames))
        return EXIT_FAILURE;
    slideSplashWindow.play();
    return EXIT_SUCCESS;
}

Note: the images for these examples are available, along with more examples, in the examples folder, although you can use your own images.

Note

Slide Splash is published under the zlib [licence][Licence]. It requires C++11 and [SFML] version 2.

(SlideSplash v1.2)