Fixed assertion failures
This commit is contained in:
parent
a57f81e0b3
commit
b9e8fca5cc
|
@ -5,11 +5,15 @@ namespace sdlu
|
||||||
{
|
{
|
||||||
RenderWindow::RenderWindow()
|
RenderWindow::RenderWindow()
|
||||||
{
|
{
|
||||||
|
m_pWindow = nullptr;
|
||||||
|
m_pRenderer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderWindow::RenderWindow(Vector2u dimension, const std::string& title,
|
RenderWindow::RenderWindow(Vector2u dimension, const std::string& title,
|
||||||
Uint32 windowFlags, Uint32 rendererFlags)
|
Uint32 windowFlags, Uint32 rendererFlags)
|
||||||
{
|
{
|
||||||
|
m_pWindow = nullptr;
|
||||||
|
m_pRenderer = nullptr;
|
||||||
Create(dimension, title, windowFlags, rendererFlags);
|
Create(dimension, title, windowFlags, rendererFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +25,9 @@ namespace sdlu
|
||||||
void RenderWindow::Create(Vector2u dimension, const std::string& title,
|
void RenderWindow::Create(Vector2u dimension, const std::string& title,
|
||||||
Uint32 windowFlags, Uint32 rendererFlags)
|
Uint32 windowFlags, Uint32 rendererFlags)
|
||||||
{
|
{
|
||||||
|
// Don't create a window when it already exists
|
||||||
|
if (!IS_NULLPTR(m_pWindow)) return;
|
||||||
|
|
||||||
m_pWindow = SDL_CreateWindow(title.c_str(),
|
m_pWindow = SDL_CreateWindow(title.c_str(),
|
||||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||||
dimension.x, dimension.y,
|
dimension.x, dimension.y,
|
||||||
|
@ -37,14 +44,21 @@ namespace sdlu
|
||||||
|
|
||||||
void RenderWindow::Close()
|
void RenderWindow::Close()
|
||||||
{
|
{
|
||||||
|
// Don't destroy a window that doesn't exist
|
||||||
|
if (IS_NULLPTR(m_pWindow)) return;
|
||||||
|
|
||||||
|
SDL_DestroyRenderer(m_pRenderer);
|
||||||
|
m_pRenderer = nullptr;
|
||||||
|
|
||||||
SDL_DestroyWindow(m_pWindow);
|
SDL_DestroyWindow(m_pWindow);
|
||||||
|
m_pWindow = nullptr;
|
||||||
|
|
||||||
OnClose();
|
OnClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderWindow::IsOpen()
|
bool RenderWindow::IsOpen()
|
||||||
{
|
{
|
||||||
return !IS_NULLPTR(m_pWindow);
|
return (!SDL_GetWindowID(m_pWindow) ? false : true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderWindow::PollEvent(SDL_Event* event)
|
bool RenderWindow::PollEvent(SDL_Event* event)
|
||||||
|
@ -89,8 +103,8 @@ namespace sdlu
|
||||||
|
|
||||||
Vector2u RenderWindow::GetSize()
|
Vector2u RenderWindow::GetSize()
|
||||||
{
|
{
|
||||||
unsigned int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
SDL_GetWindowSize(m_pWindow, x, y);
|
SDL_GetWindowSize(m_pWindow, &x, &y);
|
||||||
return Vector2u(x, y);
|
return Vector2u(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,4 +117,14 @@ namespace sdlu
|
||||||
{
|
{
|
||||||
SDL_SetWindowSize(m_pWindow, width, height);
|
SDL_SetWindowSize(m_pWindow, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string RenderWindow::GetTitle()
|
||||||
|
{
|
||||||
|
return SDL_GetWindowTitle(m_pWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderWindow::SetTitle(std::string title)
|
||||||
|
{
|
||||||
|
SDL_SetWindowTitle(m_pWindow, title.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -126,6 +126,21 @@ namespace sdlu
|
||||||
*/
|
*/
|
||||||
void SetSize(unsigned int width, unsigned int height);
|
void SetSize(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the current window title
|
||||||
|
*
|
||||||
|
* @return The title of the widnow
|
||||||
|
*/
|
||||||
|
std::string GetTitle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets a new window title
|
||||||
|
*
|
||||||
|
* @param[in] title The new window title
|
||||||
|
*/
|
||||||
|
void SetTitle(std::string title);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SDL_Window* m_pWindow; ///< A pointer to the window object
|
SDL_Window* m_pWindow; ///< A pointer to the window object
|
||||||
SDL_Renderer* m_pRenderer; ///< A pointer to the renderer object
|
SDL_Renderer* m_pRenderer; ///< A pointer to the renderer object
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
sdlu::Vector2f vecA(.4f, -2.3f);
|
sdlu::Vector2f vecA(.4f, -2.3f);
|
||||||
sdlu::Vector2f vecB(-8.9f, 0.003f);
|
sdlu::Vector2f vecB(-8.9f, 0.003f);
|
||||||
sdlu::Vector2f vec = vecA + vecB;
|
sdlu::Vector2f vec = vecA + vecB;
|
||||||
|
@ -17,7 +19,14 @@ int main(int argc, char** argv)
|
||||||
while (window.WaitEvent(&event))
|
while (window.WaitEvent(&event))
|
||||||
{
|
{
|
||||||
std::cout << event.type << std::endl;
|
std::cout << event.type << std::endl;
|
||||||
|
if (event.window.event == SDL_WINDOWEVENT_CLOSE)
|
||||||
|
{
|
||||||
|
window.Close();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in a new issue