~sircmpwn/hare-users

hare-sdl2: added some missing bindings v1 APPLIED

~mateusmd: 2
 added some missing bindings
 fixed usage of deprecated functions

 2 files changed, 129 insertions(+), 14 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-users/patches/38405/mbox | git am -3
Learn more about email & git

[PATCH hare-sdl2 1/2] added some missing bindings Export this patch

From: mateusmd <mikomdias@yahoo.com>

---
 sdl2/render.ha | 139 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 127 insertions(+), 12 deletions(-)

diff --git a/sdl2/render.ha b/sdl2/render.ha
index 2b0dd07..545aae5 100644
--- a/sdl2/render.ha
+++ b/sdl2/render.ha
@@ -6,6 +6,39 @@ export type SDL_Renderer = void;
// An efficient driver-specific representation of pixel data. (Opaque)
export type SDL_Texture = void;

export type SDLPixelFormatValues = enum u32 {
    SDL_PIXELFORMAT_UNKNOWN,
    SDL_PIXELFORMAT_INDEX1LSB,
    SDL_PIXELFORMAT_INDEX1MSB,
    SDL_PIXELFORMAT_INDEX4LSB,
    SDL_PIXELFORMAT_INDEX4MSB,
    SDL_PIXELFORMAT_INDEX8,
    SDL_PIXELFORMAT_RGB332,
    SDL_PIXELFORMAT_RGB444,
    SDL_PIXELFORMAT_RGB555,
    SDL_PIXELFORMAT_BGR555,
    SDL_PIXELFORMAT_ARGB4444,
    SDL_PIXELFORMAT_RGBA4444,
    SDL_PIXELFORMAT_ABGR4444,
    SDL_PIXELFORMAT_BGRA4444,
    SDL_PIXELFORMAT_ARGB1555,
    SDL_PIXELFORMAT_RGBA5551,
    SDL_PIXELFORMAT_ABGR1555,
    SDL_PIXELFORMAT_BGRA5551,
    SDL_PIXELFORMAT_RGB565,
    SDL_PIXELFORMAT_BGR565,
    SDL_PIXELFORMAT_RGB24,
    SDL_PIXELFORMAT_BGR24,
    SDL_PIXELFORMAT_RGB888,
    SDL_PIXELFORMAT_RGBX8888,
    SDL_PIXELFORMAT_BGR888,
    SDL_PIXELFORMAT_BGRX8888,
    SDL_PIXELFORMAT_ARGB8888,
    SDL_PIXELFORMAT_RGBA8888,
    SDL_PIXELFORMAT_ABGR8888,
    SDL_PIXELFORMAT_BGRA8888,
};

