|
1
|
|
|
|
|
|
|
|
|
|
2
|
|
|
from .libtcod import _lib, _ffi, _int, _bytes, _unpack_char_p, _PropagateException |
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
# high precision time functions |
|
5
|
|
|
def sys_set_fps(fps): |
|
6
|
|
|
"""Set the maximum frame rate. |
|
7
|
|
|
|
|
8
|
|
|
You can disable the frame limit again by setting fps to 0. |
|
9
|
|
|
|
|
10
|
|
|
:param int fps: A frame rate limit (i.e. 60) |
|
11
|
|
|
""" |
|
12
|
|
|
_lib.TCOD_sys_set_fps(fps) |
|
13
|
|
|
|
|
14
|
|
|
def sys_get_fps(): |
|
15
|
|
|
"""Return the current frames per second. |
|
16
|
|
|
|
|
17
|
|
|
This the actual frame rate, not the frame limit set by |
|
18
|
|
|
:any:`tcod.sys_set_fps`. |
|
19
|
|
|
|
|
20
|
|
|
This number is updated every second. |
|
21
|
|
|
|
|
22
|
|
|
:rtype: int |
|
23
|
|
|
""" |
|
24
|
|
|
return _lib.TCOD_sys_get_fps() |
|
25
|
|
|
|
|
26
|
|
|
def sys_get_last_frame_length(): |
|
27
|
|
|
"""Return the delta time of the last rendered frame in seconds. |
|
28
|
|
|
|
|
29
|
|
|
:rtype: float |
|
30
|
|
|
""" |
|
31
|
|
|
return _lib.TCOD_sys_get_last_frame_length() |
|
32
|
|
|
|
|
33
|
|
|
def sys_sleep_milli(val): |
|
34
|
|
|
"""Sleep for 'val' milliseconds. |
|
35
|
|
|
|
|
36
|
|
|
:param int val: Time to sleep for in milliseconds. |
|
37
|
|
|
|
|
38
|
|
|
.. deprecated:: 2.0 |
|
39
|
|
|
Use :any:`time.sleep` instead. |
|
40
|
|
|
""" |
|
41
|
|
|
_lib.TCOD_sys_sleep_milli(val) |
|
42
|
|
|
|
|
43
|
|
|
def sys_elapsed_milli(): |
|
44
|
|
|
"""Get number of milliseconds since the start of the program. |
|
45
|
|
|
|
|
46
|
|
|
:rtype: int |
|
47
|
|
|
|
|
48
|
|
|
.. deprecated:: 2.0 |
|
49
|
|
|
Use :any:`time.clock` instead. |
|
50
|
|
|
""" |
|
51
|
|
|
return _lib.TCOD_sys_elapsed_milli() |
|
52
|
|
|
|
|
53
|
|
|
def sys_elapsed_seconds(): |
|
54
|
|
|
"""Get number of seconds since the start of the program. |
|
55
|
|
|
|
|
56
|
|
|
:rtype: float |
|
57
|
|
|
|
|
58
|
|
|
.. deprecated:: 2.0 |
|
59
|
|
|
Use :any:`time.clock` instead. |
|
60
|
|
|
""" |
|
61
|
|
|
return _lib.TCOD_sys_elapsed_seconds() |
|
62
|
|
|
|
|
63
|
|
|
def sys_set_renderer(renderer): |
|
64
|
|
|
"""Change the current rendering mode to renderer. |
|
65
|
|
|
|
|
66
|
|
|
.. deprecated:: 2.0 |
|
67
|
|
|
RENDERER_GLSL and RENDERER_OPENGL are not currently available. |
|
68
|
|
|
""" |
|
69
|
|
|
_lib.TCOD_sys_set_renderer(renderer) |
|
70
|
|
|
|
|
71
|
|
|
def sys_get_renderer(): |
|
72
|
|
|
"""Return the current rendering mode. |
|
73
|
|
|
|
|
74
|
|
|
""" |
|
75
|
|
|
return _lib.TCOD_sys_get_renderer() |
|
76
|
|
|
|
|
77
|
|
|
# easy screenshots |
|
78
|
|
|
def sys_save_screenshot(name=None): |
|
79
|
|
|
"""Save a screenshot to a file. |
|
80
|
|
|
|
|
81
|
|
|
By default this will automatically save screenshots in the working |
|
82
|
|
|
directory. |
|
83
|
|
|
|
|
84
|
|
|
The automatic names are formatted as screenshotNNN.png. For example: |
|
85
|
|
|
screenshot000.png, screenshot001.png, etc. Whichever is available first. |
|
86
|
|
|
|
|
87
|
|
|
:param str file: File path to save screenshot. |
|
88
|
|
|
|
|
89
|
|
|
""" |
|
90
|
|
|
if name is not None: |
|
91
|
|
|
name = _bytes(name) |
|
92
|
|
|
_lib.TCOD_sys_save_screenshot(name or _ffi.NULL) |
|
93
|
|
|
|
|
94
|
|
|
# custom fullscreen resolution |
|
95
|
|
|
def sys_force_fullscreen_resolution(width, height): |
|
96
|
|
|
"""Force a specific resolution in fullscreen. |
|
97
|
|
|
|
|
98
|
|
|
Will use the smallest available resolution so that: |
|
99
|
|
|
|
|
100
|
|
|
* resolution width >= width and |
|
101
|
|
|
resolution width >= root console width * font char width |
|
102
|
|
|
* resolution height >= height and |
|
103
|
|
|
resolution height >= root console height * font char height |
|
104
|
|
|
""" |
|
105
|
|
|
_lib.TCOD_sys_force_fullscreen_resolution(width, height) |
|
106
|
|
|
|
|
107
|
|
|
def sys_get_current_resolution(): |
|
108
|
|
|
"""Return the current resolution as (width, height)""" |
|
109
|
|
|
w = _ffi.new('int *') |
|
110
|
|
|
h = _ffi.new('int *') |
|
111
|
|
|
_lib.TCOD_sys_get_current_resolution(w, h) |
|
112
|
|
|
return w[0], h[0] |
|
113
|
|
|
|
|
114
|
|
|
def sys_get_char_size(): |
|
115
|
|
|
"""Return the current fonts character size as (width, height)""" |
|
116
|
|
|
w = _ffi.new('int *') |
|
117
|
|
|
h = _ffi.new('int *') |
|
118
|
|
|
_lib.TCOD_sys_get_char_size(w, h) |
|
119
|
|
|
return w[0], h[0] |
|
120
|
|
|
|
|
121
|
|
|
# update font bitmap |
|
122
|
|
|
def sys_update_char(asciiCode, fontx, fonty, img, x, y) : |
|
|
|
|
|
|
123
|
|
|
"""Dynamically update the current frot with img. |
|
124
|
|
|
|
|
125
|
|
|
All cells using this asciiCode will be updated |
|
126
|
|
|
at the next call to :any:`tcod.console_flush`. |
|
127
|
|
|
|
|
128
|
|
|
:param int asciiCode: Ascii code corresponding to the character to update. |
|
129
|
|
|
:param int fontx: Left coordinate of the character |
|
130
|
|
|
in the bitmap font (in tiles) |
|
131
|
|
|
:param int fonty: Top coordinate of the character |
|
132
|
|
|
in the bitmap font (in tiles) |
|
133
|
|
|
:param img: An image containing the new character bitmap. |
|
134
|
|
|
:param int x: Left pixel of the character in the image. |
|
135
|
|
|
:param int y: Top pixel of the character in the image. |
|
136
|
|
|
""" |
|
137
|
|
|
_lib.TCOD_sys_update_char(_int(asciiCode), fontx, fonty, img, x, y) |
|
138
|
|
|
|
|
139
|
|
|
def sys_register_SDL_renderer(callback): |
|
140
|
|
|
"""Register a custom randering function with libtcod. |
|
141
|
|
|
|
|
142
|
|
|
The callack will receive a :any:`CData <ffi-cdata>` void* to an |
|
143
|
|
|
SDL_Surface* struct. |
|
144
|
|
|
|
|
145
|
|
|
The callback is called on every call to :any:`tcod.console_flush`. |
|
146
|
|
|
|
|
147
|
|
|
:param callable callback: A function which takes a single argument. |
|
148
|
|
|
""" |
|
149
|
|
|
with _PropagateException() as propagate: |
|
150
|
|
|
@_ffi.def_extern(onerror=propagate) |
|
151
|
|
|
def _pycall_sdl_hook(sdl_surface): |
|
|
|
|
|
|
152
|
|
|
callback(sdl_surface) |
|
153
|
|
|
_lib.TCOD_sys_register_SDL_renderer(_lib._pycall_sdl_hook) |
|
154
|
|
|
|
|
155
|
|
|
def sys_check_for_event(mask, k, m): |
|
156
|
|
|
"""Check for events. |
|
157
|
|
|
|
|
158
|
|
|
mask can be any of the following: |
|
159
|
|
|
|
|
160
|
|
|
* tcod.EVENT_NONE |
|
161
|
|
|
* tcod.EVENT_KEY_PRESS |
|
162
|
|
|
* tcod.EVENT_KEY_RELEASE |
|
163
|
|
|
* tcod.EVENT_KEY |
|
164
|
|
|
* tcod.EVENT_MOUSE_MOVE |
|
165
|
|
|
* tcod.EVENT_MOUSE_PRESS |
|
166
|
|
|
* tcod.EVENT_MOUSE_RELEASE |
|
167
|
|
|
* tcod.EVENT_MOUSE |
|
168
|
|
|
* tcod.EVENT_FINGER_MOVE |
|
169
|
|
|
* tcod.EVENT_FINGER_PRESS |
|
170
|
|
|
* tcod.EVENT_FINGER_RELEASE |
|
171
|
|
|
* tcod.EVENT_FINGER |
|
172
|
|
|
* tcod.EVENT_ANY |
|
173
|
|
|
|
|
174
|
|
|
:param mask: Event types to wait for. |
|
175
|
|
|
:param Key k: :any:`tcod.Key` instance which might be updated with |
|
176
|
|
|
an event. Can be None. |
|
177
|
|
|
|
|
178
|
|
|
:param Mouse m: :any:`tcod.Mouse` instance which might be updated |
|
179
|
|
|
with an event. Can be None. |
|
180
|
|
|
""" |
|
181
|
|
|
k = _ffi.NULL if k is None else k._struct |
|
182
|
|
|
m = _ffi.NULL if m is None else m._struct |
|
183
|
|
|
return _lib.TCOD_sys_check_for_event(mask, k, m) |
|
184
|
|
|
|
|
185
|
|
|
def sys_wait_for_event(mask, k, m, flush) : |
|
|
|
|
|
|
186
|
|
|
"""Wait for events. |
|
187
|
|
|
|
|
188
|
|
|
mask can be any of the following: |
|
189
|
|
|
|
|
190
|
|
|
* tcod.EVENT_NONE |
|
191
|
|
|
* tcod.EVENT_KEY_PRESS |
|
192
|
|
|
* tcod.EVENT_KEY_RELEASE |
|
193
|
|
|
* tcod.EVENT_KEY |
|
194
|
|
|
* tcod.EVENT_MOUSE_MOVE |
|
195
|
|
|
* tcod.EVENT_MOUSE_PRESS |
|
196
|
|
|
* tcod.EVENT_MOUSE_RELEASE |
|
197
|
|
|
* tcod.EVENT_MOUSE |
|
198
|
|
|
* tcod.EVENT_FINGER_MOVE |
|
199
|
|
|
* tcod.EVENT_FINGER_PRESS |
|
200
|
|
|
* tcod.EVENT_FINGER_RELEASE |
|
201
|
|
|
* tcod.EVENT_FINGER |
|
202
|
|
|
* tcod.EVENT_ANY |
|
203
|
|
|
|
|
204
|
|
|
If flush is True then the buffer will be cleared before waiting. Otherwise |
|
205
|
|
|
each available event will be returned in the order they're recieved. |
|
206
|
|
|
|
|
207
|
|
|
:param mask: Event types to wait for. |
|
208
|
|
|
:param Key k: :any:`tcod.Key` instance which might be updated with |
|
209
|
|
|
an event. Can be None. |
|
210
|
|
|
|
|
211
|
|
|
:param Mouse m: :any:`tcod.Mouse` instance which might be updated |
|
212
|
|
|
with an event. Can be None. |
|
213
|
|
|
|
|
214
|
|
|
:param bool flush: Clear the buffer before waiting. |
|
215
|
|
|
""" |
|
216
|
|
|
k = _ffi.NULL if k is None else k._struct |
|
217
|
|
|
m = _ffi.NULL if m is None else m._struct |
|
218
|
|
|
return _lib.TCOD_sys_wait_for_event(mask, k, m, flush) |
|
219
|
|
|
|
|
220
|
|
|
def clipboard_set(string): |
|
221
|
|
|
"""Set the clipboard contents to string. |
|
222
|
|
|
|
|
223
|
|
|
.. versionadded:: 2.0 |
|
224
|
|
|
""" |
|
225
|
|
|
_lib.TCOD_sys_clipboard_set(_bytes(string)) |
|
226
|
|
|
|
|
227
|
|
|
def clipboard_get(): |
|
228
|
|
|
"""Return the current contents of the clipboard. |
|
229
|
|
|
|
|
230
|
|
|
.. versionadded:: 2.0 |
|
231
|
|
|
""" |
|
232
|
|
|
return _unpack_char_p(_lib.TCOD_sys_clipboard_get()) |
|
233
|
|
|
|
|
234
|
|
|
__all__ = [_name for _name in list(globals()) if _name[0] != '_'] |
|
235
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.