Added protected OnEvent functions for inheritance
This commit is contained in:
parent
0611493afd
commit
10d19f7f58
6 changed files with 98 additions and 18 deletions
|
@ -1,3 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "graphics/RenderWindow.hpp"
|
||||
#include "graphics/RenderWindow.hpp"
|
||||
|
||||
#include "exceptions/Exceptions.hpp"
|
|
@ -8,5 +8,7 @@
|
|||
|
||||
#include "ObjectCreationException.hpp"
|
||||
|
||||
#define THROW_IF_NOT( condition, exception ) ( condition ? throw exception : false )
|
||||
#define THROW_IF( condition, exception ) ( condition ? false : throw exception )
|
||||
#define IS_NULLPTR( x ) (x == nullptr)
|
||||
|
||||
#define THROW_IF( condition, exception ) ( condition ? throw exception : false)
|
||||
#define THROW_IF_NOT( condition, exception ) ( THROW_IF(!condition, exception) )
|
|
@ -1,8 +1,6 @@
|
|||
#include "RenderWindow.hpp"
|
||||
#include "../exceptions/Exceptions.hpp"
|
||||
|
||||
#define IS_NULLPTR( x ) (x == nullptr)
|
||||
|
||||
namespace sdlu
|
||||
{
|
||||
RenderWindow::RenderWindow()
|
||||
|
@ -15,16 +13,14 @@ namespace sdlu
|
|||
Create(dimension, title, windowFlags, rendererFlags);
|
||||
}
|
||||
|
||||
RenderWindow::~RenderWindow()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -35,5 +31,19 @@ namespace sdlu
|
|||
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, rendererFlags);
|
||||
THROW_IF(IS_NULLPTR(m_pRenderer),
|
||||
ObjectCreationException("Failed to create SDL_Renderer."));
|
||||
|
||||
OnCreate();
|
||||
}
|
||||
|
||||
void RenderWindow::Close()
|
||||
{
|
||||
SDL_DestroyWindow(m_pWindow);
|
||||
|
||||
OnClose();
|
||||
}
|
||||
|
||||
bool RenderWindow::IsOpen()
|
||||
{
|
||||
return !IS_NULLPTR(m_pWindow);
|
||||
}
|
||||
}
|
|
@ -37,6 +37,8 @@ namespace sdlu
|
|||
RenderWindow(const RenderWindow& other) = delete;
|
||||
RenderWindow(const RenderWindow&& other) = delete;
|
||||
|
||||
virtual ~RenderWindow();
|
||||
|
||||
/**
|
||||
* @brief Creates the window and renderer.
|
||||
*
|
||||
|
@ -50,8 +52,40 @@ namespace sdlu
|
|||
void Create(Vector2u dimension, const std::string& title,
|
||||
Uint32 windowFlags, Uint32 rendererFlags);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Destroys the window and renderer.
|
||||
*/
|
||||
void Close();
|
||||
|
||||
/**
|
||||
* @brief Wether or not the window object is created
|
||||
*
|
||||
* @return True if the window is open, False if not
|
||||
*/
|
||||
bool IsOpen();
|
||||
|
||||
protected:
|
||||
SDL_Window* m_pWindow; ///< A pointer to the window object
|
||||
SDL_Renderer* m_pRenderer; ///< A pointer to the renderer object
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief This function is called after Create() finishes
|
||||
*/
|
||||
virtual void OnCreate();
|
||||
|
||||
/**
|
||||
* @brief This function is called after a SDL_WINDOWEVENT_RESIZED is polled.
|
||||
* (PollEvent() must be called for this to work)
|
||||
*
|
||||
* @return True if the resize event should be popped from the event queue before
|
||||
returning the polled event to the user
|
||||
*/
|
||||
virtual bool OnResize();
|
||||
|
||||
/**
|
||||
* @brief This function is called after Close() finishes.
|
||||
*/
|
||||
virtual void OnClose();
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue