a
    V$c                     @   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Zd dlZd dlZd dlZdadae aG dd dejjZdd Zdd	 Zd
d Z dd Z!dd Z"dS )    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicodeNc                       s6   e Zd Z fddZd
ddZdd Zdd	 Z  ZS )ProgressBarc                    sZ   t t|   tj|| _tj|| _| j \| _	| _
t| j	| j
f| _d| _d S )Ng        )superr   __init__pygame_sdl2imageload
foreground
backgroundget_sizewidthheightSurfacecounter)selfr   r   	__class__ renpy/display\presplash.pyr   1   s    zProgressBar.__init__Nc                 C   s    | j || _ | j|| _d S N)r   convert_alphar   )r    surfacer#   r#   r$   r&   9   s    zProgressBar.convert_alphac                 C   s   | j | jfS r%   )r   r   )r    r#   r#   r$   r   =   s    zProgressBar.get_sizec                 C   sZ   |  j d7  _ | jt| j | d }| jdd|| j}| j| jd | j|d d S )N   r   r   r   )	r   r   minr   
subsurfacer   r   blitr   )r    totalr   r   r#   r#   r$   update@   s
    zProgressBar.update)N)__name__
__module____qualname__r   r&   r   r.   __classcell__r#   r#   r!   r$   r   /   s   
r   c                 C   s<   ddg}|D ]*}t j|| | }t j|r|  S qd S )Nz.pngz.jpg)ospathjoinexists)	base_namerootallowed_extsextfnr#   r#   r$   	find_fileH   s    
r<   c                 C   sT  dt jv rdS td|d}|sBtd|d}td|d}|r>|sBdS tjr\ddl}|jj  t	j
  |rxt	j|}nt||}|at	j
d}| \}}	|d |d d  |d  }
|d	 |d
 d  |	d  }t	j
jtjd ||	ft	j|
|fda|r |t }t |d n |t  t |jd t  t adS )z9
    Called to display the presplash when necessary.
    RENPY_LESS_UPDATESN	presplash)r8   presplash_foregroundpresplash_backgroundr      r(      )flagsposr)   )r3   environr<   renpywindowsctypeswindlluser32SetProcessDPIAwarer   displayinitr   r   r   progress_barget_display_boundsr   WindowsysargvWINDOW_BORDERLESSwindowr&   get_surfacer,   r   r.   time
start_time)basedirgamedirpresplash_fnforeground_fnbackground_fnrH   r>   boundsswshxyr#   r#   r$   startQ   sB    


rb   c                  C   sz   t d u rd S trJtjjrJtttjjjd  t  	tj
d t   tj D ] } | jtjkrTtjjdddqTd S )N   r)   Fr   )relaunchstatus)rT   rN   rF   gamescriptr.   lenscript_filesrU   r,   r   r   eventgettypeQUITQuitException)evr#   r#   r$   pump_window   s    rp   c                  C   s8   t jrddl} | d tdu r$dS t  dadadS )zM
    Called just before we initialize the display to hide the presplash.
    r   NzpresplashEnd();)rF   
emscripten
run_scriptrT   destroyrN   )rq   r#   r#   r$   end   s    
rt   c                  C   s6   t stjsdS ttjj } | t  dkr2t  qdS )zB
    Pump window to the end of config.minimum_presplash_time.
    Nr   )rT   rF   mobilerW   configminimum_presplash_timerV   rp   )end_timer#   r#   r$   sleep   s
    
ry   )#
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r3   rQ   rV   r   rF   rT   rN   rW   spriteSpriter   r<   rb   rp   rt   ry   r#   r#   r#   r$   <module>   s   8	<