| 1 | #include "ZydecoCommon.hpp" |
| 2 | #include "CommonSDL2.hpp" |
| 3 | #include "WindowSDL2.hpp" |
| 4 |
|
| 5 |
|
| 6 | static Logger LOGGER("WINDOW"); |
| 7 |
|
| 8 |
|
| 9 | WindowSDL2::WindowSDL2(std::string title, uint64_t window_config_flags): |
| 10 | m_windowTitle(title) |
| 11 | { |
| 12 | LOGGER.Log(Logger::DEBUG, "WindowSDL2 creating ('{}')", title); |
| 13 |
|
| 14 | SDL_CallPointerReturningFunction(SDL_CreateWindow, m_pSdlWindow, |
| 15 | m_windowTitle.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, window_config_flags); |
| 16 |
|
| 17 | SDL_CallPointerReturningFunction(SDL_CreateRenderer, m_pSdlRenderer, |
| 18 | m_pSdlWindow, -1, SDL_RENDERER_ACCELERATED); |
| 19 | |
| 20 | SDL_CallPointerReturningFunction(SDL_GL_CreateContext, m_glContext, m_pSdlWindow); |
| 21 |
|
| 22 | SDL_ShowWindow(m_pSdlWindow); |
| 23 |
|
| 24 | LOGGER.Log(Logger::DEBUG, "WindowSDL2 created", title); |
| 25 | } |
| 26 |
|
| 27 | WindowSDL2::~WindowSDL2() |
| 28 | { |
| 29 | LOGGER.Log(Logger::DEBUG, "Destroying window '{}'", m_windowTitle); |
| 30 | SDL_GL_DeleteContext(m_glContext); |
| 31 | SDL_DestroyRenderer(m_pSdlRenderer); |
| 32 | SDL_DestroyWindow(m_pSdlWindow); |
| 33 | } |
| 34 |
|
| 35 | bool WindowSDL2::Update(uint64_t time_since_last_update_us) |
| 36 | { |
| 37 | LOGGER.Log(Logger::TRACE, "Refreshing SDL window {}", time_since_last_update_us); |
| 38 |
|
| 39 | // Update SDL renderer display |
| 40 | SDL_CallErrorReturningFunction(SDL_RenderClear, m_pSdlRenderer); |
| 41 |
|
| 42 | // Update OpenGL context display |
| 43 | SDL_GL_SwapWindow(m_pSdlWindow); |
| 44 |
|
| 45 | SDL_RenderPresent(m_pSdlRenderer); |
| 46 |
|
| 47 | return false; |
| 48 | } |
| 49 |
|
| 50 | void WindowSDL2::SetTitle(std::string new_title) |
| 51 | { |
| 52 | m_windowTitle = new_title; |
| 53 | SDL_SetWindowTitle(m_pSdlWindow, m_windowTitle.c_str()); |
| 54 | } |
| 55 |
|
| 56 | void WindowSDL2::SetFullscreen(bool is_fullscreen) |
| 57 | { |
| 58 | SDL_CallErrorReturningFunction(SDL_SetWindowFullscreen, m_pSdlWindow, is_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); |
| 59 | } |
| 60 |
|
| 61 | void WindowSDL2::SetSize(uint64_t new_width, uint64_t new_height) |
| 62 | { |
| 63 | SDL_SetWindowSize(m_pSdlWindow, new_width, new_height); |
| 64 | } |
| 65 |
|
| 66 | void WindowSDL2::SetPosition(uint64_t new_x, uint64_t new_y) |
| 67 | { |
| 68 | SDL_SetWindowPosition(m_pSdlWindow, new_x, new_y); |
| 69 | } |
| 70 |
|