a
    V$caG                     @   s   d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZd dlmZmZ d dlmZ G dd dejjjZG dd	 d	eZG d
d dejjjZG dd dejjjZ dS )    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicodeN)renderRender)Matrix2Dc                       s@   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Z  Z	S )Solidz
    :doc: disp_imagelike

    A displayable that fills the area its assigned with `color`.

    ::

        image white = Solid("#fff")

    c                    s8   t t| jf i | |d ur.tj|| _nd | _d S N)superr   __init__renpyeasycolor)selfr   
properties	__class__ renpy/display\imagelike.pyr   .   s    zSolid.__init__c                 C   s
   t | jS r   )hashr   r   r!   r!   r"   __hash__7   s    zSolid.__hash__c                 C   s   |  |sdS | j|jkS NF)_equalsr   r   or!   r!   r"   __eq__:   s    
zSolid.__eq__c                 C   s   g S r   r!   r$   r!   r!   r"   visit@   s    zSolid.visitc                 C   s   t jj| j||\}}t||}t||}| jp8| jj}t||}|d u s\|dks\|dkr`|S d}	||	k st||	k rt jj	|||}
nRt jj	|	|	|}
t
d|	 | ddd|	 | |_t
d| |	 ddd| |	 |_||
d |S )Nr   
         ?r   r   )r   displaylayout
xyminimumsstylemaxr   r   drawsolid_texturer   forwardreverseblit)r   widthheightstatxminimumyminimumr   rvSIZEtexr!   r!   r"   r   C   s    


  zSolid.render)
__name__
__module____qualname____doc__r   r%   r*   r+   r   __classcell__r!   r!   r   r"   r   "   s   	r   c                   @   s&   e Zd ZdZdddZedd ZdS )	BordersaO  
    :doc: disp_imagelike

    This object provides border size and tiling information to a :func:`Frame`.
    It can also provide padding information that can be supplied to the
    :propref:`padding` style property of a window or frame.

    `left`, `top`, `right`, `bottom`
        These provide the size of the insets used by a frame, and are added
        to the padding on each side. They should be zero or a positive integer.

    `pad_left`, `pad_top`, `pad_right`, `pad_bottom`
        These are added to the padding on each side, and may be positive or
        negative. (For example, if `left` is 5 and `pad_left` is -3, the final
        padding is 2.)

    The padding information is supplied via a field:

    .. attribute:: padding

        This is a four-element tuple containing the padding on each of the
        four sides.
    r   c	           	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _d S r   )lefttoprightbottompad_leftpad_top	pad_right
pad_bottom)	r   rH   rI   rJ   rK   rL   rM   rN   rO   r!   r!   r"   r   x   s    zBorders.__init__c                 C   s,   | j | j | j| j | j| j | j| j fS r   )rH   rL   rI   rM   rJ   rN   rK   rO   r$   r!   r!   r"   padding   s
    



zBorders.paddingN)r   r   r   r   )rB   rC   rD   rE   r   propertyrP   r!   r!   r!   r"   rG   _   s   
rG   c                	       s~   e Zd ZdZdZi ZdZdd Zd fd
d	Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Z  ZS )Framea  
    :doc: disp_imagelike
    :args: (image, left=0, top=0, right=None, bottom=None, tile=False, **properties)
    :name: Frame

    A displayable that resizes an image to fill the available area,
    while preserving the width and height of its borders. It is often
    used as the background of a window or button.

    .. figure:: frame_example.png

        Using a frame to resize an image to double its size.

    `image`
        An image manipulator that will be resized by this frame.

    `left`
        The size of the border on the left side. This can also be a
        :func:`Borders` object, in which case that object is used in place
        of the other parameters.

    `top`
        The size of the border on the top.

    `right`
        The size of the border on the right side. If None, defaults
        to `left`.

    `bottom`
        The side of the border on the bottom. If None, defaults to `top`.

    `tile`
        If set to True, tiling is used to resize sections of the image,
        rather than scaling. If set to the string "integer", the nearest
        integer number of tiles will be used in each direction. That set of
        full tiles will then be scaled up or down to fit the required area.

    ::

         # Resize the background of the text window if it's too small.
         init python:
             style.window.background = Frame("frame.png", 10, 10)
                 ?c                 C   s,   |dk r(| j | _| j | _| j| _| j| _d S )N   )xborderrH   rJ   yborderrI   rK   )r   versionr!   r!   r"   after_upgrade   s
    zFrame.after_upgradeNr   TFc                    s   t t| jf i | tj|| _| jj| _t|t	rT|}|j
}|j}|j}|j}|	| _t|
| _|d u rp|}|d u r||}|d u r|}|d u r|}|| _
|| _|| _|| _d S r   )r   rR   r   r   r   displayableimage_duplicatable
isinstancerG   rH   rI   rJ   rK   tilefloat
tile_ratio)r   r[   rH   rI   rJ   rK   rV   rW   bilinearr^   r`   r   insetsr   r!   r"   r      s.    


zFrame.__init__c              
   C   s>   d | j| j| j| j| j| jdkr.d | jn| jr8dndS )Nz<Frame {!r} ({},{},{},{}){}>integerz
 tile ({})z tile )formatr[   rH   rI   rJ   rK   r^   r`   r$   r!   r!   r"   __repr__   s    
zFrame.__repr__c                 C   s   |  |sdS | j|jkrdS | j|jkr.dS | j|jkr>dS | j|jkrNdS | j|jkr^dS | j|jkrndS | j|jkr~dS dS )NFT)r'   r[   rH   rI   rJ   rK   r^   r`   r(   r!   r!   r"   r*      s"    
zFrame.__eq__c              	      s\  t jj|}t jj|}jjp(j}t|||||   \ttt|t|j	j
 }jj }t|d }|r|rj	| | }	j
