summaryrefslogtreecommitdiff
path: root/lzr.h
blob: 497bd52c36684739835c99794c19659f0873c15f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Licensing informations can be found at the end of the file. */
#pragma once
#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include <stdint.h>

#ifndef LZR_DISABLE_IMAGE
#	define LZR_ENABLE_IMAGE
#endif
#ifndef LZR_DISABLE_MIXER
#	define LZR_ENABLE_MIXER
#endif
#ifndef LZR_DISABLE_GFX
#	define LZR_ENABLE_GFX
#endif

/* devmode tracks and autoreloads ressources on change */
#ifndef LZR_DISABLE_DEVMODE
#	define LZR_ENABLE_DEVMODE
#endif

#define LZR_MAX_IMAGES  64
#define LZR_MAX_SOUNDS  64
#define LZR_BUTTON(btn) LZR_ButtonDown(LZR_BUTTON_##btn)
#define LZR_IMAGE(img)  LZR_ImageLoad(img)

typedef struct LZR_Config {
	unsigned int display_width;
	unsigned int display_height;
	unsigned int target_fps;
	unsigned int tile_size;
	const char *title;
	double ratio;
	bool disable_bind_menu;
	bool hide_cursor;
} LZR_Config;

typedef enum LZR_EventType {
	LZR_EVENT_QUIT,
	LZR_EVENT_BUTTON_DOWN,
	LZR_EVENT_BUTTON_UP,
	LZR_EVENT_MOUSE_MOVE
} LZR_EventType;

typedef enum LZR_Button {
	LZR_BUTTON_LEFT,
	LZR_BUTTON_RIGHT,
	LZR_BUTTON_UP,
	LZR_BUTTON_DOWN,
	LZR_BUTTON_O,
	LZR_BUTTON_X,
	LZR_BUTTON_MOUSE_L,
	LZR_BUTTON_MOUSE_M,
	LZR_BUTTON_MOUSE_R,
	LZR_BUTTON_COUNT
} LZR_Button;

typedef struct LZR_Event {
	LZR_EventType type;
	LZR_Button button;
	int x, y;
} LZR_Event;

typedef struct LZR_ImageDrawSettings {
	int ix, iy, width, height;
	double scale_x, scale_y, angle;
	bool center, flip_h, flip_v;
} LZR_ImageDrawSettings;

int LZR_Init(LZR_Config cfg);
void LZR_Quit(void);
bool LZR_ShouldQuit(void);
bool LZR_PollEvent(LZR_Event *e);
void LZR_CycleEvents(void);
bool LZR_ButtonDown(LZR_Button btn);
void LZR_ButtonBind(LZR_Button btn, unsigned int code);
char *LZR_PathPrefix(const char *path);
int LZR_ImageLoad(const char *path);
int LZR_SoundLoad(const char *path, float volume);
int LZR_DrawBegin(void);
int LZR_DrawEnd(void);
int LZR_DrawSetColor(float r, float g, float b, float a);
int LZR_DrawClear(void);
int LZR_DrawPoint(int x, int y);
int LZR_DrawPoints(int *x, int *y, int n);
int LZR_DrawLine(int x0, int y0, int x1, int y1);
int LZR_DrawRectangle(bool fill, int x, int y, int w, int h);
int LZR_DrawCircle(bool fill, int x, int y, int radius);
int LZR_DrawPolygon(bool fill, int *vx, int *vy, int n);
int LZR_DrawImage(int id, int x, int y);
int LZR_DrawImageEx(int id, int x, int y, LZR_ImageDrawSettings stg);
int LZR_DrawTile(int id, int tile, int x, int y, double rot, int flip);
int LZR_PlaySound(int id);
int LZR_SetMusicVolume(float volume);
int LZR_PlayMusic(const char *path, int loops);
void LZR_StopMusic(void);
void LZR_ToggleFullscreen(void);
uint64_t LZR_GetTick(void);
void LZR_ScreenTransform(int *x, int *y);
void LZR_MousePosition(int *x, int *y);

#ifdef __cplusplus
}
#endif

/*
** Copyright (c) 2022, 2023 kdx
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to
** deal in the Software without restriction, including without limitation the
** rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
** sell copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
** IN THE SOFTWARE.
*/