Ë
    c­øcO#  ã                   óR   — d dl Z d dlmZ ddlmZ ddlmZ ddlmZ  G d„ de«      Zy)	é    N)ÚGdké   )ÚAbstractClassicTool)Úutilities_get_magic_path)Úutilities_get_rgba_for_xyc                   ó|   ‡ — e Zd Zd Zˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zˆ xZS )Ú	ToolPaintc                 ó|   •— t         ‰| �  dt        d«      d|«       d | _        d| _        | j                  dd«       y )NÚpaintÚPaintztool-paint-symbolicFÚ
paint_algoÚreplace)ÚsuperÚ__init__Ú_Ú_magic_pathÚuse_sizeÚadd_tool_action_enum)ÚselfÚwindowÚkwargsÚ	__class__s      €ú4/usr/lib/python3/dist-packages/drawing/tool_paint.pyr   zToolPaint.__init__   s:   ø€ ä�'Ñ�7œA˜g›JÐ(=¸vÔFØ€$ÔØ€$„-Ø×Ñ˜L¨)Õ4ó    c                 ó   — t        d«      S )NzPainting options)r   )r   s    r   Úget_options_labelzToolPaint.get_options_label"   s   € Ü	
ÐÓ	Ðr   c                 óÜ   — | j                  d«      }|dk(  rt        d«      gS |dk(  rt        d«      gS | j                  dz   t        d«      z   }| j                  dz   t        d«      z   }||gS )	Nr   Úclippingz5Click on an area to replace its color by transparencyÚwholez(Click on the canvas to entirely paint itz - zMay not work for complex shapesz4It will not work well if the area's edges are blurry)Úget_option_valuer   Úlabel)r   r   Úlabel_warning1Úlabel_warning2s       r   Úget_editing_tipszToolPaint.get_editing_tips%   s†   € Ø×$Ñ$ \Ó2€*Ø�:ÒÜÐDÓEÐ
FÐFØ�WÒÜÐ7Ó8Ð
9Ð9à—:‘: Ñ%¬Ð*KÓ(LÑL€.Ø—:‘: Ñ%¬ð +Jó )Kñ K€.à
˜.Ð	)Ð)r   c                 ó>   — | j                  |j                  ||«       y )N)Úset_common_valuesÚbutton)r   ÚeventÚsurfaceÚevent_xÚevent_ys        r   Úon_press_on_areazToolPaint.on_press_on_area3   s   € Ø×Ñ˜Ÿ™ w°Õ8r   c                 óž  — |dk  s+||j                  «       kD  s|dk  s||j                  «       kD  ry t        |||«      | _        | j	                  d«      dk(  rt        |||| j                  d«      | _        n4| j	                  d«      dk(  rt        |||| j                  d«      | _        n	 | j                  ||«      }| j                  |«       y )Nr   r   Úfillr   r   é   )
Ú	get_widthÚ
get_heightr   Ú	old_colorr    r   r   r   Úbuild_operationÚapply_operation)r   r(   r)   r*   r+   Ú	operations         r   Úon_release_on_areazToolPaint.on_release_on_area6   sÈ   € àˆq‚[�G˜g×/Ñ/Ó1Ò1Øˆq‚[�G˜g×0Ñ0Ó2Ò2Ø	ä,¨W°g¸wÓG€$„.à	×Ñ˜<Ó(¨FÒ2Ü.¨w¸Ø/6¸¿¹ÀQóH€4Õà×Ñ˜\Ó*¨iÒ7Ü.¨w¸Ø/6¸¿¹ÀQóH€4Õð à×"Ñ" 7¨GÓ4€)Ø×Ñ�yÕ!r   c                 óš   — | j                   | j                  d«      | j                  | j                  | j                  | j
                  dœ}|S )Nr   )Útool_idÚalgoÚnew_rgbaÚ	antialiasÚold_rgbaÚpath)Úidr    Ú
