Skip to content

Commit 27738c4

Browse files
4B796C65@gmail.com4B796C65@gmail.com
authored andcommitted
KeyRepeat, getMap, SDL
1 parent 3af43d0 commit 27738c4

File tree

5 files changed

+76
-3
lines changed

5 files changed

+76
-3
lines changed

CHANGELOG.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
* added a method to iterate over all coordinates in a Console, getMap
12
* drawStr can be configured to scroll or raise an error
2-
3+
* You can now configure or disable key repeating with tdl.event.setKeyRepeat
4+
35
1.1.4
46
* Merged the Typewriter and MetaConsole classes,
57
You now have a virtual cursor with Console and Window objects

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
version='1.1.4',
1111
author='Kyle Stewart',
1212
author_email='4B796C65+pythonTDL@gmail.com',
13-
description='Simple graphical library for making a rogue-like or other tile-based video game.',
13+
description='Pythonic port of rogue-like library libtcod.',
1414
long_description="""python-tdl is a ctypes port of "libtcod".
1515
16-
The library is used for displaying tilesets (ansi, unicode, or graphical) in true color.
16+
The library is used for displaying tilesets (ANSI, Unicode, or graphical) in true color.
17+
18+
It also provides functionality to compute path-finding and field of view.
1719
""",
1820
url='http://code.google.com/p/python-tdl/',
1921
download_url='http://code.google.com/p/python-tdl/downloads/list',

tdl/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ def getSize(self):
632632
"""
633633
return self.width, self.height
634634

635+
def getMap(self):
636+
"""Return an iterator with every possible (x, y) value for this console."""
637+
return itertools.product(range(self.width), range(self.height))
638+
635639
def move(self, x, y):
636640
"""Move the virtual cursor.
637641

tdl/__tcod.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,47 @@ def _get_library_crossplatform():
5555
except NameError:
5656
c_bool = c_byte
5757

58+
# ---------------- SDL ----------------
59+
60+
class SDL_Rect(Structure):
61+
_fields_ = [('x', c_int16),
62+
('y', c_int16),
63+
('width', c_uint16),
64+
('height', c_uint16)]
65+
66+
class SDL_PixelFormat(Structure):
67+
_fields_ = [('palette', c_void_p),
68+
('BitsPerPixel', c_uint8),
69+
('BytesPerPixel', c_uint8),
70+
('Rloss', c_uint8),
71+
('Gloss', c_uint8),
72+
('Bloss', c_uint8),
73+
('Aloss', c_uint8),
74+
('Rshift', c_uint8),
75+
('Gshift', c_uint8),
76+
('Bshift', c_uint8),
77+
('Ashift', c_uint8),
78+
('Rmask', c_uint32),
79+
('Gmask', c_uint32),
80+
('Bmask', c_uint32),
81+
('Amask', c_uint32),
82+
('colorkey', c_uint32),
83+
('alpha', c_uint8),
84+
]
85+
86+
class SDL_Surface(Structure):
87+
_fields_ = [('flags', c_uint32),
88+
('PixelFormat', POINTER(SDL_PixelFormat)),
89+
('width', c_int),
90+
('height', c_int),
91+
('pitch', c_uint16),
92+
('pixels', c_void_p), # Read-write
93+
('rect', SDL_Rect),
94+
('refcount', c_int)
95+
]
96+
97+
# ---------------- libtcod ----------------
98+
5899
# COLOR
59100

60101
class _Color(Structure):
@@ -392,6 +433,15 @@ def __iter__(self):
392433
_lib.TCOD_sys_get_current_resolution.restype = None
393434
_lib.TCOD_sys_get_current_resolution.argtypes = (POINTER(c_int), POINTER(c_int))
394435

436+
_lib.TCOD_sys_clipboard_set.restype = None
437+
_lib.TCOD_sys_clipboard_set.argtypes = (c_char_p,)
438+
_lib.TCOD_sys_clipboard_get.restype = c_char_p
439+
_lib.TCOD_sys_clipboard_get.argtypes = ()
440+
441+
_RENDERCALL = CFUNCTYPE(None, POINTER(SDL_Surface))
442+
_lib.TCOD_sys_register_SDL_renderer.restype = None
443+
_lib.TCOD_sys_register_SDL_renderer.argtypes = None
444+
395445
# IMAGE
396446

397447
# TCOD_image_t = c_void_p

tdl/event.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,21 @@ def keyWait():
418418
return KeyDown('F4', '', True, False, True, False, False)
419419
time.sleep(.001)
420420

421+
def setKeyRepeat(delay=500, interval=0):
422+
"""Change or disable key repeat.
423+
424+
@type delay: int
425+
@param delay: Milliseconds before a held key begins to repeat.
426+
427+
Key repeat can be disabled entirely by setting a delay of zero.
428+
429+
@type interval: int
430+
@param interval: Milliseconds between key repeats.
431+
432+
An interval of zero will repeat every frame.
433+
"""
434+
_lib.TCOD_console_set_keyboard_repeat(delay, interval)
435+
421436
def isWindowClosed():
422437
"""Returns True if the exit button on the window has been clicked and
423438
stays True afterwards.

0 commit comments

Comments
 (0)