lexsdl 0.3.0

A wrapper for SDL2 to abstract away annoying parts
//! C functions and structs.
//!
//! All public C functions and structs are defined here.
//!
//! They can be called but the use of unsafe is necessary.
//!
//! The documentation for them is in the <a href=https://gitlab.com/Alexevier/lexsdl/-/releases>GitLab</a> repo as download in the releases page.
use libc::*;
use sdl2_sys::*;
use crate::types::*;



// LEXSDL.h
extern "C" {
	/* Inits */
	pub fn LEXSDL_Init(flags: u32) -> c_int;
	pub fn LEXSDL_InitIMG(flags: c_int) -> c_int;
	pub fn LEXSDL_Terminate();
	pub fn LEXSDL_Quit();
}

// LEXSDL_internal.h
#[allow(dead_code)]
#[allow(non_snake_case)]
#[repr(C)]
pub struct LexSdlData {
	/* Windowing(?) */
	pub window: *mut SDL_Window,
	/* Rendering */
	pub renderer: *mut SDL_Renderer,
	pub bgColor: [u8;4],
	pub drColor: [u8;4],
	pub textures: *mut *mut SDL_Texture,
	sprites: *mut LEXSDL_Sprite,
	pub texturesQuantity: TextureID,
	pub spritesQuantity: SpriteID,
	/* Event */
	pub eventQuit: u8 ,
	pub keyboardState: *const u8,
	pub mouseState: LEXSDL_Mouse,
	/* Timing */
	pub deltaTicksLast: u32,
	pub deltaTicksCurrent: u32,
	pub delta: u32,
	pub deltaFloat: c_float,
}

#[allow(dead_code)]
#[allow(non_snake_case)]
#[repr(C)]
struct LEXSDL_Sprite {
	frames: u32,
	delta: u32,
	currentFrame: u32,
	fps: u32,
	textureID: c_int,
	frameDimensions: SDL_Rect,
	freed: u8,
}

extern "C" {
	#[allow(dead_code)]
	pub static LEXSDLDATA: LexSdlData;
}



// LEXSDL_event.h
extern "C" {
	/* Setup */
	pub fn LEXSDL_SetupEvents() -> c_int;

	/* Handeling */
	pub fn LEXSDL_HandleEvents();
	
	/* Events */
	pub fn LEXSDL_EventKey(scancode: u16) -> u8;
	pub fn LEXSDL_EventQuit() -> u8;
	
	/* Manipulation */
	pub fn LEXSDL_EventDoQuit();
	pub fn LEXSDL_EventCancelQuit();
}



// LEXSDL_mouse.h
#[repr(C)]
pub struct LEXSDL_Mouse {
	x: c_int,
	y: c_int,
	left: u8,
	right: u8,
	middle: u8,
	x1: u8,
	x2: u8,
}

extern "C" {
	/* Getter */
	pub fn LEXSDL_GetMouse() -> *const LEXSDL_Mouse;

	/* Manipulation */
	pub fn LEXSDL_MouseUpdate();
	
	/* Position */
	pub fn LEXSDL_MousePos(x: *mut c_int, y: *mut c_int);
	pub fn LEXSDL_MousePosX() -> c_int;
	pub fn LEXSDL_MousePosY() -> c_int;

	/* Clicks */
	pub fn LEXSDL_MouseLeft() -> u8;
	pub fn LEXSDL_MouseRight() -> u8;
	pub fn LEXSDL_MouseMiddle() -> u8;
	pub fn LEXSDL_MouseX1() -> u8;
	pub fn LEXSDL_MouseX2() -> u8;
}



// LEXSDL_renderer.h
extern "C" {
	/* Creation */
	pub fn LEXSDL_CreateRenderer(flags: u32) -> *mut SDL_Renderer;
	
	/* Getters and Setters */
	pub fn LEXSDL_GetBackgroundColor(r: *mut u8, g: *mut u8, b: *mut u8, a: *mut u8);
	pub fn LEXSDL_GetDrawColor(r: *mut u8, g: *mut u8, b: *mut u8, a: *mut u8);
	pub fn LEXSDL_GetRenderer() -> *mut SDL_Renderer;
	pub fn LEXSDL_SetRenderer(renderer: *mut SDL_Renderer);

	/* Manipulation */
	pub fn LEXSDL_SetBackgroundColor(r: u8, g: u8, b: u8, a: u8);
	pub fn LEXSDL_SetDrawColor(r: u8, g: u8, b: u8, a: u8);

	/* Renderer Functions */
	pub fn LEXSDL_NewFrame() -> c_int;
	pub fn LEXSDL_ShowFrame();
}



