src/context.c

changeset 253
6ab35fcb8676
parent 214
9d460888a83e
--- a/src/context.c	Tue Aug 05 16:53:25 2025 +0200
+++ b/src/context.c	Tue Aug 05 20:00:24 2025 +0200
@@ -28,9 +28,8 @@
 #include "ascension/context.h"
 #include "ascension/error.h"
 
-#include <SDL2/SDL.h>
-#include <SDL2/SDL_ttf.h>
-#include <SDL2/SDL_image.h>
+#include <SDL3/SDL.h>
+#include <SDL3_ttf/SDL_ttf.h>
 
 #include <GL/glew.h>
 
@@ -74,13 +73,10 @@
     );
 
     // initialize SDL
-    const int supported_img_flags = IMG_INIT_PNG | IMG_INIT_JPG;
-    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+    if (!SDL_Init(SDL_INIT_VIDEO)) {
         asc_error("Failed to initialize SDL: %s", SDL_GetError());
-    } else if (TTF_Init() < 0) {
-        asc_error("Failed to initialize SDL_ttf: %s", TTF_GetError());
-    } else if (IMG_Init(supported_img_flags) != supported_img_flags) {
-        asc_error("Failed to initialize SDL_img: %s", IMG_GetError());
+    } else if (!TTF_Init()) {
+        asc_error("Failed to initialize SDL_ttf: %s", SDL_GetError());
     }
     SDL_ClearError();
     asc_context.total_nanos = asc_nanos();
@@ -98,7 +94,6 @@
     asc_font_cache_destroy();
 
     // quit SDL
-    IMG_Quit();
     TTF_Quit();
     SDL_Quit();
 
@@ -141,7 +136,7 @@
     asc_context.input.mouse_yrel = 0;
 
     // reset key flags
-    for (unsigned int i = 0 ; i < SDL_NUM_SCANCODES ; i++) {
+    for (unsigned int i = 0 ; i < SDL_SCANCODE_COUNT ; i++) {
         asc_clear_flag(asc_context.input.keys[i], ASC_KEY_RELEASE_FLAG|ASC_KEY_PRESS_FLAG);
     }
 
@@ -149,26 +144,28 @@
     SDL_Event event;
     while (SDL_PollEvent(&event)) {
         switch (event.type) {
-            case SDL_QUIT:
+            case SDL_EVENT_QUIT:
                 asc_set_flag(asc_context.flags, ASC_FLAG_QUIT);
                 break;
-            case SDL_WINDOWEVENT: {
-                if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
-                    asc_event_window_resized(
-                            event.window.windowID,
-                            event.window.data1,
-                            event.window.data2
-                    );
-                } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
-                    unsigned int idx = asc_window_index(event.window.windowID);
-                    asc_context.windows[idx].focused = true;
-                } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
-                    unsigned int idx = asc_window_index(event.window.windowID);
-                    asc_context.windows[idx].focused = false;
-                }
+            case SDL_EVENT_WINDOW_RESIZED: {
+                asc_event_window_resized(
+                        event.window.windowID,
+                        event.window.data1,
+                        event.window.data2
+                );
                 break;
             }
-            case SDL_MOUSEMOTION: {
+            case SDL_EVENT_WINDOW_FOCUS_GAINED: {
+                unsigned int idx = asc_window_index(event.window.windowID);
+                asc_context.windows[idx].focused = true;
+                break;
+            }
+            case SDL_EVENT_WINDOW_FOCUS_LOST: {
+                unsigned int idx = asc_window_index(event.window.windowID);
+                asc_context.windows[idx].focused = false;
+                break;
+            }
+            case SDL_EVENT_MOUSE_MOTION: {
                 // accumulate relative motion
                 asc_context.input.mouse_xrel += event.motion.xrel;
                 asc_context.input.mouse_yrel += event.motion.yrel;
@@ -180,15 +177,15 @@
                         asc_window_index(event.motion.windowID);
                 break;
             }
-            case SDL_KEYDOWN:
+            case SDL_EVENT_KEY_DOWN:
                 // we only set the down and press flags if the key is not already known to be down
-                if (asc_key_up(event.key.keysym.scancode)) {
-                    asc_context.input.keys[event.key.keysym.scancode] = ASC_KEY_DOWN_FLAG|ASC_KEY_PRESS_FLAG;
+                if (asc_key_up(event.key.scancode)) {
+                    asc_context.input.keys[event.key.scancode] = ASC_KEY_DOWN_FLAG|ASC_KEY_PRESS_FLAG;
                 }
                 break;
-            case SDL_KEYUP:
+            case SDL_EVENT_KEY_UP:
                 // we can directly set the release flag - it will be cleared next round
-                asc_context.input.keys[event.key.keysym.scancode] = ASC_KEY_RELEASE_FLAG;
+                asc_context.input.keys[event.key.scancode] = ASC_KEY_RELEASE_FLAG;
                 break;
         }
     }

mercurial