ó
X–Tc           @   s6   d  d l  Z  d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   reft   Viewc           B   s•  e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d  „  Z" d! „  Z# d" „  Z$ d# „  Z% d$ „  Z& d% „  Z' d& „  Z( d' „  Z) d( „  Z* d) „  Z+ d* „  Z, d+ „  Z- d, „  Z. d- „  Z/ d. „  Z0 d/ „  Z1 d0 „  Z2 d1 „  Z3 d2 „  Z4 d3 „  Z5 d4 „  Z6 d5 „  Z7 e8 e e ƒ Z9 e8 e e ƒ Z: e8 e e ƒ Z; e8 e e ƒ Z< e8 e e ƒ Z= e8 e e ƒ Z> e8 e* e+ ƒ Z? e8 e, e. ƒ Z@ e8 e- e/ ƒ ZA e8 e e ƒ ZB e8 e e ƒ ZC e8 e$ e% ƒ ZD e8 e e ƒ ZE e8 e e ƒ ZF e8 e e ƒ ZG e8 e& e' ƒ ZH e8 e  e! ƒ ZI e8 e" e# ƒ ZJ e8 e( e) ƒ ZK e8 e0 e1 ƒ ZL e8 e2 e3 ƒ ZM e8 e4 ƒ ZN e8 e5 ƒ ZO e8 e6 e7 ƒ ZP d6 „  ZQ d7 „  ZR d8 „  ZS d9 „  ZT d: „  ZU d; „  ZV d< „  ZW d= „  ZX RS(>   só  
    Creates a new view with a scene or view as a parent. A view is a collection
    of Sprites and Views that can be collectively transformed - e.g., flipped,
    cropped, scaled, offset, hidden, etc. A View can also have a ``mask``, in
    order to treat it as a single collidable object. Like a Sprite, a View cannot
    be moved between Scenes.
    
    :param parent: The view or scene that this View belongs in.
    :type parent: :func:`View <spyral.View>` or :func:`Scene <spyral.Scene>`
    c         C   s  t  j | j ƒ |  _ t  j | j ƒ |  _ t  j | j ƒ |  _ t  j d d ƒ |  _ t |  _ t	 |  _
 t | ƒ |  _ d |  _ t  j d d ƒ |  _ g  |  _ d  |  _ d  |  _ t ƒ  |  _ t ƒ  |  _ t | j ƒ |  _ |  j ƒ  j |  ƒ |  j ƒ  j |  ƒ |  j ƒ  j |  ƒ d  S(   Ni    t   topleft(   t   spyralt   Vec2Dt   sizet   _sizet   _output_sizet
   _crop_sizet   _post   Falset   _cropt   Truet   _visiblet   _wreft   _parentt   _anchort   _offsett   _layerst   Nonet   _layert   _maskt   sett	   _childrent   _child_viewst   scenet   _scenet	   _add_viewt
   _add_childt   _apply_style(   t   selft   parent(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   __init__   s$    						c         C   s6   |  j  j | ƒ t | t ƒ r2 |  j j | ƒ n  d S(   s°   
        Starts keeping track of the entity as a child of this view.

        :param entity: The new entity to keep track of.
        :type entity: a View or a Sprite.
        N(   R   t   addt
   isinstanceR   R   (   R   t   entity(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR   %   s    c         C   s$   |  j  j | ƒ |  j j | ƒ d S(   s¹   
        Stops keeping track of the entity as a child of this view, if it exists.

        :param entity: The entity to keep track of.
        :type entity: a View or a Sprite.
        N(   R   t   discardR   (   R   R#   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _remove_child0   s    c         C   sU   x! t  |  j ƒ D] } | j ƒ  q W|  j j ƒ  |  j j ƒ  |  j ƒ  j |  ƒ d S(   s‹   
        Completely remove any parent's links to this view. When you want to
        remove a View, you should call this function.
        N(   t   listR   t   killt   clearR   R   t
   _kill_view(   R   t   child(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR'   :   s
    c         C   s   |  j  S(   sÚ   
        Return this View's mask, a spyral.Rect representing the collidable area.
        
        :rtype: :class:`Rect <spyral.Rect>` if this value has been set,
                otherwise it will be ``None``.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt	   _get_maskE   s    c         C   s   | |  _  |  j ƒ  d S(   s  
        Set this View's mask. Triggers a recomputation of the collision box.
        :param mask: The region that this View collides with, or None
        (indicating that the default should be used).
        :type mask: a :class:`Rect <spyral.Rect>`, or None.
        N(   R   t   _set_collision_box(   R   t   mask(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt	   _set_maskN   s    	c         C   s,   |  j  ƒ  x |  j D] } | j ƒ  q Wd S(   sƒ   
        Set this View's collision box, and then also recursively recompute
        the collision box for any child Views.
        N(   R,   R   t   _set_collision_box_tree(   R   t   view(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR/   X   s    
c         C   sI   |  j  ƒ  |  j ƒ  t j d d d |  ƒ } t j j d | |  j ƒ d S(   sÇ   
        Called when this View has changed a visual property, ensuring that the
        offset and collision box are recomputed; also triggers a
        `spyral.internal.view.changed` event.
        t   namet   changedR0   s   spyral.internal.view.changedN(   t   _recalculate_offsetR/   R   t   Eventt   eventt   handleR   (   R   t   changed_event(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _changeda   s    

c         C   sn   |  j  r> t j j |  j |  j  j d |  j  j d ƒ |  _ n, t j j |  j |  j d |  j d ƒ |  _ d S(   s7   
        Recalculates the offset of this View.
        i    i   N(   R   R   t   utilt   _anchor_offsetR   R   R   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR3   o   s    	
c         C   s   |  j  S(   sm   
        Returns the position (:func:`Vec2D <spyral.Vec2D>`) of this View within its
        parent.
        (   R	   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_pos}   s    c         C   s3   | |  j  k r d  St j | ƒ |  _  |  j ƒ  d  S(   N(   R	   R   R   R8   (   R   t   pos(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_pos„   s    c         C   s   |  j  S(   sP   
        The layer (a ``str``) that this View is on, within its parent.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt
   _get_layerŠ   s    c         C   s@   | |  j  k r d  S| |  _  |  j ƒ  j |  | ƒ |  j ƒ  d  S(   N(   R   R   t   _set_view_layerR8   (   R   t   layer(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt
   _set_layer   s
    	c         C   s   t  |  j ƒ S(   sP  
        A list of strings representing the layers that are available for this
        view. The first layer is at the bottom, and the last is at the top. For
        more information on layers, check out the :ref:`layers <ref.layering>`
        appendix.

        .. note:
            
            Layers can only be set once.
        (   t   tupleR   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_layers—   s    c         C   sQ   |  j  s, | |  _  |  j ƒ  j |  | ƒ n! |  j  | k r> n t j d ƒ ‚ d  S(   Ns/   You can only define the layers for a view once.(   R   R   t   _set_view_layersR   t   LayersAlreadySetError(   R   t   layers(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_layers¤   s    	
c         C   s   |  j  ƒ  d S(   sk   
        The x coordinate of the view, which will remain synced with the
        position. Number.
        i    (   R;   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_x®   s    c         C   s   |  j  | |  j ƒ  f ƒ d  S(   N(   R=   t   _get_y(   R   t   x(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_xµ   s    c         C   s   |  j  ƒ  d S(   sk   
        The y coordinate of the view, which will remain synced with the
        position. Number.
        i   (   R;   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyRI   ¸   s    c         C   s   |  j  |  j ƒ  | f ƒ d  S(   N(   R=   RH   (   R   t   y(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_y¿   s    c         C   s   |  j  S(   s}   
        Defines an :ref:`anchor point <ref.anchors>` where coordinates are relative to
        on the view. String.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_anchorÂ   s    c         C   s4   | |  j  k r d  S| |  _  |  j ƒ  |  j ƒ  d  S(   N(   R   R3   R8   (   R   t   anchor(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_anchorÉ   s
    	
c         C   s   |  j  d S(   s0   
        The width of the view. Number.
        i    (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt
   _get_widthÐ   s    c         C   s   |  j  | |  j ƒ  ƒ d  S(   N(   t	   _set_sizet   _get_height(   R   t   width(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt
   _set_widthÖ   s    c         C   s   |  j  d S(   s1   
        The height of the view. Number.
        i   (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyRS   Ù   s    c         C   s   |  j  |  j ƒ  | ƒ d  S(   N(   RR   RQ   (   R   t   height(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_heightß   s    c         C   s   |  j  d S(   sJ   
        The width of this view when drawn on the parent. Number.
        i    (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_output_widthâ   s    c         C   s   |  j  | |  j ƒ  f ƒ d  S(   N(   t   _set_output_sizet   _get_output_height(   R   RT   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_output_widthè   s    c         C   s   |  j  d S(   sK   
        The height of this view when drawn on the parent. Number.
        i   (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyRZ   ë   s    c         C   s   |  j  |  j ƒ  | f ƒ d  S(   N(   RY   RX   (   R   RV   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_output_heightñ   s    c         C   s   |  j  d S(   s8   
        The width of the cropped area. Number.
        i    (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_crop_widthô   s    c         C   s   |  j  | |  j ƒ  f ƒ d  S(   N(   t   _set_crop_sizet   _get_crop_height(   R   RT   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_crop_widthú   s    c         C   s   |  j  d S(   s9   
        The height of the cropped area. Number.
        i   (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR_   ý   s    c         C   s   |  j  |  j ƒ  | f ƒ d  S(   N(   R^   R]   (   R   RV   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_crop_height  s    c         C   s   |  j  S(   sŽ   
        The (width, height) of this view's coordinate space
        (:class:`Vec2D <spyral.Vec2d>`). Defaults to size of the parent.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt	   _get_size  s    c         C   s3   | |  j  k r d  St j | ƒ |  _  |  j ƒ  d  S(   N(   R   R   R   R8   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyRR     s    c         C   s   |  j  S(   s”   
        The (width, height) of this view when drawn on the parent
        (:class:`Vec2D <spyral.Vec2d>`). Defaults to size of the parent.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_output_size  s    c         C   s3   | |  j  k r d  St j | ƒ |  _  |  j ƒ  d  S(   N(   R   R   R   R8   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyRY     s    c         C   s   |  j  S(   s˜   
        The (width, height) of the area that will be cropped; anything outside
        of this region will be removed when the crop is active.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_crop_size   s    c         C   s3   | |  j  k r d  St j | ƒ |  _  |  j ƒ  d  S(   N(   R   R   R   R8   (   R   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR^   '  s    c         C   s   |  j  |  j S(   s  
        A scale factor from the size to the output_size for the view. It will
        always contain a :class:`Vec2D <spyral.Vec2D>` with an x factor and a
        y factor, but it can be set to a numeric value which will be set for
        both coordinates.
        (   R   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt
   _get_scale-  s    c         C   sg   t  | t t f ƒ r* t j | | ƒ } n  | |  j ƒ  k r@ d  S|  j t j | ƒ |  _ |  j ƒ  d  S(   N(	   R"   t   intt   floatR   R   Re   R   R   R8   (   R   t   scale(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt
   _set_scale6  s    c         C   s   |  j  ƒ  d S(   sO   
        The x factor of the scaling. Kept in sync with scale. Number.
        i    (   Re   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_scale_x>  s    c         C   s   |  j  ƒ  d S(   sO   
        The y factor of the scaling. Kept in sync with scale. Number.
        i   (   Re   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_scale_yD  s    c         C   s!   |  j  | |  j ƒ  d f ƒ d  S(   Ni   (   Ri   Re   (   R   RJ   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_scale_xJ  s    c         C   s!   |  j  |  j ƒ  d | f ƒ d  S(   Ni    (   Ri   Re   (   R   RL   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_scale_yM  s    c         C   s   |  j  S(   st   
        Whether or not this View and its children will be drawn (``bool``).
        Defaults to ``False``.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_visibleP  s    c         C   s*   |  j  | k r d  S| |  _  |  j ƒ  d  S(   N(   R   R8   (   R   t   visible(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _set_visibleW  s    	c         C   s   |  j  S(   s€   
        A ``bool`` that determines whether the view should crop anything
        outside of it's size (default: True).
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt	   _get_crop]  s    c         C   s*   |  j  | k r d  S| |  _  |  j ƒ  d  S(   N(   R   R8   (   R   t   crop(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt	   _set_cropd  s    	c         C   s
   |  j  ƒ  S(   sŽ   
        The first parent :class:`View <spyral.View>` or 
        :class:`Scene <spyral.Scene>` that this View belongs to. Read-only.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   _get_parentk  s    c         C   s
   |  j  ƒ  S(   sq   
        The top-most parent :class:`Scene <spyral.Scene>` that this View
        belongs to. Read-only.
        (   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt
   _get_scener  s    c         C   s   t  j |  j |  j ƒ S(   s½   
        A :class:`Rect <spyral.Rect>` representing the position and size of
        this View. Can be set through a ``Rect``, a 2-tuple of position and
        size, or a 4-tuple.
        (   R   t   RectR	   R   (   R   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt	   _get_recty  s    c         G   sÃ   t  | ƒ d k rQ | d } | j | j |  _ |  _ | j | j |  _ |  _ nn t  | ƒ d k r€ | d |  _ | d |  _ n? t  t	 ƒ d k r³ t	 \ |  _ |  _ |  _ |  _ n t
 d ƒ ‚ d  S(   Ni   i    i   i   s   TODO: You done goofed.(   t   lenRJ   RL   t   wt   hRT   RV   R<   R   t   argst
   ValueError(   R   t   rectt   r(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt	   _set_rect  s    
!c         C   sm   |  j  ri | j |  j 7_ | j |  j ƒ |  j rS | j t j d |  j	 ƒ ƒ n  |  j
 ƒ  j | ƒ n  d S(   sŠ   
        If this View is visible, applies offseting, scaling, and cropping
        before passing it up the transformation chain.
        i    N(   i    i    (   Ro   t   positionR<   t   apply_scaleRh   Rr   t   clipR   Rv   t	   crop_sizeR   t   _blit(   R   t   blit(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR„   §  s    		c         C   sp   |  j  rl | j |  j 7_ | j |  j ƒ |  j rS | j t j d |  j	 ƒ ƒ n  |  j
 ƒ  j | | ƒ n  d S(   sŠ   
        If this View is visible, applies offseting, scaling, and cropping
        before passing it up the transformation chain.
        i    N(   i    i    (   Ro   R€   R<   R   Rh   Rr   R‚   R   Rv   Rƒ   R   t   _static_blit(   R   t   keyR…   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR†   ³  s    		c         C   s]   | j  |  j 7_  | j |  j ƒ |  j rJ | j t j d |  j ƒ ƒ n  |  j	 ƒ  j
 | ƒ S(   sž   
        Transforms the given collision box according to this view's scaling,
        cropping, and offset; then passes the box to this boxes parent.
        i    (   i    i    (   R€   R<   R   Rh   Rr   R‚   R   Rv   Rƒ   R   t   _warp_collision_box(   R   t   box(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyRˆ   ¿  s
    	c         C   s©   |  j  d k	 r= |  j  j |  j } t j d |  j  j ƒ } n% |  j |  j } t j d |  j ƒ } t j j	 | | ƒ } |  j
 ƒ  j | ƒ } |  j ƒ  j |  | j ƒ d S(   s4   
        Updates this View's collision box.
        i    N(   i    i    (   i    i    (   R   R   R   R   R   Rv   R   R	   R9   t   _CollisionBoxR   Rˆ   R   R,   R}   (   R   R<   t   areat   ct
   warped_box(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR,   Ê  s    c         C   s¶   d d d d d d d d d	 d
 d d d d d d d d d d d g } x< | D]4 } | | k rL | j  | ƒ } t |  | | ƒ qL qL Wt | ƒ d k r² t j j |  | j ƒ  ƒ n  d S(   sÙ   
        Applies the *properties* to this scene. This is called when a style
        is applied.

        :param properties: a mapping of property names (strings) to values.
        :type properties: ``dict``
        R<   RJ   RL   R€   RT   RV   R   t   output_widtht   output_heightt   output_sizeRO   R@   RF   Ro   Rh   t   scale_xt   scale_yRr   t
   crop_widtht   crop_heightRƒ   i    N(   t   popt   setattrRx   R   t
   exceptionst   unused_style_warningt   iterkeys(   R   t
   propertiest   simplet   propertyt   value(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   __stylize__Ø  s    			c         C   s   |  j  ƒ  j |  | ƒ S(   s  
        Returns whether this view is colliding with the sprite or view.

        :param other: A sprite or a view
        :type other: :class:`Sprite <spyral.Sprite>` or a 
                     :class:`View <spyral.View>`
        :returns: A ``bool``
        (   R   t   collide_sprite(   R   t   other(    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyRŸ   í  s    	c         C   s   |  j  ƒ  j |  | ƒ S(   s·   
        Returns whether this view is colliding with the point.

        :param point: A point
        :type point: :class:`Vec2D <spyral.Vec2D>`
        :returns: A ``bool``
        (   R   t   collide_point(   R   R<   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR¡   ø  s    c         C   s   |  j  ƒ  j |  | ƒ S(   s±   
        Returns whether this view is colliding with the rect.

        :param rect: A rect
        :type rect: :class:`Rect <spyral.Rect>`
        :returns: A ``bool``
        (   R   t   collide_rect(   R   R}   (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR¢     s    (Y   t   __name__t
   __module__t   __doc__R    R   R%   R'   R+   R.   R/   R8   R3   R;   R=   R>   RA   RC   RG   RH   RK   RI   RM   RN   RP   RQ   RU   RS   RW   RX   R[   RZ   R\   R]   R`   R_   Ra   Rb   RR   Rc   RY   Rd   R^   Re   Ri   Rj   Rk   Rl   Rm   Rn   Rp   Rq   Rs   Rt   Ru   Rw   R   Rœ   R<   R@   RF   RJ   RL   RO   Rh   R‘   R’   RT   RV   R   R-   RŽ   R   R   R“   R”   Rƒ   Ro   Rr   R   R   R}   R„   R†   Rˆ   R,   Rž   RŸ   R¡   R¢   (    (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyR      s¬   
			
				
										
																																														
(   R   t   weakrefR    R   t   objectR   (    (    (    s/   /usr/lib/python2.7/site-packages/spyral/view.pyt   <module>   s   