Skip to content
Snippets Groups Projects
Select Git revision
  • a4247b20af4c5a8f3bf7f027a0032ebb3ffe5407
  • develop default protected
  • 5.5
  • 5.1
  • master protected
  • deprecated/4-22
6 results

UniLogBlueprintFunctionLibrary.cpp

Blame
  • Window.cpp 880 B
    /**
     * Window.cpp
     *
     * @author David Maul
     */
    
    #include "Window.hpp"
    
    #include <stdexcept>
    
    namespace advanced_wars
    {
    
    Window::Window(std::string title, int w, int h)
    {
        /// Init width and height
        m_width = w;
        m_height = h;
    
        // Generate SDL main window
        m_window = SDL_CreateWindow(
            title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, m_width, m_height,
            SDL_WINDOW_SHOWN);
    
        if (m_window == nullptr)
        {
            throw std::runtime_error(
                "SDL window could not be generated: " + std::string(SDL_GetError()));
        }
    }
    
    int Window::w()
    {
        return m_width;
    }
    
    int Window::h()
    {
        return m_height;
    }
    
    SDL_Window* Window::sdlWindow()
    {
        return m_window;
    }
    
    Window::~Window()
    {
        if (m_window != nullptr)
        {
            SDL_DestroyWindow(m_window);
            m_window = nullptr;
        }
    }
    
    } // namespace advanced_wars