diff options
Diffstat (limited to 'src/TZR.h')
-rw-r--r-- | src/TZR.h | 55 |
1 files changed, 52 insertions, 3 deletions
@@ -1,6 +1,7 @@ #pragma once #include <limits.h> #include <SDL2/SDL_main.h> +#include <SDL2/SDL_mixer.h> #include <SDL2/SDL_render.h> #include <SDL2/SDL_scancode.h> #include <stdbool.h> @@ -11,6 +12,7 @@ enum TZR_ResourceType { TZR_RES_RAW, TZR_RES_IMAGE, + TZR_RES_SOUND, ___TZR_RES_COUNT }; @@ -35,10 +37,13 @@ typedef struct TZR_Rect TZR_Rect; typedef enum TZR_ResourceType TZR_ResourceType; typedef struct TZR_Raw TZR_Raw; typedef struct TZR_Image TZR_Image; +typedef struct TZR_Sound TZR_Sound; typedef struct TZR_Resource TZR_Resource; typedef enum TZR_EventType TZR_EventType; typedef struct TZR_Event TZR_Event; typedef struct TZR_DrawImageArgs TZR_DrawImageArgs; +typedef struct TZR_DrawRectangleArgs TZR_DrawRectangleArgs; +typedef struct TZR_PlaySoundArgs TZR_PlaySoundArgs; typedef enum TZR_KeyState TZR_KeyState; struct TZR_Config { @@ -47,6 +52,8 @@ struct TZR_Config { int height; int target_fps; bool pixel_perfect; + bool show_cursor; + bool mixer; const char *title; }; @@ -79,6 +86,10 @@ struct TZR_Image { SDL_Texture *ptr; }; +struct TZR_Sound { + Mix_Chunk *ptr; +}; + struct TZR_Resource { TZR_ResourceType type; char *path; /* allocated and freed by TZR; can be NULL */ @@ -86,6 +97,7 @@ struct TZR_Resource { union { TZR_Raw raw; /* raw file data */ TZR_Image image; + TZR_Sound sound; }; }; @@ -108,6 +120,23 @@ struct TZR_DrawImageArgs { float sy; bool center; }; + +struct TZR_DrawRectangleArgs { + int _; + int x; + int y; + int w; + int h; + bool fill; + bool center; +}; + +struct TZR_PlaySoundArgs { + int _; + int id; + int loop; + float volume; +}; /* headers/TZR_globals.h */ extern TZR_Config ___tzr_config; @@ -124,8 +153,11 @@ extern unsigned long ___tzr_min_dt; extern int ___tzr_should_quit; extern int ___tzr_mouse_x; extern int ___tzr_mouse_y; -extern const char *___tzr_command[___TZR_RES_COUNT]; extern TZR_KeyState ___tzr_keystates[SDL_NUM_SCANCODES]; +extern TZR_KeyState ___tzr_mousestates[256]; +extern float ___tzr_scale; +extern int ___tzr_off_x; +extern int ___tzr_off_y; /* headers/TZR_resource.h */ #define TZR_RES TZR_LoadResource @@ -170,6 +202,14 @@ void TZR_ResourcesWatch(void); [[nodiscard]] int TZR_DirectResourceLoad(TZR_Resource *res, const void *data, int size); void TZR_DestroyResource(TZR_Resource *res, int free_path); +/* headers/TZR_sound.h */ + +#define TZR_PlaySound(...) _TZR_PlaySound(&(const TZR_PlaySoundArgs){ \ + .id=0, .loop=0, .volume=1.0f, ._=0, __VA_ARGS__ }) +#ifdef TZR_PARANOID +[[nodiscard]] +#endif +int _TZR_PlaySound(const TZR_PlaySoundArgs *args); /* headers/TZR_events.h */ /* Write event data to `e`. Return 0 when event queue is empty. */ @@ -177,6 +217,8 @@ int TZR_PollEvent(TZR_Event *e); /* Drain queued events with TZR_PollEvent and call TZR_ResourcesWatch. */ void TZR_CycleEvents(void); + +void TZR_GetMousePosition(int *x, int *y); /* headers/TZR_render.h */ /* All draw calls should happen between TZR_DrawBegin and TZR_DrawEnd. @@ -217,10 +259,13 @@ int TZR_DrawLine(int x0, int y0, int x1, int y1); /* Return -1 on error. Draw rectangle at `x`;`y` position of size `w`x`h` in the * framebuffer. */ +#define TZR_DrawRectangle(...) _TZR_DrawRectangle( \ + &(const TZR_DrawRectangleArgs){ \ + .x=0, .y=0, .w=0, .h=0, .fill=false, .center=false, ._=0, __VA_ARGS__ }) #ifdef TZR_PARANOID [[nodiscard]] #endif -int TZR_DrawRectangle(bool fill, int x, int y, int w, int h); +int _TZR_DrawRectangle(const TZR_DrawRectangleArgs *args); /* Return -1 on error. Draw texture ressource `id` at `x`;`y` position of * the framebuffer. */ @@ -231,6 +276,8 @@ int TZR_DrawRectangle(bool fill, int x, int y, int w, int h); [[nodiscard]] #endif int _TZR_DrawImage(const TZR_DrawImageArgs *args); + +void TZR_ScreenTransform(int *x, int *y); /* headers/TZR_keystate.h */ TZR_KeyState TZR_GetKeyState(int scancode); @@ -251,6 +298,8 @@ bool TZR_IsKeyPressed(int scancode); .height=224, \ .target_fps=60, \ .pixel_perfect=true, \ + .show_cursor=false, \ + .mixer=true, \ .title="TZR", \ ._=0, __VA_ARGS__ }) @@ -268,4 +317,4 @@ int TZR_ShouldQuit(void); unsigned long TZR_GetTick(void); -/* commit hash: 8b92076145893cfdaf3e648e0324b163c1a6d28e */ +/* commit hash: e96c359a840974adea4d3d1d3445377f159ecdf0 */ |