@@ -172,6 +172,16 @@ class TDLError(Exception):
172
172
"""
173
173
174
174
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
+ """
175
185
176
186
def __new__ (cls , * rgb ):
177
187
if not rgb :
@@ -271,6 +281,12 @@ class _BaseConsole(object):
271
281
@undocumented: console
272
282
@ivar width: The width of this console in tiles. Do not overwrite this.
273
283
@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
274
290
"""
275
291
276
292
class _ConsoleAttribute (object ):
@@ -344,6 +360,7 @@ def __init__(self):
344
360
self ._default_fg = _format_color ((255 , 255 , 255 ))
345
361
self ._default_bg = _format_color ((0 , 0 , 0 ))
346
362
self ._default_blend = _lib .TCOD_BKGND_SET
363
+ self ._color_key = _ffi .NULL
347
364
348
365
def _normalizePoint (self , x , y ):
349
366
"""Check if a point is in bounds and make minor adjustments.
@@ -447,6 +464,25 @@ def set_colors(self, fg=None, bg=None):
447
464
if bg is not None :
448
465
self ._default_bg = _format_color (bg , self ._default_bg )
449
466
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
+
450
486
def print_str (self , string ):
451
487
"""Print a string at the virtual cursor.
452
488
@@ -737,12 +773,17 @@ def blit(self, source, x=0, y=0, width=None, height=None, srcX=0, srcY=0):
737
773
x , y , width , height = self ._normalizeRect (x , y , width , height )
738
774
srcX , srcY , width , height = source ._normalizeRect (srcX , srcY , width , height )
739
775
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
+
740
780
# translate source and self if any of them are Window instances
741
781
srcX , srcY = source ._translate (srcX , srcY )
742
782
source = source .console
743
783
x , y = self ._translate (x , y )
744
784
self = self .console
745
785
786
+
746
787
if self == source :
747
788
# if we are the same console then we need a third console to hold
748
789
# onto the data, otherwise it tries to copy into itself and
0 commit comments