
    kj6                     j    d dl mZ d dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
mZ  G d de          ZdS )	    )Path)AnyN)Image)
BaseWindow)GLFW_keyKeysc                       e Zd ZdZdZeZddddZdef fdZ	d	e
d
dfdZd	e
d
dfdZed
eeef         fd            Zej        d	eeef         d
dfd            Zed
eeef         fd            Zej        d	eeef         d
dfd            Zed
e
fd            Zej        d	e
d
dfd            Zed
e
fd            Zej        d	e
d
dfd            Zed
e
fd            Zej        d	e
d
dfd            Zed
efd            Zej        d	ed
dfd            Zd<dZed
e
fd            Zej        d	e
d
dfd            Zd<dZded
dfdZd ed
dfd!Zd"ed#ed$ed%eded
dfd&Zd"ed'e d(e d
dfd)Z!d"ed*ed%eded
df
d+Z"d"ed,e d-e d
dfd.Z#d"ed/ed
dfd0Z$d"ed1ed2ed
df fd3Z%d"ed4ed
dfd5Z&d"ed6ed
dfd7Z'd"ed8ed
dfd9Z(d"ed
dfd:Z)d<d;Z* xZ+S )=Windowz
    Window based on GLFW
    glfw         )r   r   r   kwargsc                     t                      j        di | t          j                    st	          d          t          j        t          j        t          j                   t          j        t          j        t          j	                   t          j        t          j
        | j        d                    t          j        t          j        | j        d                    t          j        t          j        t          j                   t          j        t          j        d           t          j        t          j        | j                   t          j        t          j        | j                   t          j        t          j        d           t          j        t          j        d           t          j        t          j        d           t          j        t          j        | j                   t          j        t          j        t          j                   d }t          j        | j        | j        | j        |d           | _        d| _         | j!        r| "                    d           | j        s"t          j#                     t	          d          | j$        | _%        t          j&        | j                  \  | _'        | _(        t          j)        | j                   | j*        rt          j+        d           nt          j+        d           t          j,        | j        | j-                   t          j.        | j        | j/                   t          j0        | j        | j1                   t          j2        | j        | j3                   t          j4        | j        | j5                   t          j6        | j        | j7                   t          j8        | j        | j9                   t          j:        | j        | j;                   t          j<        | j        | j=                   t          j>        | j        | j?                   | @                                 | A                                 d S )	NzFailed to initialize glfwr   r   T      zFailed to create window )Bsuper__init__r   init
