a
    F­^i< ã                #   @   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mZmZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl Z e ¡ Z!zd dl"Z"e"j# W n e$yä   dZ"Y n0 e j%rôd dl%Z%ej& 'd¡Z(ej& 'd¡Z)ej& 'd¡Z*ej& 'd¡Z+e,ej& -¡ ƒZ.e. /e)¡ e. /e+¡ ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAejBejCejDejEejFejGejHejIejJejKejLejMejNe(e)e*e+h#ZOd	ZPd
aQdaRdd„ ZSdd„ ZTdd„ ZUdd„ ZVG dd„ de$ƒZWG dd„ de$ƒZXG dd„ deYƒZZdd„ Z[G dd„ de j\j]ƒZ^e j_ `d¡aaG dd „ d e j\j]ƒZbG d!d"„ d"e j\j]ƒZcG d#d$„ d$e j\j]ƒZdd0d&d'„ZeG d(d)„ d)e\ƒZfd*d+„ ZgG d,d-„ d-e\ƒZhd
ZiG d.d/„ d/e\ƒZjdS )1é    )ÚdivisionÚabsolute_importÚwith_statementÚprint_functionÚunicode_literals)ÚPY2Ú
basestringÚbchrÚbordÚchrÚopenÚpystrÚrangeÚroundÚstrÚtobytesÚunicode)ÚOptionalÚTupleNÚ	TIMEEVENTÚPERIODICÚREDRAWÚ	EVENTNAMEé2   ç        ç      ð?c                  C   s"   t j dd¡} t ¡ at| ƒad S )NZRENPY_TIMEWARPz1.0)ÚosÚenvironÚgetÚtimeÚ	time_baseÚfloatÚ	time_mult)Úwarp© r$   úVC:\Program Files (x86)\Steam\steamapps\common\Selene ~Apoptosis~\renpy\display\core.pyÚ	init_timev   s    r&   c                  C   s   t   ¡ } t| t t  S ©N)r   r    r"   )Útr$   r$   r%   Úget_time€   s    r)   c                  C   sJ   t j ¡ } | s| S | d dkr.| d dkr.| S t| d dƒt| d dƒfS )zs
    Returns the screen size. Always returns at least 256, 256, to make sure
    that we don't divide by zero.
    r   é   é   )ÚpygameÚdisplayÚget_sizeÚmax)Úsizer$   r$   r%   r.   …   s    
r.   c                 C   s   t j ¡ j | |¡S )zD
    Get the displayable on the given layer with the given tag.
    )ÚrenpyÚgameÚcontextÚscene_listsÚget_displayable_by_tag)ÚlayerÚtagr$   r$   r%   Údisplayable_by_tag–   s    r8   c                   @   s   e Zd ZdZdS )ÚIgnoreEventzo
    Exception that is raised when we want to ignore an event, but
    also don't want to return anything.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r$   r$   r%   r9   ž   s   r9   c                   @   s   e Zd ZdZdd„ ZdS )ÚEndInteractionz
    Exception that can be raised (for example, during the render method of
    a displayable) to end the current interaction immediately.
    c                 C   s
   || _ d S r'   )Úvalue)Úselfr?   r$   r$   r%   Ú__init__«   s    zEndInteraction.__init__N)r:   r;   r<   r=   rA   r$   r$   r$   r%   r>   ¥   s   r>   c                   @   s   e Zd ZdZg ZdS )Úabsolutez7
    This represents an absolute float coordinate.
    N)r:   r;   r<   r=   Ú	__slots__r$   r$   r$   r%   rB   ¯   s   rB   c                 C   sÂ   |\}}}}}	}
}|du rd}|du r*d}|du r6d}|du rBd}|	du rNd}	|
du rZd}
|j tu rl|| 9 }|j tu r~||9 }||	 | }|j tu rœ||9 }|j tu r®||9 }||
 | }||fS )a  
    Performs the Ren'Py placement algorithm.

    `width`, `height`
        The width and height of the area the image will be
        placed in.

    `size`
        The size of the image to be placed.

    `placement`
        The tuple returned by Displayable.get_placement().
    Nr   )Ú	__class__r!   )ÚwidthÚheightÚswÚshÚ	placementÚxposÚyposÚxanchorÚyanchorÚxoffsetÚyoffsetZ	_subpixelÚxÚyr$   r$   r%   Úplace¶   s0    



rR   c                   @   s0   e Zd ZdZdZdZdZdZdd„ Zdd„ Z	dS )	ÚDisplayableArgumentsz[
    Represents a set of arguments that can be passed to a duplicated
    displayable.
    r$   NFc                 K   s$   t ƒ }|j | j¡ |j |¡ |S )z|
        Returns a copy of this object with the various fields set to the
        values they were given in kwargs.
        )rS   Ú__dict__Úupdate)r@   ÚkwargsÚrvr$   r$   r%   Úcopyû   s    zDisplayableArguments.copyc                 C   s4   t jjr0t jjr0td d | j¡d | j¡¡ƒ‚d S )Nz+Image '{}' does not accept attributes '{}'.ú )	r1   ÚconfigÚ	developerÚreport_extraneous_attributesÚ	ExceptionÚformatÚjoinÚnameÚargs©r@   r$   r$   r%   Ú
extraneous  s
    

þzDisplayableArguments.extraneous)
r:   r;   r<   r=   r`   ra   ÚprefixÚlintrX   rc   r$   r$   r$   r%   rS   è   s   rS   Údefaultc                   @   sx  e Zd ZdZdZdZdZdZdZdZ	g Z
dZdZeƒ ZdZdZdZdZdZdZdd„ ZdMdd	„ZdNd
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 dOdd„Z!dPd d!„Z"d"d#„ Z#d$d%„ Z$d&d'„ Z%d(d)„ Z&d*d+„ Z'dQd,d-„Z(d.d/„ Z)d0d1„ Z*d2d3„ Z+d4d5„ Z,dRd7d8„Z-d9d:„ Z.d;d<„ Z/d=d>„ Z0d?d@„ Z1dAdB„ Z2dCdD„ Z3dEdF„ Z4dSdGdH„Z5dIdJ„ Z6dKdL„ Z7dS )TÚDisplayablezú
    The base class for every object in Ren'Py that can be
    displayed to the screen.

    Drawables will be serialized to a savegame file. Therefore, they
    shouldn't store non-serializable things (like pygame surfaces) in
    their fields.
    NÚ Fc                 C   s
   | |k S r'   r$   ©r@   Úor$   r$   r%   Ú__ne__[  s    zDisplayable.__ne__rf   c                 K   sL   |dkr|st | _ntj ||¡| _|| _|p0|| _|| _|d urH|| _d S )Nrf   )Údefault_styleÚstyler1   ÚStyleÚ
focus_namerf   Ú_tooltipÚ_args)r@   Úfocusrf   rm   rq   ZtooltipZdefault_focusÚ
propertiesr$   r$   r%   rA   ^  s    
zDisplayable.__init__c                 C   s   t   | ¡}|dur||_|S )z†
        Makes a shallow copy of the displayable. If `args` is provided,
        replaces the arguments with the stored copy.
        N)rX   rq   )r@   ra   rW   r$   r$   r%   Ú_copyn  s    
zDisplayable._copyc                 C   s   |r|j r| ¡  | S )a7  
        Makes a duplicate copy of the following kids of displayables:

        * Displayables that can accept arguments.
        * Displayables that maintain state that should be reset before being
          shown to the user.
        * Containers that contain (including transitively) one of the other
          kinds of displayables.

        Displayables that contain state that can be manipulated by the user
        are never copied.

        This should call _unique on children that have been copied before
        setting its own _duplicatable flag.
        )ra   rc   )r@   ra   r$   r$   r%   Ú
_duplicate{  s    
zDisplayable._duplicatec                 C   s   | j S )z:
        Returns the tooltip of this displayable.
        )rp   rb   r$   r$   r%   Ú_get_tooltip‘  s    zDisplayable._get_tooltipc                 C   s   | S )zg
        Returns a version of this displayable that will not change as it is
        rendered.
        r$   rb   r$   r$   r%   Ú_in_current_store˜  s    zDisplayable._in_current_storec                 C   s
   d| _ dS )z
        This is called when a displayable is "unique", meaning there will
        only be one reference to it, ever, from the tree of displayables.
        FN)Ú_duplicatablerb   r$   r$   r%   Ú_unique   s    zDisplayable._uniquec                 C   s   | j j||d}|  |¡S )z0
        Obsolete alias for _duplicate.
        )r`   ra   )rq   rX   ru   )r@   r`   Ú
parametersÚar$   r$   r%   Úparameterizeª  s    zDisplayable.parameterizec                 C   sH   t | ƒt |ƒurdS | j|jkr$dS | j|jkr4dS | j|jkrDdS dS )z´
        This is a utility method that can be called by a Displayable's
        __eq__ method, to compare displayables for type and displayable
        component equality.
        FT)Útypero   rm   rf   ri   r$   r$   r%   Ú_equals²  s    zDisplayable._equalsc                 C   s   d S r'   r$   rb   r$   r$   r%   Ú
_repr_infoÇ  s    zDisplayable._repr_infoc                 C   sn   t  | ¡}|  ¡ }|d u r|S |rJ|d dkr:|d dksJd d|df¡}| d¡}d |d |d|d	 f¡S )
Nr   ú(éÿÿÿÿú)rh   z at rY   Úaté   )ÚobjectÚ__repr__r   r_   Ú
rpartition)r@   ZrepZreprinfoZpartor$   r$   r%   r†   Ê  s    


ýzDisplayable.__repr__c                 C   sX   | j p|}| jr|| |ƒ n| jd ur0|d |ƒ |  ¡ D ]}|d u rFq8| ||¡ q8d S r'   )ro   Ú	focusableÚvisitÚfind_focusable)r@   Úcallbackro   Úir$   r$   r%   rŠ   ×  s    


zDisplayable.find_focusablec                 C   s*   |   | jd d¡ |s&tj | jj¡ dS )zD
        Called to indicate that this widget has the focus.
        Úhover_TN)Úset_style_prefixÚroler1   ÚexportsZplayrm   Úhover_sound©r@   rf   r$   r$   r%   rr   æ  s    zDisplayable.focusc                 C   s   |   | jd d¡ dS )zK
        Called to indicate that this widget has become unfocused.
        Úidle_TN)rŽ   r   r’   r$   r$   r%   Úunfocusð  s    zDisplayable.unfocusc                 C   s.   t jjjrt jjj| urd S t j ¡ jj| u S r'   )r1   r-   rr   Zgrabr2   r3   r4   Úfocusedrb   r$   r$   r%   Ú
is_focused÷  s    zDisplayable.is_focusedc                 C   s0   || j jkrdS | j  |¡ tjj | d¡ dS )z×
        Called to set the style prefix of this widget and its child
        widgets, if any.

        `root` - True if this is the root of a style tree, False if this
        has been passed on to a child.
        Nr   )rm   rd   Ú
set_prefixr1   r-   ÚrenderÚredraw)r@   rd   Úrootr$   r$   r%   rŽ   þ  s    	zDisplayable.set_style_prefixc                 C   s   t dƒ‚dS )a   
        Called to display this displayable. This is called with width
        and height parameters, which give the largest width and height
        that this drawable can be drawn to without overflowing some
        bounding box. It's also given two times. It returns a Surface
        that is the current image of this drawable.

        @param st: The time since this widget was first shown, in seconds.
        @param at: The time since a similarly named widget was first shown,
        in seconds.
        zRender not implemented.N)r]   )r@   rE   rF   Ústrƒ   r$   r$   r%   r˜     s    zDisplayable.renderc                 C   s   dS )a¨  
        Called to report than an event has occured. Ev is the raw
        pygame event object representing that event. If the event
        involves the mouse, x and y are the translation of the event
        into the coordinates of this displayable. st is the time this
        widget has been shown for.

        @returns A value that should be returned from Interact, or None if
        no value is appropriate.
        Nr$   )r@   ÚevrP   rQ   r›   r$   r$   r%   Úevent  s    zDisplayable.eventc                 C   s
   | j  ¡ S )z¹
        Returns a style object containing placement information for
        this Displayable. Children are expected to overload this
        to return something more sensible.
        )rm   Úget_placementrb   r$   r$   r%   rž   *  s    zDisplayable.get_placementc                 C   sZ   |du rt ƒ }|  ¡ D ]6}|du r$qt|ƒ}||v r6q| |¡ | ||¡ q|| ƒ dS )zo
        Calls the callback on this displayable, and then on all children
        of this displayable.
        N)Úsetr‰   ÚidÚaddÚ	visit_all)r@   r‹   ÚseenÚdÚid_dr$   r$   r%   r¢   3  s    
