Skip to content
Snippets Groups Projects
Select Git revision
  • 012f25c2b7904a7be9f8d492286715aaf5623389
  • master default
  • 1.1
  • 1.0
4 results

tokenize.h

Blame
  • SDLApplication.hpp 1.66 KiB
    #pragma once
    #include <SDL2/SDL.h>
    #include <stdexcept>
    #include <string>
    
    /**
     * @brief Base Class for Game managing SDL State.
     */
    class SDLApplication
    {
      public:
        /**
         * @brief Create a new Application with a Window and Renderer.
         * @param title Title shown at top of Window.
         * @param width Width of the Window.
         * @param height Height of the Window.
         * @throw std::runtime_error When Initialization of SDL2 fails.
         */
        SDLApplication(const std::string &title, int width, int height);
        SDLApplication(const SDLApplication &) = delete;
        SDLApplication &operator=(const SDLApplication &) = delete;
        virtual ~SDLApplication();
    
        /**
         * @brief Handle Events produced.
         * @param event The event to handle.
         */
        virtual void handleEvent(SDL_Event &event) = 0;
        /**
         * @brief Update state of the underlying Renderer for drawing.
         */
        virtual void render() = 0;
        /**
         * @brief Run the application until a SDL_QUIT Event is produced.
         */
        virtual void run();
    
      private:
        /**
         * @brief Title of the Window.
         */
        std::string m_Title;
        /**
         * @brief Current Width of the Window.
         */
        int m_Width;
        /**
         * @brief Current Height of the Window.
         */
        int m_Height;
        /**
         * @brief Wether the Application is running or received a Quit event.
         */
        bool m_Running;
        /**
         * @brief Helper to ensure that SDL_Quit is only called once.
         */
        bool m_SDLInitialized;
        /**
         * @brief SDL Window to use as drawing Target.
         */
        SDL_Window *m_Window;
        /**
         * @brief SDL Renderer associated with the Window.
         */
        SDL_Renderer *m_Renderer;
    };