-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_sdl.aot.pyh
136 lines (131 loc) · 4.01 KB
/
module_sdl.aot.pyh
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
import <SDL/SDL.h>
static SDL_Surface *_sdl_window_surf = NULL;
static int _sdl_width = 0;
static int _sdl_height = 0;
##define(DEBUG_SDL=1)
class sdlwrapper(object):
def initialize(self):
if SDL_Init(SDL_INIT_VIDEO) < 0:
print("WARN: could not init sdl video")
def quit(self):
SDL_Quit()
def flip(self):
##SDL_UpdateRect(_sdl_window_surf, 0,0,0,0);
SDL_Flip( SDL_GetVideoSurface() )
def clear(self, clr):
int r = clr[0].number.val
int g = clr[1].number.val
int b = clr[2].number.val
SDL_Rect rect
rect.x = 0;
rect.y = 0;
rect.w = _sdl_width;
rect.h = _sdl_height;
Uint32 c = SDL_MapRGB(_sdl_window_surf->format,r,g,b)
SDL_FillRect(_sdl_window_surf, &rect, c)
def delay(self, ms):
if defined(__EMSCRIPTEN_major__):
pass
else:
SDL_Delay( int(ms) )
##################################
def window(self, sz):
global _sdl_width, _sdl_height, _sdl_window_surf
print("sdl_create_window....")
int w = sz[0]
int h = sz[1]
_sdl_width = w
_sdl_height = h
_sdl_window_surf = SDL_SetVideoMode( w, h, 32, SDL_SWSURFACE )
if not _sdl_window_surf:
print("SDL ERROR: could not get sdl surface from window")
raise RuntimeError("SDL ERROR: could not get sdl surface from window")
def draw(self, pos, clr):
if defined(DEBUG_SDL):
print(pos)
print(clr)
SDL_Rect r;
r.x = pos[0].number.val;
r.y = pos[1].number.val;
if pos.type.type_id==TP_VEC2:
r.w = 1;
r.h = 1;
elif pos.type.type_id==TP_QUAT:
r.w = pos[2].number.val;
r.h = pos[3].number.val;
elif len(pos) == 4:
r.w = pos[2].number.val;
r.h = pos[3].number.val;
else:
r.w = 1;
r.h = 1;
int red = clr[0].number.val;
int gre = clr[1].number.val;
int blu = clr[2].number.val;
if defined(DEBUG_SDL):
std::cout << " rect(" << r.x << "," << r.y << "," << r.w << "," << r.h << ")" << std::endl;
std::cout << " color(" << red << "," << gre << "," << blu << ")" << std::endl;
Uint32 c = SDL_MapRGB(_sdl_window_surf->format,red,gre,blu)
SDL_FillRect(_sdl_window_surf, &r, c)
def poll(self):
SDL_Event e;
#tp_obj r = tp_list(tp);
#tp_obj r = tp_tiny_list()
self._events.lst.val->clear()
tp_obj r = self._events
int num_events = -1
tp_obj d
while SDL_PollEvent(&e) and num_events+1 < TINY_LIST_MAX_SIZE:
#tp_obj d = tp_extern_interface()
#tp_set(tp,d, "type", tp_number(e.type));
#d.set("type", tp_number(e.type))
#d.set("type", "SOME_EVENT")
switch e.type:
case SDL_KEYDOWN:
r.lst.val->end ++
d = r.lst.val->items[++num_events]
d.set("type", "KEYDOWN");
d.set("key", tp_number(e.key.keysym.scancode));
d.set("sym", tp_number(e.key.keysym.sym));
d.set("mod", tp_number(e.key.keysym.mod));
break;
case SDL_KEYUP:
r.lst.val->end ++
d = r.lst.val->items[++num_events]
d.set("type", "KEYUP");
d.set("key", tp_number(e.key.keysym.scancode));
d.set("sym", tp_number(e.key.keysym.sym));
d.set("mod", tp_number(e.key.keysym.mod));
break;
case SDL_MOUSEMOTION:
r.lst.val->end ++
d = r.lst.val->items[++num_events]
d.set("type", "MOUSE");
d.set("x", tp_number(e.motion.x));
d.set("y", tp_number(e.motion.y));
d.set("rx", tp_number(e.motion.xrel));
d.set("ry", tp_number(e.motion.yrel));
d.set("state", tp_number(e.motion.state));
break;
case SDL_MOUSEBUTTONDOWN:
r.lst.val->end ++
d = r.lst.val->items[++num_events]
d.set("type", "PRESS");
d.set("x", tp_number(e.button.x));
d.set("y", tp_number(e.button.y));
d.set("button", tp_number(e.button.button));
break;
case SDL_MOUSEBUTTONUP:
r.lst.val->end ++
d = r.lst.val->items[++num_events]
d.set("type", "CLICK");
d.set("x", tp_number(e.button.x));
d.set("y", tp_number(e.button.y));
d.set("button", tp_number(e.button.button));
break;
return r
def __init__(self):
##self._events = [tp_extern_interface()] * TINY_LIST_MAX_SIZE
self._events = tp_tiny_list()
for i in range(TINY_LIST_MAX_SIZE-1):
self._events.lst.val->append(tp_extern_interface())