
    \
j                     <     G d  d          Z  G d de           ZdS )c                   \    e Zd ZdZd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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.
    @       c                     |                     |            || _        i | _        t                      | _        || _        d| _        dS )a(  Create an instance of a Frame.

        :Parameters:
            `window` : `~pyglet.window.Window`
                The SpatialHash will recieve events from this Window.
                Appropriate events will be passed on to all added Widgets.
            `cell_size` : int
                The cell ("bucket") size for each cell in the hash.
                Widgets may span multiple cells.
            `order` : int
                Widgets use internal OrderedGroups for draw sorting.
                This is the base value for these Groups.
        r   r   N)push_handlers
_cell_size_cellsset_active_widgets_order
_mouse_pos)selfwindow	cell_sizeorders       J/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/gui/frame.py__init__zFrame.__init__0   sD     	T"""#"uu    c                 ^    t          || j        z            t          || j        z            fS )zNormalize position to cell)intr	   )r   xys      r   _hashzFrame._hashE   s+    1t&''Q-@)A)AAAr   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S )z!Add a Widget to the spatial hash.r            N)	r   aabbranger
   
setdefaultr   addupdate_groupsr   r   widgetmin_vecmax_vecijs         r   
add_widgetzFrame.add_widgetI   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[)))))r   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   r   r   r   N)r   r   r    r
   getremover$   s         r   remove_widgetz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   c                     | j                             |                     ||          t                                D ]4}|                    ||||           | j                            |           5dS z7Pass the event to any widgets within range of the mouseN)r
   r,   r   r   on_mouse_pressr   r"   r   r   r   buttons	modifiersr%   s         r   r1   zFrame.on_mouse_pressX   sq    koodjjA&6&6>> 	- 	-F!!!Q;;; $$V,,,,	- 	-r   c                 |    | j         D ]}|                    ||||           | j                                          dS z7Pass the event to any widgets that are currently activeN)r   on_mouse_releaseclearr2   s         r   r7   zFrame.on_mouse_release^   sL    * 	> 	>F##Aq'9====""$$$$$r   c           	      `    | j         D ]}|                    ||||||           ||f| _        dS r6   )r   on_mouse_dragr   )r   r   r   dxdyr3   r4   r%   s           r   r:   zFrame.on_mouse_dragd   sF    * 	C 	CF  Ar2w	BBBBQ$r   c                     | j                             |                     ||          t                                D ]}|                    ||||           dS r0   )r
   r,   r   r   on_mouse_scroll)r   r   r   index	directionr%   s         r   r>   zFrame.on_mouse_scrollj   sZ    koodjjA&6&6>> 	; 	;F""1a	::::	; 	;r   c                 <   | j         D ]}|                    ||||           | j                            |                     ||          t                                D ]4}|                    ||||           | j                             |           5||f| _        dS r0   )r   on_mouse_motionr
   r,   r   r   r"   r   )r   r   r   r;   r<   r%   s         r   rB   zFrame.on_mouse_motiono   s    * 	1 	1F""1aR0000koodjjA&6&6>> 	- 	-F""1aR000 $$V,,,,Q$r   c                     | j                              | j        | j         t	                                D ]}|                    |           dS r0   )r
   r,   r   r   r   on_text)r   textr%   s      r   rD   zFrame.on_textx   sO    koojdj$/&BCEEJJ 	! 	!FNN4    	! 	!r   c                     | j                              | j        | j         t	                                D ]}|                    |           dS r0   )r
   r,   r   r   r   on_text_motionr   motionr%   s      r   rG   zFrame.on_text_motion}   sQ    koojdj$/&BCEEJJ 	* 	*F!!&))))	* 	*r   c                     | j                              | j        | j         t	                                D ]}|                    |           dS r0   )r
   r,   r   r   r   on_text_motion_selectrH   s      r   rK   zFrame.on_text_motion_select   sQ    koojdj$/&BCEEJJ 	1 	1F((0000	1 	1r   N)r   r   )__name__
__module____qualname____doc__r   r   r*   r.   r1   r7   r:   r>   rB   rD   rG   rK    r   r   r   r   %   s            *B B B* * *7 7 7- - -% % %  ; ; ;
  ! ! !
* * *
1 1 1 1 1r   r   c                   B     e Zd ZdZd fd	Z fdZ fdZ 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 witih `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.
    r   c                     t                                          ||           || _        t                      | _        d S )N)r   )superr   	_modifierr   _moving_widgets)r   r   r   modifier	__class__s       r   r   zMovableFrame.__init__   s9    u---!"uur   c                    | j         |z  dk    r| j                            |                     ||          t	                                D ]2}|                    ||          r| j                            |           3| j        D ]}|                     |           d S t                      
                    ||||           d S )Nr   )rU   r
   r,   r   r   
_check_hitrV   r"   r.   rT   r1   r   r   r   r3   r4   r%   rX   s         r   r1   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 N)rV   r*   r8   rT   r7   r[   s         r   r7   zMovableFrame.on_mouse_release   sc    * 	$ 	$FOOF####""$$$  Aw	:::::r   c                     | j         D ]}|j        \  }}	||z   |	|z   f|_        t                                          ||||||           d S r]   )rV   positionrT   r:   )r   r   r   r;   r<   r3   r4   r%   wxwyrX   s             r   r:   zMovableFrame.on_mouse_drag   s^    * 	/ 	/F_FB 2grBw.FOOaBGY?????r   r   )	rL   rM   rN   rO   r   r1   r7   r:   __classcell__)rX   s   @r   rR   rR      s         % % % % % %
= = = = =; ; ; ; ;@ @ @ @ @ @ @ @ @r   rR   N)r   rR   rP   r   r   <module>rc      su   J`1 `1 `1 `1 `1 `1 `1 `1F)@ )@ )@ )@ )@5 )@ )@ )@ )@ )@r   