zDisplayable.visit_allc                 C   s   g S )zÁ
        Called to ask the displayable to return a list of its children
        (including children taken from styles). For convenience, this
        list may also include None values.
        r$   rb   r$   r$   r%   r‰   J  s    zDisplayable.visitc                 C   s   dS )z9
        Called once per widget per interaction.
        Nr$   rb   r$   r$   r%   Úper_interactS  s    zDisplayable.per_interactc                 C   s   dS )zv
        Called to ask this displayable to call the callback with all
        the images it may want to load.
        Nr$   rb   r$   r$   r%   Úpredict_oneZ  s    zDisplayable.predict_onec                 C   s   dS )z‰
        Called to ask this displayable to cause image prediction
        to occur for images that may be loaded by its actions.
        Nr$   rb   r$   r$   r%   Úpredict_one_actionb  s    zDisplayable.predict_one_actionTc                 C   sv   |   ¡ }|d }	t|||j|j|ƒ\}
}|
|7 }
||7 }|
|f}|durr|	r`| ||||d¡ n| ||||d¡ |S )aæ  
        This places a render (which must be of this displayable)
        within a bounding area. Returns an (x, y) tuple giving the location
        the displayable was placed at.

        `dest`
            If not None, the `surf` will be blitted to `dest` at the
            computed coordinates.

        `x`, `y`, `width`, `height`
            The bounding area.

        `surf`
            The render to place.

        `main`
            This is passed to Render.blit().
        é   N)rž   rR   rE   rF   Úsubpixel_blitÚblit)r@   ÚdestrP   rQ   rE   rF   ÚsurfÚmainrI   ÚsubpixelrJ   rK   Úposr$   r$   r%   rR   j  s    zDisplayable.placec                 C   s.   || j krdS || _ | jr*tjj | d¡ dS )zH
        Sets the transform event of this displayable to event.
        Nr   )Útransform_eventÚtransform_event_responderr1   r-   r˜   r™   ©r@   r   r$   r$   r%   Úset_transform_event  s
    
zDisplayable.set_transform_eventc                 C   s   dS )zQ
        Returns True if the displayable handles event, False otherwise.
        Fr$   r³   r$   r$   r%   Ú_handles_event  s    zDisplayable._handles_eventc                 C   s   dS )zÆ
        Returns None if this displayable is ready to be hidden, or
        a replacement displayable if it doesn't want to be hidden
        quite yet. Kind is either "hide" or "replaced".
        Nr$   )r@   r›   rƒ   Úkindr$   r$   r%   Ú_hide¤  s    zDisplayable._hidec                 C   s   dS )z!
        No longer used.
        Nr$   rb   r$   r$   r%   Ú_show­  s    zDisplayable._showc                 C   s   | S )z¸
        If this displayable is part of a chain of one or more references,
        returns the ultimate target of those references. Otherwise, returns
        the displayable.
        r$   rb   r$   r$   r%   Ú_target²  s    zDisplayable._targetc                 C   s   |S )z¯
        If this is a transform, makes a copy of the transform and sets
        the child of the innermost transform to this. Otherwise,
        simply returns child.
        r$   )r@   Úchildr$   r$   r%   Ú_change_transform_child»  s    z#Displayable._change_transform_childc                 C   s   dS )zF
        Clears out the children of this displayable, if any.
        Nr$   rb   r$   r$   r%   Ú_clearÄ  s    zDisplayable._clearc                 C   sÎ   g }|rd}nd}d}|   ¡ d d |… D ]>}|d ur(| ¡ }| ¡ r(t|tjjjƒr\|g}q(| |¡ q(d 	|¡}| 
dd¡}| 
dd¡}| jj}|d u rž|}|d ur¾tjj|d|id	d
 }t|ƒ|ƒ}|S )Nr   r+   rh   z: z::ú:z: :Útext)Úscoper   )r‰   Ú_ttsÚstripÚ
isinstancer1   r-   ÚttsZTTSDoneÚappendr_   Úreplacerm   ÚaltÚsubstitutionsÚ
substituter}   )r@   Zdefault_altÚreverserW   ÚorderZspeechrŒ   rÆ   r$   r$   r%   Ú_tts_commonË  s,    
zDisplayable._tts_commonc                 C   s   |   ¡ S )zÀ
        Returns the self-voicing text of this displayable and all of its
        children that cannot take focus. If the displayable can take focus,
        returns the empty string.
        ©rË   rb   r$   r$   r%   rÀ   ñ  s    zDisplayable._ttsc                 C   s   |   ¡ S )z{
        Returns the self-voicing text of this displayable and all of its
        children that cannot take focus.
        rÌ   rb   r$   r$   r%   Ú_tts_allú  s    zDisplayable._tts_all)NFrf   NNF)N)F)F)N)T)NF)8r:   r;   r<   r=   rˆ   Zfull_focus_namer   r±   r²   Ú_mainZ_composite_partsZ	_locationZ_uses_scoperS   rq   rx   Ú	_clippingrp   Z	_box_skipÚ_offer_sizeÚdelayrk   rA   rt   ru   rv   rw   ry   r|   r~   r   r†   rŠ   rr   r”   r–   rŽ   r˜   r   rž   r¢   r‰   r¦   r§   r¨   rR   r´   rµ   r·   r¸   r¹   r»   r¼   rË   rÀ   rÍ   r$   r$   r$   r%   rg     sh   





	
	
&			
&	rg   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚSceneListEntryzŒ
    Represents a scene list entry. Since this was replacing a tuple,
    it should be treated as immutable after its initial creation.
    c                 C   s(   || _ || _|| _|| _|| _|| _d S r'   )r7   ÚzorderÚ	show_timeÚanimation_timeÚdisplayabler`   )r@   r7   rÓ   rÔ   rÕ   rÖ   r`   r$   r$   r%   rA     s    zSceneListEntry.__init__c                 C   s   t | j| j| j| j| jfƒS r'   )Úiterr7   rÓ   rÔ   rÕ   rÖ   rb   r$   r$   r%   Ú__iter__  s    zSceneListEntry.__iter__c                 C   s   | j | j| j| j| jf| S r'   )r7   rÓ   rÔ   rÕ   rÖ   )r@   Úindexr$   r$   r%   Ú__getitem__  s    zSceneListEntry.__getitem__c                 C   s   d| j | j| jf S )Nz<SLE: %r %r %r>)r7   r`   rÖ   rb   r$   r$   r%   r†     s    zSceneListEntry.__repr__c                 C   s   t | j| j| j| j| j| jƒS r'   )rÒ   r7   rÓ   rÔ   rÕ   rÖ   r`   rb   r$   r$   r%   rX     s    úzSceneListEntry.copyc                 C   s<   | }| j d u s| jd u r8|  ¡ }|j p(||_ |jp4||_|S r'   )rÔ   rÕ   rX   )r@   r   rW   r$   r$   r%   Úupdate_time"  s    zSceneListEntry.update_timeN)
r:   r;   r<   r=   rA   rØ   rÚ   r†   rX   rÛ   r$   r$   r$   r%   rÒ     s   	rÒ   c                	       s  e Zd ZdZdZdd„ Zdd„ Z‡ fdd„Zd@d
d„Zdd„ Z	dAdd„Z
dd„ Zddg g dddddf	dd„Zdd„ ZdBdd„Zdd„ ZdCdd„ZdDdd „ZdEd"d#„Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ ZdFd.d/„Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Zd>d?„ Z ‡  Z!S )GÚ
SceneListszd
    This stores the current scene lists that are being used to display
    things to the user.
    é   c                 C   sz   t | di ƒ| _t | di ƒ| _tjjtjj D ]H}|| jvr\g | j|< i | j|< d g f| j|< || jvr,d g f| j|< q,d S )NÚcamera_listÚcamera_transform)	ÚgetattrrÞ   rß   r1   rZ   ÚlayersÚ
top_layersÚat_listÚlayer_at_list©r@   rŒ   r$   r$   r%   Úafter_setstate6  s    



zSceneLists.after_setstatec                 C   s´   |dk rBi | _ i | _tjjtjj D ]}i | j |< d g f| j|< q$|dk rPd| _|dk r„| jD ]}dd„ | j| D ƒ| j|< q^g | _|dk r’d | _|dk r¢| j	| _
|d	k r°i | _d S )
Nr+   é   Fé   c                 S   s   g | ]}t |d  Ž ‘qS )r'   )rÒ   ©Ú.0rŒ   r$   r$   r%   Ú
<listcomp>T  ó    z,SceneLists.after_upgrade.<locals>.<listcomp>é   r©   rÝ   )rã   rä   r1   rZ   rá   râ   Úshown_windowÚadditional_transientÚ
drag_groupÚimage_predict_infoÚshownÚlayer_transform)r@   ÚversionrŒ   Úkr$   r$   r%   Úafter_upgradeD  s$    

zSceneLists.after_upgradec              	      s°  t t| ƒ ¡  d| _i | _i | _i | _i | _|| _g | _	d | _
i | _i | _|rXtjjtjj D ]¤}z|j| d d … | j|< W n tyœ   g | j|< Y n0 ||jv rÞ|j|  ¡ | j|< |j| | j|< |j| | j|< q`i | j|< d g f| j|< d g f| j|< q`tjjD ]}|  |¡ q| jd d d | _|j
| _
| j |j¡ | j |j¡ nTtjjtjj D ]6}g | j|< i | j|< d g f| j|< d g f| j|< qhd | _d | _d S )NF©rd   )ÚsuperrÜ   rA   rî   rá   rã   rä   rÞ   rò   rï   rð   ró   rß   r1   rZ   râ   ÚKeyErrorrX   Úoverlay_layersÚclearÚreplace_transientr•   rU   Úmusic)r@   Úoldslrò   rŒ   ©rD   r$   r%   rA   a  sL    



zSceneLists.__init__Úhidec                 C   sD   t jjD ]}|  |d¡ q| jD ]\}}| j|||d q g | _dS )aW  
        Replaces the contents of the transient display list with
        a copy of the master display list. This is used after a
        scene is displayed to get rid of transitions and interface
        elements.

        `prefix`
            The prefix/event to use. Set this to None to prevent the hide
            from happening.
        Tr÷   N)r1   rZ   Útransient_layersrû   rï   Úremove)r@   rd   rŒ   r6   r7   r$   r$   r%   rü   °  s
    zSceneLists.replace_transientc                 C   s"   t jjD ]}| j| r dS qdS )a2  
        This returns True if all transient layers are empty. This is
        used by the rollback code, as we can't start a new rollback
        if there is something in a transient layer (as things in the
        transient layer may contain objects that cannot be pickled,
        like lambdas.)
        FT)r1   rZ   r  rá   rå   r$   r$   r%   Útransient_is_emptyÄ  s    	
zSceneLists.transient_is_emptyFc                 C   s    |du r|S t |tjjjƒr |S tjjr2| ¡ }n|}t |tjjj	ƒsJ|S tjjr\| ¡ }n|}t |tjjj	ƒs„tjjj	|d }}| 
|¡ |rœ| |¡ |S )zr
        If the old thing is a transform, then move the state of that transform
        to the new thing.
        N©rº   )rÂ   r1   r-   ÚscreenÚScreenDisplayablerZ   Útake_state_from_targetr¹   ÚmotionÚ	TransformÚ
take_stateÚtake_execution_state)r@   Z	old_thingZ	new_thingÚ	executionÚold_transformÚnew_transformr$   r$   r%   Útransform_stateÓ  s$    



zSceneLists.transform_statec           	      C   sä   d}d}t | j| ƒD ]<\}}|du r|jr6|j|ks@|j|kr|}|du r|j}q|du rltjj |d¡}t | j| ƒD ]H\}}|du rz|j|kr´|jrÂ|j|ks®|j|v rÂ|}qz|j|krz|}qz|du rÚt	| j| ƒ}|||fS )ak  
        This finds the spot in the named layer where we should insert the
        displayable. It returns two things: an index at which the new thing
        should be added, and an index at which the old thing should be hidden.
        (Note that the indexes are relative to the current state of the list,
        which may change on an add or remove.)
        Nr   )
