Source code for codex.canvas

"""A rectangular area for graphics and other child objects.

The Canvas is a basic rectangular area on the screen where you can draw lines, 
text, images, and more. You can also add other child objects to a parent 
Canvas. The children are drawn on top of their parents.

POSITION:
    Every Canvas has an X,Y position on its parent Canvas. This position is 
    the X,Y coordinate of the upper-left corner of the child relative to its 
    parent. The position may be changed at any time to move the child around 
    on top of its parent.

    Position values may be negative. An object may be positioned partially or
    fully off of the parent. Child objects are clipped to their parent Canvas.        

BITMAP:
    A Canvas is a `Bitmap` you can draw on with the `Bitmap` functions.
"""

import bitmap
import colors

[docs]class Canvas(bitmap.Bitmap): """A rectangular area for graphics and other child objects.""" def __init__(self, width, height, x=0, y=0, scale=1, transparent_color=colors.TRANSPARENT): """Create a new Canvas. A Canvas has a simple bitmap background. In fact, a Canvas IS a Bitmap with some added features. The Canvas manages a list of child objects (like other Canvases) that are drawn on top of their parent Canvas. Args: width (int): The width (in pixels) of the Canvas. height (int): The height (in pixels) of the Canvas. x (int, optional): The x coordinate relative to the parent object. Defaults to 0. y (int, optional): The y coordinate relative to the parent object. Defaults to 0. scale (int, optional): transparent_color (bool, optional): The pixel value considered to be transparent (default is colors.TRANSPARENT). """ # Implemented in C pass @property def x(self): """Get or set this object's X coordinate relative to its parent.""" # Implemented in C pass @x.setter def x(self,value): # Implemented in C pass @property def y(self): """Get or set this object's Y coordinate relative to its parent.""" # Implemented in C pass @y.setter def y(self,value): # Implemented in C pass
[docs] def show(self, obj): """ Show the given text or Image on the display. This method renders the given text or picture. This is a "simplifier" function for the curriculum. It clears the screen and scales images for simple display. You probably want 'draw_text' and 'draw_image' for most applications. Args: obj (str or Image) : The text or image to display. """ # Implemented in C pass
[docs] def print(self, obj, color=colors.WHITE, cursor_x=None, cursor_y=None, scale=2, end='\n', background=colors.BLACK): """Print a text string onto this Canvas. Writes/scrolls the existing content. Args: thing (object): either a string (for text) or an Image color (tuple, optional): text color. Default is WHITE. cursor_x (int, optional): x char coord of text. Default is current. cursor_y (int, optional): y char coord of text. Default is current. scale (int, optional): scaling factor. Default is 2. end (str, optional): the character to print on the end of the line. Default is \\n. background (int, optional): background color. Default is None (Transparent). """ # Implemented in C pass
[docs] def add_child(self, child, position=-1): """Add a child object to this Canvas. Args: child (Canvas): The child object. position (int, optional): The index of the child within the peer list. Defaults to -1 (the end of the list). """ # Implemented in C pass
[docs] def remove_child(self, child): """Remove a child from this Canvas. Args: child (Canvas): The child to remove. """ # Implemented in C pass
[docs] def remove_all_children(self): """Remove all children from this Canvas""" # Implemented in C pass