
    ^j                     t    d Z ddlmZ ddlmZ erddlmZ ddlmZ  G d d          Z	 G d d	e	          Z
d
S )zWIP.    )annotations)TYPE_CHECKING)
WidgetBase)
BaseWindowc                      e Zd ZdZd0d1dZd2dZd Zed             Zej	        d             Zd3dZ
d3dZd4dZd4dZd5d Zd5d!Zd6d$Zd7d'Zd8d(Zd9d+Zd:d-Zd:d.Zd/S );Framea  The base Frame object, implementing a 2D spatial hash.

    A `Frame` provides an efficient way to handle dispatching
    keyboard and mouse events to Widgets. This is done by
    implementing a 2D spatial hash. Only Widgets that are in the
    vicinity of the mouse pointer will be passed Window events,
    which can greatly improve efficiency when a large quantity
    of Widgets are in use.
    T@   r   windowr   enablebool	cell_sizeintorderreturnNonec                    || _         || _        || _        i | _        t	                      | _        || _        d| _        | j        r| j                             |            dS dS )a6  Create an instance of a Frame.

        Args:
            window:
                The SpatialHash will receive events from this Window.
                Appropriate events will be passed on to all added Widgets.
            enable:
                Whether to enable frame.
            cell_size:
                The cell ("bucket") size for each cell in the hash.
                Widgets may span multiple cells.
            order:
                Widgets use internal ordered Groups for draw sorting.
                This is the base value for these Groups.
        )r   r   N)	_window_enable
_cell_size_cellsset_active_widgets_order
_mouse_pospush_handlers)selfr
   r   r   r   s        K/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/gui/frame.py__init__zFrame.__init__   sj      #"uu< 	-L&&t,,,,,	- 	-    xfloatytuple[int, int]c                ^    t          || j        z            t          || j        z            fS )zNormalize position to cell.)r   r   )r   r    r"   s      r   _hashzFrame._hash0   s+    1t&''Q-@)A)AAAr   c                Z    |                      |           |                     |           d S N)remove_widget
