Added creation routine
This commit is contained in:
parent
bb14fa9423
commit
740ddc2ca6
|
@ -6,6 +6,7 @@ add_library(${PNAME}
|
||||||
|
|
||||||
target_include_directories(${PNAME} PRIVATE
|
target_include_directories(${PNAME} PRIVATE
|
||||||
${PROJECT_SOURCE_DIR}/3rdparty/SDL/include
|
${PROJECT_SOURCE_DIR}/3rdparty/SDL/include
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PNAME} PRIVATE
|
target_link_libraries(${PNAME} PRIVATE
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "structures/Vector2.hpp"
|
#include "graphics/RenderWindow.hpp"
|
|
@ -0,0 +1,44 @@
|
||||||
|
#include "RenderWindow.hpp"
|
||||||
|
|
||||||
|
#define IS_NULLPTR( x ) (x == nullptr)
|
||||||
|
|
||||||
|
namespace sdlu
|
||||||
|
{
|
||||||
|
RenderWindow::RenderWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderWindow::RenderWindow(Vector2u dimension, const std::string& title,
|
||||||
|
Uint32 windowFlags, Uint32 rendererFlags)
|
||||||
|
{
|
||||||
|
Create(dimension, title, windowFlags, rendererFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderWindow::Create(Vector2u dimension, const std::string& title,
|
||||||
|
Uint32 windowFlags, Uint32 rendererFlags)
|
||||||
|
{
|
||||||
|
// Leave the function if the window or render already exist
|
||||||
|
if (!IS_NULLPTR(m_pWindow) ||
|
||||||
|
!IS_NULLPTR(m_pRenderer))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pWindow = SDL_CreateWindow(title.c_str(),
|
||||||
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||||
|
dimension.x, dimension.y,
|
||||||
|
windowFlags);
|
||||||
|
if (IS_NULLPTR(m_pWindow))
|
||||||
|
{
|
||||||
|
// TODO: Implement exception
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, rendererFlags);
|
||||||
|
if (IS_NULLPTR(m_pRenderer))
|
||||||
|
{
|
||||||
|
// TODO: Implement exception
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,52 @@
|
||||||
#pragma once
|
/**
|
||||||
|
* @file RenderWindow.hpp
|
||||||
|
* @brief A wrapper around SDL_Window and SDL_Renderer
|
||||||
|
* @author Lauchmelder23
|
||||||
|
* @date 16.05.2020
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
#include "../structures/Vector2.hpp"
|
||||||
|
|
||||||
|
namespace sdlu
|
||||||
|
{
|
||||||
|
class RenderWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Default Constructor. No window or renderer is created.
|
||||||
|
*/
|
||||||
|
RenderWindow();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates a window and renderer with the given parameters
|
||||||
|
*
|
||||||
|
* @param dimension A vector containing the width and height
|
||||||
|
* @param title The title of the create window
|
||||||
|
*/
|
||||||
|
RenderWindow(Vector2u dimension, const std::string& title,
|
||||||
|
Uint32 windowFlags, Uint32 rendererFlags);
|
||||||
|
|
||||||
|
RenderWindow(const RenderWindow& other) = delete;
|
||||||
|
RenderWindow(const RenderWindow&& other) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates the window and renderer.
|
||||||
|
*
|
||||||
|
* This function creates the SDL_Window and SDL_Renderer objects. If
|
||||||
|
* they were already created the function does nothing and returns.
|
||||||
|
* If it fails to create either, an ObjectCreationException is thrown.
|
||||||
|
*
|
||||||
|
* @param dimension A vector containing the width and height
|
||||||
|
* @param title The title of the create window
|
||||||
|
*/
|
||||||
|
void Create(Vector2u dimension, const std::string& title,
|
||||||
|
Uint32 windowFlags, Uint32 rendererFlags);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SDL_Window* m_pWindow;
|
||||||
|
SDL_Renderer* m_pRenderer;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue