forked from ceu-lang/ceu-sdl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.ceu
88 lines (71 loc) · 2 KB
/
ui.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
#ifndef _UI_CEU
#define _UI_CEU
#include "sdl.ceu"
native @const _UI_ALIGN_LEFT, _UI_ALIGN_CENTER, _UI_ALIGN_RIGHT,
_UI_ALIGN_TOP, _UI_ALIGN_MIDDLE, _UI_ALIGN_BOTTOM;
native @pure _UI_align(), _UI_align_bg();
#define UI_SDL_COLOR_REF(to,fr) \
finalize \
to = _SDL_COLOR_REF(fr);\
with \
nothing; \
end
native do
enum {
UI_ALIGN_LEFT = 0,
UI_ALIGN_CENTER,
UI_ALIGN_RIGHT
};
enum {
UI_ALIGN_TOP = 0,
UI_ALIGN_MIDDLE,
UI_ALIGN_BOTTOM,
};
int UI_align (int p, int dim, int align)
{
switch (align)
{
case UI_ALIGN_LEFT:
//case UI_ALIGN_TOP:
return p;
case UI_ALIGN_CENTER:
//case UI_ALIGN_MIDDLE:
return p - dim/2;
case UI_ALIGN_RIGHT:
//case UI_ALIGN_BOTTOM:
return p - dim;
}
}
int UI_align_bg (int p_out, int dim_out, int dim_in, int align)
{
switch (align)
{
case UI_ALIGN_LEFT:
//case UI_ALIGN_TOP:
return p_out;
case UI_ALIGN_CENTER:
//case UI_ALIGN_MIDDLE:
return p_out + (dim_out - dim_in)/2;
case UI_ALIGN_RIGHT:
//case UI_ALIGN_BOTTOM:
return p_out + (dim_out - dim_in);
}
}
end
interface UI with
//event void ok_redraw_pre;
//event void ok_redraw_pos;
event void ok_clicked;
//event _SDL_Point* go_move;
var _SDL_Renderer& ren;
var SDL_Rect rect;
var bool should_redim;
var SDL_Color? bg_clr;
var int align_x;
var int align_y;
var int align_bg_x;
var int align_bg_y;
function @rec (SDL_Rect* rect)=>void go;
function @rec (SDL_Rect* bg, bool should_redim_)=>void go_bg;
end
#endif