equal
deleted
inserted
replaced
8 |
8 |
9 from libcpp cimport bool |
9 from libcpp cimport bool |
10 |
10 |
11 |
11 |
12 cdef extern from "sdlterm.h": |
12 cdef extern from "sdlterm.h": |
13 enum EventType: |
13 cdef struct Event_key: |
14 pass |
14 char *keyname |
|
15 Py_UNICODE unicode |
15 |
16 |
16 union Event: |
17 cdef struct Event_mouse: |
17 EventType type |
18 int x, y |
|
19 int button |
|
20 |
|
21 cdef struct Event: |
|
22 # enum |
|
23 int QUIT |
|
24 int RESIZE |
|
25 int KEYPRESS |
|
26 int MOUSEDOWN |
|
27 int MOUSEUP |
|
28 int MOUSEMOVE |
|
29 int MOUSEWHEEL |
|
30 |
|
31 int type |
|
32 Event_key key |
|
33 Event_mouse mouse |
18 |
34 |
19 cdef cppclass Terminal: |
35 cdef cppclass Terminal: |
20 Terminal() except + |
36 Terminal() except + |
21 |
37 |
22 void select_font(char *fname_regular, char *fname_bold, int ptsize) |
38 void select_font(char *fname_regular, char *fname_bold, int ptsize) |
31 |
47 |
32 void set_cursor(int x, int y) |
48 void set_cursor(int x, int y) |
33 void show_cursor(bool visible) |
49 void show_cursor(bool visible) |
34 |
50 |
35 void get_next_event(Event event) |
51 void get_next_event(Event event) |
|
52 |
|
53 int get_width() |
|
54 int get_height() |
36 |
55 |
37 |
56 |
38 cdef class SDLTerminal: |
57 cdef class SDLTerminal: |
39 cdef Terminal *thisptr # hold a C++ instance which we're wrapping |
58 cdef Terminal *thisptr # hold a C++ instance which we're wrapping |
40 |
59 |
58 self.thisptr.commit() |
77 self.thisptr.commit() |
59 |
78 |
60 def get_next_event(self): |
79 def get_next_event(self): |
61 cdef Event event |
80 cdef Event event |
62 self.thisptr.get_next_event(event) |
81 self.thisptr.get_next_event(event) |
63 return dict() |
82 if event.type == event.MOUSEMOVE: |
|
83 return ('mousemove', event.mouse.x, event.mouse.y) |
|
84 if event.type == event.MOUSEDOWN: |
|
85 return ('mousedown', event.mouse.x, event.mouse.y, event.mouse.button) |
|
86 if event.type == event.MOUSEUP: |
|
87 return ('mouseup', event.mouse.x, event.mouse.y, event.mouse.button) |
|
88 if event.type == event.KEYPRESS: |
|
89 keyname = event.key.keyname |
|
90 if keyname: |
|
91 keyname = keyname.decode() |
|
92 else: |
|
93 keyname = None |
|
94 char = event.key.unicode |
|
95 if char == '\x00': |
|
96 char = None |
|
97 return ('keypress', keyname, char) |
|
98 if event.type == event.QUIT: |
|
99 return ('quit',) |
|
100 return ('unknown',) |
64 |
101 |
|
102 property width: |
|
103 def __get__(self): return self.thisptr.get_width() |
|
104 property height: |
|
105 def __get__(self): return self.thisptr.get_height() |
|
106 |