Skip to content

Commit

Permalink
img: add LoadSizedSVGRW() and custom LoadSizedSVG() functions
Browse files Browse the repository at this point in the history
Signed-off-by: Lilis Iskandar <[email protected]>
  • Loading branch information
veeableful committed Apr 17, 2024
1 parent 374428a commit c0cec1a
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions img/sdl_image.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
// Package img is a simple library to load images of various formats as SDL surfaces.
package img

//#include <stdlib.h>
//#include "sdl_image_wrapper.h"
/*
#include <stdlib.h>
#include "sdl_image_wrapper.h"
#if !(SDL_IMAGE_VERSION_ATLEAST(2,6,0))
#if defined(WARN_OUTDATED)
#pragma message("SDL_LoadSizedSVG_RW is not supported before SDL2_image 2.6.0")
#endif
static inline SDL_Surface* SDL_LoadSizedSVG_RW(SDL_RWops* src, int width, int height)
{
SDL_Unsupported();
return NULL;
}
#endif
*/
import "C"
import (
"errors"
Expand Down Expand Up @@ -412,3 +427,21 @@ func SavePNGRW(surface *sdl.Surface, dst *sdl.RWops, freedst int) error {
}
return nil
}

// LoadSizedSVGRW loads an SVG image from an SDL data source for use as a surface with specific size.
func LoadSizedSVGRW(src *sdl.RWops, width, height int) (*sdl.Surface, error) {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_width := C.int(width)
_height := C.int(height)
_surface := C.IMG_LoadSizedSVG_RW(_src, _width, _height)

Check failure on line 436 in img/sdl_image.go

View workflow job for this annotation

GitHub Actions / test-build

could not determine kind of name for C.IMG_LoadSizedSVG_RW

Check failure on line 436 in img/sdl_image.go

View workflow job for this annotation

GitHub Actions / test-build

could not determine kind of name for C.IMG_LoadSizedSVG_RW

Check failure on line 436 in img/sdl_image.go

View workflow job for this annotation

GitHub Actions / test-build

could not determine kind of name for C.IMG_LoadSizedSVG_RW
if _surface == nil {
return nil, GetError()
}
return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
}

// LoadSizedSVG loads an SVG image from a file for use as a surface with specific size (custom function).
func LoadSizedSVG(file string, width, height int) (*sdl.Surface, error) {
src := sdl.RWFromFile(file, "r")
return LoadSizedSVGRW(src, width, height)
}

0 comments on commit c0cec1a

Please sign in to comment.