Code refactored into different files.
This commit is contained in:
parent
26c50fe1d0
commit
2429229a95
8 changed files with 217 additions and 46 deletions
36
src/texture.cpp
Normal file
36
src/texture.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "texture.hpp"
|
||||
#include "sdlerror.hpp"
|
||||
#include "sdlmain.hpp"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace cloonel {
|
||||
Texture::Texture (const std::string& parPath, SDLMain* parMain, bool parLoadNow) :
|
||||
m_path(parPath),
|
||||
m_texture(nullptr),
|
||||
m_sdlmain(parMain)
|
||||
{
|
||||
if (parLoadNow)
|
||||
Reload();
|
||||
}
|
||||
|
||||
Texture::~Texture() noexcept {
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void Texture::Destroy() noexcept {
|
||||
if (m_texture) {
|
||||
SDL_DestroyTexture(m_texture);
|
||||
m_texture = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::Reload() {
|
||||
Destroy();
|
||||
SDL_Surface* surf = SDL_LoadBMP(m_path.c_str());
|
||||
if (nullptr == surf)
|
||||
throw std::runtime_error(GetFullErrorMessage(__PRETTY_FUNCTION__, m_path));
|
||||
|
||||
m_texture = SDL_CreateTextureFromSurface(m_sdlmain->GetRenderer(), surf);
|
||||
}
|
||||
} //namespace cloonel
|
Loading…
Add table
Add a link
Reference in a new issue