
    cc                     :    d dl Z ddlmZ ddlmZ  G d de      Zy)    N   )
ToolPencil)AbstractClassicToolc                   N    e Zd Zd Zd Zd Zd Zd Zd Zd Z	ddZ
d Zd	 Zd
 Zy)ToolHighlighterc                     t        j                  | dt        d      d|       d| _        d | _        | j                  dd       | j                  dd       | j                  dd	       y )
N	highlightHighlighterztool-highlight-symbolicFhighlight-alphaThighlight-rigidhighlight-bglight)r   __init___use_operator_pathadd_tool_action_booleanadd_tool_action_enum)selfwindowkwargss      8/usr/lib/python3/dist-packages/drawing/tool_highlight.pyr   zToolHighlighter.__init__   sd     t[!M2B(A6K$$*0$70$7NG4    c                    | j                  d      | _        | j                  d      | _        | j                  d      | _        | j                  dz   }| j                  dk(  r|t        d      z  }t        d      }n|t        d      z  }t        d	      }| j                         j                         rd }||g}t        t        d |            S )
Nr   r   r   z - r   zDark text on light backgroundzAPress <Shift> to temporarily highlight on dark background insteadzLight text on dark backgroundzBPress <Shift> to temporarily highlight on light background instead)
get_option_value_bg_type_force_alpha	_is_rigidlabelr   	get_imageget_mouse_is_pressedlistfilter)r   label_optionslabel_modifier_shift	full_lists       r   get_editing_tipsz ToolHighlighter.get_editing_tips$   s    ''7$-++,=>$(():;$.**u$-	]]gA566= G H A566= G H	^^**,23)	fT9%	&&r   c                     t        d      S )NzHighlighter options)r   )r   s    r   get_options_labelz!ToolHighlighter.get_options_label8   s    	
 	!!r   c                     | j                  |j                  ||       d | _        | j                  |j                         d| j
                  v r| j                  dk(  rd| _        y d| _        y y )NSHIFTr   dark)set_common_valuesbuttonr   update_modifier_statestate_modifier_keysr   )r   eventsurfaceevent_xevent_ys        r   on_press_on_areaz ToolHighlighter.on_press_on_area=   s^    w8$*U[[)###
mmwDMDM	 $r   c                    | j                         }| j                  '|j                  | j                  | j                         n| j                  |||      rd}| j                  D ]  }|d   dk(  r|dz  } t        | j                        D ]  \  }}|d   dk(  r|d   t        j                  j                  k(  r|j                  |d   d   |d   d          N||k(  r|d   d   |z   dz  }|d   d   |z   dz  } n |j                  |d   d   |d   d           |j                  ||       |j                         | _        y )Nr    r      )get_contextr   move_tox_pressy_press_didnt_really_move	enumeratecairoPathDataTypeMOVE_TOline_to	copy_path)r   r4   r5   cairo_contextlengthptsindexs          r   
_add_pointzToolHighlighter._add_pointH   sQ   ""$-	ZZt||4}gw?6jj s
1v|
aKF
 tzz* 
1zuc
1v|
1v##+++3q6!9c!fQi0	&Aq	G#q(WAq	G#q(W
3q6!9c!fQi0
1 )&&($*r   c                 2   |j                  | j                         | j                  syt        | j                  d      }t        |j                         d   |z
        |kD  ryt        |j                         d   |z
        |dz  kD  ry|j                          y)a  Tells if the pointer has moved enough to add a new point, otherwise
		the last point will be changed.
		It's an option that can be disabled.
		The context of an highlighter tool means the direction is biased: i will
		assume the underlying text is written horizontally, and in straight
		lines; so the highlighting will also be straight, but the chosen line
		may change during the stroke.Fg      $@r   r      T)append_pathr   r   min
tool_widthabsget_current_pointnew_path)r   rF   r4   r5   rigiditys        r   r?   z"ToolHighlighter._didnt_really_movea   s     DJJ'	
$'(	(	(	*1	-	788C
	(	(	*1	-	788a<G
	r   c                 p    | j                  ||       |sy | j                         }| j                  |       y N)rJ   build_operationdo_tool_operation)r   r2   r3   r4   r5   render	operations          r   on_motion_on_areaz!ToolHighlighter.on_motion_on_areav   s2    //'7#		""$)#r   c                 j    | j                  ||       | j                         }| j                  |       y rU   )rJ   rV   apply_operation)r   r2   r3   r4   r5   rY   s         r   on_release_on_areaz"ToolHighlighter.on_release_on_area}   s,    //'7#""$)y!r   c                     | j                   | j                  | j                  | j                  | j                  | j
                  d}|S )N)tool_idrgbawidthpathbg-typehalpha)id
main_colorrO   r   r   r   )r   rY   s     r   rV   zToolHighlighter.build_operation   s=    gg??OO::mm) 
r   c                 >   | j                  |       |d   y | j                         }|j                  t        j                  j
                         |j                  t        j                  j                         |j                  |d          |d   dk(  rt        j                  j                  }nt        j                  j                  }|j                  |       |d   }|d   rd|d<    |j                  |  |j                  |d          |j!                          y )	Nrb   ra   rc   r   r`   rd   g      ?   )start_tool_operationr;   set_line_caprA   LineCapSQUAREset_line_joinLineJoinROUNDset_line_widthOperatorMULTIPLYSCREENset_operatorset_source_rgbarM   stroke)r   rY   ccontextoperatorrf   s        r   rW   z!ToolHighlighter.do_tool_operation   s    I&v	(
,,-
--.
)G,-yW$nn%%8nn##8
! *x:a=(J'
y()
//r   N)T)__name__
__module____qualname____gtype_name__r   r'   r)   r6   rJ   r?   rZ   r]   rV   rW   r9   r   r   r   r      s9    #	5'("
	)2*$"	r   r   )rA   tool_pencilr   abstract_classic_toolr   r   r9   r   r   <module>r      s   $  # 6Nj Nr   