// Flags used when creating a rendering context.
export type SDL_RendererFlags = enum u32 {
	NONE = 0,
@@ -15,6 +48,19 @@ export type SDL_RendererFlags = enum u32 {
	TARGETTEXTURE = 0x00000008,
};

export type SDL_RendererFlip = enum u32 {
    SDL_FLIP_NONE,
    SDL_FLIP_HORIZONTAL,
    SDL_FLIP_VERTICAL,
    SDL_FLIP_BOTH,
};

export type SDL_TextureAccess = enum {
    SDL_TEXTUREACCESS_STATIC,
    SDL_TEXTUREACCESS_STREAMING,
	SDL_TEXTUREACCESS_TARGET,
};

@symbol("SDL_CreateWindowAndRenderer") fn _SDL_CreateWindowAndRenderer(
	width: int, height: int, SDL_WindowFlags: SDL_WindowFlags,
	window: nullable **SDL_Window, renderer: nullable **SDL_Renderer) int;
@@ -161,6 +207,21 @@ export fn SDL_SetRenderDrawBlendMode(
	return wrapvoid(_SDL_SetRenderDrawBlendMode(renderer, mode));
};

@symbol("SDL_RenderDrawPoint") fn _SDL_RenderDrawPoint(
    renderer: *SDL_Renderer,
    x: int,
    y: int,
) int;

// Draws a point (pixel) at the given coordinates
export fn SDL_RenderDrawPoint(
    renderer: *SDL_Renderer,
    x: int,
    y: int,
) (void | error) = {
	return wrapvoid(_SDL_RenderDrawPoint(renderer, x, y));
};

@symbol("SDL_RenderCopy") fn _SDL_RenderCopy(renderer: *SDL_Renderer,
	texture: *SDL_Texture, srcrect: nullable *SDL_Rect, dstrect: nullable *SDL_Rect) int;

@@ -174,6 +235,31 @@ export fn SDL_RenderCopy(
	return wrapvoid(_SDL_RenderCopy(renderer, texture, srcrect, dstrect));
};

@symbol("SDL_RenderCopyEx") fn _SDL_RenderCopyEx(
    renderer: *SDL_Renderer,
    texture: *SDL_Texture,
    srcrect: nullable *SDL_Rect,
    dstrect: nullable *SDL_Rect,
    angle  : f64,
    center: nullable *SDL_Point,
    flip: SDL_RendererFlip,
) int;

// Sets the rendering pixel scale
export fn SDL_RenderCopyEx(
    renderer: *SDL_Renderer,
    texture: *SDL_Texture,
    srcrect: nullable *SDL_Rect,
    dstrect: nullable *SDL_Rect,
    angle  : f64,
    center: nullable *SDL_Point,
    flip: SDL_RendererFlip,
) (void | error) = {
	return wrapvoid(_SDL_RenderCopyEx(
        renderer, texture, srcrect, dstrect, angle, center, flip)
    );
};

@symbol("SDL_RenderDrawRect") fn _SDL_RenderDrawRect(
	renderer: *SDL_Renderer, rect: const nullable *SDL_Rect) int;

@@ -196,13 +282,37 @@ export fn SDL_RenderFillRect(
	return wrapvoid(_SDL_RenderFillRect(renderer, rect));
};

@symbol("SDL_CreateTexture") fn _SDL_CreateTexture(renderer: *SDL_Renderer,
	format: u32, access: int, w: int, h: int) *SDL_Texture;
@symbol("SDL_RenderSetLogicalSize") fn _SDL_RenderSetLogicalSize(
    renderer: *SDL_Renderer, w: int, h: int) int;

// Create a texture for a rendering context.
export fn SDL_CreateTexture(renderer: *SDL_Renderer,
	format: u32, access: int, w: int, h: int) (*SDL_Texture | error) = {
	return wrapptr(_SDL_CreateTexture(renderer, format, access, w, h))?: *SDL_Texture;
// Sets the rendering pixel scale
export fn SDL_RenderSetLogicalSize(
    renderer: *SDL_Renderer, 
    w: int, 
    h: int,
) (void | error) = {
	return wrapvoid(_SDL_RenderSetLogicalSize(
        renderer, w, h)
    );
};

@symbol("SDL_CreateTexture") fn _SDL_CreateTexture(
    renderer: *SDL_Renderer,
    format: u32,
    access: int,
    w: int,
    h: int) nullable *SDL_Texture;

export fn SDL_CreateTexture(
    renderer: *SDL_Renderer,
    format: u32,
    access: int,
    w: int,
    h: int
) (*SDL_Texture | error) = {
    return wrapptr(_SDL_CreateTexture(
        renderer, format, access, w, h)
    )?: *SDL_Texture;
};

@symbol("SDL_UpdateTexture") fn _SDL_UpdateTexture(texture: *SDL_Texture,
@@ -228,9 +338,14 @@ export fn SDL_LockTexture(texture: *SDL_Texture,
// Unlock a texture, uploading the changes to video memory, if needed.
export @symbol("SDL_UnlockTexture") fn SDL_UnlockTexture(texture: *SDL_Texture) void;

// An enumeration of texture access patterns.
export type SDL_TextureAccess = enum int {
	STATIC,
	STREAMING,
	TARGET
};
@symbol("SDL_RenderSetScale") fn _SDL_RenderSetScale(
    renderer: *SDL_Renderer, scaleX: f32, scaleY: f32) int;

// Sets the rendering pixel scale
export fn SDL_RenderSetScale(
    renderer: *SDL_Renderer, 
    scaleX: f32, 
    scaleY: f32,
) (void | error) = {
	return wrapvoid(_SDL_RenderSetScale(renderer, scaleX, scaleY));
};
\ No newline at end of file
-- 
2.34.5
Took 1/2, but not 2/2 (redundant with another patch). Thanks!

To git@git.sr.ht:~sircmpwn/hare-sdl2
   7c075ca..1e5cfa3  master -> master

[PATCH hare-sdl2 2/2] fixed usage of deprecated functions Export this patch

From: mateusmd <mikomdias@yahoo.com>

---
 sdl2/rwops.ha | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sdl2/rwops.ha b/sdl2/rwops.ha
index d497750..ec961a2 100644
--- a/sdl2/rwops.ha
+++ b/sdl2/rwops.ha
@@ -103,7 +103,7 @@ fn stream_seek(ctx: *SDL_RWops, offs: i64, whence: int) i64 = {
fn stream_read(ctx: *SDL_RWops, ptr: *void, sz: size, maxnum: size) size = {
	const handle = *(&ctx.hidden.unknown.data1: *io::handle);
	let buf = ptr: *[*]u8;
	match (io::readitems(handle, buf[..sz * maxnum], sz)) {
	match (io::readall(handle, buf[..sz * maxnum])) {
	case let n: size =>
		return n;
	case io::error =>
@@ -114,7 +114,7 @@ fn stream_read(ctx: *SDL_RWops, ptr: *void, sz: size, maxnum: size) size = {
fn stream_write(ctx: *SDL_RWops, ptr: *void, sz: size, num: size) size = {
	const handle = *(&ctx.hidden.unknown.data1: *io::handle);
	let buf = ptr: *[*]u8;
	match (io::writeitems(handle, buf[..sz * num], sz)) {
	match (io::writeall(handle, buf[..sz * num])) {
	case let n: size =>
		return n;
	case io::error =>
-- 
2.34.5