SDLWindow.cxx 805 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "SDLWindow.hxx"
  2. #include <algorithm>
  3. SDLWindow::SDLWindow(std::string_view title, int x, int y, int w, int h, std::uint32_t flags)
  4. {
  5. SDL::require(SDL_INIT_VIDEO);
  6. window_ = SDL_CreateWindow(title.data(), x, y, w, h, flags);
  7. if (window_==nullptr) {
  8. throw SDLError("Failed to create window");
  9. }
  10. SDL_Log("Created window successfully.");
  11. }
  12. SDLWindow::~SDLWindow()
  13. {
  14. destroy();
  15. }
  16. void SDLWindow::destroy() noexcept
  17. {
  18. if (window_!=nullptr) {
  19. SDL_DestroyWindow(window_);
  20. SDL_Log("Destroyed window successfully.");
  21. window_ = nullptr;
  22. }
  23. }
  24. SDLWindow::SDLWindow(SDLWindow&& src) noexcept
  25. :window_{src.window_}
  26. {
  27. src.window_ = nullptr;
  28. }
  29. SDLWindow& SDLWindow::operator=(SDLWindow&& src) noexcept
  30. {
  31. destroy();
  32. std::swap(window_, src.window_);
  33. return *this;
  34. }