5555
5656 After the drawing functions are called a call to L{tdl.flush} will update
5757 the screen.
58+
59+ @undocumented: style
5860"""
5961
6062import sys as _sys
@@ -183,17 +185,20 @@ class _BaseConsole(object):
183185 getCursor getSize getChar printStr setColors setMode
184186 @group Drawing Methods: draw_*, blit, clear
185187 @group Printing Methods: print_*, move, set_colors, set_mode, write, get_cursor
188+
189+ @undocumented: console
190+ @ivar width: The width of this console in tiles. Do not overwrite this.
191+ @ivar height: The height of this console in tiles. Do not overwrite this.
186192 """
187193 __slots__ = ('width' , 'height' , 'console' , '_cursor' , '_fg' ,
188- '_bg' , '_blend' , '_colorLock' , ' __weakref__' , '__dict__' )
194+ '_bg' , '_blend' , '__weakref__' , '__dict__' )
189195
190196 def __init__ (self ):
191197 self ._cursor = (0 , 0 )
192198 self ._scrollMode = 'error'
193199 self ._fg = _format_color ((255 , 255 , 255 ))
194200 self ._bg = _format_color ((0 , 0 , 0 ))
195201 self ._blend = _lib .TCOD_BKGND_SET
196- self ._colorLock = None # which object sets the ctype color options
197202
198203 def _normalizePoint (self , x , y ):
199204 """Check if a point is in bounds and make minor adjustments.
@@ -388,7 +393,7 @@ def draw_char(self, x, y, char, fg=Ellipsis, bg=Ellipsis):
388393 @see: L{get_char}
389394 """
390395 #x, y = self._normalizePoint(x, y)
391- _put_char_ex (self ._as_parameter_ , x , y , _format_char (char ),
396+ _put_char_ex (self .tcod_console , x , y , _format_char (char ),
392397 _format_color (fg , self ._fg ), _format_color (bg , self ._bg ), 1 )
393398
394399 def draw_str (self , x , y , string , fg = Ellipsis , bg = Ellipsis ):
@@ -600,15 +605,15 @@ def blit(self, source, x=0, y=0, width=None, height=None, srcX=0, srcY=0):
600605 # onto the data, otherwise it tries to copy into itself and
601606 # starts destroying everything
602607 tmp = Console (width , height )
603- _lib .TCOD_console_blit (source ._as_parameter_ ,
608+ _lib .TCOD_console_blit (source .tcod_console ,
604609 srcX , srcY , width , height ,
605- tmp ._as_parameter_ , 0 , 0 , fgalpha , bgalpha )
606- _lib .TCOD_console_blit (tmp ._as_parameter_ , 0 , 0 , width , height ,
607- self ._as_parameter_ , x , y , fgalpha , bgalpha )
610+ tmp .tcod_console , 0 , 0 , fgalpha , bgalpha )
611+ _lib .TCOD_console_blit (tmp .tcod_console , 0 , 0 , width , height ,
612+ self .tcod_console , x , y , fgalpha , bgalpha )
608613 else :
609- _lib .TCOD_console_blit (source ._as_parameter_ ,
614+ _lib .TCOD_console_blit (source .tcod_console ,
610615 srcX , srcY , width , height ,
611- self ._as_parameter_ , x , y , fgalpha , bgalpha )
616+ self .tcod_console , x , y , fgalpha , bgalpha )
612617
613618 def get_cursor (self ):
614619 """Return the virtual cursor position.
@@ -781,9 +786,16 @@ class Console(_BaseConsole):
781786 can be drawn on before being L{blit} to the root console.
782787
783788 @undocumented: getChar
789+
790+ @ivar tcod_console: Public interface to the cffi TCOD_console_t object
791+ of this instance.
792+
793+ Feel free to pass this variable to libtcod-cffi calls
794+ but keep in mind that as soon as Console instance is
795+ garbage collected the tcod_console will be deleted.
784796 """
785797
786- __slots__ = ('_as_parameter_' , '_typewriter' )
798+ __slots__ = ('tcod_console' , )
787799
788800 def __init__ (self , width , height ):
789801 """Create a new offscreen console.
@@ -796,23 +808,20 @@ def __init__(self, width, height):
796808 _BaseConsole .__init__ (self )
797809 if not _rootinitialized :
798810 raise TDLError ('Can not create Console instances before a call to tdl.init' )
799- self ._as_parameter_ = _lib .TCOD_console_new (width , height )
811+ self .tcod_console = _lib .TCOD_console_new (width , height )
800812 self .console = self
801813 self .width = width
802814 self .height = height
803- self ._typewriter = None # "typewriter lock", makes sure the colors are set to the typewriter
804- # will be phased out with the Typewriter class
805815
806816 @classmethod
807817 def _newConsole (cls , console ):
808818 """Make a Console instance, from a console ctype"""
809819 self = cls .__new__ (cls )
810820 _BaseConsole .__init__ (self )
811- self ._as_parameter_ = console
821+ self .tcod_console = console
812822 self .console = self
813823 self .width = _lib .TCOD_console_get_width (console )
814824 self .height = _lib .TCOD_console_get_height (console )
815- self ._typewriter = None
816825 return self
817826
818827 def _root_unhook (self ):
@@ -825,29 +834,29 @@ def _root_unhook(self):
825834 if (_rootConsoleRef and _rootConsoleRef () is self ):
826835 # turn this console into a regular console
827836 unhooked = _lib .TCOD_console_new (self .width , self .height )
828- _lib .TCOD_console_blit (self ._as_parameter_ ,
837+ _lib .TCOD_console_blit (self .tcod_console ,
829838 0 , 0 , self .width , self .height ,
830839 unhooked , 0 , 0 , 1 , 1 )
831840 # delete root console from TDL and TCOD
832841 _rootinitialized = False
833842 _rootConsoleRef = None
834- _lib .TCOD_console_delete (self ._as_parameter_ )
843+ _lib .TCOD_console_delete (self .tcod_console )
835844 # this Console object is now a regular console
836- self ._as_parameter_ = unhooked
845+ self .tcod_console = unhooked
837846
838847 def __del__ (self ):
839848 """
840849 If the main console is garbage collected then the window will be closed as well
841850 """
842- if self ._as_parameter_ is None :
851+ if self .tcod_console is None :
843852 return # this console was already deleted
844- if self ._as_parameter_ is _ffi .NULL :
853+ if self .tcod_console is _ffi .NULL :
845854 # a pointer to the special root console
846855 self ._root_unhook () # unhook the console and leave it to the GC
847856 return
848857 # this is a normal console pointer and can be safely deleted
849- _lib .TCOD_console_delete (self ._as_parameter_ )
850- self ._as_parameter_ = None
858+ _lib .TCOD_console_delete (self .tcod_console )
859+ self .tcod_console = None
851860
852861 def __copy__ (self ):
853862 # make a new class and blit
@@ -868,21 +877,6 @@ def __setstate__(self, state):
868877 for (x , y ), graphic in zip (_itertools .product (range (width ),
869878 range (height )), data ):
870879 self .draw_char (x , y , * graphic )
871-
872- def _replace (self , console ):
873- """Used internally
874-
875- Mostly used just to replace this Console object with the root console
876- If another Console object is used then they are swapped
877- """
878- if isinstance (console , Console ):
879- self ._as_parameter_ , console ._as_parameter_ = \
880- console ._as_parameter_ , self ._as_parameter_ # swap tcod consoles
881- else :
882- self ._as_parameter_ = console
883- self .width = _lib .TCOD_console_get_width (self ._as_parameter_ )
884- self .height = _lib .TCOD_console_get_height (self ._as_parameter_ )
885- return self
886880
887881 def _translate (self , x , y ):
888882 """Convertion x and y to their position on the root Console for this Window
@@ -894,14 +888,13 @@ def _translate(self, x, y):
894888 def clear (self , fg = Ellipsis , bg = Ellipsis ):
895889 # inherit docstring
896890 assert fg is not None and bg is not None , 'Can not use None with clear'
897- self ._typewriter = None
898891 fg = _format_color (fg , self ._fg )
899892 bg = _format_color (bg , self ._bg )
900- _lib .TCOD_console_set_default_foreground (self ._as_parameter_ ,
893+ _lib .TCOD_console_set_default_foreground (self .tcod_console ,
901894 _to_tcod_color (fg )[0 ])
902- _lib .TCOD_console_set_default_background (self ._as_parameter_ ,
895+ _lib .TCOD_console_set_default_background (self .tcod_console ,
903896 _to_tcod_color (bg )[0 ])
904- _lib .TCOD_console_clear (self ._as_parameter_ )
897+ _lib .TCOD_console_clear (self .tcod_console )
905898
906899
907900 def _set_char (self , x , y , char , fg = None , bg = None ,
@@ -914,7 +907,7 @@ def _set_char(self, x, y, char, fg=None, bg=None,
914907 AT ALL, it's up to the drawing functions to use the functions:
915908 _format_char and _format_color before passing to this."""
916909 # values are already formatted, honestly this function is redundant
917- return _put_char_ex (self ._as_parameter_ , x , y , char , fg , bg , bgblend )
910+ return _put_char_ex (self .tcod_console , x , y , char , fg , bg , bgblend )
918911
919912 def _set_batch (self , batch , fg , bg , bgblend = 1 , nullChar = False ):
920913 """
@@ -932,9 +925,9 @@ def _set_batch(self, batch, fg, bg, bgblend=1, nullChar=False):
932925 def get_char (self , x , y ):
933926 # inherit docstring
934927 x , y = self ._normalizePoint (x , y )
935- char = _lib .TCOD_console_get_char (self ._as_parameter_ , x , y )
936- bg = _lib .TCOD_console_get_char_background (self ._as_parameter_ , x , y )
937- fg = _lib .TCOD_console_get_char_foreground (self ._as_parameter_ , x , y )
928+ char = _lib .TCOD_console_get_char (self .tcod_console , x , y )
929+ bg = _lib .TCOD_console_get_char_background (self .tcod_console , x , y )
930+ fg = _lib .TCOD_console_get_char_foreground (self .tcod_console , x , y )
938931 return char , (fg .r , fg .g , fg .b ), (bg .r , bg .g , bg .b )
939932
940933 def __repr__ (self ):
0 commit comments