
    cc"                     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    '7E9f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ou5j%0lE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KK \	TKK  "..((*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=''(21''(21}fa;enn334}fa;enn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??2n%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:sC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)zSet 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=&DM'
$-%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&&24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     NN..t/F/F9=$''K' 
'7G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    >>''&mVQ:	^^--/(()=)=>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)zUse 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?    (-$$dD$%%'(&&((
Xox'$(2!
Xox'$(2!""5<<#6#6AAG+--,-
 88L8LM; =  +. lldt$4H!1 "">1a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nn//18 "$ [ Y!^kk))99;8
 "$	 [ Y!^kk))88:8 "$ hh3c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   