Ú	enumeraterá   r7   rÖ   rÓ   r1   rZ   Ú
tag_zorderr   Úlen)	r@   r6   r7   rÓ   ÚbehindÚ	add_indexÚremove_indexrŒ   Úsler$   r$   r%   Ú
find_index÷  s(    	

zSceneLists.find_indexNr   c                 C   sÒ  t |tƒstdt|ƒ ƒ‚|| jvr0td| ƒ‚|rN|  ||¡ || j| |< |rd|rd| j ||¡ |
rx| j	 
||f¡ | j| }|r˜tjjj||d}|  ||||¡\}}}d}d}|durJ|| }|j}|j}|rÞ|j}|  ||d¡sü||krü|d8 }|s2|s2tjjr2t |tjjjƒr2|j |¡}n|  ||¡}| d¡ n(t |tjjjƒsh|  |	|¡}| d¡ |duršt||||||ƒ}| ||¡ z| d	d
„ ¡ W n  tyÌ   tjjrÈ‚ Y n0 dS )aæ  
        Adds something to this scene list. Some of these names are quite a bit
        out of date.

        `thing` - The displayable to add.

        `key` - A string giving the tag associated with this thing.

        `zorder` - Where to place this thing in the zorder, an integer
        A greater value means closer to the user.

        `behind` - A list of tags to place the thing behind.

        `at_list` - The at_list associated with this
        displayable. Counterintuitively, this is not actually
        applied, but merely stored for future use.

        `name` - The full name of the image being displayed. This is used for
        image lookup.

        `atl` - If not None, an atl block applied to the thing. (This actually is
        applied here.)

        `default_transform` - The default transform that is used to initialized
        the values in the other transforms.

        `keep_st`
            If true, we preserve the shown time of a replaced displayable.
        z6Attempting to show something that isn't a displayable:z3Trying to add something to non-existent layer '%s'.r  NÚreplacedr+   rÅ   Úshowc                 S   s   d S r'   r$   )r¤   r$   r$   r%   Ú<lambda>  rì   z SceneLists.add.<locals>.<lambda>)rÂ   rg   r]   Úreprrá   Úremove_hide_replacedrã   rò   Úpredict_showrï   rÄ   r1   r-   r  ÚATLTransformr  rÖ   rÕ   rÔ   Úhide_or_replacerZ   Úkeep_running_transformr	  r»   r  r´   rÒ   Úinsertr¢   r[   )r@   r6   ÚthingÚkeyrÓ   r  rã   r`   ÚatlÚdefault_transformÚ	transientZkeep_stÚlr  r  rƒ   r›   r  Úoldr$   r$   r%   r¡     s^    *



ÿþý


zSceneLists.addc                 C   sÄ   |du rdS | j | }|| }tƒ }|jp,|}|jp6|}tjjrP|j |¡sPd}|dur¶|j	r¶|j 
¡  || || |¡}	| |¡}|	dur¶t|d |j	 |j|||	dƒ}
|
||< dS | |¡ dS )a  
        Hides or replaces the scene list entry at the given
        index. `prefix` is a prefix that is used if the entry
        decides it doesn't want to be hidden quite yet.

        Returns True if the displayable is kept, False if it is removed.
        NFú$T)rá   r)   rÔ   rÕ   r1   rZ   Úfast_unhandled_eventrÖ   rµ   r7   rw   r·   rÙ   rÒ   rÓ   Úpop)r@   r6   rÙ   rd   r'  ZoldsleÚnowr›   rƒ   r¤   r  r$   r$   r%   r  ’  s4    	



ú
zSceneLists.hide_or_replacec                 C   sD   g }| j  ¡ D ]0}|D ]&}|r0|jr0d|jv r0q| |j¡ qq|S )zÂ
        Gets all displayables reachable from this scene list.

        `current`
            If true, only returns displayables that are not in the process
            of being hidden.
        r)  )rá   Úvaluesr7   rÄ   rÖ   )r@   ÚcurrentrW   r'  r  r$   r$   r%   Úget_all_displayablesÄ  s    	zSceneLists.get_all_displayablesc                 C   sn   t t| j| ƒd ddƒD ]N}| j| | }|rH|j|ksD|j|krH qj|jrZd|jv rZq|  ||d¡ qdS )zÌ
        Removes everything on the layer that is closer to the user
        than thing, which may be either a tag or a displayable. Thing must
        be displayed, or everything will be removed.
        r+   r   r)  r   N)r   r  rá   r7   rÖ   r  )r@   r6   r"  rŒ   r  r$   r$   r%   Úremove_aboveØ  s    zSceneLists.remove_abovec                 C   s|   || j vrtd| ƒ‚|  ||dg ¡\}}}|durx| j | | j}|rj| j ||f¡ | j|  |d¡ |  |||¡ dS )a9  
        Thing is either a key or a displayable. This iterates through the
        named layer, searching for entries matching the thing.
        When they are found, they are removed from the displaylist.

        It's not an error to remove something that isn't in the layer in
        the first place.
        z8Trying to remove something from non-existent layer '%s'.r   N)	rá   r]   r  r7   rò   Úpredict_hiderã   r+  r  )r@   r6   r"  rd   Z
_add_indexr  Ú_zorderr7   r$   r$   r%   r  ì  s    

zSceneLists.removec                 C   sˆ   || j vrdS |s&g | j | dd…< n.tt| j | ƒd ddƒD ]}|  |||¡ q@| j|  ¡  | j |¡ tj	j
r„dg f| j|< dS )zœ
        Clears the named layer, making it empty.

        If hide is True, then objects are hidden. Otherwise, they are
        totally wiped out.
        Nr+   r   )rá   r   r  r  rã   rû   rò   Úpredict_scener1   rZ   Úscene_clears_layer_at_listrä   )r@   r6   r   rŒ   r$   r$   r%   rû     s    
zSceneLists.clearTc                 C   s<   |rd t |ƒf| j|< nd t |ƒf| j|< |r8d | j|< d S r'   )ÚlistrÞ   rä   ró   )r@   r6   rã   ÚresetÚcamerar$   r$   r%   Úset_layer_at_list  s
    zSceneLists.set_layer_at_listc                    s”   t | j ¡ ƒD ]\}\}}|p ˆ |f| j|< qt | j ¡ ƒD ]\}\}}|pNˆ |f| j|< q<| j ¡ D ](\}}‡ fdd„|D ƒ| j| dd…< qfdS )zm
        This finds entries with a time of None, and replaces that
        time with the given time.
        c                    s   g | ]}|  ˆ ¡‘qS r$   )rÛ   ré   ©r   r$   r%   rë   6  rì   z(SceneLists.set_times.<locals>.<listcomp>N)r5  rÞ   Úitemsrä   rá   )r@   r   r'  r(   Úllr$   r9  r%   Ú	set_times)  s    zSceneLists.set_timesc                 C   s   | j  ||¡S )zq
        Returns true if something with the prefix of the given name
        is found in the scene list.
        )rò   Úshowing)r@   r6   r`   r$   r$   r%   r=  8  s    zSceneLists.showingc                 C   s   | j  |¡S r'   )rò   Úget_showing_tags)r@   r6   r$   r$   r%   r>  @  s    zSceneLists.get_showing_tagsc                 C   s8   g }| j | D ]$}|jsqd|jv r&q| |j¡ q|S )Nr)  ©rá   r7   rÄ   ©r@   r6   rW   r  r$   r$   r%   Úget_sorted_tagsC  s    
zSceneLists.get_sorted_tagsc                 C   sR   t jjjf d|dœ|¤Ž}| | j| ¡ ||_d|_| j| |_	| j
| |_|S )zK
        Creates a Fixed with the given layer name and scene_list.
        Úfixed)Úlayoutrr   F)r1   r-   rC  ÚMultiBoxZappend_scene_listrá   Ú
layer_namerx   rä   Z_layer_at_listrÞ   Z_camera_list)r@   r6   rs   rW   r$   r$   r%   Ú
make_layerQ  s    zSceneLists.make_layerc                 C   sn  |du r| j | }|du r$| j| }|}|\}}| j |d¡}d}	|rÀ|D ],}
t|
tjjjƒrn|
|d}|}	qJ|
|ƒ}qJ|	dur˜tj	j
r˜| j||	dd tjjjdd}| |||¡ ||_|}|	| j|< |\}}| j |d¡}d}	|r`|D ].}
t|
tjjjƒr|
|d}|}	qî|
|ƒ}qî|	dur8| j||	dd tjjjdd}| |||¡ ||_|}|	| j|< |S )z…
        When `d` is a layer created with make_layer, returns `d` with the
        various at_list transforms applied to it.
        Nr  T)r  rB  ©rC  )rä   rÞ   ró   r   rÂ   r1   r-   r  r	  rZ   Úkeep_show_layer_stater  rC  rD  r¡   rE  rß   )r@   r6   r¤   rä   rÞ   rW   r   rã   r  r  r{   Úfr$   r$   r%   Útransform_layer_  sL    








zSceneLists.transform_layerc                    s@   d| ‰ d| ‰| j | }‡ ‡fdd„|D ƒ| j | dd…< dS )z^
        Removes things that are hiding or replaced, that have the given
        tag.
        úhide$ú	replaced$c                    s$   g | ]}|j ˆ kr|j ˆkr|‘qS r$   )r7   ré   ©Zhide_tagZreplaced_tagr$   r%   rë   °  rì   z3SceneLists.remove_hide_replaced.<locals>.<listcomp>N)rá   )r@   r6   r7   r'  r$   rM  r%   r  ¦  s    
zSceneLists.remove_hide_replacedc                 C   sª   t ƒ }| jD ]˜}g }| j| D ]r}|jr†|j d¡rX|j ||j ||j d¡}|s†qn.|j d¡r†|j ||j ||j d¡}|s†q| |¡ q|| j| dd…< qdS )zž
        Goes through all of the layers, and removes things that are
        hidden and are no longer being kept alive by their hide
        methods.
        rK  r   rL  r  N)	r)   rá   r7   Ú
startswithrÖ   r·   rÔ   rÕ   rÄ   )r@   r,  r'  Únewlr  r¤   r$   r$   r%   Úremove_hidden²  s    
zSceneLists.remove_hiddenc                 C   sR   | j D ]F}g }| j | D ] }|jr.d|jv r.q| |¡ q|| j | dd…< qdS )zk
        Removes everything hidden, even if it's not time yet. (Used when making a rollback copy).
        r)  Nr?  )r@   r'  rO  r  r$   r$   r%   Úremove_all_hiddenÐ  s    

zSceneLists.remove_all_hiddenc                 C   s>   || j vrtd| ƒ‚| j | D ]}|j|kr |j  S q dS )z±
        Returns the displayable on the layer with the given tag, or None
        if no such displayable exists. Note that this will usually return
        a Transform.
        úUnknown layer %r.N)rá   r]   r7   rÖ   )r@   r6   r7   r  r$   r$   r%   r5   ã  s    

z!SceneLists.get_displayable_by_tagc                 C   s>   || j vrtd| ƒ‚| j | D ]}|j|kr |j  S q dS )z²
        Returns the displayable on the layer with the given name, or None
        if no such displayable exists. Note that this will usually return
        a Transform.
        rR  N)rá   r]   r`   rÖ   )r@   r6   r`   r  r$   r$   r%   Úget_displayable_by_nameó  s    

z"SceneLists.get_displayable_by_namec                 C   s¼   || j vrtd| ƒ‚| j | D ]}|j|kr  q8q dS tƒ }|jdurT||j }nd}|jdurn||j }nd}tjj 	|j
||||¡}	|	j}
|	j}t|||
||j
 ¡ ƒ\}}|||
|fS )z6
        Implements renpy.get_image_bounds().
        rR  Nr   )rá   r]   r7   r)   rÔ   rÕ   r1   r-   r˜   Úrender_for_sizerÖ   rE   rF   rR   rž   )r@   r6   r7   rE   rF   r  r,  r›   rƒ   r­   rG   rH   rP   rQ   r$   r$   r%   Úget_image_bounds  s$    



zSceneLists.get_image_boundsc                 C   sF   g }| j  |g ¡D ].}|jdu r"qd|jv r.q| |j|jf¡ q|S )z8
        Returns a list of (tag, zorder) pairs.
        Nr)  )rá   r   r7   rÄ   rÓ   r@  r$   r$   r%   Úget_zorder_list&  s    

zSceneLists.get_zorder_listc                 C   s<   | j  |g ¡}|D ]}|j|kr||_q|jdd„ d dS )z6
        Changes the zorder for tag on layer.
        c                 S   s   | j S r'   )rÓ   )r  r$   r$   r%   r  C  rì   z*SceneLists.change_zorder.<locals>.<lambda>)r#  N)rá   r   r7   rÓ   Úsort)r@   r6   r7   rÓ   Úslr  r$   r$   r%   Úchange_zorder8  s
    
zSceneLists.change_zorder)r   )F)F)r   )F)TF)NN)"r:   r;   r<   r=   Ú__version__ræ   rö   rA   rü   r  r  r  r¡   r  r/  r0  r  rû   r8  r<  r=  r>  rA  rF  rJ  r  rP  rQ  r5   rS  rU  rV  rY  Ú__classcell__r$   r$   rÿ   r%   rÜ   .  sN   O

$+õ
s2





G#rÜ   r   c                 C   s   t j | ¡jS )zj
    Returns either the current scenelists object, or the one for the
    context at the given index.
    )r1   r2   r3   r4   )rÙ   r$   r$   r%   r4   F  s    r4   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú	MouseMovezA
    This contains information about the current mouse move.
    c                 C   sB   t ƒ | _|d ur|| _nd| _tjj ¡ \| _| _|| _	|| _
d S ©Nr   )r)   ÚstartÚdurationr1   r-   ÚdrawÚget_mouse_posÚstart_xÚstart_yÚend_xÚend_y©r@   rP   rQ   r_  r$   r$   r%   rA   T  s    zMouseMove.__init__c                 C   s„   t ƒ | j }|| jkr.tjj | j| j¡ dS d| | j }t	| j
|| j| j
   ƒ}t	| j|| j| j   ƒ}tjj ||¡ dS )z‚
        Performs the mouse move. Returns True if this should be called
        again, or False if the move has finished.
        Fr   T)r)   r^  r_  r1   r-   r`  Úset_mouse_posrd  re  Úintrb  rc  )r@   ÚelapsedÚdonerP   rQ   r$   r$   r%   Úperforma  s    