| | }
nd}	d}
t|d }|r|rj| | }j| | }nd}d}tjjjd dkr$ |	||
|S  fdd}t||	||
| S )NrU   r   rendererswc                    s  | dkr| }| }n|  }|  }|dkr4|}|}n| }| }|dkrV|}|}	n| }| }	|dkrx|}
|}n| }
| }||ks|	|krd S || }||	 }|| }|
| }|dks|dks|dks|dkrd S   ||	||f}||ks||krjr6|| }}td|| || r0dnd }td|| || rPdnd }|| sl|| rֈjdkr|| t| jk rtd|d }|| t| jk rtd|d }|| ||  }}t||}d|_d|_td|D ]0}td|D ]}|	||| || f qq|| }}|}||ksJ||krt||}t
d| | ddd| | |_t
d| | ddd| | |_|	|d |}	|||f d S )Nr   rS   rc   Tr-   r.   )
subsurfacer^   r3   r_   r`   r   	xclipping	yclippingr   r8   r   r6   r7   )x0x1y0y1dx0sx0dx1sx1dy0sy0dy1sy1cswcshcdwcdhcrctwcthxtilesytilesnewcrxycrenddhdwr?   r   shrh   r!   r"   r4   4  sr     
  
 

  zFrame.render.<locals>.draw)r3   r2   r=   r>   childr[   r   get_sizeintrH   rJ   rI   rK   minr   r/   r4   info	sw_renderr   draw_pattern)r   r9   r:   r;   r<   r[   bwbhrV   rH   rJ   rW   rI   rK   r4   r!   r   r"   r     s:    c
zFrame.renderc                 C   s   |r:|r|d|d| ||| d| |r:|| dd| |rN|d|||  ||| ||  |rv|| d||  |r|r|d|| d ||| | d |r|| d| d d S )Nr   r!   )r   r4   rH   rI   rJ   rK   r!   r!   r"   r     s"    zFrame.draw_patternc                    s   | d \tjjd  } fdd}	|	|||| tjj}
|
	|d |

| |
S )NTc                    sz  | dkr| }| }n|  }|  }|dkr4|}|}n| }| }|dkrV|}|}	n| }| }	|dkrx|}
|}n| }
| }||ks|	|ks||ks|
|krd S || ||	 f}t || t |
| f}||	|d |d f}||krfjrH|\}}|\}}td|| || r(dnd }td|| || rHdnd }|| sd|| rjdkr|| t| jk rtd|d }|| t| jk rtd|d }tjj	|| || f|}t
d|D ]0}t
d|D ]}|||| || f qqjdu r4|dd||f}n|| || f}|}||krftjj||}|} |||f d S )Nr   rS   rc   T)r   ri   r^   r3   r_   r`   r   r/   pgrendersurface_unscaledr   r8   scalereal_transform_scale)rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   srcsizedstsizesurftilewtilehdstwdsthr   r   surf2r   r   destr   r   r   r   sourcerh   r!   r"   r4     sn     
 
zFrame.sw_render.<locals>.drawr.   )render_to_texturer   r   r/   swdrawsurfacer   r   r   r8   
depends_on)r   r   r   r   rH   rI   rJ   rK   r?   r4   rrvr!   r   r"   r     s    
^
zFrame.sw_renderc                 C   s>   | j |}|| j u r| S |  | |}||_ |j|_|S r   )r[   
_duplicate_unique_copyr\   )r   argsr[   r?   r!   r!   r"   r   +  s    

zFrame._duplicatec                 C   s   | j   d| _d S r&   )r[   r   r\   r$   r!   r!   r"   r   8  s    
zFrame._uniquec                 C   s*   | j  }|| j u r| S |  }||_ |S r   )r[   _in_current_storer   )r   r[   r?   r!   r!   r"   r   <  s    

zFrame._in_current_storec                 C   s   g }| j | |S r   )r2   _visit_frame)r   r?   r!   r!   r"   r+   F  s    zFrame.visit)	NNNNr   r   TFrT   )rB   rC   rD   rE   __version__r   r`   rY   r   rf   r*   r   r   r   r   r   r   r+   rF   r!   r!   r   r"   rR      s&   ,   % o
rR   c                       s*   e Zd ZdZd fdd	Zdd Z  ZS )FileCurrentScreenshotaY  
    :doc: file_action_function

    A displayable that shows the screenshot that will be saved with the current
    file, if a screenshot has been taken when entering a menu or with
    :func:`FileTakeScreenshot`.

    If there is no current screenshot, `empty` is shown in its place. (If `empty` is
    None, it defaults to :func:`Null`.)
    Nc                    s4   t t| jf i | |d u r*tjj }|| _d S r   )r   r   r   r   r/   r0   Nullempty)r   r   r   r   r!   r"   r   X  s    zFileCurrentScreenshot.__init__c           
      C   sd   t jjj}|d u r*t jj| j||||S t jj|}| \}}t jj	||}	|	
|d |	S )Nr.   )r   r/   	interfacescreenshot_surfacer   r   r4   load_texturer   r   r8   )
r   r9   r:   r;   r<   ssrA   whr?   r!   r!   r"   r   a  s    
zFileCurrentScreenshot.render)N)rB   rC   rD   rE   r   r   rF   r!   r!   r   r"   r   L  s   	r   )!
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r   renpy.display.renderr   r   renpy.display.matrixr   r/   coreDisplayabler   objectrG   rR   r   r!   r!   r!   r"   <module>   s   8=/   A