// LEXSDL_texture.h
extern "C" {
	/* Creation/Loading */
	pub fn LEXSDL_TextureAdd(texture: *mut SDL_Texture) -> c_int;
	pub fn LEXSDL_TextureLoad(file: *const c_char) -> c_int;
	pub fn LEXSDL_TextureLoadBytes(data: *const u8, len: c_int) -> c_int;
	
	/* Getters */
	pub fn LEXSDL_TextureGet(id: c_int) -> *mut SDL_Texture;

	/* Manipulation */
	pub fn LEXSDL_TextureChange(id: c_int, r: u8, g: u8, b: u8);
	pub fn LEXSDL_TextureChangeAlpha(id: c_int, a: u8);
	pub fn LEXSDL_TextureDestroy(id: c_int);
	
	/* Drawing */
	pub fn LEXSDL_TextureDraw(id: c_int, srcrect: *const SDL_Rect, dstrect: *const SDL_Rect);
	pub fn LEXSDL_TextureDrawAt(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int);
	pub fn LEXSDL_TextureDrawFill(id: c_int);
	pub fn LEXSDL_TextureDrawRot(id: c_int, srcrect: *const SDL_Rect, dstrect: *const SDL_Rect, rot: c_double);
	pub fn LEXSDL_TextureDrawRotAt(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int, rot: c_double);
	pub fn LEXSDL_TextureDrawRotCenterAt(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int, rot: c_double, cx: c_int, cy: c_int);
}



// LEXSDL_sprite.h
extern "C" {
	/* Creation */
	pub fn LEXSDL_CreateSprite(textureID: c_int, frames: u32, fps: u32, frameDimensions: SDL_Rect) -> c_int;
	
	/* Getters */
	pub fn LEXSDL_SpriteGetCurrentFrame(id: c_int) -> u32;
	pub fn LEXSDL_SpriteGetFrameDimensions(id: c_int) -> SDL_Rect;
	pub fn LEXSDL_SpriteGetFrames(id: c_int) -> u32;
	pub fn LEXSDL_SpriteGetFps(id: c_int) -> u32;
	pub fn LEXSDL_SpriteGetTexture(id: c_int) -> *mut SDL_Texture;
	pub fn LEXSDL_SpriteGetTextureId(id: c_int) -> c_int;
	pub fn LEXSDL_SpriteSetTextureId(id: c_int, textureID: c_int) -> c_int;
	
	/* Manipulation */
	pub fn LEXSDL_SpriteClone(id: c_int) -> c_int;
	pub fn LEXSDL_SpriteSkipFrames(id: c_int, frames: u32);
	pub fn LEXSDL_SpriteSetFrame(id: c_int, frame: u32);
	pub fn LEXSDL_SpriteStep(id: c_int);
	pub fn LEXSDL_SpriteUpdate(id: c_int);
	
	/* Drawing */
	pub fn LEXSDL_SpriteDraw(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int);
	pub fn LEXSDL_SpriteDrawFlip(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int);
	pub fn LEXSDL_SpriteDrawFlipRot(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int, rot: c_double);
	pub fn LEXSDL_SpriteDrawRot(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int, rot: c_double);
	
	/* Playing */
	pub fn LEXSDL_SpritePlay(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int);
	pub fn LEXSDL_SpritePlayBackground(id: c_int);
	pub fn LEXSDL_SpritePlayFlip(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int);
	pub fn LEXSDL_SpritePlayFlipRot(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int, rot: c_double);
	pub fn LEXSDL_SpritePlayRot(id: c_int, x: c_int, y: c_int, w: c_int, h: c_int, rot: c_double);
}



// LEXSDL_timing.h
extern "C" {
	pub fn LEXSDL_DeltaUpdate();
	
	/* Getting the Delta */
	pub fn LEXSDL_DeltaTime() -> u32;
	pub fn LEXSDL_DeltaTimeFloat() -> c_float;
}



// LEXSDL_window.h
extern "C" {
	/* Getter and Setter */
	pub fn LEXSDL_GetWindow() -> *mut SDL_Window;
	pub fn LEXSDL_SetWindow(window: *mut SDL_Window);
	
	/* Creation */
	pub fn LEXSDL_CreateWindow(title: *const c_char, flags: u32) -> *mut SDL_Window;
	pub fn LEXSDL_CreateWindowSized(title: *const c_char, width: c_int, height: c_int, flags: u32) -> *mut SDL_Window;
}