zMouseMove.performN)r:   r;   r<   r=   rA   rk  r$   r$   r$   r%   r\  O  s   r\  c                  C   s|   t jr
dS tt jjddƒrdS zDt jr^ddl} d}| j| jj	j
_| jj	 
|¡d@ rXW dS W dS W dS  tyv   Y dS 0 dS )z6
    Returns true if we should go into safe mode.
    FÚ	safe_modeTr   Né   i €  )r1   Úsafe_mode_checkedrà   r2   ra   ÚwindowsÚctypesÚc_ushortÚwindllÚuser32ZGetKeyStateÚrestyper]   )rp  ZVK_SHIFTr$   r$   r%   Úget_safe_modev  s    ru  c                   @   sÚ   e Zd ZdZi Zdd„ Zd5dd„Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zd6dd„Zdd„ Zdd„ Zdd„ Zd7d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d0d1„ Zd2d3„ Zd4S )8ÚRendereraß  
    A Renderer (also known as a draw object) is responsible for drawing a
    tree of displayables to the window. It also provides other services that
    involved drawing and the SDL main window, as documented here.

    A Renderer is responsible for updating the renpy.game.preferences.fullscreen
    and renpy.game.preferences.physical_size preferences, when these are
    changed from outside the game.

    A renderer has an info dict, that contains the keys from pygame_sdl2.display.Info(),
    and then:
    - "renderer", the name of the Renderer.
    - "resizable", true if the window can be resized.
    - "additive", true if additive blendering is supported.
    - "models", true if model-based rendering is being used.
    c                 C   s   dS )zš
        This returns a pair contining the total amount of memory consumed by
        textures, and a count of the number of textures that exist.
        Nr$   rb   r$   r$   r%   Úget_texture_size¨  s    zRenderer.get_texture_sizeFc                 C   s   dS )aO  
        This is called before a draw operation to check to see if the state of
        the draw objects needs to be updated after an external event has occured.
        Things that require draw updates might be:

        * The window has changed its size.
        * The window has changed full-screen status.
        * `force` is given, which generally means that it's likely the GL
          context has become invalid.

        After this has been called, the system should be in a good state for
        rendering.

        Returns True if a redraw is required, False otherwise.
        Nr$   )r@   Úforcer$   r$   r%   rU   ®  s    zRenderer.updatec                 C   s   dS )z˜
        This creates a renderer with the given `virtual_size`. It returns
        True of the renderer initialized correctly, False otherwise.
        Nr$   )r@   Úvirtual_sizer$   r$   r%   Úinit¿  s    zRenderer.initc                 C   s   dS )zO
        This shuts down the renderer until the next call to ``init``.
        Nr$   rb   r$   r$   r%   ÚquitÅ  s    zRenderer.quitc                 C   s   dS )a	  
        This is called to implement resizing and changing the fullscreen
        mode. It is expected to determine the size to use using
        renpy.game.preferences.physical_size, and the fullscreen mode
        using renpy.game.preferences.fullscreen.
        Nr$   rb   r$   r$   r%   ÚresizeÊ  s    zRenderer.resizec                 C   s   dS )z~
        Returns True if we can block to wait for input, False if the screen
        needs to be immediately redrawn.
        Nr$   rb   r$   r$   r%   Ú	can_blockÒ  s    zRenderer.can_blockc                 C   s   dS )aP  
        Determines if the screen needs to be redrawn. Returns True if it
        does.

        `needs_redraw`
            True if the needs_redraw flag is set.

        `first_pass`
            True if this is the first pass through the interact loop.

        `can_block`
            The value of self.can_block, from above.
        Nr$   )r@   Úneeds_redrawÚ
first_passr}  r$   r$   r%   Úshould_redrawØ  s    zRenderer.should_redrawc                 C   s   || j v r| j |= dS )zr
        Called to indicated that `surf` has changed and textures based on
        it should not be used.
        N)Útexture_cache)r@   r­   r$   r$   r%   Úmutated_surfaceç  s    
zRenderer.mutated_surfacec                 C   s   dS )zß
        Loads a surface into a texture.

        `surf`
            The pygame.Surface to load.

        `transient`
            True if the texture is unlikely to be used for more than a single
            frame.
        Nr$   )r@   r­   r&  r$   r$   r%   Úload_textureð  s    zRenderer.load_texturec                 C   s   dS )zw
        This is called in the main thread to indicate that one texture
        should be loaded into the GPU.
        Nr$   rb   r$   r$   r%   Úready_one_textureü  s    zRenderer.ready_one_texturec                 C   s   dS )z>
        Removes all cached textures, to free memory.
        Nr$   rb   r$   r$   r%   Úkill_textures  s    zRenderer.kill_texturesc                 C   s   dS )zy
        This is called to create a (`w` x `h`) texture of a single
        color.

        Returns the texture.
        Nr$   )r@   ÚwÚhÚcolorr$   r$   r%   Úsolid_texture  s    zRenderer.solid_textureTc                 C   s   dS )zü
        This draw the screen.

        `surftree`
            A Render object (the root of a tree of Render objects) that
            will be drawn to the screen.

        `flip`
            If True, the drawing will be presented to the user.
        Nr$   )r@   ÚsurftreeÚflipr$   r$   r%   Údraw_screen  s    zRenderer.draw_screenc                 C   s   dS )z«
        Converts `what`, a tree of Renders, to a texture of the same size.

        `alpha`
            A hint as to if the texture should have an alpha channel.
        Nr$   )r@   ÚwhatÚalphar$   r$   r%   Úrender_to_texture  s    zRenderer.render_to_texturec                 C   s   dS )z¹
        Returns true if the pixel is not 100% transparent.

        `what`
            A tree of renders.

        `x`, `y`
            The coordinates of the pixels to check.
        Nr$   )r@   r  rP   rQ   r$   r$   r%   Úis_pixel_opaque#  s    zRenderer.is_pixel_opaquec                 C   s   dS )zv
        Gets a texture that is half the size of `what`, which may be
        a texture or a tree of Renders.
        Nr$   )r@   r  r$   r$   r%   Úget_half.  s    zRenderer.get_halfc                 C   s   dS )zM
        Translates (`x`, `y`) from physical to virtual coordinates.
        ©r   r   r$   ©r@   rP   rQ   r$   r$   r%   Útranslate_point4  s    zRenderer.translate_pointc                 C   s   dS )zO
        Untranslates (`x`, `y`) from virtual to physical coordinates.
        r’  r$   r“  r$   r$   r%   Úuntranslate_point;  s    zRenderer.untranslate_pointc                 C   s   |S )z¡
        This translates the .pos field of `ev` from physical coordinates to
        virtual coordinates. Returns an (x, y) pait of virtual coordinates.
        r$   ©r@   rœ   r$   r$   r%   Úmouse_eventB  s    zRenderer.mouse_eventc                 C   s   dS )zW
        Returns the x and y coordinates of the mouse, in virtual coordinates.
        r’  r$   rb   r$   r$   r%   ra  J  s    zRenderer.get_mouse_posc                 C   s$   |   ||¡\}}tj ||g¡ dS )zI
        Moves the mouse to the virtual coordinates `x` and `y`.
        N)r•  r,   ÚmouseÚset_posr“  r$   r$   r%   rg  Q  s    zRenderer.set_mouse_posc                 C   s   dS )zv
        This returns a pygame.Surface that is the result of rendering
        `surftree`, a tree of Renders.
        Nr$   )r@   rŠ  r$   r$   r%   Ú
screenshotY  s    zRenderer.screenshotc                 C   s   dS )zŠ
        On platforms where CPU usage is gated by the need to redraw, sleeps
        a short amount of time to keep the CPU idle.
        Nr$   rb   r$   r$   r%   Úevent_peek_sleep_  s    zRenderer.event_peek_sleepc                 C   s   dS )zN
        Returns the physical size of the window, in physical pixels.
        Nr$   rb   r$   r$   r%   Úget_physical_sizee  s    zRenderer.get_physical_sizeN)F)F)T)r:   r;   r<   r=   r  rw  rU   rz  r{  r|  r}  r€  r‚  rƒ  r„  r…  r‰  rŒ  r  r  r‘  r”  r•  r—  ra  rg  rš  r›  rœ  r$   r$   r$   r%   rv  ”  s4   
	

rv  c                	   @   sô  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dwdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zdxd!d"„Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zdyd,d-„Zd.d/„ Zdzd0d1„Zd{d3d4„Zd5d6„ Zd|d7d8„Zd9d:„ Zd;d<„ Zd=d>„ Z d?d@„ Z!dAdB„ Z"dCdD„ Z#dEdF„ Z$dGdH„ Z%dIdJ„ Z&d}dKdL„Z'dMdN„ Z(dOdP„ Z)dQdR„ Z*dSdT„ Z+dUdV„ Z,dWdX„ Z-dYdZ„ Z.d[d\„ Z/d]d^„ Z0d_d`„ Z1dadb„ Z2dcdd„ Z3dedf„ Z4d~dgdh„Z5didj„ Z6dkdl„ Z7d2ddddmg d+ddnf	dodp„Z8dqdr„ Z9dsdt„ Z:dudv„ Z;d+S )Ú	InterfaceaN  
    This represents the user interface that interacts with the user.
    It manages the Display objects that display things to the user, and
    also handles accepting and responding to user input.

    @ivar display: The display that we used to display the screen.

    @ivar profile_time: The time of the last profiling.

    @ivar screenshot: A screenshot, or None if no screenshot has been
    taken.

    @ivar old_scene: The last thing that was displayed to the screen.

    @ivar transition: A map from layer name to the transition that will
    be applied the next time interact restarts.

    @ivar transition_time: A map from layer name to the time the transition
    involving that layer started.

    @ivar transition_from: A map from layer name to the scene that we're
    transitioning from on that layer.

    @ivar suppress_transition: If True, then the next transition will not
    happen.

    @ivar force_redraw: If True, a redraw is forced.

    @ivar restart_interaction: If True, the current interaction will
    be restarted.

    @ivar pushed_event: If not None, an event that was pushed back
    onto the stack.

    @ivar mouse: The name of the mouse cursor to use during the current
    interaction.

    @ivar ticks: The number of 20hz ticks.

    @ivar frame_time: The time at which we began drawing this frame.

    @ivar interact_time: The time of the start of the first frame of the current interact_core.

    @ivar time_event: A singleton ignored event.

    @ivar event_time: The time of the current event.

    @ivar timeout_time: The time at which the timeout will occur.
    c                 C   s¶  d | _ d | _i | _i | _i | _i | _i | _d| _d| _d| _	d| _
