
    cc                     N    d dl Z d dlZd dlmZ ddlmZ ddlmZ  G d de      Zy)    N)Gdk   )AbstractBrush)utilities_smooth_pathc                   L     e Zd Zd Zd Z fdZd Zd Zd Zd Z	d Z
d Z xZS )	BrushSimplec                 f    t        d      dz   }|r|t        d      z  }|gS |t        d      z  }|gS )NzSimple brushz - z$Width depends on the stylus pressurez Width depends on the mouse speed)_)selfuse_pressurebrush_directionlabels       6/usr/lib/python3/dist-packages/drawing/brush_simple.py	_get_tipszBrushSimple._get_tips   sF    
N
e
#%A4555 . 	A0115
.    c                     |j                  t        j                  j                         |j	                  t        j
                  j                          |j                  |d     t        | !  ||       y )Nrgba)	set_line_capcairoLineCapROUNDset_line_joinLineJoinset_source_rgbasuperdraw_preview)r   	operationcairo_context	__class__s      r   r   zBrushSimple.draw_preview   sW    U]]001enn223-6!23'y-0r   c                     |d   r0t        dt        |d   dz              |d<   | j                  ||      S t        |d         dk  ry| j	                  ||       y)zBrush with dynamic width, where the variation of width is drawn by a
		succession of segments. If pressure is detected, the width is pressure-
		sensitive, otherwise it's speed-sensitive (with a heavy ponderation to
		make it less ugly).
is_previewr   
line_widthg?path   N)maxintr   lenoperation_on_mask)r   r   r   s      r   do_brush_operationzBrushSimple.do_brush_operation   sf     | C	,(?#(E$FG9\


I}
556	a 
M2r   c                    |j                  t        j                  j                         |j	                  t        j
                  j                         |j                          |d   D ]  }|j                  |d   |d           |j                         }|d   r-|j                          t        ||       |j                         }n|}| j                  |d   |d         }d}|j                          |D ]  }|dz   }| j                  |      \  }	}
}|	s|j                  |
|       2|j                         \  }}|j                  ||dz
            | j                  ||       |j!                          |j                  |
|        y )Nr#   xysmoothr"   r   r   )r   r   r   r   r   r   new_pathline_to	copy_pathr   _build_widths_future_pointmove_toget_current_pointset_line_width_add_segmentstroke)r   r   r   ptraw_pathsmoothed_pathwidthsisegmentokfuture_xfuture_y	current_x	current_ys                 r   do_masked_brush_opzBrushSimple.do_masked_brush_op,   sx   U]]001enn223 f +bC"S'*+$$&(x 1 **,== i/<1HI& ! 
-g1u1 ..w72x
(H-'99;9iq1u.]G,8,
-r   c           
         g }g }d}|D ]u  }|d   2|j|j                  | j                  |d   |d   |d   |d                n:|8|d   dk(  s|d   dk(  rd}n|d   |d   z   dz  }|j                  ||z  dz         |}w t        |      dk(  r|t        |      }t	        |      }	d}
|D ]_  }dt        |t	        dd|z        z        z   }|
dk(  r	||z   dz  }
n||
z   |
z   d	z  }
t	        dt        |
            }|j                  |       a |S )
zBuild an array of widths from the raw data, either using the value of
		the pressure or based on the estimated speed of the movement.Npr+   r,   r      r   g?r$   )append	_get_distr'   minr%   r&   )r   manual_path
base_widthr;   distsp2r8   	seg_widthmin_distmax_dist
temp_widthdist	new_widthwidths                 r   r1   zBrushSimple._build_widthsT   sP    &
%" bgo	~
\\$..C"S'2c7BsGDE 
~
3131ic7RW$)i ]]:	)A-.
2$ 	[A%j8%j8: tC
SD4K%8899IQz)Q.Zz)J6!;Z3z?#E
MM% 
-r   c           	      8   |d   t         j                  j                  k(  r;|j                  |d   d   |d   d   |d   d   |d   d   |d   d   |d   d          y |d   t         j                  j                  k(  r|j                  |d   d   |d   d          y y )Nr   r   rF   r$         )r   PathDataTypeCURVE_TOcurve_toLINE_TOr/   )r   r   ptss      r   r6   zBrushSimple._add_segment{   s    Vu!!***#a&)SVAYAq	3q6!903Aq	3q6!9F
1v##+++QCF1I. ,r   c                     |d   t         j                  j                  k(  rd|d   d   |d   d   fS |d   t         j                  j                  k(  rd|d   d   |d   d   fS d|d   d   |d   d   fS )Nr   Tr   rV   rW   F)r   rX   rY   r[   )r   r\   s     r   r2   zBrushSimple._future_point   s    Vu!!***
Aq	3q6!9
$$
1v##+++
Aq	3q6!9
$$
QCF1I
%%r   c                 Z    ||z
  ||z
  z  ||z
  ||z
  z  z   }t        j                  |      S )N)mathsqrt)r   x1y1x2y2dist2s         r   rH   zBrushSimple._get_dist   s5    7rBw
27rBw"7
7%	5	r   )__name__
__module____qualname____gtype_name__r   r   r)   rC   r1   r6   r2   rH   __classcell__)r   s   @r   r   r      s2    13"#-P%N/&r   r   )	r   r_   gi.repositoryr   abstract_brushr   utilities_pathsr   r    r   r   <module>ro      s!      ) 2D- Dr   