ValueErrorwindow_hintCONTEXT_CREATION_APINATIVE_CONTEXT_API
CLIENT_API
OPENGL_APICONTEXT_VERSION_MAJOR
gl_versionCONTEXT_VERSION_MINOROPENGL_PROFILEOPENGL_CORE_PROFILEOPENGL_FORWARD_COMPAT	RESIZABLE	resizableVISIBLEvisibleDOUBLEBUFFER
DEPTH_BITSSTENCIL_BITSSAMPLESsamplesSCALE_TO_MONITORTRUEcreate_windowwidthheighttitle_window
_has_focus
fullscreen_set_fullscreen	terminate_cursorcursorget_framebuffer_size_buffer_width_buffer_heightmake_context_currentvsyncswap_intervalset_key_callbackglfw_key_event_callbackset_cursor_pos_callbackglfw_mouse_event_callbackset_mouse_button_callbackglfw_mouse_button_callbackset_scroll_callbackglfw_mouse_scroll_callbackset_window_size_callbackglfw_window_resize_callbackset_char_callbackglfw_char_callbackset_window_focus_callbackglfw_window_focusset_cursor_enter_callbackglfw_cursor_enterset_window_iconify_callbackglfw_window_iconifyset_window_close_callbackglfw_window_closeinit_mgl_contextset_default_viewport)selfr   monitor	__class__s      ^/home/agentuser/manim-venv/lib/python3.11/site-packages/moderngl_window/context/glfw/window.pyr   zWindow.__init__   sj   ""6"""y{{ 	:8999 	2D4KLLL$/:::3T_Q5GHHH3T_Q5GHHH,d.FGGG3T:::888t|444*D111"---*A...t|444.	:::)$*dk4:wX\]]? 	'  &&&| 	8N6777l262KDL2Y2Y/D/!$,///: 	"q!!!!q!!!dlD,HIII$T\43QRRR&t|T5TUUU t/NOOO%dlD4TUUUt|T-DEEE&t|T5KLLL&t|T5KLLL(t7OPPP&t|T5KLLL!!#####    valuereturnNc           	      v   t          j                    }t          j        |          }| j        r|j        nt           j        }| | _        t          j        t           j        | j                   |r| j	        | j
        f| _        | j        | _        t          j        | j        |dd|j        j	        |j        j
        |           t          j        t           j        |j        j                   t          j        t           j        |j        j                   t          j        t           j        |j        j                   t          j        t           j        |j                   n&t          j        | j        d g| j        | j        |R   | j        rt          j        d           d S t          j        d           d S Nr   r   )r   get_primary_monitorget_video_moder=   refresh_rate	DONT_CAREr$   r   r#   r/   r0   _non_fullscreen_sizeposition_non_fullscreen_positionset_window_monitorr2   sizeRED_BITSbitsred
GREEN_BITSgreen	BLUE_BITSblueREFRESH_RATEr>   )rU   rZ   rV   moder`   s        rX   r5   zWindow._set_fullscreenU   s   *,,"7++,0JJt((DN"888 	(,
DK(?D%,0MD)#		    T]DIM:::T_dio>>>T^TY^<<<T.0ABBBB # . *	
     : 	"q!!!!!q!!!!!rY   c                 .    t          j        |           d S N)r   r>   rU   rZ   s     rX   
_set_vsynczWindow._set_vsync~   s    5!!!!!rY   c                     | j         | j        fS )ztuple[int, int]: current window size.

        This property also support assignment::

            # Resize the window to 1000 x 1000
            window.size = 1000, 1000
        )_width_heightrU   s    rX   rf   zWindow.size   s     {DL((rY   c                 T    t          j        | j        |d         |d                    d S r]   )r   set_window_sizer2   rr   s     rX   rf   zWindow.size   s'    T\58U1X>>>>>rY   c                 4    t          j        | j                  S )ztuple[int, int]: The current window position.

        This property can also be set to move the window::

            # Move window to 100, 100
            window.position = 100, 100
        )r   get_window_posr2   rw   s    rX   rc   zWindow.position   s     "4<000rY   c                 ^    t          j        | j        |d         |d                   | _        d S r]   )r   set_window_posr2   	_positionrr   s     rX   rc   zWindow.position   s&    ,T\58U1XNNrY   c                     | j         S )zbool: Is the window visible?

        This property can also be set::

            # Hide or show the window
            window.visible = False
        )_visiblerw   s    rX   r&   zWindow.visible   s     }rY   c                     || _         |rt          j        | j                   d S t          j        | j                   d S rq   )r   r   show_windowr2   hide_windowrr   s     rX   r&   zWindow.visible   sC     	+T\*****T\*****rY   c                     | j         S )zbool: Should the mouse cursor be visible inside the window?

        This property can also be assigned to::

            # Disable cursor
            window.cursor = False
        )r7   rw   s    rX   r8   zWindow.cursor   s     |rY   c                     | j         sg|du r0t          j        | j        t          j        t          j                   n3|du r/t          j        | j        t          j        t          j                   || _        d S )NTF)mouse_exclusivityr   set_input_moder2   CURSORCURSOR_NORMALCURSOR_HIDDENr7   rr   s     rX   r8   zWindow.cursor   sf    % 	S}}#DL$+t?QRRRR%#DL$+t?QRRRrY   c                     | j         S )u  bool: If mouse exclusivity is enabled.

        When you enable mouse-exclusive mode, the mouse cursor is no longer
        available. It is not merely hidden – no amount of mouse movement
        will make it leave your application. This is for example useful
        when you don't want the mouse leaving the screen when rotating
        a 3d scene.

        This property can also be set::

            window.mouse_exclusivity = True
        )_mouse_exclusivityrw   s    rX   r   zWindow.mouse_exclusivity   s     &&rY   c                     || _         |du rOt          j        | j                  | _        t          j        | j        t          j        t          j                   d S | j        | _	        d S )NT)
r   r   get_cursor_posr2   
_mouse_posr   r   CURSOR_DISABLEDr7   r8   rr   s     rX   r   zWindow.mouse_exclusivity   sV    "'D=="1$,??DOdk4;OPPPPP,DKKKrY   c                     | j         S )zlstr: Window title.

        This property can also be set::

            window.title = "New Title"
        )_titlerw   s    rX   r1   zWindow.title   s     {rY   c                 H    t          j        | j        |           || _        d S rq   )r   set_window_titler2   r   rr   s     rX   r1   zWindow.title   s"    dlE222rY   c                 <    d| _         |                                  dS )z0Suggest to glfw the window should be closed soonTN)
is_closing_close_funcrw   s    rX   closezWindow.close   s!    rY   c                 4    t          j        | j                  S )z3bool: Checks if the window is scheduled for closing)r   window_should_closer2   rw   s    rX   r   zWindow.is_closing   s     '555rY   c                 :    t          j        | j        |           d S rq   )r   set_window_should_closer2   rr   s     rX   r   zWindow.is_closing   s    $T\599999rY   c                 ~    t          j        | j                   | xj        dz  c_        t          j                     dS )z5Swap buffers, increment frame counter and pull eventsr   N)r   swap_buffersr2   _framespoll_eventsrw   s    rX   r   zWindow.swap_buffers   s:    $,'''rY   modsc                 x    |dz  dk    | j         _        |dz  dk    | j         _        |dz  dk    | j         _        dS )zChecks key modifiersr   r      N)
_modifiersshiftctrlalt)rU   r   s     rX   _handle_modifierszWindow._handle_modifiers  s>     $qA#ax1}"Qh!mrY   	icon_pathc                 d    t          j        |          }t          j        | j        d|           d S )Nr   )r   openr   set_window_iconr2   )rU   r   images      rX   	_set_iconzWindow._set_icon	  s.    
9%%T\1e44444rY   windowkeyscancodeactionc                 |   | j         || j        k    r|                                  || j        j        k    r| j        || j        k    r| j         | _        |                     |           || j        j        k    rd| j        |<   n|| j        j	        k    r
d| j        |<   | 
                    ||| j                   dS )a  Key event callback for glfw.
        Translates and forwards keyboard event to :py:func:`keyboard_event`

        Args:
            window: Window event origin
            key: The key that was pressed or released.
            scancode: The system-specific scancode of the key.
            action: ``GLFW_PRESS``, ``GLFW_RELEASE`` or ``GLFW_REPEAT``
            mods: Bit field describing which modifier keys were held down.
        NTF)exit_key	_exit_keyr   keysACTION_PRESS_fs_keyr4   r   _key_pressed_mapACTION_RELEASE_key_event_funcr   )rU   r   r   r   r   r   s         rX   r@   zWindow.glfw_key_event_callback  s     =$)>)>JJLLLTY+++0HSTXT`M`M`"&/1DOt$$$TY+++)-D!#&&ty///).D!#&S&$/:::::rY   xposyposc                     t          |          t          |          }}|                     ||          \  }}| j        j        r|                     ||||           dS |                     ||||           dS )a'  Mouse position event callback from glfw.
        Translates the events forwarding them to :py:func:`cursor_event`.

        Screen coordinates relative to the top-left corner

        Args:
            window: The window
            xpos: viewport x pos
            ypos: viewport y pos
        N)int_calc_mouse_deltamouse_statesany_mouse_drag_event_func_mouse_position_event_func)rU   r   r   r   dxdys         rX   rB   z Window.glfw_mouse_event_callback)  s     YYD		d''d33B  	@''dB;;;;;++D$B?????rY   buttonc                    |                      |           | j                            |d          }|dk    rdS t          j        | j                  \  }}|t          j        k    r/|                     |d           |                     |||           dS |                     |d           | 	                    |||           dS )a  Handle mouse button events and forward them to the example

        Args:
            window: The window
            button: The button creating the event
            action: Button action (press or release)
            mods: They modifiers such as ctrl or shift
        NTF)
r   _mouse_button_mapgetr   r   r2   PRESS!_handle_mouse_button_state_change_mouse_press_event_func_mouse_release_event_func)rU   r   r   r   r   r   r   s          rX   rD   z!Window.glfw_mouse_button_callback<  s     	t$$$'++FB77R<<F(66
dTZ2264@@@((tV<<<<<2265AAA**4v>>>>>rY   x_offsety_offsetc                 2    |                      ||           dS )zHandle mouse scroll events and forward them to the example

        Args:
            window: The window
            x_offset (float): x wheel offset
            y_offest (float): y wheel offset
        N)_mouse_scroll_event_func)rU   r   r   r   s       rX   rF   z!Window.glfw_mouse_scroll_callbackU  s      	%%h99999rY   	codepointc                 J    |                      t          |                     dS )zHandle text input (only unicode charaters)

        Args:
            window: The glfw window
            codepoint (int): The unicode codepoint
        N)_unicode_char_entered_funcchr)rU   r   r   s      rX   rJ   zWindow.glfw_char_callback_  s$     	''I77777rY   r/   r0   c                     ||c| _         | _        t          j        | j                  \  | _        | _        |                                  t                      	                    | j        | j                   dS )z
        Window resize callback for glfw

        Args:
            window: The window
            width: New width
            height: New height
        N)
ru   rv   r   r9   r2   r:   r;   rT   r   resize)rU   r   r/   r0   rW   s       rX   rH   z"Window.glfw_window_resize_callbackh  sh     %*6!T\262KDL2Y2Y/D/!!###t)4+>?????rY   focusedc                 $    |dk    rdnd| _         dS )zCalled when the window focus is changed.

        Args:
            window: The window instance
            focused (int): 0: de-focus, 1: focused
        r   TFN)r3   )rU   r   r   s      rX   rL   zWindow.glfw_window_focusw  s     #*Q,,$$ErY   enterc                     dS )zcalled when the cursor enters or leaves the content area of the window.

        Args:
            window: the window instance
            enter (int): 0: leave, 1: enter
        Nr   )rU   r   r   s      rX   rN   zWindow.glfw_cursor_enter  s	     	rY   	iconifiedc                 V    |dk    | _         |                     |dk    rdnd           dS )zCalled when the window is minimized or restored.

        Args:
            window: The window
            iconified (int): 1 = minimized, 0 = restored.
        r   r   TFN)r   _iconify_func)rU   r   r   s      rX   rP   zWindow.glfw_window_iconify  s5     "Q9>>44u=====rY   c                 .    |                                   dS )z Called when the window is closedN)r   )rU   r   s     rX   rR   zWindow.glfw_window_close  s    

rY   c                 ,    t          j                     dS )zGracefully terminate GLFWN)r   r6   rw   s    rX   destroyzWindow.destroy  s    rY   )r[   N),__name__
__module____qualname____doc__namer   r   r   r   r   boolr5   rs   propertytupler   rf   setterrc   r&   r8   r   strr1   r   r   r   r   r   r   r   r@   floatrB   rD   rF   rJ   rH   rL   rN   rP   rR   r   __classcell__)rW   s   @rX   r
   r
      s        
 DD  7$ 7$ 7$ 7$ 7$ 7$ 7$r'"T '"d '" '" '" '"R" " " " " " )eCHo ) ) ) X) 
[?%S/ ?d ? ? ? [? 1%S/ 1 1 1 X1 _OeCHo O$ O O O _O     X ^+T +d + + + ^+     X ]D T    ] '4 ' ' ' X' 't ' ' ' ' ' s    X \3 4    \   
 6D 6 6 6 X6 : : : : : :   ,h ,4 , , , ,54 5D 5 5 5 5;; (;47;AI;QY;	; ; ; ;8@ @5 @ @RV @ @ @ @&??#+?5=?EM?	? ? ? ?2: : :QV :[_ : : : :8 8 8 8 8 8 8@# @c @3 @SW @ @ @ @ @ @: :c :d : : : : C D    ># ># >$ > > > >            rY   r
   )pathlibr   typingr   r   PILr   moderngl_window.context.baser   !moderngl_window.context.glfw.keysr   r   r
   r   rY   rX   <module>r      s                       3 3 3 3 3 3 < < < < < < < <N N N N NZ N N N N NrY   