d | _d| _d| _d | _d | _d | _d | _d| _g | _tƒ | _d| _d | _d| _d| _tj tddi¡| _tj t¡| _ d| _!d| _"i | _#d| _$d| _%d| _&d| _'t(j)j*t(j)j+ D ]T}|t(j)j,v r<t(j)j,| \}}}}t-|d|d||||dd	| j#|< qôt-ƒ | j#|< qôg | _.d| _/d | _0d| _1d| _2d| _3t4 5¡ | _6tƒ  tƒ | _0d | _7| t(j8_9| t(j:_9d| _;d| _<t4 ¡ | _=d | _>d | _?d | _@d | _Ad | _Bt(jC Dd¡| _E| jErît(jFpôt(j)jG| _Gd| _
t(j)jHrt(j)jI Jt(j)jH¡ d| _Kd| _LtMƒ | _;dt(_N|  O¡ | _Pt(j:jQ Rd| jP¡ d	| _S|  TtU¡ d| _Vg | _Wd
| _Xd | _Yd | _Zi | _[d| _\d| _]z|  ^¡  W n t_y°   Y n0 d S )NFr   rf   ÚmodalT)	rJ   rL   rK   rM   ÚxmaximumÚymaximumÚxminimumÚyminimumÚclippingÚtouchzDPI scale factor: %fr   g‘?)`rš  Úscreenshot_surfaceÚ	old_sceneÚ
transitionÚongoing_transitionÚtransition_timeÚtransition_fromÚsuppress_transitionZ
quick_quitÚforce_redrawÚrestart_interactionÚpushed_eventÚticksr˜  Útimeout_timeÚ
last_eventZcurrent_contextÚroll_forwardÚ
fullscreenÚpreloadsr)   r&   Ú
frame_timeÚinteract_timeÚ	quit_timeÚin_quit_eventr,   r   ÚEventr   Ú
time_eventr   Úredraw_eventÚmouse_focusedÚkeyboard_focusedÚlayer_propertiesrî   Úignore_touchÚclear_screenshotÚaudio_pausedr1   rZ   rá   râ   Úlayer_clippingÚdictZtransition_info_stackÚ
event_timeÚmouse_event_timeÚ
show_mouseÚdisplay_resetÚprofile_onceÚ	threadingÚcurrent_threadÚthreadÚwindow_captionr2   Ú	interfacer-   rl  Úbgscreenshot_neededÚbgscreenshot_eventÚbgscreenshot_surfaceÚ
mouse_moveÚtext_editingÚ	text_rectÚold_text_rectr   Úvariantr¤  Ú
emscriptenÚtouch_keyboardÚperiodic_callbackÚperiodic_callbacksrÄ   ÚstartedÚfullscreen_videoru  rn  Úsetup_dpi_scalingZ	dpi_scaleÚlogÚwriteÚmaximum_framerate_timeÚmaximum_framerateÚinitial_maximum_framerateÚstart_interactÚframe_timesÚframe_durationÚcursor_cacheÚ	old_mouseÚtransition_delayÚfirst_frameÚforce_predictionÚsetup_nvdrsr]   )r@   r6   rP   rQ   r†  r‡  r$   r$   r%   rA   ¢  s¼    ÷




zInterface.__init__c                 C   sz   ddl m}m} |j}|j}|j}|j}||_tj	j
 d¡ |ƒ  |ƒ }|r^tj	j
 d|¡ ntj	j
 d¡ t |¡ d S )Nr   )ÚcdllÚc_char_pz5nvdrs: Loaded, about to disable thread optimizations.znvdrs: %r (can be ignored)z%nvdrs: Disabled thread optimizations.)rp  rë  rì  ÚnvdrsÚdisable_thread_optimizationÚrestore_thread_optimizationÚget_nvdrs_errorrt  r1   r-   rÝ  rÞ  ÚatexitÚregister)r@   rë  rì  rí  rî  rï  rð  Úerrorr$   r$   r%   rê  p  s    zInterface.setup_nvdrsc           
      C   s  dt jv rtt jd ƒS tjs"dS z´dd l}ddlm}m} |jj	 
¡  |jj	j}||_|g|_|jj	j}||g|_|jjj}||_||g|_d}|d ƒ}|||ƒd }	|d |ƒ |	tjjk rÒtjj d|	¡ d}	|	W S  ty   tjj d¡ tjj ¡  Y dS 0 d S )	NZRENPY_HIGHDPIr   r   )Úc_void_pÚc_intéX   g      X@zDe minimus DPI scale, was %rz%Could not determine DPI scale factor:)r   r   r!   r1   ro  rp  rô  rõ  rr  rs  ÚSetProcessDPIAwareÚGetDCrt  ÚargtypesÚ	ReleaseDCZgdi32ÚGetDeviceCapsrZ   Úde_minimus_dpi_scaler-   rÝ  rÞ  r]   Ú	exception)
r@   rp  rô  rõ  rø  rú  rû  Z
LOGPIXELSXZdcrW   r$   r$   r%   rÜ  „  s8    






zInterface.setup_dpi_scalingc                 C   sü  ddl }| jrdS tjr |  ¡  tj dtjj	p2d 
d¡¡ tj dtjj	pNd 
d¡¡ tjj ¡  ztj ¡  tj ¡  W n tyŽ   Y n0 |  ¡  tjj ¡  t ¡  tjr¾tjdd…= tjj ¡  tjj ¡  tj d¡ d| _|  ¡  tjj ¡  tj  t!t"¡ tj# $d	¡ | j%s*tjj& ¡  tj# 'tj(tj)tj*g¡ tjjrÌi | _+i }tjj ,¡ D ]h\}}g }|D ]J}||vr¬|\}}}	tjj- .|¡}
tj /|
||	¡||< | 0|| ¡ qr|| j+|< qbd
 1t ¡ t2 ¡}tjrøtjj3søt4|ƒ dS )zQ
        Starts the interface, by opening a window and setting the mode.
        r   NZSDL_APP_NAMEzRen'Py Gameúutf-8ZSDL_AUDIO_DEVICE_APP_NAMEzInterface startTFz%Total time until interface ready: {}s)5Ú	tracebackrÚ  r1   ÚandroidÚcheck_android_startr,   r-   ÚhintrZ   r`   ÚencodeÚaudiorz  r˜  r]   Ú	post_initÚemulatorZinit_emulatorÚgcÚcollectÚgarbager˜   Úrender_readyÚ	presplashÚendr®   Z	log_clockÚset_moder¾   ÚfontZ
load_fontsr   Ú	set_timerr   ÚPERIODIC_INTERVALr   Úset_grabrl  Ú
controllerr   ÚMOUSEMOTIONÚMOUSEBUTTONDOWNÚMOUSEBUTTONUPrå  r:  ÚimZload_surfaceÚColorCursorrÄ   r^   Úimport_timeÚlog_to_stdoutÚprint)r@   rÿ  Zcursorsr#  Zcursor_listr'  rŒ   ÚfnrP   rQ   r­   Úsr$   r$   r%   r^  ®  sX    



zInterface.startc                 C   sì   t j dd¡ t j dd¡ t j dd¡ t j dd¡ t j dd¡ tjjr\t j dd¡ t j tjj¡ tjjp„t	j
 tjd	 ¡}|t	jd
< | jdd |  ¡  tjr´t d¡ t j ¡ D ](}|tv rÌq¾|tjjv rÚq¾t j |¡ q¾dS )zV
        This is called after display init, but before the window is created.
        Z&SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITORÚ0Z SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSSZSDL_TOUCH_MOUSE_EVENTSÚ1ZSDL_MOUSE_TOUCH_EVENTSZSDL_EMSCRIPTEN_ASYNCIFYZSDL_MOUSE_FOCUS_CLICKTHROUGHr   ZSDL_VIDEO_X11_WMCLASST©rx  N)r,   r-   r  r1   rZ   Úmouse_focus_clickthroughÚset_screensaverÚallow_screensaverÚsave_directoryr   ÚpathÚbasenameÚsysÚargvr   Úset_window_captionÚset_iconr   Úwakelockr   Úget_standard_eventsÚenabled_eventsÚpygame_eventsÚset_blocked)r@   ZwmclassrŒ   r$   r$   r%   r  	  s(    

zInterface.post_initc                 C   s.   t jr*ddlm} |dƒ}| ¡  tdƒ dS )z>
        Called after the first frame has been drawn.
        r   ©Ú	autoclassz#org.renpy.android.PythonSDLActivityzHid presplash.N)r1   r   Újniusr0  ZhidePresplashr  )r@   r0  ZPythonSDLActivityr$   r$   r%   Úafter_first_frame*	  s
    zInterface.after_first_framec                 C   sÂ   t jj}|r¾zšt j |¡ }t jj ||¡}W d  ƒ n1 s@0    Y  | ¡ \}}t	||ƒ}t jj
 ||fd¡}| ||| d || d f¡ |}tj |¡ W n t jjy¼   Y n0 dS )z;
        This is called to set up the window icon.
        NTr„   )r1   rZ   Úwindow_iconÚloaderÚloadr-   ÚscaleÚimage_load_unscaledr.   r/   ÚpgrenderÚsurface_unscaledr«   r,   r)  Ú	webloaderÚDownloadNeeded)r@   ZiconrI  r  ÚiwZihZimaxZ	square_imr$   r$   r%   r)  6	  s     þ"
 zInterface.set_iconFc                 C   sh   t jj}|d u rd}t j |¡t jj }t j ¡ r:|d7 }|sL|| j	krLd S || _	t
j | d¡¡ d S )NzA Ren'Py Gamez - autoreloadrþ  )r1   rZ   Úwindow_titleÚtranslationÚtranslate_stringÚstoreZ_window_subtitler   Zget_autoreloadrÌ  r,   r-   Úset_captionr  )r@   rx  r=  Zcaptionr$   r$   r%   r(  R	  s    
zInterface.set_window_captionc                 C   s   t j ¡  d S r'   )r,   r-   Úiconifyrb   r$   r$   r%   rB  d	  s    zInterface.iconifyc                    s   dt jv rdtj_tjjj}t j d|¡}tj	 d|¡}|tj_tj
sRtjsRtjrZdg‰ntjrjg d¢‰nddg‰g }dD ]}|ˆv rz| |d ¡ qztjjr´|ˆ ‰||vr¼d}nˆ| ‰|ˆv rÌ|d	g‰|d	krÚd	g‰tj
sötjsötjsöˆd	g ‰| jrd	g‰i ‰ ‡ ‡fd
d„}|ddddƒ |ddddƒ |ddddƒ |ddddƒ |ddddƒ |ddddƒ |d	ddƒ g ‰‡ ‡fdd„}ˆD ]}||ƒ qŒˆS )zC
        Figures out the list of draw constructors to try.
        ZRENPY_RENDERERFÚrendererÚgles)ÚglÚanglerD  rE  Ú2ÚautorG   c                    st   | ˆvrdS z.t |ƒ tj| }t||ƒ}||Ž ˆ | < W dS  tyn   tjj d 	| ¡¡ tjj 
¡  Y dS 0 d S )NFTzCouldn't import {0} renderer:)Ú
__import__r&  Úmodulesrà   r]   r1   r-   rÝ  rÞ  r^   rý  )r`   ÚmodÚclsra   ÚmoduleZ
draw_class)Údraw_objectsÚ	renderersr$   r%   Ú	make_draw	  s    

z2Interface.get_draw_constructors.<locals>.make_drawzrenpy.gl.gldrawZGLDrawrF  Úgl2zrenpy.gl2.gl2drawZGL2DrawZangle2Zgles2zrenpy.display.swdrawÚSWDrawc                    s4   | ˆ v rˆ  | ˆ |  f¡ ntjj d | ¡¡ d S )NzUnknown renderer: {0})rÄ   r1   r-   rÝ  rÞ  r^   )r`   )rN  rW   r$   r%   Úappend_draw»	  s    z4Interface.get_draw_constructors.<locals>.append_draw)r   r   r1   rZ   rQ  r2   ÚpreferencesrC  r   Úsessionr   ÚiosrÖ  ro  rÄ   rl  )r@   rC  Zgl2_renderersrŒ   rP  rS  r$   )rN  rO  rW   r%   Úget_draw_constructorsg	  sT    



zInterface.get_draw_constructorsc                 C   sP   t jjdurt jj ¡  t jjj ¡  t jj ¡  t j	j	 
¡  t jjj ¡  dS )z;
        Kills all textures that have been loaded.
        N)r1   r-   r`  r…  r  Úcacherû   r˜   Úfree_memoryr¾   Zlayout_cache_clearÚvideoÚtexturerb   r$   r$   r%   r…  Æ	  s    zInterface.kill_texturesc                 C   s   t jjj ¡  dt jj_dS )z;
        Kills all surfaces that have been loaded.
        N)r1   r-   r  rX  rû   rM  Úbo_cacherb   r$   r$   r%   Úkill_surfacesÓ	  s    zInterface.kill_surfacesc                 C   s^   |   ¡  tj ¡  tj d¡ d| _d| _d| _d| _d| _	d| _
d| _d| _d| _g | _dS )zB
        This is called when the window has been resized.
        NFT)r…  r,   r#  Ústop_text_inputÚset_text_input_rectrÓ  rÔ  rÇ  r¬  r¼  r½  Z	minimizedr­  rÈ  rã  rb   r$   r$   r%   Úbefore_resizeÛ	  s    
zInterface.before_resizec                 C   s
  t j dd¡r*t jjj dd¡t jj_dS t jj	t jj
f}t jjrNt jjg}n|  ¡ }|D ]`\}}t jj d¡ t jj d |¡¡ | |¡r°|t j_|j dd¡t jj_ qÎqZtj ¡  qZdt jj_tdƒ‚|jd t jd< t jjt jj_t jrt ¡  tj ¡  dS )	zb
        This constructs the draw object and sets the initial size of the
        window.
        Ú_keep_rendererFÚmodelsNrh   zInitializing {0} renderer:zCould not set video mode.rC  )r1   rU  r   r-   r`  Úinfor˜   rb  rZ   Úscreen_widthÚscreen_heightrW  rÝ  rÞ  r^   rz  r,   Údestroyr2   rT  r³  r]   rQ  Ú
persistentZ_gl2r   r   )r@   ry  Zdrawsr`   r`  r$   r$   r%   r  û	  s,    

zInterface.set_modec                 C   sâ   z$dt jj_t jj ¡  W dt jj_ndt jj_0 t jj |t jjt jj¡}|r^t jj	 
|¡ t jrnt d¡ t ¡ }| j |¡ || jd  t jjkr¦| j d¡ q‚t jj ¡  t jj ¡  || _|| _| jrÞ|  ¡  d| _d S )NTFr   )r1   r-   r˜   Ú	per_framer  Úrender_screenrZ   rd  re  r`  rŒ  rÖ  Úsleepr   rã  rÄ   Úperformance_windowr+  Ú
mark_sweeprr   Útake_focusesrŠ  rÛ  rè  r2  )r@   Úroot_widgetrÛ  r`  rŠ  r,  r$   r$   r%   rŒ  "
  s0    
ý
zInterface.draw_screenc                 C   sÈ   d| _ | jsdS |rLtjsL| j ¡  d| _| j d¡s>tdƒ‚| j	}d| _	ntj
j | j¡}tj
j ||¡}tj
j |¡ || _t ¡ ,}tj
j ||d¡ | ¡ | _W d  ƒ n1 sº0    Y  dS )a  
        This takes a screenshot of the current screen, and stores it so
        that it can gotten using get_screenshot()

        `background`
           If true, we're in a background thread. So queue the request
           until it can be handled by the main thread.
        FNTr   zScreenshot timed out.r   )rÀ  rÚ  r1   rÖ  rÏ  rû   rÎ  Úwaitr]   rÐ  r-   r`  rš  rŠ  r6  Úsmoothscaler˜   r‚  r¥  ÚioÚBytesIOrM  Úsave_pngÚgetvalue)r@   r6  Ú
