U
    Pe                     @   s@   d Z dZddlmZ ddlmZ ddlmZ G dd deZdS )	z6
Double Tap
==========

Search touch for a double tap
)InputPostprocDoubleTap    )time)Config)Vectorc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r   a>  
    InputPostProcDoubleTap is a post-processor to check if
    a touch is a double tap or not.
    Double tap can be configured in the Kivy config file::

        [postproc]
        double_tap_time = 250
        double_tap_distance = 20

    Distance parameter is in the range 0-1000 and time is in milliseconds.
    c                 C   s6   t dd}|d | _t dd}|d | _i | _d S )NZpostprocdouble_tap_distanceg     @@double_tap_time)r   getintr   r   touches)selfdisttap_time r   A/tmp/pip-unpacked-wheel-xzebddm3/kivy/input/postproc/doubletap.py__init__   s
    

zInputPostprocDoubleTap.__init__c                 C   s   d}d|j kr|j}| jD ]}|j|kr*q| j| \}}|dkrBq|jrJqtt|j|jt|j	|j
}|| jkrvq|js|jrqd}d|j kr|j}||krq||_|  S dS )zFind a double tap touch within self.touches.
        The touch must be not a previous double tap and the distance must be
        within the specified threshold. Additionally, the touch profiles
        must be the same kind of touch.
        Nbuttonend)Zprofiler   r	   uidis_double_tapr   distanceZsxZsyZosxZosyr   Zis_mouse_scrolling)r
   refZ
ref_buttontouchidetypetouchr   Ztouch_buttonr   r   r   find_double_tap#   s4    




z&InputPostprocDoubleTap.find_double_tapc           
      C   s   | j dks| jdkr|S |D ]Z\}}|js,q|dkrf| |}|rfd|_|j|j }||_|j }||_ ||f| j|j< qt }g }| j	 D ]8}	| j|	 \}}|dkrq||j | jk rq|
|	 q|D ]}	| j|	= q|S )Nr   beginTr   )r   r   Zis_touchr   r   Z
time_startr	   r   r   keysappend)
r
   eventsr   r   Z
double_tapr   r   Ztime_currentZ	to_deleter   r   r   r   processD   s4    

zInputPostprocDoubleTap.processN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s   !r   N)	r"   __all__r   Zkivy.configr   Zkivy.vectorr   objectr   r   r   r   r   <module>   s
   