Ë
    c­øc‚"  ã                   óN   — d dl Z d dlmZmZmZ ddlmZ ddlmZ  G d„ de«      Z	y)é    N)ÚGtkÚGdkÚ	GdkPixbufé   )ÚAbstractAbstractTool)Ú&utilities_gdk_rgba_to_normalized_arrayc                   óª   ‡ — e Zd Zd Zˆ fd„Zˆ fd„Zˆ fd„Zˆ fd„Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zˆ fd
„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zdd„Zdd„Zˆ xZS )ÚAbstractCanvasToolc                 óŒ   •— t         ‰| �  ||||«       d| _        d | _        d| _        d| _        d| _        d| _        d | _        y )Nr   r   TFÚ )	ÚsuperÚ__init__Úmenu_idÚcentered_boxÚneeded_width_for_longÚaccept_selectionÚapply_to_selectionÚ_directionsÚ_expansion_rgba)ÚselfÚtool_idÚlabelÚ	icon_nameÚwindowÚkwargsÚ	__class__s         €úA/usr/lib/python3/dist-packages/drawing/abstract_transform_tool.pyr   zAbstractCanvasTool.__init__   sO   ø€ Ü�'Ñ�7˜E 9¨fÔ5Ø€$„,Ø€$ÔØ €$ÔØ€$ÔØ!€$ÔØ€$Ôð €$Õó    c                 óL   •— t         ‰| �  «        | j                  «       | _        y ©N)r   Úon_tool_selectedÚselection_is_activer   ©r   Úargsr   s     €r   r!   z#AbstractCanvasTool.on_tool_selected'   s   ø€ Ü�'ÑÔØ ×4Ñ4Ó6€$Õr   c                 óú   •— t         ‰| �  «        | j                  dd«       | j                  dd«       | j                  dd«       | j                  dd«       | j                  dd«       | j                  dd«       y )	NÚselection_deleteFÚselection_cutÚunselectÚ
select_allÚcancel_transformTÚapply_transform)r   Úupdate_actions_stateÚset_action_sensitivityr#   s     €r   r,   z'AbstractCanvasTool.update_actions_state+   sq   ø€ ä�'ÑÔ à×ÑÐ0°%Ô8Ø×Ñ˜o¨uÔ5Ø×Ñ˜j¨%Ô0Ø×Ñ˜l¨EÔ2à×ÑÐ0°$Ô7Ø×ÑÐ/°Õ6r   c                 ó¸   •— |sH| j                  «       r8| j                  «        | j                  j                  «       j	                  «        t
        ‰| �  |«       y r    )r"   Ú!on_apply_transform_tool_operationr   Úget_selection_toolÚunselect_and_applyr   Úgive_back_control)r   Úpreserve_selectionr   s     €r   r2   z$AbstractCanvasTool.give_back_control7   sD   ø€ Ù	 × 8Ñ 8Ô :Ø×)Ñ)Ô+Ø‡;�;×!Ñ!Ó#×6Ñ6Ô8Ü�'ÑÐ.Õ/r   c                 óô   — |dkD  r(d| j                   v r| j                  j                  «        |dkD  r(d| j                   v r| j                  j                  «        | j	                  «       j                  «        y )Nr   ÚeÚs)r   r   Úaction_go_lastÚaction_go_bottomÚ	get_imageÚfake_scrollbar_update)r   Úh_growthÚv_growths      r   Ú_scroll_to_endz!AbstractCanvasTool._scroll_to_end=   s_   € Ø�‚\Ø	ˆT×ÑÑØ‡K�K×ÑÔ Ø�‚\Ø	ˆT×ÑÑØ‡K�K× Ñ Ô"Ø‡.�.Ó×(Ñ(Õ*r   c                 óF   — | j                  «       }| j                  |«       y r    )Úbuild_operationÚdo_tool_operation)r   Ú	operations     r   Úbuild_and_do_opz"AbstractCanvasTool.build_and_do_opH   s   € Ø×"Ñ"Ó$€)Ø×Ñ˜Õ#r   c                 ó´  — | j                  «       j                  }| j                  «       }|r”|j                  | j	                  «       dd«       |j                  «        | j                  «       j                  |z   }| j                  «       j                  |z   }t        j                  ||||«       |j                  «        nz|j                  t        j                  j                  «       t        j                  ||dd«       |j                  «        |j                  t        j                  j                  «       | j                  «       j!                  «        y)z=Part of the previewing methods shared by all transform tools.r   N)r9   Útemp_pixbufÚget_contextÚset_source_surfaceÚget_surfaceÚpaintÚget_selectionÚselection_xÚselection_yr   Úcairo_set_source_pixbufÚset_operatorÚcairoÚOperatorÚSOURCEÚOVERÚupdate)r   Úis_selectionÚlocal_dxÚlocal_dyÚpixbufÚcairo_contextÚxÚys           r   Útemp_previewzAbstractCanvasTool.temp_previewL   s  € à�>‰>Ó×'Ñ'€&Ø×"Ñ"Ó$€-ÙØ×#Ñ# D×$4Ñ$4Ó$6¸¸1Ô=Ø×ÑÔØ×ÑÓ×'Ñ'¨(Ñ2€1Ø×ÑÓ×'Ñ'¨(Ñ2€1Ü×Ñ˜}¨f°a¸Ô;Ø×ÑÕà×ÑœeŸn™n×3Ñ3Ô4Ü×Ñ˜}¨f°a¸Ô;Ø×ÑÔØ×ÑœeŸn™n×1Ñ1Ô2Ø‡.�.Ó×ÑÕr   c                 ó†   — | j                  «        | j                  «       }| j                  |«       | j                  «        y r    )Úrestore_pixbufr?   Úapply_operationÚ"on_cancel_transform_tool_operation)r   r$   rA   s      r   r/   z4AbstractCanvasTool.on_apply_transform_tool_operation`   s6   € Ø×ÑÔØ×"Ñ"Ó$€)Ø×Ñ�yÔ!Ø×)Ñ)Õ+r   c                 ó†   — | j                   r| j                  j                  «        y | j                  j                  «        y r    )r   r   Úforce_selectionÚback_to_previous)r   r$   s     r   r^   z5AbstractCanvasTool.on_cancel_transform_tool_operationf   s+   € Ø	×ÒØ‡;�;×ÑÕ à‡;�;×ÑÕ!r   c                 ój   •— d|d<   t         ‰| �  |«       | j                  «       j                  «        y )NFÚ
is_preview)r   r]   r9   Ú
reset_temp)r   rA   r   s     €r   r]   z"AbstractCanvasTool.apply_operationl   s-   ø€ Ø!€)ˆLÑÜ�'Ñ˜)Ô$Ø‡.�.Ó×ÑÕr   c                 ó€   — |d   r| j                  |d   |d   |d   «       y | j                  |d   |d   |d   «       y )Nrc   rS   rT   rU   )rZ   Ú
apply_temp)r   Úops     r   Úcommon_end_operationz'AbstractCanvasTool.common_end_operationq   sF   € ØˆÒØ×Ñ�R˜Ñ'¨¨J©¸¸J¹ÕHà‡?�?�2�nÑ% r¨*¡~°r¸*±~ÕFr   c                 ó  — | j                  «       j                  j                  «       }|r"| j                  «       j	                  |||«       y | j                  «       j                  |«       | j                  «       j                  «        y r    )r9   rD   ÚcopyrI   Úupdate_from_transform_toolÚset_main_pixbufÚuse_stable_pixbuf)r   Úoperation_is_selectionÚldxÚldyÚ
new_pixbufs        r   rf   zAbstractCanvasTool.apply_tempw   sc   € Ø�~‰~Ó×+Ñ+×0Ñ0Ó2€*ÙØ×ÑÓ×2Ñ2°:¸sÀCÕHà‡>�>Ó×#Ñ# JÔ/Ø‡>�>Ó×%Ñ%Õ'r   c                 ó²   — |d   }|d   }|d   }|d   }d}||k  r|dz  }n
||kD  r|dz  }||k  r|dz  }n
||kD  r|d	z  }| j                   |k(  ry
|| _         y)zÃSet the directions of the user's future operation for tools such as
		`scale` or `crop`.
		It returns a boolean telling whether or not the directions changed since
		the last call to this method.ÚwlÚwrÚhtÚhbr   Únr6   Úwr5   FT)r   )	r   Úevent_xÚevent_yÚn_sizesÚw_leftÚw_rightÚh_topÚh_bottomÚ
directionss	            r   Ú_set_directionsz"AbstractCanvasTool._set_directions‚   s�   € ð
 �4‰=€&Ø�D‰M€'Ø
�$‰-€%Ø�T‰]€(à€*Øˆu‚_Ø�Ñ�:Ø�ÒØ�Ñ€:ØˆvÒØ�Ñ�:Ø�ÒØ�Ñ€:à	×Ñ˜Ò#Ø
à €4ÔØ
r   c                 óZ   — | j                   dk(  rd| _        y| j                   dz   | _        y)z@Set the cursor name, depending on the previously set directions.r   znot-allowedz-resizeN)r   Úcursor_name)r   s    r   Ú_set_cursor_namez#AbstractCanvasTool._set_cursor_nameœ   s+   € à	×Ñ˜ÒØ#€4Õà×&Ñ&¨Ñ2€4Õr   c                 ó   — | j                  «       j                  | j                  | j                  | j                  «      }| j                  |||«      r,| j                  «        | j                  j                  d«       yy)zQSet the accurate cursor depending on the position of the pointer on
		the canvas.TN)	r9   Úget_nineths_sizesr   Ú_xÚ_yr�   r„   r   Ú
set_cursor)r   ry   rz   r{   s       r   Úset_directional_cursorz)AbstractCanvasTool.set_directional_cursor£   sh   € ð �N‰NÓ×.Ñ.¨t×/FÑ/FØ9=¿¹À$Ç'Á'óK€'ð 
×Ñ˜' 7¨GÔ4Ø×ÑÔØ‡;�;×Ñ˜$Õð 5r   c                  ó   — y r    © )r   ÚarearW   s      r   Úon_draw_abovez AbstractCanvasTool.on_draw_above°   s   € Ør   c                 ó  — | j                  «       j                  }t        j                  ||||«       | j                  «       j	                  «       r-|j                  «       j                  t        j                  «       |j                  «        y r    )
r9   rD   r   rL   Úis_zoomed_surface_sharpÚ
get_sourceÚ
set_filterrN   ÚFILTER_NEARESTrH   )r   rW   rX   rY   rV   s        r   Ú_draw_temp_pixbufz$AbstractCanvasTool._draw_temp_pixbuf³   sd   € Ø�>‰>Ó×'Ñ'€&Ü×Ñ˜m¨V°Q¸Ô:Ø	‡^�^Ó×-Ñ-Ô/Ø×ÑÓ×(Ñ(¬×)=Ñ)=Ô>Ø×ÑÕr   c                 óš  — |\  }}}}}}	|j                  «       }
|j                  «       }||
z  ||z  z   |dz  z   }||
z  ||z  z   |	dz  z   }t        j                  t        j                  j
                  t        |«      t        |«      «      }t        j                  |«      }|r4t        | j                  «      } |j                  |Ž  |j                  «        t        j                  ||||||	¬«      }	 |j                  |«       |j!                  |dd«       |j                  «        |S #  | j                  t        d«      «       |cY S xY w)zŒUse cairo.Matrix to apply a transformation to `source_surface` using
		the coefficients in `coefs` and return a new surface with the result.é   )ÚxxÚyxÚxyÚyyÚx0Úy0zError: invalid valuesr   )Ú	get_widthÚ
get_heightrN   ÚImageSurfaceÚFormatÚARGB32ÚintÚContextr   r   Úset_source_rgbarH   ÚMatrixÚ	transformÚ
show_errorÚ_rF   )r   Úsource_surfaceÚcoefsÚprefillÚp_xxÚp_yxÚp_xyÚp_yyÚp_x0Úp_y0Úsource_wÚsource_hrx   ÚhÚnew_surfacerW   Úcolor_arrayÚms                     r   Úget_deformed_surfacez'AbstractCanvasTool.get_deformed_surfaceº   s?  € ð (-Ñ$€$ˆˆd�D˜$ à×%Ñ%Ó'€(Ø×&Ñ&Ó(€(Ø
ˆX�o˜˜x™Ñ'¨$°©(Ñ2€!Ø
ˆX�o˜˜x™Ñ'¨$°©(Ñ2€!ä×"Ñ"¤5§<¡<×#6Ñ#6¼¸A»ÄÀAÃÓG€+Ü—-‘- Ó,€-áô
 8¸×8LÑ8LÓM€;Ø €=× Ñ  +Ñ.Ø×ÑÔô ‡l�l�d˜t¨°¸$À4ÔH€!ðØ×Ñ˜1Ôð ×"Ñ" >°1°aÔ8Ø×ÑÔØ	ÐøðØ‡?�?”1Ð,Ó-Ô.Ø
Òús   Ã4D* Ä*E
c                 óJ   — | j                  d«      }| j                  ||«       y)zBWhen the canvas grows, the color of the new pixels is parametrablezcrop-expandN)Úget_option_valueÚ_force_expansion_rgba)r   Ú	event_btnÚ
color_types      r   Ú_update_expansion_rgbaz)AbstractCanvasTool._update_expansion_rgbaÞ   s"   € à×$Ñ$ ]Ó3€*Ø×Ñ˜Z¨Õ3r   c                 ór  — |dk(  r&| j                  «       j                  «       }|| _        y |dk(  r1|dk(  r,| j                  j                  j	                  «       }|| _        y |dk(  r1|dk(  r,| j                  j                  j                  «       }|| _        y t        j                  dddd¬«      }|| _        y )NÚinitialÚ	secondaryr   é   g      ð?g        )ÚredÚgreenÚblueÚalpha)	r9   Úget_initial_rgbar   Úoptions_managerÚget_right_colorÚget_left_colorr   ÚRGBAr   )r   r½   r¼   Úexp_rgbas       r   r»   z(AbstractCanvasTool._force_expansion_rgbaã   s«   € Ø�9ÒØ�n‰nÓ×/Ñ/Ó1€8ð "€$Õð �[Ò  Y°!¢^Ø�k‰k×)Ñ)×9Ñ9Ó;€8ð
 "€$Õð	 �[Ò  Y°!¢^Ø�k‰k×)Ñ)×8Ñ8Ó:€8ð "€$Õô �h‰h˜3 c°¸3Ô?€8Ø!€$Õr   )F)r   )Ú__name__Ú
__module__Ú__qualname__Ú__gtype_name__r   r!   r,   r2   r=   rB   rZ   r/   r^   r]   rh   rf   r�   r„   rŠ   rŽ   r”   r¸   r¾   r»   Ú__classcell__)r   s   @r   r
   r
      sn   ø„ Ø&€ô
ô7ô
7ô0ò+ò$òò(,ò"ô ò
Gò(òò43ò	 òòóóH4÷
	"r   r
   )
rN   Úgi.repositoryr   r   r   Úabstract_toolr   Úutilities_colorsr   r
   rŒ   r   r   ú<module>rÕ      s%   ðó$ ß -Ñ -å /Ý DôT"Ð-õ T"r   