Rename class

This commit is contained in:
Stepanov Igor 2025-10-10 23:19:51 +03:00
parent 3e48768e96
commit 73f64c87ec
4 changed files with 32 additions and 32 deletions

View file

@ -119,7 +119,7 @@ Mousecode input_util::mousecode_from(const std::string& name) {
return static_cast<Mousecode>(found->second); return static_cast<Mousecode>(found->second);
} }
input_sdl::input_sdl(window_sdl& window) : window(window) { input_sdl::input_sdl(SDLWindow& window) : window(window) {
input_util::initialize(); input_util::initialize();
// We should always get char stream (maybe) // We should always get char stream (maybe)
SDL_StartTextInput(window.getSdlWindow()); SDL_StartTextInput(window.getSdlWindow());

View file

@ -3,7 +3,7 @@
#include "window/input.hpp" #include "window/input.hpp"
#include "window/window.hpp" #include "window/window.hpp"
class window_sdl; class SDLWindow;
class input_sdl final : public Input { class input_sdl final : public Input {
public: public:
@ -11,7 +11,7 @@ public:
inline static constexpr short keys_buffer_size = inline static constexpr short keys_buffer_size =
mouse_keys_offset + sizeof(mousecodes_all) / sizeof(mousecodes_all[0]); mouse_keys_offset + sizeof(mousecodes_all) / sizeof(mousecodes_all[0]);
input_sdl(window_sdl& window); input_sdl(SDLWindow& window);
void pollEvents() override; void pollEvents() override;
@ -53,5 +53,5 @@ private:
std::vector<Keycode> pressedKeys; std::vector<Keycode> pressedKeys;
std::unordered_map<Keycode, util::HandlersList<>> keyCallbacks; std::unordered_map<Keycode, util::HandlersList<>> keyCallbacks;
window_sdl& window; SDLWindow& window;
}; };

View file

@ -141,7 +141,7 @@ static bool initialize_gl(int width, int height) {
return true; return true;
} }
window_sdl::window_sdl(DisplaySettings *settings, std::string title) noexcept { SDLWindow::SDLWindow(DisplaySettings *settings, std::string title) noexcept {
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
logger.error() << "failed to initialize SDL: " << SDL_GetError(); logger.error() << "failed to initialize SDL: " << SDL_GetError();
isSuccessfull = false; isSuccessfull = false;
@ -217,7 +217,7 @@ window_sdl::window_sdl(DisplaySettings *settings, std::string title) noexcept {
logger.info() << "monitor content scale: " << scale; logger.info() << "monitor content scale: " << scale;
} }
window_sdl::~window_sdl() { SDLWindow::~SDLWindow() {
if (window) { if (window) {
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
} }
@ -228,32 +228,32 @@ window_sdl::~window_sdl() {
} }
} }
void window_sdl::swapBuffers() noexcept { void SDLWindow::swapBuffers() noexcept {
if (!SDL_GL_SwapWindow(window)) [[unlikely]] { // C++20 needed if (!SDL_GL_SwapWindow(window)) [[unlikely]] { // C++20 needed
logger.error() << "Cant swap buffer: " << SDL_GetError(); logger.error() << "Cant swap buffer: " << SDL_GetError();
} }
resetScissor(); resetScissor();
} }
bool window_sdl::isMaximized() const { bool SDLWindow::isMaximized() const {
return (SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED) != 0; return (SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED) != 0;
} }
bool window_sdl::isFocused() const { bool SDLWindow::isFocused() const {
Uint32 flags = SDL_GetWindowFlags(window); Uint32 flags = SDL_GetWindowFlags(window);
return (flags & SDL_WINDOW_INPUT_FOCUS) != 0 || return (flags & SDL_WINDOW_INPUT_FOCUS) != 0 ||
(flags & SDL_WINDOW_MOUSE_FOCUS) != 0; (flags & SDL_WINDOW_MOUSE_FOCUS) != 0;
} }
bool window_sdl::isIconified() const { bool SDLWindow::isIconified() const {
return (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) != 0; return (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) != 0;
} }
bool window_sdl::isShouldClose() const { bool SDLWindow::isShouldClose() const {
return toClose; return toClose;
} }
void window_sdl::setShouldClose(bool flag) { void SDLWindow::setShouldClose(bool flag) {
toClose = flag; toClose = flag;
} }
void window_sdl::setCursor(CursorShape shape) { void SDLWindow::setCursor(CursorShape shape) {
// so it method called each frame, we always recreate cursor. // so it method called each frame, we always recreate cursor.
// Refactor it // Refactor it
if (cursor) { if (cursor) {
@ -318,7 +318,7 @@ void window_sdl::setCursor(CursorShape shape) {
SDL_SetCursor(cursor); SDL_SetCursor(cursor);
} }
} }
void window_sdl::toggleFullscreen() { void SDLWindow::toggleFullscreen() {
fullscreen = !fullscreen; fullscreen = !fullscreen;
if (!SDL_SetWindowFullscreen(window, fullscreen)) { if (!SDL_SetWindowFullscreen(window, fullscreen)) {
logger.error() << "Cant toggle fullscreen window: " << SDL_GetError(); logger.error() << "Cant toggle fullscreen window: " << SDL_GetError();
@ -328,11 +328,11 @@ void window_sdl::toggleFullscreen() {
<< SDL_GetError(); << SDL_GetError();
} }
} }
bool window_sdl::isFullscreen() const { bool SDLWindow::isFullscreen() const {
return fullscreen; return fullscreen;
} }
void window_sdl::setIcon(const ImageData *image) { void SDLWindow::setIcon(const ImageData *image) {
if (image == nullptr) { if (image == nullptr) {
logger.error() << "Image is nullptr"; logger.error() << "Image is nullptr";
return; return;
@ -361,7 +361,7 @@ void window_sdl::setIcon(const ImageData *image) {
SDL_DestroySurface(iconSurface); SDL_DestroySurface(iconSurface);
} }
void window_sdl::pushScissor(glm::vec4 area) { void SDLWindow::pushScissor(glm::vec4 area) {
if (scissorStack.empty()) { if (scissorStack.empty()) {
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
} }
@ -389,13 +389,13 @@ void window_sdl::pushScissor(glm::vec4 area) {
scissorArea = area; scissorArea = area;
} }
void window_sdl::resetScissor() { void SDLWindow::resetScissor() {
scissorArea = glm::vec4(0.0f, 0.0f, size.x, size.y); scissorArea = glm::vec4(0.0f, 0.0f, size.x, size.y);
scissorStack = std::stack<glm::vec4>(); scissorStack = std::stack<glm::vec4>();
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
} }
void window_sdl::popScissor() { void SDLWindow::popScissor() {
if (scissorStack.empty()) { if (scissorStack.empty()) {
logger.warning() << "extra Window::popScissor call"; logger.warning() << "extra Window::popScissor call";
return; return;
@ -418,11 +418,11 @@ void window_sdl::popScissor() {
scissorArea = area; scissorArea = area;
} }
double window_sdl::time() { double SDLWindow::time() {
return static_cast<double>(SDL_GetTicksNS()) / 1'000'000'000; return static_cast<double>(SDL_GetTicksNS()) / 1'000'000'000;
} }
void window_sdl::setFramerate(int framerate) { void SDLWindow::setFramerate(int framerate) {
/*todo*/ /*todo*/
if (!SDL_GL_SetSwapInterval(framerate)) { if (!SDL_GL_SetSwapInterval(framerate)) {
logger.error() << "Failed to set framerate: " << SDL_GetError(); logger.error() << "Failed to set framerate: " << SDL_GetError();
@ -431,7 +431,7 @@ void window_sdl::setFramerate(int framerate) {
// todo: move somewhere // todo: move somewhere
// Possible do with SDL_RenderReadPixels // Possible do with SDL_RenderReadPixels
std::unique_ptr<ImageData> window_sdl::takeScreenshot() { std::unique_ptr<ImageData> SDLWindow::takeScreenshot() {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
auto data = std::make_unique<ubyte[]>(size.x * size.y * 3); auto data = std::make_unique<ubyte[]>(size.x * size.y * 3);
glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1);
@ -441,17 +441,17 @@ std::unique_ptr<ImageData> window_sdl::takeScreenshot() {
); );
} }
[[nodiscard]] bool window_sdl::isValid() const { [[nodiscard]] bool SDLWindow::isValid() const {
return isSuccessfull; return isSuccessfull;
} }
[[nodiscard]] SDL_Window *window_sdl::getSdlWindow() const { [[nodiscard]] SDL_Window *SDLWindow::getSdlWindow() const {
return window; return window;
} }
std::tuple<std::unique_ptr<Window>, std::unique_ptr<Input>> Window::initialize( std::tuple<std::unique_ptr<Window>, std::unique_ptr<Input>> Window::initialize(
DisplaySettings *settings, std::string title DisplaySettings *settings, std::string title
) { ) {
auto window = std::make_unique<window_sdl>(settings, title); auto window = std::make_unique<SDLWindow>(settings, title);
if (!window->isValid()) { if (!window->isValid()) {
return {nullptr, nullptr}; return {nullptr, nullptr};
} }

View file

@ -5,14 +5,14 @@
#include "window/window.hpp" #include "window/window.hpp"
class window_sdl final : public Window { class SDLWindow final : public Window {
public: public:
window_sdl(DisplaySettings *settings, std::string title) noexcept; SDLWindow(DisplaySettings *settings, std::string title) noexcept;
~window_sdl(); ~SDLWindow();
window_sdl(const window_sdl &) = delete; SDLWindow(const SDLWindow &) = delete;
window_sdl(window_sdl &&) = default; SDLWindow(SDLWindow &&) = default;
window_sdl &operator=(const window_sdl &) = delete; SDLWindow &operator=(const SDLWindow &) = delete;
window_sdl &operator=(window_sdl &&) = default; SDLWindow &operator=(SDLWindow &&) = default;
void swapBuffers() noexcept override; void swapBuffers() noexcept override;