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g d¢Zdd„ ZG dd„ deƒZeƒ ZdS )	é    )ÚdivisionÚabsolute_importÚwith_statementÚprint_functionÚunicode_literals)ÚPY2Ú
basestringÚbchrÚbordÚchrÚopenÚpystrÚrangeÚroundÚstrÚtobytesÚunicodeN)ÚnÚneÚeÚseÚsÚswÚwÚnwc                 C   s4   t jj | d¡}|dur0t j |¡ t jj ¡ ‚dS )zC
    This is called with a gesture to dispatch it as an event.
    N)	ÚrenpyÚconfigÚgesturesÚgetÚexportsÚqueue_eventÚdisplayÚcoreÚIgnoreEvent)ÚgestureÚevent© r&   úrenpy/display\gesture.pyÚdispatch_gesture"   s    r(   c                       sD   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z‡  Z	S )ÚGestureRecognizerc                    s   t t| ƒ ¡  d | _d | _d S ©N)Úsuperr)   Ú__init__ÚxÚy©Úself©Ú	__class__r&   r'   r,   /   s    zGestureRecognizer.__init__c                 C   sF   || _ || _tjjtjj | _tjjtjj | _d | _	d| _
g | _d S )Nr   )r-   r.   r   r   Úscreen_widthÚgesture_component_sizeÚmin_componentÚgesture_stroke_sizeÚ
min_strokeÚcurrent_strokeÚstroke_lengthÚstrokes)r0   r-   r.   r&   r&   r'   Ústart5   s    zGestureRecognizer.startc                 C   sÚ   | j d u rd S || j  }|| j }t ||¡}|| jk r<d S || _ || _t || ¡d tj d }|dk rt|d7 }tt|d ƒ }|| j	krž|  j
|7  _
n|| _	|| _
| j
| jkrÖ| jrÊ| jd |krÖ| j |¡ d S )Né´   g     €6@r   ih  é-   éÿÿÿÿ)r-   r.   ÚmathÚhypotr5   Úatan2ÚpiÚ
DIRECTIONSÚintr8   r9   r7   r:   Úappend)r0   r-   r.   ÚdxÚdyÚlengthÚangleÚstroker&   r&   r'   Ú
take_pointH   s(    




zGestureRecognizer.take_pointc                 C   sL   d }| j d u rd S | jr<tjj}|d u r,t}|d | j¡ƒ}d | _ d | _|S )NÚ_)r-   r:   r   r   r(   Újoinr.   )r0   ÚrvÚfuncr&   r&   r'   Úfinishh   s    
zGestureRecognizer.finishc                 C   s   d | _ d | _d S r*   )r-   r.   r/   r&   r&   r'   Úcancel{   s    zGestureRecognizer.cancelc                 C   sl   |j tjkr|  ||¡ nN|j tjkr>|jd rh|  ||¡ n*|j tjkrh|  ||¡ |jdkrh|  	¡ S d S )Nr   é   )
ÚtypeÚpygameÚMOUSEBUTTONDOWNr;   ÚMOUSEMOTIONÚbuttonsrK   ÚMOUSEBUTTONUPÚbuttonrP   )r0   Úevr-   r.   r&   r&   r'   r%      s    

zGestureRecognizer.event)
Ú__name__Ú
__module__Ú__qualname__r,   r;   rK   rP   rQ   r%   Ú__classcell__r&   r&   r1   r'   r)   -   s    r)   )Ú
__future__r   r   r   r   r   Úrenpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r?   Úpygame_sdl2rT   r   rC   r(   Úobjectr)   Ú
recognizerr&   r&   r&   r'   Ú<module>   s   8a