backgroundr­   Úsior$   r$   r%   Útake_screenshotG
  s"    



zInterface.take_screenshotc                 C   s,   | j r(d| _ tjj | j¡| _| j ¡  dS )z?
        Handles requests for a background screenshot.
        FN)	rÎ  r1   r-   r`  rš  rŠ  rÐ  rÏ  rŸ   rb   r$   r$   r%   Úcheck_background_screenshoto
  s    z%Interface.check_background_screenshotc                 C   sJ   | j s
dS | j}|sF| jtjjtjjft ¡ | j	ud | j}|  
¡  |S )zu
        Gets the current screenshot, as a string. Returns None if there isn't
        a current screenshot.
        N)ru  )rÚ  rš  rw  r1   rZ   Úthumbnail_widthÚthumbnail_heightrÉ  rÊ  rË  Úlose_screenshot©r@   rW   r$   r$   r%   Úget_screenshoty
  s    þzInterface.get_screenshotc                 C   s   d| _ d| _dS )z8
        This deallocates the saved screenshot.
        N)rš  r¥  rb   r$   r$   r%   r{  Ž
  s    zInterface.lose_screenshotc                 C   st   t jj | j¡}t jjr&| t jj¡}z*t jj 	||¡ t j
rLt
 d| ¡ W dS  tyn   t jjrh‚ Y dS 0 dS )zE
        Saves a full-size screenshot in the given filename.
        zFSDownload('%s');TFN)r1   r-   r`  rš  rŠ  rZ   Úscreenshot_cropÚ
subsurfacer6  Úimage_save_unscaledrÖ  Ú
run_scriptr]   Údebug)r@   ÚfilenameÚwindowr$   r$   r%   Úsave_screenshot–
  s    zInterface.save_screenshotNc                 C   s’   d| _ | jsdS tjj | j¡}|dur8tjj ||¡}tjj	 
|¡ || _t ¡ *}tjj ||d¡ | ¡ W  d  ƒ S 1 s„0    Y  dS )zR
        This takes a screenshot of the last thing drawn, and returns it.
        FNr   )rÀ  rÚ  r1   r-   r`  rš  rŠ  r6  rp  r˜   r‚  r¥  rq  rr  rM  rs  rt  )r@   r0   r­   rv  r$   r$   r%   Úscreenshot_to_bytes«
  s    
zInterface.screenshot_to_bytesc              	   C   sÒ   t jjsd S t jjjsd S t j ¡ jjr,d S t j	j
rÎt jj}dt j_tdƒ t j ¡ j}t j ¡ j}zFd t j ¡ _d t j ¡ _t j	 
¡  W |t j_|t j ¡ _|t j ¡ _n"|t j_|t j ¡ _|t j ¡ _0 d S )NFzempty window)r1   r@  Z_windowr2   rT  Úshow_empty_windowr3   r4   rî   rZ   Úempty_windowZ_historyÚPPPÚsay_attributesÚtemporary_attributes)r@   Zold_historyZold_say_attributesÚold_temporary_attributesr$   r$   r%   Úshow_windowÃ
  s,    
ýzInterface.show_windowc                 C   sR   t jjrt j ||¡}|r | jr,|  ¡  dS |  |¡ | jdt jj d|dS d S )NFTÚwith)Útrans_pauseÚsuppress_overlayr˜  rû   )r1   rZ   Úwith_callbackr«  Ú	with_noneÚset_transitionÚinteractÚoverlay_during_with)r@   ÚtransÚpairedrû   r$   r$   r%   Údo_withä
  s    

ýzInterface.do_withTc                 C   s°   t dƒ |  ¡  |r|  ¡  tj ¡ j}|  |¡ ¡ D ]6\}}|du rX| j	sl|| j
|< q6|| j	vr6|| j
|< q6tjjD ]}| |¡ qv| ¡  d|_tjjr¬dtj_dtj_dS )zo
        Implements the with None command, which sets the scene we will
        be transitioning from.
        zstart of with noneNF)r‰  r  Úcompute_overlayr1   r2   r3   r4   Úcompute_scener:  r§  r¦  rZ   rú   rû   rü   rî   r@  Ú_side_image_attributes_resetÚ_side_image_attributes)r@   Úoverlayr4   r6   r¤   rŒ   r$   r$   r%   r’  ó
  s$    
zInterface.with_nonec                 C   s¦   t | jƒ}|D ]’}|du rF| j dd¡ | j dd¡ | j dd¡ q| j || j¡pXd}| j |d¡}| j| |kr| j |d¡ | j |d¡ | j |d¡ qdS )zx
        This runs at the end of each interaction to remove the transitions
        that have run their course.
        Nr   )r5  r¨  r+  r©  rª  r   rµ  rç  )r@   rá   r'  r^  rÑ   r$   r$   r%   Úend_transitions  s    
zInterface.end_transitionsc                 C   s4   | j r|sdS |du r&| j |d¡ n
|| j|< dS )ze
        Sets the transition that will be performed as part of the next
        interaction.
        N)r«  r§  r+  )r@   r§  r6   rx  r$   r$   r%   r“  .  s
    
zInterface.set_transitionc                 C   sT   t jrt d¡ | jr| jS tj ¡ }|jtjkrJ|  	¡  t j
j ¡  dS || _|S )zP
        This peeks the next event. It returns None if no event exists.
        r   N)r1   rÖ  rj  r®  r,   r   Úpollr}   ÚNOEVENTrx  r-   r`  r›  r–  r$   r$   r%   Ú
event_peek<  s    

zInterface.event_peekc                 C   s8   t jrt d¡ | jr$| j}d| _n
tj ¡ }|| _|S )za
        Called to busy-wait for an event while we're waiting to
        redraw a frame.
        r   N)r1   rÖ  rj  r®  r,   r   rŸ  r±  r|  r$   r$   r%   Ú
event_pollS  s    

zInterface.event_pollc                 C   sn   | j r| j }d| _ || _|S |  ¡  tjrZt d¡ tj ¡ }|j	tj
krLqdt d¡ q4n
tj ¡ }|| _|S )z~
        This is in its own function so that we can track in the
        profiler how much time is spent in interact.
        Nr   r+   )r®  r±  rx  r1   rÖ  rj  r,   r   rŸ  r}   r   ro  )r@   rW   rœ   r$   r$   r%   Ú
event_waitf  s    


zInterface.event_waitc                 C   s\   t jjrd S t j d¡ t jjD ]
}|ƒ  q t j ¡ j	j
rNt jjD ]
}|ƒ  qBt j ¡  d S )Nr  )r1   r@  r  Zuir6   rZ   Úoverlay_functionsr2   r3   r4   rî   Úwindow_overlay_functionsÚcloserå   r$   r$   r%   r™  †  s    zInterface.compute_overlayc                 C   s¨   i }i }t jjt jj D ].}| || j| ¡ ||< }| ||¡||< qt jjj	dd}i |_i |_
t jjD ].}|| |j|< || |j
|< | || ¡ ql||d< |S )zz
        This converts scene lists into a dictionary mapping layer
        name to a Fixed containing that layer.
        rB  rG  N)r1   rZ   rá   râ   rF  r¾  rJ  r-   rC  rD  Ú
raw_layersr¡   )r@   r4   ÚrawrW   r6   r¤   rš   r$   r$   r%   rš  —  s    zInterface.compute_scenec                 C   s´   | j du rtj ¡  | jt ¡ d kr4tjjdd | jrHtjjdd tjj	dur¢t ¡ | _tjj
dd dtj_z"d| _tjj tjj	¡ W d| _q°d| _0 ntjjdd dS )zD
        This is called to handle the user invoking a quit.
        Ng      è?T)Úsave)Zonly_fullscreenF)rš  r1   r   rw  r·  r   r{  r¸  rZ   Úquit_actionZ
movie_stopr@  Úmouse_visibler-   ÚbehaviorÚrunrb   r$   r$   r%   Ú
quit_event±  s    


zInterface.quit_eventc                 C   sl   || j u rdS || _ |du r4tj ¡  tj d¡ n4|du rTtj ¡  tj d¡ ntj d¡ | ¡  dS )z¦
        Sets the current mouse cursor.

        True sets a visible system cursor. False hides the cursor. A ColorCursor
        object sets a cursor image.
        NTF)ræ  r,   r˜  r6  Úset_visibleÚactivate)r@   Úcursorr$   r$   r%   Ú	set_mouseÏ  s    


zInterface.set_mousec                 C   s
   d| _ dS )zg
        Called from the controller to hide the mouse when a controller
        event happens.
        r   N)rÅ  rb   r$   r$   r%   Ú
hide_mouseæ  s    zInterface.hide_mousec                 C   sX   t jjd ur,| jt jj t jj ¡ k r,d}nt jjo<t j	j
 }|oR| joRt jjj }|S )NF)r1   rZ   Úmouse_hide_timerÅ  r-   Úcorer)   r@  r«  r2   Ú
less_mouserÆ  rZ  r³  )r@   Úvisibler$   r$   r%   Úis_mouse_visibleî  s
    &zInterface.is_mouse_visiblec                 C   sJ   t jj ¡ }|r|d u r| j}|r0|| jvr0d}|dkrFtt jddƒ}|S )Nrf   Zdefault_mouse)r1   r-   rr   Z	get_mouser˜  rå  rà   r@  )r@   Z
cache_onlyZinteractionÚ
mouse_kindr$   r$   r%   Úget_mouse_nameù  s    zInterface.get_mouse_namec                 C   sú   |   ¡ }|d urZtj ¡ \}}d|  kr6tjjk rZn n d|  krRtjjk rZn nd}|sl|  d¡ d S | jd u r„|  d¡ d S tj	j
jr¶t| jtjjƒr¨tj ¡  |  d¡ d S |  d¡}|| jv rè| j| }|| jt|ƒ  }nd}|  |¡ d S )Nr   FT)r¸  r1   r   ra  rZ   rd  re  r²  rå  r2   rT  Úsystem_cursorrÂ   ræ  r,   r˜  r  r6  rº  r¯  r  )r@   Úmouse_displayabler·  rP   rQ   r¹  Zanimr±  r$   r$   r%   Úupdate_mouse  s,    8








zInterface.update_mousec                 C   s   t |||ƒ| _d| _dS )z_
        Sets the mouse position. Duration can be a number of seconds or
        None.
        TN)r\  rÑ  r¬  rf  r$   r$   r%   rg  -  s    zInterface.set_mouse_posc                 C   s   t ƒ | j |kS )zs
        Returns true if the screen has been drawn in the last `seconds_ago`,
        and false otherwise.
        )r)   rµ  )r@   Zseconds_agor$   r$   r%   Údrawn_since6  s    zInterface.drawn_sincec                 C   sB   t jjpt jj}t jjr(|s(t j d¡ t j 	d¡ t j 
¡  dS )z.
        Create a mobile reload file.
        ú	_reload-1TN)r1   r@  Ú	main_menuÚ
_in_replayrZ   Úsave_on_mobile_backgroundÚloadsaver©  rg  rU   Úsave_MP)r@   Zshould_skip_saver$   r$   r%   Úmobile_save>  s
    zInterface.mobile_savec                 C   s   t j d¡ dS )z6
        Delete an unused mobile reload file.
        r¿  N)r1   rÃ  Úunlink_saverb   r$   r$   r%   Úmobile_unlinkJ  s    zInterface.mobile_unlinkc                 C   sB   ddl m} |dƒ}|jrdS tjj d¡ |  ¡  t 	d¡ dS )zs
        Delays until the android screen is visible, to ensure the
        GL context is created properly.
        r   r/  zorg.libsdl.app.SDLActivityNz8App not focused at interface start, shutting down early.r+   )
r1  r0  Z	mHasFocusr1   r-   rÝ  rÞ  rÅ  r   Ú_exit)r@   r0  ZSDLActivityr$   r$   r%   r  S  s    zInterface.check_android_startc                 C   sH  |j tjkrdS tj ¡  tjj ¡  tj 	t
d¡ tj 	td¡ tj 	td¡ |  ¡  tjjrªtjr ztj ¡  W n   Y n0 ddlm} |dƒ}| d¡ t d¡ tj ¡  tjrÄt d¡ tdƒ tj ¡ }|j tjkrìt d¡ |j tjkrÌqüqÌtdƒ |  ¡  tj 	t
t¡ tjj ¡  tjr8t d¡ d| _ d| _!dS )z3
        Handles the SDL2 suspend process.
        Fr   r/  zjava.lang.SystemzEntered background.zEntering foreground.T)"r}   r,   ÚAPP_WILLENTERBACKGROUNDr   ro  r1   r  Ú	pause_allr   r  r   r   r   rÅ  rZ   Úquit_on_mobile_backgroundr   ZactivityZfinishAndRemoveTaskr1  r0  Úexitr&  r   rY  r*  r  ÚAPP_TERMINATINGÚAPP_DIDENTERFOREGROUNDrÇ  r  Úunpause_allrÇ  r­  )r@   rœ   r0  ÚSystemr$   r$   r%   Úcheck_suspende  sH    