main_colorÚ_use_antialiasr2   r   )r   ÚxÚyr5   s       r   r3   zToolPaint.build_operationL   sH   € à�g‰gØ× Ñ  Ó.ð �‰Ø×#Ñ#Ø�~‰~Ø×Ññ	€)ð 
Ðr   c                 óä   — | j                  |«       |d   dk(  r| j                  |«       y |d   dk(  r| j                  |«       y |d   dk(  r| j                  |«       y | j	                  |«       y )Nr9   r   r   r.   )Ústart_tool_operationÚ_op_replaceÚ	_op_wholeÚ_op_fillÚ_op_clipping)r   r5   s     r   Údo_tool_operationzToolPaint.do_tool_operationY   sk   € Ø×Ñ˜IÔ&àˆvÑ˜)Ò#Ø×Ñ�IÕØ�Ñ˜GÒ#Ø‡>�>�)ÕØ�Ñ˜FÒ"Ø‡=�=�Õà×Ñ�YÕr   c                 óh   — | j                  «       } |j                  |d   Ž  |j                  «        y)z4Paint the entire image regardless of existing pixelsr:   N)Úget_contextÚset_source_rgbar   ©r   r5   Úcairo_contexts      r   rF   zToolPaint._op_wholeg   s1   € à×"Ñ"Ó$€-Ø€-×Ñ ¨:Ñ!6Ñ7Ø×ÑÕr   c                 óœ   — |d   €y| j                  «       } |j                  |d   Ž  |j                  |d   «       |j                  «        y)zxSimple but ugly, and it's relying on the precision of the provided
		path whose creation is based on shitty heurisctics.r=   Nr:   )rK   rL   Úappend_pathr.   rM   s      r   rG   zToolPaint._op_fillm   sV   € ð ˆvÑÐØ	Ø×"Ñ"Ó$€-Ø€-×Ñ ¨:Ñ!6Ñ7Ø×Ñ˜I fÑ-Ô.ð ×ÑÕr   c           
      ó  — |d   €y| j                  «       }t        j                  |«      }|d   }|j                  dddd«       |j	                  |d   «       |j                  t        j                  j                  «       |j                  d«       |j                  t        j                  j                  «       |j                  «        | j                  «       j                  t        j                   |dd|j#                  «       |j%                  «       «      «       d}d	|z  }||k  r“t'        d|d   |z   «      }t'        d|d
   |z   «      }t'        d|d   |z   «      }	t)        t+        d|«      «      }t)        t+        d|«      «      }t)        t+        d|	«      «      }	| j-                  |||	«       |d
z   }||k  rŒ“| j/                  «        | j1                  «       }
|
j	                  |d   «       |
j                  t        j                  j2                  «       |
j                  dddd«       |
j                  d«       |j                  t        j                  j                  «       |
j                  «        |
j5                  «        |
j                  t        j                  j6                  «       t        j8                  |
| j                  «       j:                  dd«       |
j=                  «        | j?                  «        |
j                  t        j                  j@                  «        |
j                  |d   Ž  |
j	                  |d   «       |
j                  d«       |
j                  «        |
j5                  «        y)zÌAlgorithmically less ugly than `_op_fill`, but the replacing strategy
		itself doesn't handle (semi-) transparent colors correctly. Looks fine
		when there is no alpha at all and the anti-aliasing is off.r=   Nr<   éÿ   g      ð?é   r   é
   éÿÿÿÿr   r/   é   r:   )!Úget_surfaceÚcairoÚContextrL   rP   Úset_operatorÚOperatorÚDEST_INÚset_line_widthÚset_antialiasÚ	AntialiasÚNONEÚstroke_preserveÚ	get_imageÚset_temp_pixbufr   Úpixbuf_get_from_surfacer0   r1   ÚmaxÚintÚminÚ_replace_temp_with_alphaÚrestore_pixbufrK   ÚCLEARr.   ÚOVERÚcairo_set_source_pixbufÚtemp_pixbufr   Únon_destructive_show_modifÚ	DEST_OVER)r   r5   r)   rN   r<   Ú	TOLERANCEÚiÚredÚgreenÚblueÚcairo_context2s              r   rE   zToolPaint._op_replace|   sï  € ð ˆvÑÐØ	ð ×ÑÓ€'Ü—-‘- Ó(€-Ø�zÑ"€(Ø×Ñ  S¨#¨sÔ3Ø×Ñ˜I fÑ-Ô.Ø×ÑœUŸ^™^×3Ñ3Ô4Ø×Ñ˜qÔ!Ø×ÑœeŸo™o×2Ñ2Ô3Ø×ÑÔ!ð ‡.�.Ó×"Ñ"¤3×#>Ñ#>¸wØ˜A˜w×0Ñ0Ó2°G×4FÑ4FÓ4Hó$Jô Kð €)Øˆ9�n€!Ø	ˆIŠÜ	ˆQ�˜‘˜A‘Ó	€3Üˆq�(˜1‘+˜a‘-Ó €5Ü
