fix cursors

This commit is contained in:
Igor Stepanov 2025-10-10 17:27:40 +03:00
parent 640cfcc3d0
commit 4e97923cee
2 changed files with 12 additions and 2 deletions

View file

@ -257,7 +257,13 @@ void window_sdl::setShouldClose(bool flag) {
}
void window_sdl::setCursor(CursorShape shape) {
SDL_Cursor *cursor = nullptr;
// so it method called each frame, we always recreate cursor.
// Refactor it
if (cursor) {
SDL_DestroyCursor(cursor);
cursor = nullptr;
}
switch (shape) {
case CursorShape::ARROW:
cursor = SDL_CreateSystemCursor(
@ -313,7 +319,6 @@ void window_sdl::setCursor(CursorShape shape) {
}
if (cursor) {
SDL_SetCursor(cursor);
SDL_DestroyCursor(cursor);
}
}
void window_sdl::toggleFullscreen() {
@ -321,6 +326,10 @@ void window_sdl::toggleFullscreen() {
if (!SDL_SetWindowFullscreen(window, fullscreen)) {
logger.error() << "Cant toggle fullscreen window: " << SDL_GetError();
}
if (!SDL_SyncWindow(window)) {
logger.error() << "Cant sync window after toggle fullscreen: "
<< SDL_GetError();
}
}
bool window_sdl::isFullscreen() const {
return fullscreen;

View file

@ -49,6 +49,7 @@ private:
SDL_Window *window = nullptr;
SDL_Renderer *renderer = nullptr;
SDL_Cursor *cursor = nullptr;
SDL_GLContext context = nullptr;
std::stack<glm::vec4> scissorStack;