Skip to content

Commit d4d3fda

Browse files
committed
added set_color_key method, updated docstrings
1 parent f8d3bc9 commit d4d3fda

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tdl/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ class TDLError(Exception):
172172
"""
173173

174174
class Color(object):
175+
"""A simple mutable color class.
176+
177+
Can be initialized in multiple ways::
178+
179+
color = tdl.Color(255, 0, 255) # from 3 items
180+
color = tdl.Color(0xff00ff) # from 0xRRGGBB
181+
color = tdl.Color(color) # copy a color instance
182+
183+
@since: 1.5.0
184+
"""
175185

176186
def __new__(cls, *rgb):
177187
if not rgb:
@@ -271,6 +281,12 @@ class _BaseConsole(object):
271281
@undocumented: console
272282
@ivar width: The width of this console in tiles. Do not overwrite this.
273283
@ivar height: The height of this console in tiles. Do not overwrite this.
284+
@ivar ch: Access character data
285+
@since: 1.5.0
286+
@ivar fg: Access foreground colors
287+
@since: 1.5.0
288+
@ivar bg: Access background colors
289+
@since: 1.5.0
274290
"""
275291

276292
class _ConsoleAttribute(object):
@@ -344,6 +360,7 @@ def __init__(self):
344360
self._default_fg = _format_color((255, 255, 255))
345361
self._default_bg = _format_color((0, 0, 0))
346362
self._default_blend = _lib.TCOD_BKGND_SET
363+
self._color_key = _ffi.NULL
347364

348365
def _normalizePoint(self, x, y):
349366
"""Check if a point is in bounds and make minor adjustments.
@@ -447,6 +464,25 @@ def set_colors(self, fg=None, bg=None):
447464
if bg is not None:
448465
self._default_bg = _format_color(bg, self._default_bg)
449466

467+
def set_color_key(self, bg=None):
468+
"""Sets the transparent color key of this instance.
469+
470+
@type bg: (r, g, b), int, or None
471+
@param bg: If the background color of the Console matches this color
472+
then the tile will not be copied during a L{blit}.
473+
474+
Can be set to None to disable the color key.
475+
476+
@see: L{blit},
477+
@since: 1.5.0
478+
"""
479+
bg = _format_color(bg, -1)
480+
if bg == -1:
481+
bg = _ffi.NULL
482+
else:
483+
bg = _ffi.new('TCOD_color_t *', bg)
484+
self._color_key = bg
485+
450486
def print_str(self, string):
451487
"""Print a string at the virtual cursor.
452488
@@ -737,12 +773,17 @@ def blit(self, source, x=0, y=0, width=None, height=None, srcX=0, srcY=0):
737773
x, y, width, height = self._normalizeRect(x, y, width, height)
738774
srcX, srcY, width, height = source._normalizeRect(srcX, srcY, width, height)
739775

776+
# set key color of console cdata to current Console or Window instance
777+
_lib.TCOD_console_set_key_color(source.console.tcod_console,
778+
source._color_key)
779+
740780
# translate source and self if any of them are Window instances
741781
srcX, srcY = source._translate(srcX, srcY)
742782
source = source.console
743783
x, y = self._translate(x, y)
744784
self = self.console
745785

786+
746787
if self == source:
747788
# if we are the same console then we need a third console to hold
748789
# onto the data, otherwise it tries to copy into itself and

0 commit comments

Comments
 (0)