forked from ceu-lang/ceu-sdl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sdl.ceu
156 lines (141 loc) · 4.69 KB
/
sdl.ceu
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifndef _SDL_CEU
#define _SDL_CEU
data SDL_Color with
var u8 r;
var u8 g;
var u8 b;
var u8 a;
end
data SDL_Point with
var int x;
var int y;
end
data SDL_Rect with
var int x;
var int y;
var int w;
var int h;
end
native @const _GL_SCISSOR_TEST, _GL_TEXTURE_2D;
native _glEnable(), _glDisable(), _glScissor();
native @plain _SDL_Rect, _SDL_Point, _SDL_Color,
_SDL_TouchFingerEvent,
_SDL_Texture;
native @const _SDL_TRUE, _SDL_FALSE,
_SDL_BLENDMODE_NONE, _SDL_BLENDMODE_BLEND,
_SDL_BUTTON_LEFT,
_SDL_BUTTON_RIGHT,
_SDL_KEYDOWN,
_SDL_MOUSEBUTTONDOWN,
_SDL_PIXELFORMAT_UNKNOWN,
_SDL_SCANCODE_AC_BACK,
_SDL_RENDERER_ACCELERATED,
_SDL_RENDERER_PRESENTVSYNC,
_SDL_TEXTINPUT,
_SDL_TEXTUREACCESS_STATIC,
_SDL_TEXTUREACCESS_TARGET,
_SDL_WINDOW_SHOWN,
_SDL_WINDOW_RESIZABLE,
_SDL_WINDOWEVENT_RESIZED,
_AUDIO_S16SYS;
native @const _SDLK_ESCAPE,
_SDLK_BACKSPACE,
_SDLK_RETURN,
_SDLK_p;
native @nohold _SDL_GL_BindTexture(),
_SDL_CreateWindow(),
_SDL_CreateRenderer(),
_SDL_CreateSoftwareRenderer(),
_SDL_CreateTexture(),
_SDL_CreateTextureFromSurface(),
_SDL_FreeSurface(),
_SDL_GetMouseState(),
_SDL_GetRendererInfo(),
_SDL_GetRendererOutputSize(),
_SDL_GetWindowSize(),
_SDL_HasIntersection(),
_SDL_SetWindowFullscreen(),
_SDL_SetRenderDrawColor(),
_SDL_RenderClear(),
_SDL_RenderDrawLine(),
_SDL_RenderDrawRect(),
_SDL_RenderFillRect(),
_SDL_RenderCopy(),
_SDL_RenderPresent(),
_SDL_DestroyRenderer(),
_SDL_DestroyTexture(),
_SDL_DestroyWindow(),
_SDL_FreeSurface(),
_SDL_QueryTexture(),
_SDL_Quit(),
_SDL_Delay(),
_SDL_SetEventFilter(),
_SDL_SetRenderDrawBlendMode(),
_SDL_SetRenderTarget(),
_SDL_SetTextInputRect(),
_SDL_SetWindowDisplayMode(),
_SDL_SetWindowTitle(),
_SDL_StartTextInput(),
_SDL_StopTextInput(),
_IMG_LoadTexture(),
_TTF_CloseFont(),
_TTF_Init(),
_TTF_OpenFont(),
_TTF_Quit(),
_TTF_RenderText_Blended(),
_TTF_RenderText_Shaded(),
_TTF_RenderText_Solid(),
_TTF_SizeText(),
_Mix_LoadWAV(),
_Mix_FreeChunk(),
_Mix_FreeMusic(),
_Mix_PlayChannel(),
_Mix_PlayMusic(),
_Mix_Playing(),
_Mix_CloseAudio(),
_Mix_OpenAudio();
native @nohold _SDL_Circle_vs_Mouse(),
_SDL_Circle_vs_Point(),
_SDL_Circle_vs_Circle(),
_SDL_Rect_vs_Mouse(),
_SDL_Rect_vs_Point(),
_SDL_Rect2Point(),
_SDL_Point2Rect(),
_SDL_Touch2Point();
native do
int SDL_Rect_vs_Mouse (SDL_Rect* r, SDL_MouseButtonEvent* but) {
return (but->x >= r->x) && (but->x <= r->x+r->w)
&& (but->y >= r->y) && (but->y <= r->y+r->h);
}
int SDL_Rect_vs_Point (SDL_Rect* r, SDL_Point* pt) {
return (pt->x >= r->x) && (pt->x <= r->x+r->w)
&& (pt->y >= r->y) && (pt->y <= r->y+r->h);
}
SDL_Point* SDL_Touch2Point (SDL_Point* pt, SDL_TouchFingerEvent* e, int w, int h) {
pt->x = e->x * w;
pt->y = e->y * h;
return pt;
}
SDL_Point SDL_Rect2Point (SDL_Rect* r) {
SDL_Point pt = { r->x+r->w/2, r->y+r->h/2 };
return pt;
}
SDL_Rect SDL_Point2Rect (SDL_Point* pt, int radix) {
SDL_Rect r = { pt->x-radix, pt->y-radix, radix*2, radix*2 };
return r;
}
##ifdef SDL_MATH
int SDL_Circle_vs_Mouse (SDL_Point* pos, int rad, SDL_MouseButtonEvent* but) {
SDL_Point pt = { but->x, but->y };
return SDL_Circle_vs_Point(pos, rad, &pt);
}
int SDL_Circle_vs_Point (SDL_Point* pos, int rad, SDL_Point* pt) {
return sqrt( pow(pos->x-pt->x,2) + pow(pos->y-pt->y,2) ) < rad;
}
int SDL_Circle_vs_Circle (SDL_Point* pos1, int rad1, SDL_Point* pos2, int rad2) {
return sqrt( pow(pos1->x-pos2->x,2) + pow(pos1->y-pos2->y,2) )
< rad1+rad2;
}
##endif
end
#endif