Skip to content
Snippets Groups Projects
Select Git revision
  • a0eb463229794098d4e1ec6cfe3537b320025b56
  • main default protected
  • leveleditor
  • david-author
  • clang-tidy-cleanup
  • architecture-refactoring
  • cleanUpMenus
  • doxygen-cleanup
  • project-structure-refactoring
  • interpolation
  • buildingFeatures
  • win_end_screen
  • helpMenu
  • leveleditor-placement
  • text-rendering
  • updated_unit_contextmenu
  • level-from-commandline
  • unit_contextmenu
  • player
  • engine-scaling
  • clang-tidy
21 results

Window.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