zInterface.check_suspendc                 C   s"   | j  ¡  | j ¡  | j ¡  dS )z5
        Called when we enter a new context.
        N)r¨  rû   rª  r©  rb   r$   r$   r%   Úenter_context¨  s    

zInterface.enter_contextc                 C   s*   zt j | j¡ W n ty$   Y n0 dS )z9
        Posts a time_event object to the queue.
        N)r,   r   Úpostrº  r]   rb   r$   r$   r%   Úpost_time_event²  s    zInterface.post_time_eventc                 C   s    d| _ tjjjddddd dS )zO
        Called after a longpress, to ignore the mouse button release.
        TNr   F©rf   )r¿  r1   r-   rr   Úmouse_handlerrb   r$   r$   r%   Úafter_longpress¼  s    zInterface.after_longpressc                 C   s*   |   ¡ }|du rdS |jtjtjfv S dS )zV
        Returns true if the next event in the queue is a text editing event.
        NF)r¡  r}   r,   Ú	TEXTINPUTÚTEXTEDITINGr–  r$   r$   r%   Útext_event_in_queueÄ  s    zInterface.text_event_in_queuec                 C   s4  t jjdurt jj| _| jduròtj ¡ o4tj ¡  }| jrPt j	j
ddddu }| j| jkrº| j\}}}}t jj ||¡\}}t jj || || ¡\}}	|||| |	| f}
tj |
¡ | jrÄ|rðtj ¡  | jrðt j	 ¡  t j	jdddd n6| jr(tj ¡  tj d¡ | jr(t j	jddd | j| _dS )zB
        Updates the text input state and text rectangle.
        NZ_touch_keyboardÚscreens)r6   T)Ú_layerZ
_transient)r1   r@  Z
_text_rectrÓ  r,   r#  Úhas_screen_keyboard_supportÚis_screen_keyboard_shownr×  r   Z
get_screenrÔ  r-   r`  r•  r_  Ústart_text_inputr­  Zshow_screenr^  Zhide_screen)r@   Z	not_shownrP   rQ   r†  r‡  Zx0Zy0Úx1Úy1Úrectr$   r$   r%   Úupdate_text_rectÏ  s4    




ý
zInterface.update_text_rectc                 C   s(   |du rd| _ nt| j tƒ | ƒ| _ dS )z\
        Forces Ren'Py to draw the screen at the maximum framerate for `t` seconds.
        Nr   )rß  r/   r)   )r@   r(   r$   r$   r%   rà  ú  s    zInterface.maximum_frameratec              	   K   s(  t  dd¡ | js|  ¡  | jr(|  ¡  d| _|| _t j ¡ }|j	rLt
dƒ‚d|_	|s^|  ¡  | j}g | _z2d| _t jjD ]
}|ƒ  q|d}	tƒ }
|	r¼| jf ||||
dœ|¤Ž\}	}d| _q’|W d| _d|_	|rät j ¡ j}| ¡  |  ¡  d| _t j ¡  ¡  dt j ¡ j_t jjdur&dt jj_t jjr@dt j_dt j_S |  ¡  d| _t j ¡  ¡  dt j ¡ j_t jjdur„dt jj_t jjr$dt j_dt j_n„d| _d|_	|rÆt j ¡ j}| ¡  |  ¡  d| _t j ¡  ¡  dt j ¡ j_t jjdurdt jj_t jjr"dt j_dt j_0 dS )z
        This handles an interaction, restarting it if necessary. All of the
        keyword arguments are passed off to interact_core.
        r+   zstart of new interactionFz\Cannot start an interaction in the middle of an interaction, without creating a new context.T)r´  r  ÚpauseÚpause_startN)r1   ÚplogrÚ  r^  rÀ  r{  r  r2   r3   Úinteractingr]   r  r´  râ  rZ   Ústart_interact_callbacksr)   Úinteract_coreré  r4   rü   rž  r­  Ú	mark_seenrî   rÝ  Údid_interactionr@  r›  rœ  )r@   rû   Zsuppress_windowr  rä  rV   r3   r´  rŒ   Úrepeatrå  rW   r4   r$   r$   r%   r”    sˆ    


ç     


ë

zInterface.interactc                 C   s    t jjsdS t ¡ }|d t jjkrœt  dd¡ |d t jjd krJd}n|d t jjd krdd}nd}t |¡ tj	rt j
 |¡ tj	dd…= t  dd¡ dS )zE
        Considers if we should peform a garbage collection.
        Nr   r„   z	before gcr+   zafter gc)r1   rZ   Ú	manage_gcr  Ú	get_countÚidle_gc_countræ  Úgc_thresholdsr  r	  ZmemoryZprint_garbage)r@   ÚcountÚgenr$   r$   r%   Úconsider_gcO  s    
zInterface.consider_gcc                 C   sÌ  |rt  dd¡ nt  dd¡ tƒ }d}|  ¡ r:| js:q¨|rB|sTtƒ |d krTq¨|dkrn|  ¡  |d7 }q(|dkrŒt jj ¡  |d7 }q(|dkr°|r¦t j	r¦|  
¡  |d7 }q(|dkr&| jsÊ|d7 }q(z| j |¡}W n tyð   d}Y n0 |du rd| _|d7 }n|d	u r¦|s¦|d7 }q(|d
krV|rLt j	rLt jjj ¡  |d7 }q(|dkrŒ| js‚t j ¡  t j ¡  d| _|d7 }q(t jjj ¡ r¨d	| _q¨q(|r¼t  dd¡ nt  dd¡ dS )z:
        Tasks that are run during "idle" frames.
        r+   zstart idle_frame (expensive)zstart idle_frame (inexpensive)gü©ñÒMb@?r„   rç   rè   NFrí   r©   Tzend idle_frame (expensive)zend idle_frame (inexpensive))r1   ræ  r)   r¡  ré  ró  r-   r`  r„  rÖ  Úexec_js_cmdÚprediction_coroutineÚsendÚ
ValueErrorr  rX  Zpreload_thread_passÚdid_autosaverÃ  Úautosaverg  Úcheck_updaterj  )r@   r}  Ú	expensiver^  ÚstepÚresultr$   r$   r%   Ú
idle_framek  sd    















zInterface.idle_framerf   r   c
           4   
      sÎ  t  dd¡ t j ¡  |p t jj}|ˆ_|ˆ_|ˆ_t jj	 
|¡ t jj	 ¡  |ˆ_|ˆ_t jjpht jj‰dˆ_ˆr”ˆj ¡  ˆj ¡  ˆj ¡  nFˆjD ]>}
|
ˆjvrªqšˆj|
 ˆj|
< ˆj|
  ¡ ˆj|
< dˆj|
< qšˆj ¡  |rˆjsôdS dˆjvrdS ˆrdS ˆjsdS dˆ_|ˆ_tƒ }|}|ˆ_t jjD ]}|ƒ  q>ˆ ¡  t jj j! "¡  t j#j# $¡  t jj% &¡  t jj'j( ¡  t jj	j) ¡  t*j+ t*j,t-t.t/f¡ ˆ 0¡  t j 1¡ j2}| 3¡  |sÖˆ 4¡  t jj'j5dd}i |_6g ‰ |sFt jj7D ]}| 8|¡ ˆ  9|¡ qþ|durFt jj: ;|¡}| 8|¡ ˆ  9|¡ ˆ <|¡‰t jj= >ˆd ¡ t  dd¡ ˆ ?¡ D ].}zt jj% @|¡ W n tAy    Y n0 qvt  dd	¡ |durât jj: B|¡}| 8||	|	¡ ˆ  9|¡ t jj'j5dd}i |_6ˆd jC|_C‡ ‡‡‡fd
d„}t jj6D ]}|||ƒ qˆj Ddd¡r|ˆs|t jj'j5dd}i |_6ˆjd jC|_Ct jj6D ]*}ˆjd j6| }||j6|< | 8|¡ qrˆjd ||d}tE|tFƒsÈtAd| ƒ‚ˆj Ddd¡}| 8|||¡ |du rtE|t jjGjHƒr| I¡  |r†t jjJr,t jj:jKg dd}nt jj:jKg dd}| 8|¡ ˆ  9|¡ t jj: B|jL¡}| 8|||¡ ˆ  9|¡ n
| 8|¡ t jjMD ]}|||ƒ qŽt jjNjOD ]}| 8|¡ qªt jjP}|durøtE|tFƒsà|ƒ }|durø| 8|dd¡ ~t jj% Q|¡ˆ_QˆjQ Rd¡ t jj:jS ¡  t jjT U¡  t jj: V¡  | Wdd„ ¡ t jj: X¡  ˆˆ_t jjY Zˆ ¡ ˆjrvdS d}d}dˆ_[dˆ_\d}d}d} t j]j] ^¡  d}!d}"dt j__d}#d}$z~z,| du rDt  dd¡ t j` ad¡ t jb c¡  t jdstejf Ddd¡rt jg h¡  t jjiD ]}|ƒ rd}qt jjjjkˆjkkrJt jjl m¡  t jjljnˆjodrbd}ˆjps’|s~t*j+ qtr¡s€t jjl s|||$¡r€dˆ_pt jjt u¡  t jjT ^¡ }%dˆ_vtƒ ˆ_t j]j] w¡  ˆ x||%|% pÜ|"¡ |rPˆj[styˆjtƒ ˆjz ƒˆ_[| {ˆj[¡ ˆj |¡ D ] \}
}&|&du rˆj[ˆj|
< qt jjt }ˆjˆj[¡ |#d7 }#t j j~d7  _~t jjszˆj€r¬t  dd¡ t j ‚¡  t j ¡  t  dd¡ dˆ_€|rDˆjƒrDˆjƒj„t*j…t*j†t*j,fv rDt jjl ‡¡ \}'}(t jjN Nˆjƒ|'|(¡\})}'}(ˆjˆrd}'d}(t j‰r.ˆjƒj„t*j†kr.d}'d}(t jjYjŠd|'|(dd d}d}t*j‹ Œt/d¡ t*j+ t/g¡ d}ˆ ¡  t jŽj ¡  ˆj‘duržˆj‘ ’¡ sždˆ_‘ˆj	rBˆjo	sBW W dd „ |j6 |¡ D ƒˆ_“t jj”D ]}| |¡ qÐt jj j! •¡  t*j‹ Œt.d¡ t*j‹ Œt/d¡ ˆ –¡  t j 1¡  j—|| 7  _—dˆ_t  dd!¡ dS t jjT ˜¡ 	rXd}d}"t jjt ™¡ 	rjd}d}*t jjt š¡ }+t jjl ›¡ }$ˆjœtƒ k	r˜d}$|+du
r4|
s4|$
r4|+|k
rF|+tƒ  },t|,dƒ},|,}!|,dk
rzt*j+ žˆjŸ¡ W n tA
y    Y n0 t*j‹ Œt/d¡ nt*j‹ Œt/tyt |,d" ƒdƒ¡ |+}nd}!t*j‹ Œt/d¡ ˆj¡
s^t*j‹ Œt.d¡ nnˆj¡tƒ  },t|,dƒ},|,}*|,dk
r dˆ_¡t*j‹ Œt.d¡ ˆ 0¡  n,ˆj¡|k
rÌt*j‹ Œt.t |,d" d ƒ¡ ˆj¡}|$
sè|#t jj¢k
sèˆj£r,|p|!d#k p|*d#k pt jjT ¤¡  }-ˆj£r d}-d}$ˆ ¢|$|-¡ |sN|$rNˆj‘sNt jjT ¤¡ rrt  dd$¡ ˆ ¥¡ })t  dd%|)¡ n"t  dd&¡ ˆ ¦¡ })t  dd'|)¡ |)j„t*j§krÎ|$rÂ|sÂˆjQsÂˆj‘sÂt*j‹ ¨d¡ qÂ|)j„t*j©kr|)jªt*j«krˆ ¬¡ }.|.dur|.j„t*j©kr|.jªt*j­krqÂˆ ®|)¡r,qÂ|)j„t.krPd}t*j+ t.g¡ d|)_¯t j‰r‚|)j„t*j…kst|)j„t*j†kr‚t*j+ |)j„¡ |)j„t/kr¤t*j+ t/g¡ d}qÂ|)j„t-krdt°t*j+ Dt-g¡ƒ }/ˆ j±|/7  _±t jj²D ]}|ƒ  qÜt j]j] ³¡  t jj= ³¡  t jj´ ³¡  ˆ µ|¡ qÂ|)j„t*j¶kr6ˆ ·¡  qÂ|)j„t*j¸kr\|)j#rT|)ˆ_¹ndˆ_¹nh|)j„t*jºkrrdˆ_¹nR|)j„t*j»kr¤t*jª ¼¡ t*j½@ rÂt*jª ¾d¡ qÂn ˆj¹rÄ|)j„t*j©t*j¿fv rÄqÂ|)j„t*jÀkr tEt jjlt jjÁjÂƒrÂdt jjl_Ãdt jjÄ_pqÂ|)j„t*jÅkr<tEt jjlt jjÁjÂƒr.dt jjl_Ãdt jjÄ_pqÂˆjˆrh|)j„t*j†krh|)jÆdkrhdˆ_ˆqÂ|)j„t*j,kr¦t*j+ Dt*j,g¡}0t°|0ƒr˜|0d })t jÇr¦dˆ_È|)j„t*j,ksÐ|)j„t*j…ksÐ|)j„t*j†krt jjÉ ¡ ˆ_Êˆjˆrüt jjYjŠddddd |rt jjt Ë|d¡ |)j„t*jÌkrØ|)jÍd@ r^|)jÎs@t jjY Ï¡  |)jÎˆ_È|r^t jjt Ë|d¡ |)jÍd(@ rr|)jÎˆ_Ðt jjjjÑsÌt*j Ò¡ s¦ˆjÓs¦t j]j] Ô¡  dˆ_Ón&t*j Ò¡ rÌˆjÓrÌt j]j] Õ¡  dˆ_Ót*jª ¾d¡ t jjl Ö|)¡\}'}(t jŽj× ‡|'|(¡\}'}(t jjN N|)|'|(¡\})}'}(|)du r$qÂˆjÈr4ˆjˆr<d}'d}(t jj´ +|)¡})|)sTqÂt jj: |)¡ tƒ  ˆ_Ø}z´ˆjÙrŽt jjÚjÛ +|)|'|(¡ t  dd)¡ t jjY Š|)|'|(¡} t  dd*¡ | du rÒ| +|)|'|(d¡} | du rêt jjY Ü|)¡} t  dd+¡ | durW qDt jjÝr’t jj: Þ|)d,¡rZˆjß à|'|(t jját jjâ t jj” ¡}1t j ãt jjÝ|1¡ n8t jj: Þ|)d-¡r’ˆjß à|'|(t jj6¡}1t j ãt jjÝ|1¡ ˆj Ddd¡r"ˆs"|s"t jjär"t jjJrÈd}2nd}2t jj: Þ|)|2¡r"ˆj ådd¡ ˆj ådd¡ ˆj ådd¡ ˆj ådd¡ dˆ_tæƒ ‚W nn tæy’   |)j„t.krHˆ 0¡  t jçrŽ|)j„t*j†krŽtè|)d.dƒd/krŽˆjsŽt jjYjŠddddd Y n0 |t jjt ™¡ O }ˆjrÂW W dd „ |j6 |¡ D ƒˆ_“t jj”D ]}| |¡ qÎt jj j! •¡  t*j‹ Œt.d¡ t*j‹ Œt/d¡ ˆ –¡  t j 1¡  j—|| 7  _—dˆ_t  dd!¡ dS qÂ|rV| rVdˆ_d| fW W dd „ |j6 |¡ D ƒˆ_“t jj”D ]}| |¡ q~t jj j! •¡  t*j‹ Œt.d¡ t*j‹ Œt/d¡ ˆ –¡  t j 1¡  j—|| 7  _—dˆ_t  dd!¡ S  téyª }3 z¤d|3jêfW  Y d}3~3W dd „ |j6 |¡ D ƒˆ_“t jj”D ]}| |¡ q2t jj j! •¡  t*j‹ Œt.d¡ t*j‹ Œt/d¡ ˆ –¡  t j 1¡  j—|| 7  _—dˆ_t  dd!¡ S d}3~30 0 W dd „ |j6 |¡ D ƒˆ_“t jj”D ]}| |¡ qÌt jj j! •¡  t*j‹ Œt.d¡ t*j‹ Œt/d¡ ˆ –¡  t j 1¡  j—|| 7  _—dˆ_t  dd!¡ nŽdd „ |j6 |¡ D ƒˆ_“t jj”D ]}| |¡ qZt jj j! •¡  t*j‹ Œt.d¡ t*j‹ Œt/d¡ ˆ –¡  t j 1¡  j—|| 7  _—dˆ_t  dd!¡ 0 dS )0a”  
        This handles one cycle of displaying an image to the user,
        and then responding to user input.

        @param show_mouse: Should the mouse be shown during this
        interaction? Only advisory, and usually doesn't work.

        @param trans_pause: If given, we must have a transition. Should we
        add a pause behavior during the transition?

        @param suppress_overlay: This suppresses the display of the overlay.
        @param suppress_underlay: This suppresses the display of the underlay.

        `pause`
            If not None, the amount of time before the interaction ends with
            False being returned.
        r+   zstart interact_coreFN)FNrB  rG  zcomputed scenezfinal predictc                    s’   ˆ| }ˆ   |¡ ˆj |d ¡rzˆszˆj| ˆj| |d}t|tƒsRtd| ƒ‚ˆj |d ¡}|  |||¡ || j	|< n|| j	|< |  |¡ d S )N©Ú