add_widget)r   widgets     r   _on_reposition_handlerzFrame._on_reposition_handler4   s.    6"""r   c                    | j         S )z6Whether to enable frame.

        :type: bool
        )r   )r   s    r   r   zFrame.enable8   s     |r   c                    t          |          | _        | j        r| j                            |            d S | j                            |            d S r'   )r   r   r   r   remove_handlers)r   values     r   r   zFrame.enable@   sQ    E{{< 	/L&&t,,,,,L((.....r   r*   r   c                    | j         |j        dd           | j         |j        dd          }}t          |d         |d         dz             D ]`}t          |d         |d         dz             D ]>}| j                            ||ft                                                    |           ?a|                    | j                   |	                    d| j
                   dS )z!Add a Widget to the spatial hash.r            on_repositionN)r%   aabbranger   
setdefaultr   addupdate_groupsr   set_handlerr+   r   r*   min_vecmax_vecijs         r   r)   zFrame.add_widgetH   s    %4:v{1Q3'78*$*fkRSTURUFV:Wwqz71:>22 	B 	BA71:wqzA~66 B B&&1vsuu5599&AAAABT[)))?D,GHHHHHr   c                H    | j         |j        dd           | j         |j        dd          }}t          |d         |d         dz             D ]S}t          |d         |d         dz             D ]1}| j                            ||f                              |           2TdS )z&Remove a Widget from the spatial hash.r   r1   r2   r3   N)r%   r5   r6   r   getremover;   s         r   r(   zFrame.remove_widgetQ   s    %4:v{1Q3'78*$*fkRSTURUFV:Wwqz71:>22 	7 	7A71:wqzA~66 7 7A''..v66667	7 	7r   symbol	modifiersc                    | j                              | j        | j         t	                                D ]}|                    ||           dS z8Pass the event to any widgets within range of the mouse.N)r   rA   r%   r   r   on_key_pressr   rC   rD   r*   s       r   rG   zFrame.on_key_pressZ   sS    koojdj$/&BCEEJJ 	3 	3F	2222	3 	3r   c                    | j                              | j        | j         t	                                D ]}|                    ||           dS rF   )r   rA   r%   r   r   on_key_releaserH   s       r   rJ   zFrame.on_key_release_   sS    koojdj$/&BCEEJJ 	5 	5F!!&)4444	5 	5r   buttonsc                    | j                             |                     ||          t                                D ]4}|                    ||||           | j                            |           5dS rF   )r   rA   r%   r   on_mouse_pressr   r8   r   r    r"   rK   rD   r*   s         r   rM   zFrame.on_mouse_pressd   sq    koodjjA&6&6>> 	- 	-F!!!Q;;; $$V,,,,	- 	-r   c                |    | j         D ]}|                    ||||           | j                                          dS z8Pass the event to any widgets that are currently active.N)r   on_mouse_releaseclearrN   s         r   rQ   zFrame.on_mouse_releasej   sL    * 	> 	>F##Aq'9====""$$$$$r   dxdyc           	     `    | j         D ]}|                    ||||||           ||f| _        dS rP   )r   on_mouse_dragr   )r   r    r"   rS   rT   rK   rD   r*   s           r   rV   zFrame.on_mouse_dragp   sF    * 	C 	CF  Ar2w	BBBBQ$r   scroll_xscroll_yc                    | j                             |                     ||          t                                D ]}|                    ||||           dS rF   )r   rA   r%   r   on_mouse_scroll)r   r    r"   rW   rX   r*   s         r   rZ   zFrame.on_mouse_scrollv   sZ    koodjjA&6&6>> 	= 	=F""1a8<<<<	= 	=r   c                    | j                                         D ]}|D ]}|                    ||||            ||f| _        dS )z7Pass the event to any widgets within range of the mouseN)r   valueson_mouse_motionr   )r   r    r"   rS   rT   cellr*   s          r   r]   zFrame.on_mouse_motion{   s_    K&&(( 	5 	5D 5 5&&q!R44445Q$r   textstrc                    | j                              | j        | j         t	                                D ]}|                    |           dS rF   )r   rA   r%   r   r   on_text)r   r_   r*   s      r   rb   zFrame.on_text   sO    koojdj$/&BCEEJJ 	! 	!FNN4    	! 	!r   motionc                    | j                              | j        | j         t	                                D ]}|                    |           dS rF   )r   rA   r%   r   r   on_text_motionr   rc   r*   s      r   re   zFrame.on_text_motion   sQ    koojdj$/&BCEEJJ 	* 	*F!!&))))	* 	*r   c                    | j                              | j        | j         t	                                D ]}|                    |           dS rF   )r   rA   r%   r   r   on_text_motion_selectrf   s      r   rh   zFrame.on_text_motion_select   sQ    koojdj$/&BCEEJJ 	1 	1F((0000	1 	1r   N)Tr	   r   )
r
   r   r   r   r   r   r   r   r   r   )r    r!   r"   r!   r   r#   )r*   r   r   r   )rC   r   rD   r   r   r   
r    r   r"   r   rK   r   rD   r   r   r   r    r   r"   r   rS   r   rT   r   rK   r   rD   r   r   r   )
r    r   r"   r   rW   r!   rX   r!   r   r   )
r    r   r"   r   rS   r   rT   r   r   r   )r_   r`   r   r   )rc   r   r   r   )__name__
__module____qualname____doc__r   r%   r+   propertyr   setterr)   r(   rG   rJ   rM   rQ   rV   rZ   r]   rb   re   rh    r   r   r   r      s        - - - - -4B B B B        X ]/ / ]/I I I I7 7 7 73 3 3 3
5 5 5 5
- - - -% % % %   = = = =
   ! ! ! !
* * * *
1 1 1 1 1 1r   r   c                  J     e Zd ZdZdd fdZd fdZd fdZd fdZ xZS )MovableFramea  A Frame that allows Widget repositioning.

    When a specified modifier key is held down, Widgets can be
    repositioned by dragging them. Examples of modifier keys are
    Ctrl, Alt, Shift. These are defined in the `pyglet.window.key`
    module, and start with `MOD_`. For example::

        from pyglet.window.key import MOD_CTRL

        frame = pyglet.gui.frame.MovableFrame(mywindow, modifier=MOD_CTRL)

    For more information, see the `pyglet.window.key` submodule
    API documentation.
    Tr   r
   r   r   r   r   r   modifierr   r   c                    t                                          |||           || _        t                      | _        dS )a  Create an instance of a MovableFrame.

        This is a similar to the standard Frame class, except that
        you can specify a modifier key. When this key is held down,
        Widgets can be re-positioned by drag-and-dropping.

        Args:
            window:
                The SpatialHash will receive events from this Window.
                Appropriate events will be passed on to all added Widgets.
            enable:
                Whether to enable frame.
            order:
                Widgets use internal ordered Groups for draw sorting.
                This is the base value for these Groups.
            modifier:
                A key modifier, such as `pyglet.window.key.MOD_CTRL`
        )r   r   N)superr   	_modifierr   _moving_widgets)r   r
   r   r   rt   	__class__s        r   r   zMovableFrame.__init__   s=    & 	e<<<!"uur   r    r"   rK   rD   c                   | j         |z  dk    r| j                            |                     ||          t	                                D ]2}|                    ||          r| j                            |           3| j        D ]}|                     |           d S t                      
                    ||||           d S )Nr   )rw   r   rA   r%   r   
_check_hitrx   r8   r(   rv   rM   r   r    r"   rK   rD   r*   ry   s         r   rM   zMovableFrame.on_mouse_press   s    >I%))+//$**Q*:*:CEEBB 5 5$$Q** 5(,,V444. + +""6****+ + GG""1a)<<<<<r   c                    | j         D ]}|                     |           | j                                          t                                          ||||           d S r'   )rx   r)   rR   rv   rQ   r|   s         r   rQ   zMovableFrame.on_mouse_release   sc    * 	$ 	$FOOF####""$$$  Aw	:::::r   rS   rT   c                    | j         D ]}|j        \  }}	||z   |	|z   f|_        t                                          ||||||           d S r'   )rx   positionrv   rV   )r   r    r"   rS   rT   rK   rD   r*   wxwyry   s             r   rV   zMovableFrame.on_mouse_drag   s^    * 	/ 	/F_FB 2grBw.FOOaBGY?????r   )Tr   r   )
r
   r   r   r   r   r   rt   r   r   r   ri   rj   )	rk   rl   rm   rn   r   rM   rQ   rV   __classcell__)ry   s   @r   rs   rs      s         % % % % % % %.= = = = = =; ; ; ; ; ;@ @ @ @ @ @ @ @ @ @r   rs   N)rn   
__future__r   typingr   pyglet.gui.widgetsr   pyglet.windowr   r   rs   rq   r   r   <module>r      s    

 " " " " " "             )------((((((D1 D1 D1 D1 D1 D1 D1 D1N;@ ;@ ;@ ;@ ;@5 ;@ ;@ ;@ ;@ ;@r   