aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-13 16:30:46 +0100
committerDrew DeVault <sir@cmpwn.com>2024-04-19 11:10:28 +0200
commitf2e40ecffec519e1094ed829f8735309ae67997f (patch)
tree8168a12577b1a7f38f0a692aa049b5c3debb3e87
parentAdd SDL_GetRendererOutputSize. (diff)
downloadhare-chip8-f2e40ecffec519e1094ed829f8735309ae67997f.tar.gz
add a few functions
these are some sdl functions i needed for a project. there is not much structure beyond that.
-rw-r--r--sdl2/keyboard.ha10
-rw-r--r--sdl2/pixels.ha15
-rw-r--r--sdl2/surface.ha9
-rw-r--r--sdl2/video.ha11
4 files changed, 44 insertions, 1 deletions
diff --git a/sdl2/keyboard.ha b/sdl2/keyboard.ha
index d42fa8a..cc137d2 100644
--- a/sdl2/keyboard.ha
+++ b/sdl2/keyboard.ha
@@ -643,3 +643,13 @@ export fn SDL_GetKeyFromName(name: str) (SDL_Keycode | error) = {
};
return sym;
};
+
+@symbol("SDL_GetKeyboardState") fn _SDL_GetKeyboardState(numkeys: *int) *[*]bool;
+
+export fn SDL_GetKeyboardState() []bool = {
+ let numkeys: int = 0;
+ let arr = _SDL_GetKeyboardState(&numkeys);
+ let arr = arr[..numkeys];
+ return arr;
+};
+
diff --git a/sdl2/pixels.ha b/sdl2/pixels.ha
index 75ccb99..7aa8733 100644
--- a/sdl2/pixels.ha
+++ b/sdl2/pixels.ha
@@ -1,4 +1,5 @@
// TODO: Flesh me out
+use types::c;
export type SDL_Color = struct {
r: u8,
@@ -38,3 +39,17 @@ export type SDL_PixelFormat = struct {
};
export def SDL_PIXELFORMAT_ARGB8888: u32 = 0x16362004;
+
+@symbol("SDL_GetPixelFormatName") fn _SDL_GetPixelFormatName(format: u32)
+ const *c::char;
+
+// Get the human readable name of a pixel format.
+export fn SDL_GetPixelFormatName(format: u32) str = {
+ return c::tostr(_SDL_GetPixelFormatName(format))!;
+};
+
+// Map an RGB triple to an opaque pixel value for a given pixel format.
+export @symbol("SDL_MapRGB") fn SDL_MapRGB(format: *SDL_PixelFormat, r: u8, g: u8, b: u8) u32;
+
+// Map an RGBA quadruple to a pixel value for a given pixel format.
+export @symbol("SDL_MapRGBA") fn SDL_MapRGBA(format: *SDL_PixelFormat, r: u8, g: u8, b: u8, a: u8) u32;
diff --git a/sdl2/surface.ha b/sdl2/surface.ha
index 24153c3..7b6438e 100644
--- a/sdl2/surface.ha
+++ b/sdl2/surface.ha
@@ -35,3 +35,12 @@ export fn SDL_CreateRGBSurface(flags: u32,
return wrapptr(_SDL_CreateRGBSurface(flags, width, height, depth, Rmask,
Gmask, Bmask, Amask))?: *SDL_Surface;
};
+
+// NB SDL_BlitSurface is aliased to SDL_UpperBlit via a macro in the SDL header
+@symbol("SDL_UpperBlit") fn _SDL_BlitSurface(src: *SDL_Surface,
+ srcrect: nullable *SDL_Rect, dst: *SDL_Surface, dstrect: nullable *SDL_Rect) int;
+
+// Perform a fast surface copy to a destination surface.
+export fn SDL_BlitSurface(src: *SDL_Surface, srcrect: nullable *SDL_Rect, dst: *SDL_Surface, dstrect: nullable *SDL_Rect) (void | error) = {
+ return wrapvoid(_SDL_BlitSurface(src, srcrect, dst, dstrect));
+};
diff --git a/sdl2/video.ha b/sdl2/video.ha
index 466052e..2627b48 100644
--- a/sdl2/video.ha
+++ b/sdl2/video.ha
@@ -99,10 +99,19 @@ export @symbol("SDL_DestroyWindow") fn SDL_DestroyWindow(window: *SDL_Window) vo
export @symbol("SDL_GetWindowSize") fn SDL_GetWindowSize(window: *SDL_Window,
w: nullable *int, h: nullable *int) void;
-// Get the SDL surface associated with the window.
@symbol("SDL_GetWindowSurface") fn _SDL_GetWindowSurface(window: *SDL_Window)
*SDL_Surface;
+// Get the SDL surface associated with the window.
export fn SDL_GetWindowSurface(window: *SDL_Window) (*SDL_Surface | error) = {
return wrapptr(_SDL_GetWindowSurface(window))?: *SDL_Surface;
};
+
+// Copy the window surface to the screen.
+@symbol("SDL_UpdateWindowSurface") fn _SDL_UpdateWindowSurface(window: *SDL_Window)
+ int;
+
+export fn SDL_UpdateWindowSurface(window: *SDL_Window) (void | error) = {
+ return wrapvoid(_SDL_UpdateWindowSurface(window));
+};
+