old_widgetÚ
new_widgetú1Expected transition to be a displayable, not a %r)
rÄ   r¨  r   rª  rÂ   rg   r]   r©  r¡   rá   )Úwherer6   Zscene_layerr–  r©  ©Zfocus_rootsÚscener@   r«  r$   r%   Ú	add_layery  s     
ÿþ

z*Interface.interact_core.<locals>.add_layerrÿ  r  Údismiss)r  Zdismiss_unfocusedZdismiss_hard_pauser   c                 S   s   |   ¡ S r'   )r¦   )rŒ   r$   r$   r%   r  Ü  rì   z)Interface.interact_core.<locals>.<lambda>)TNTi  zstart of interact while loopé
   ÚRENPY_SIMULATE_DOWNLOADr  z	end framezstart framer   rÕ  c                 S   s   i | ]\}}|t |d dƒ“qS )rÑ   r   )rà   )rê   rõ   Úvr$   r$   r%   Ú
<dictcomp>á  rì   z+Interface.interact_core.<locals>.<dictcomp>zend interact_coreiè  gš™™™™™É?zpre peekzpost peek {!r}zpre waitzpost wait {!r}r„   zstart mouse focus handlingzstart event handlingzfinish event handlingÚ	inspectorZfull_inspectorÚwhichl   ÿÿ )ër1   ræ  r>  Úcheck_languager@  r  Úsuppress_underlayr  r-   r  Zshow_overlay_screensÚprepare_screensr²  rÆ  rZ   Úskippingr2   Úless_updatesr«  r¨  rû   rª  r©  r§  r¦  rw   r­  r˜  r)   rµ  Úinteract_callbacksr(  r  rX  Útickr¾   Z	text_tickÚpredictr6  rC  Zsize_groupsZupdated_screensr,   r   r  r   r   r   rÔ  r3   r4   rP  r™  rD  rá   Úunderlayr¡   rÄ   r¬  ZRollForwardrš  rÃ   Zset_rootr-  rÖ   r]   ZPauseBehaviorr§  r   rÂ   rg   Ú	transformr	  Zupdate_stateZ_dismiss_pauseZSayBehaviorrÑ   râ   r  r  r¼  rõ  rö  Zadj_registeredrZ  Zearly_interactZinput_pre_per_interactr¢   Zinput_post_per_interactrr   Zbefore_interactr¶  rø  r  r”  Úafter_rollbackr  Únot_infinite_loopr4  Úcheck_autoreloadrÖ  r   r   r:  Úprocess_downloaded_resourcesÚneeds_redraw_callbacksrT  r³  r`  r|  rU   rÇ  r¬  ÚpeekÚ
ALL_EVENTSr€  r˜   Úprocess_redrawsrÓ  Zadvance_timerŒ  r/   rä  r<  r:  Úadjust_render_cache_timesÚframesÚprofilerÈ  ÚperformanceÚanalyzer±  r}   r  r  ra  r¿  r   rÖ  r   r  rã  ÚtestÚtestexecutionÚexecuterÑ  rk  rç  rú   Zend_tickró  ÚruntimeZfrequentÚcheck_redrawsÚredraw_timer}  rß  ÚminrÓ  r»  rh  r°  rþ  ré  Zplayingr¢  r£  r   ro  ÚKEYDOWNr#  ÚK_LCTRLr¡  ÚK_RALTrÑ  rž  r  r¯  rÙ  Zperiodicr  r½  ÚQUITr®  rÙ  rÒ  rØ  ÚKEYMAPCHANGEDÚget_modsÚKMOD_GUIÚset_modsÚKEYUPÚVIDEOEXPOSEZswdrawrR  Zfull_redrawrÍ  ÚVIDEORESIZEÚbuttonro  r¼  rµ  rÅ  r™   ÚACTIVEEVENTÚstateÚgainZclear_focusr½  Úaudio_when_minimizedÚ
get_activerÁ  rÊ  rÏ  r—  Z	testmouserÄ  r¤  ZgestureZ
recognizerZkey_handlerr  Z	map_eventrŠ  Úmain_displayables_at_pointr  Úcontext_clear_layersÚinvoke_in_new_contextÚdismiss_blocking_transitionsr+  r9   Úmobilerà   r>   r?   )4r@   rÆ  r  r  r  r˜  r´  r²  rä  rå  rõ   Ú
start_timeÚend_timerŒ   r4   rn  Zrfwr†  ZpbZlayers_rootr  r6   Zold_rootr¤   r–  r©  Úsbr¼  r~  r  Zold_timeout_timeZold_redraw_timerW   Z
_redraw_inZvideo_frame_drawnÚframer}  rÛ  r
  rP   rQ   rœ   Z_timeout_inr*  Z	time_leftrû  Zev2ÚeventsZevsr'  r  Úer$   r  r%   ré  Ë  sÒ   







ý







ÿ
þ








ÿ
ÿþ


(  e€ € †






("$

	




ÿþ

ÿ
þ




$&

(Ø
áäézInterface.interact_corec                 C   s8   |dk rd S | j r(t| j| | j ƒ| _ n| j| | _ d S r]  )r°  r+  rÄ  )r@   Úoffsetr$   r$   r%   Útimeoutü  s
    zInterface.timeoutc                 C   s   |   ¡  dS )zt
        Called before a quit or restart to finish any pending work that might
        block other threads.
        N)rx  rb   r$   r$   r%   Úfinish_pending  s    zInterface.finish_pendingc              
   C   sŠ   t js
dS t d¡}t|ƒdkr$dS t d¡ zt j |¡ W nF ty„ } z.t jj	 
|¡ t jj	 
d|f ¡ W Y d}~n
d}~0 0 dS )zJ
        Execute a command from JS if required (emscripten only).
        Nzwindow._renpy_cmdr   zdelete window._renpy_cmdz$Error while executing JS command: %s)r1   rÖ  Zrun_script_stringr  r  ÚpythonÚpy_execr]   r-   rÝ  rÞ  )r@   ÚcmdrG  r$   r$   r%   rô    s    

zInterface.exec_js_cmd)F)F)N)F)T)NF)FT)TFFN)<r:   r;   r<   r=   rA   rê  rÜ  r^  r  r2  r)  r(  rB  rW  r…  r]  r`  r  rŒ  rw  rx  r}  r{  r…  r†  r  r˜  r’  rž  r“  r¡  r¢  r£  r™  rš  r®  r²  r³  r¸  rº  r½  rg  r¾  rÅ  rÇ  r  rÑ  rÒ  rÔ  r×  rÚ  rã  rà  r”  ró  rþ  ré  rI  rJ  rô  r$   r$   r$   r%   r  o  s’   2 O*W%
_ '%
(

!

$
 
%		C

+

Ka÷
      7	r  )r   )kÚ
__future__r   r   r   r   r   Úrenpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   Útypingr   r   r&  r   r   rq  rÉ  rX   r  rñ  Úpygame_sdl2r,   r1   r  r   rz  r]   rÖ  r   rò  r   r   r   r   rŸ   r+  r  r¡   r/  rÍ  ÚAPP_LOWMEMORYrÉ  ÚAPP_DIDENTERBACKGROUNDÚAPP_WILLENTERFOREGROUNDrÎ  ÚWINDOWEVENTÚ
SYSWMEVENTr,  r4  rÙ  rØ  r0  r  r  r  Ú
MOUSEWHEELÚJOYAXISMOTIONÚJOYHATMOTIONÚJOYBALLMOTIONÚJOYBUTTONDOWNÚJOYBUTTONUPÚJOYDEVICEADDEDÚJOYDEVICEREMOVEDÚCONTROLLERAXISMOTIONÚCONTROLLERBUTTONDOWNÚCONTROLLERBUTTONUPÚCONTROLLERDEVICEADDEDÚCONTROLLERDEVICEREMOVEDÚRENDER_TARGETS_RESETr,  r  r    r"   r&   r)   r.   r8   r9   r>   r!   rB   rR   r…   ÚObjectrS   rm   rn   rl   rg   rÒ   rÜ   r4   r\  ru  rv  rá  r  r$   r$   r$   r%   Ú<module>   s¾   8



Ô0

2'   s,      
	' Y