@@ -85,11 +85,12 @@ def _formatChar(char):
8585 """
8686 if char is None :
8787 return None
88- if isinstance (char , _INTTYPES ):
89- return char
88+ # if isinstance(char, _INTTYPES):
89+ # return char
9090 if isinstance (char , _STRTYPES ) and len (char ) == 1 :
9191 return ord (char )
92- raise TypeError ('Expected char parameter to be a single character string, number, or None, got: %s' % repr (char ))
92+ return int (char ) # conversion faster than type check
93+ #raise TypeError('Expected char parameter to be a single character string, number, or None, got: %s' % repr(char))
9394
9495_fontinitialized = False
9596_rootinitialized = False
@@ -139,19 +140,8 @@ def _iscolor(color):
139140# def __len__(self):
140141# return 3
141142
142- def _formatColor (color ):
143- """Format the color to ctypes
144- """
145- if color is None or color is False :
146- return color
147- if isinstance (color , _Color ):
148- return color
149- #if isinstance(color, Color):
150- # return color._getCType()
151- if isinstance (color , _INTTYPES ):
152- # format a web style color with the format 0xRRGGBB
153- return _Color (color >> 16 & 0xff , color >> 8 & 0xff , color & 0xff )
154- return _Color (* color )
143+ # Format the color to ctypes, will preserve None and False
144+ _formatColor = _Color .new
155145
156146def _getImageSize (filename ):
157147 """Try to get the width and height of a bmp of png image file"""
@@ -199,8 +189,11 @@ def _normalizePoint(self, x, y):
199189 Respects Pythons negative indexes. -1 starts at the bottom right.
200190 Replaces the _drawable function
201191 """
202- assert isinstance (x , _INTTYPES ), 'x must be an integer, got %s' % repr (x )
203- assert isinstance (y , _INTTYPES ), 'y must be an integer, got %s' % repr (y )
192+ #assert isinstance(x, _INTTYPES), 'x must be an integer, got %s' % repr(x)
193+ #assert isinstance(y, _INTTYPES), 'y must be an integer, got %s' % repr(y)
194+ # force int, always faster than type checking
195+ x = int (x )
196+ y = int (y )
204197
205198 assert (- self .width <= x < self .width ) and (- self .height <= y < self .height ), \
206199 ('(%i, %i) is an invalid postition on %s' % (x , y , self ))
@@ -263,6 +256,32 @@ def _lockColors(self, forceUpdate=False):
263256 _lib .TCOD_console_set_default_foreground (self .console , self .fgcolor )
264257 #
265258
259+ def setScrollMode (self , mode ):
260+ """Configure how this console will react to the cursor writing past the
261+ end if the console.
262+
263+ This is for methods that use the virtual cursor, such as L{printStr}.
264+
265+ @type mode: string
266+ @param mode: Possible settings are:
267+
268+ - 'error' - A TDLError will be raised once the cursor
269+ reaches the end of the console. Everything up until
270+ the error will still be drawn.
271+
272+ This is the default setting.
273+
274+ - 'scroll' - The console will scroll up as stuff is
275+ written to the end.
276+
277+ You can restrict the region with L{tdl.Window} when
278+ doing this.
279+ """
280+ MODES = ['error' , 'scroll' ]
281+ if mode .lower () not in MODES :
282+ raise TDLError ('mode must be one of %s, got %s' % (MODES , repr (mode )))
283+ self ._scrollMode = mode .lower ()
284+
266285 def setColors (self , fg = None , bg = None ):
267286 """Sets the colors to be used with the L{printStr} function.
268287
0 commit comments