ˆa�˜!‘˜Q‘Ó
€4Ü	ŒS��c‹]Ó	€3ÜŒs�3˜‹Ó€5Ü
Œc�#�t‹nÓ
€4Ø× Ñ   e¨TÔ2Øˆ�s€1ð 	
ˆI‹ð ×ÑÔà×#Ñ#Ó%€.ð ×Ñ˜Y vÑ.Ô/Ø×ÑœeŸn™n×2Ñ2Ô3Ø× Ñ   c¨3°Ô4Ø×Ñ Ô"Ø×ÑœeŸo™o×2Ñ2Ô3Ø× Ñ Ô"Ø×ÑÔð ×ÑœeŸn™n×1Ñ1Ô2Ü×Ñ˜nØ'+§~¡~Ó'7×'CÑ'CÀQÈôKà×ÑÔØ×!Ñ!Ô#ð ×ÑœeŸn™n×6Ñ6Ô7Ø €.× Ñ  )¨JÑ"7Ñ8Ø×Ñ˜Y vÑ.Ô/à×Ñ Ô"Ø× Ñ Ô"Ø×ÑÕr   c                 ó˜   — |d   }|d   }|d   }|d   }d}| j                  ||||«       | j                  «        | j                  «        y)z?Replace the color with transparency by adding an alpha channel.r<   r   r   r/   N)Ú	_clip_redri   rn   )r   r5   r<   Úr0Úg0Úb0Úmargins          r   rH   zToolPaint._op_clippingÉ   sV   € à�zÑ"€(Ø��{€"Ø��{€"Ø��{€"à€&Ø‡.�.�˜˜R Ô$Ø×ÑÔØ×!Ñ!Õ#r   c                 ó|   — t        d|z  |dz   «      D ]'  }||z   }|dk  sŒ|dk\  sŒ| j                  ||||«       Œ) y ©NrU   r   rR   r   )ÚrangeÚ_clip_green)r   r{   rx   ry   rz   rq   Úrs          r   rw   zToolPaint._clip_red×   sJ   € Ü��f‘˜f q™jÓ)ò (€aØ	ˆA�v€1Øˆ3ƒh�1˜“6Ø×Ñ�V˜Q  BÕ'ñ(r   c                 ó|   — t        d|z  |dz   «      D ]'  }||z   }|dk  sŒ|dk\  sŒ| j                  ||||«       Œ) y r}   )r~   Ú
_clip_blue)r   r{   r€   ry   rz   rq   Úgs          r   r   zToolPaint._clip_greenÝ   sH   € Ü��f‘˜f q™jÓ)ò &€aØ	ˆA�v€1Øˆ3ƒh�1˜“6Ø‡O�O�F˜A˜q "Õ%ñ&r   c                 óz   — t        d|z  |dz   «      D ]&  }||z   }|dk  sŒ|dk\  sŒ| j                  |||«       Œ( y r}   )r~   Ú_replace_main_with_alpha)r   r{   r€   rƒ   rz   rq   Úbs          r   r‚   zToolPaint._clip_blueã   sH   € Ü��f‘˜f q™jÓ)ò +€aØ	ˆA�v€1Øˆ3ƒh�1˜“6Ø×!Ñ! ! Q¨Õ*ñ+r   c                 ó†   — | j                  «       j                  d|||«      }| j                  «       j                  |«       y ©NT)Úget_main_pixbufÚ	add_alpharb   Úset_main_pixbuf©r   rr   rs   rt   Ú
new_pixbufs        r   r…   z"ToolPaint._replace_main_with_alphaé   s6   € Ø×#Ñ#Ó%×/Ñ/°°c¸5À$ÓG€*Ø‡.�.Ó×"Ñ" :Õ.r   c                 óš   — | j                  «       j                  j                  d|||«      }| j                  «       j                  |«       y rˆ   )rb   rm   rŠ   rc   rŒ   s        r   rh   z"ToolPaint._replace_temp_with_alphaí   s:   € Ø�~‰~Ó×+Ñ+×5Ñ5°d¸CÀÈÓM€*Ø‡.�.Ó×"Ñ" :Õ.r   )Ú__name__Ú
__module__Ú__qualname__Ú__gtype_name__r   r   r$   r,   r6   r3   rI   rF   rG   rE   rH   rw   r   r‚   r…   rh   Ú__classcell__)r   s   @r   r	   r	      sZ   ø„ Ø€ô5òò
*ò9ò"ò,ò
 òòòKòZ
$ò(ò&ò+ò/ö/r   r	   )	rX   Úgi.repositoryr   Úabstract_classic_toolr   Úutilities_pathsr   r   r	   © r   r   ú<module>r˜      s%   ðó$ Ý Ý 6Ý 5Ý 6ôW/Ð#õ W/r   