U
    Pe                     @   s<   d Z dZddlmZ ddlmZ ddlZG dd deZdS )zH
Retain Touch
============

Reuse touch to counter lost finger behavior
)InputPostprocRetainTouch    )Config)VectorNc                   @   s    e Zd ZdZdd Zdd ZdS )r   a  
    InputPostprocRetainTouch is a post-processor to delay the 'up' event of a
    touch, to reuse it under certains conditions. This module is designed to
    prevent lost finger touches on some hardware/setups.

    Retain touch can be configured in the Kivy config file::

        [postproc]
            retain_time = 100
            retain_distance = 50

    The distance parameter is in the range 0-1000 and time is in milliseconds.
    c                 C   s4   t ddd | _t ddd | _g | _i | _d S )NZpostprocZretain_timeg     @@Zretain_distance)r   getinttimeoutdistance
_available_links)self r   C/tmp/pip-unpacked-wheel-xzebddm3/kivy/input/postproc/retaintouch.py__init__   s    z!InputPostprocRetainTouch.__init__c           
      C   s  | j dkr|S t }|d d  D ]j\}}|js4q"|dkr|||f |j| jkr| j|j }||j_| j	| | j|j= n||j_| j	| q"|dkr|j| jkr| j|j }|j
|_
|j|_|j|_|j|_|||f |	||f n q"|dkr"d }d}| jD ]L}t|j|j}|| jkr4q|j|jkrFq||k r|}|}q|d krhq"|| j|j< | j| |||f q"| jd d  D ]8}|jj}	||	 | j kr| j| |	d|f q|S )Nr   endupdatebegini )r   timeZis_touchremoveuidr	   ZudZ__pp_retain_time__r   appendxyZsxZsyr   sposr   	__class__)
r
   eventsdetypetouchZ	selectionZselection_distanceZtouch2Ztouch_distancetr   r   r   process$   s`    



z InputPostprocRetainTouch.processN)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   )	r"   __all__Zkivy.configr   Zkivy.vectorr   r   objectr   r   r   r   r   <module>   s
   