
    ^jp,                        d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 erd dl
mZmZ d dlmZmZ d dlmZ  G d d	e	          Zd
S )    )annotations)TYPE_CHECKING)GL_TRIANGLE_STRIPGL_SRC_ALPHAGL_ONE_MINUS_SRC_ALPHA)Sprite)AbstractImage	Animation)BatchGroup)
TextLayoutc            	          e Zd ZdZdddddeeddf	d; fdZedeeddfd<d            Zd=dZ	d>dZ
ed?d            Zej        d@d!            ZedAd"            Zej        d#             ZedAd$            Zej        d%             ZedAd&            Zej        d'             ZedAd(            Zej        dBd*            ZedAd+            ZedAd,            Zed-             Zd. ZedAd/            Zej        dCd0            ZedAd1            Zej        dDd2            ZedEd3            Zej        dFd5            ZedGd7            Zej        dHd:            Z xZS )I	NinePatcha  Pseudo Nine-patch object for variable sized dialog windows.

    This class takes in a single image, splits it into 9 equal parts,
    and allows creating variable sized dialog windows without distoring
    the aspect of the edges. This is not a "real" nine-patch, as it
    does not look for any embedded markers in the image data. Instead,
    it simply splits the source image into 9 equally sized segments,
    and stretches the center segments to allow dynamic sizing. Make
    sure your input images do not have any transparent borders, as
    this can affect the final size.

    NinePatch is a subclass of :py:class:`~pyglet.sprite.Sprite`,
    and shares most of the same API. The exception is that scaling
    properties cannot be used, and will raise an exception. Instead,
    use :py:meth:`NinePatch.width` and :py:meth:`NinePatch.height`
    properties if you want to change the size after creation.
    r   NimgAbstractImage | Animationxfloatyzwidth
int | Noneheight	blend_srcint
blend_destbatchBatch | NonegroupGroup | Nonec           
         t          ||j                  | _        t          ||j                  | _        t                                          |||||||	|
           dS )a  Create a NinePatch instance.

        Args:
            img:
                The Image to split into segments.
            x:
                The X coordinate of the NinePatch.
            y:
                The Y coordinate of the NinePatch.
            z:
                The Z coordinate of the NinePatch.
            width:
                The desired width of the NinePatch. This must be
                greater or equal to the provided image width.
            height:
                The desired height of the NinePatch. This must be
                greater or equal to the provided image height.
            blend_src:
                OpenGL blend source mode; for example, ``GL_SRC_ALPHA``.
            blend_dest:
                OpenGL blend destination mode; for example, ``GL_ONE_MINUS_SRC_ALPHA``.
            batch:
                Optional batch to add the NinePatch to.
            group:
                Optional parent group of the NinePatch.
        N)maxr   _widthr   _heightsuper__init__)selfr   r   r   r   r   r   r   r   r   r   	__class__s              O/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/gui/ninepatch.pyr%   zNinePatch.__init__!   sX    F %++63:..aAy*eUKKKKK    layoutr   borderc                    |j         |z
  }|j        |z
  }	|j        dz
  }
t          |j        |z
  |z             }t          |j        |	z
  |z             } | |||	|
||||||
  
        S )a  Given a Label, create a NinePatch instance sized to surround it.

        A NinePatch instance will be created that is sized to the Layout's left, bottom,
        right, and top attributes. This happens at the time of creation, and is not dynamic.

        The NinePatch's ``z`` position will be set to the Layout's ``z`` position - 1. This
        will help ensure the NinePatch renders below the label *if* OpenGL depth testing is
        enabled. If not, you should provide a Group with a proper ordering to ensure the
        correct rendering order.

        Args:
            img:
                The Image to split into segments.
            layout:
                A pyglet Label or Layout instance to query the size from.
            border:
                Additional padding, in pixels, to place around the label.
            blend_src:
                OpenGL blend source mode; for example, ``GL_SRC_ALPHA``.
            blend_dest:
                OpenGL blend destination mode; for example, ``GL_ONE_MINUS_SRC_ALPHA``.
            batch:
                Optional batch to add the NinePatch to.
            group:
                Optional parent group of the NinePatch.
           )leftbottomr   r   righttop)clsr   r*   r+   r   r   r   r   r   r   r   r   r   s                r(   create_around_layoutzNinePatch.create_around_layoutH   s{    H K& MF"HqLFL1$v-..VZ!^f,--s31a	:ueTTTr)   returnNonec                   d}| j         j        \  }}|z
  dz  |z
  dz  fdt          d          D             }| j                            dt
          || j        | j        d|                                 fd| j	        dz  fd| j
        | j        | j        fdz  fd| j        | j        z  | j        | j        z  fdz  fd| j        fdz  fd|f          | _        d S )	N)r   r      r-                     r:   
   r8   	   r7         r?      r>      r=      rD   r;   c                `    g | ]*}t          d           D ]}|z  z   |z  z   dfD ]}|+S )r7   r   )range).0vhiseg_hseg_wuv_xuv_ys       r(   
<listcomp>z1NinePatch._create_vertex_list.<locals>.<listcomp>   sW    fffQE!HHffqteai?OQUX]`aXaQacd>effqfffffr)   r7      fBn)positioncolors	translatescalerotation
tex_coords)_textureuvrF   programvertex_list_indexedr   _batch_group_get_vertices_rgba_x_y_z_scale_scale_x_scale_y	_rotation_vertex_list)	r&   indicesuv_wuv_huvsrK   rL   rM   rN   s	        @@@@r(   _create_vertex_listzNinePatch._create_vertex_lists   s   2
 "&!1dD$!! gffffff%((fff L<<!7DK4--//0$*r/*TWdgtw7"<=T]2DK4MNQSSTDN,r12Sz = # #r)   tuplec                   | j         sdS | j        }|j        dz  }|j        dz  }| j        |z
  |z
  }| j        |z
  |z
  }|j         }||z   }||z   }||z   }	|j         }
|
|z   }||z   }||z   }d}g ||
|||
|||
||	|
|||||||||||	||||||||||||	||||||||||||	||R S )N)0r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   r   )_visiblerY   r   r   r"   r#   anchor_xanchor_y)r&   r   
edge_widthedge_heightcenter_widthcenter_heightx0x1x2x3y0y1y2y3r   s                  r(   r_   zNinePatch._get_vertices   sp   } 	@!>-CQJ*q.K;3j@L L;6DM,BjBl"BjB,Bk!Bm#Bk!BA@B @ @A @r @2 @q @" @b @! @R @ @Q @@@@!@#%@'(@*,@.0@23@57@9;@=>@@@@!@#%@'(@*,@.0@23@57@9;@=>@ @ @ @  "@ $&@ ()@ +-@ /1@ 34@ 68@ :<@ >?@ @ @r)   tuple[float, float, float]c                *    | j         | j        | j        fS )z7The (x, y, z) coordinates of the NinePatch, as a tuple.)ra   rb   rc   r&   s    r(   rS   zNinePatch.position   s     w((r)   rS   c                X    |\  | _         | _        | _        |dz  | j        j        d d <   d S NrP   ra   rb   rc   rh   rU   )r&   rS   s     r(   rS   zNinePatch.position   s2    $,!$')1B#AAA&&&r)   c                    | j         S )zX coordinate of the NinePatch.)ra   r   s    r(   r   zNinePatch.x        wr)   c                V    || _         || j        | j        fdz  | j        j        d d <   d S r   r   )r&   r   s     r(   r   zNinePatch.x   s3    *+TWdg)>)C#AAA&&&r)   c                    | j         S )zY coordinate of the NinePatch.)rb   r   s    r(   r   zNinePatch.y   r   r)   c                V    || _         | j        || j        fdz  | j        j        d d <   d S r   )rb   ra   rc   rh   rU   )r&   r   s     r(   r   zNinePatch.y   s3    *.'1dg)>)C#AAA&&&r)   c                    | j         S )zZ coordinate of the NinePatch.)rc   r   s    r(   r   zNinePatch.z   r   r)   c                V    || _         | j        | j        |fdz  | j        j        d d <   d S r   )rc   ra   rb   rh   rU   )r&   r   s     r(   r   zNinePatch.z   s3    *.'47A)>)C#AAA&&&r)   c                    | j         S )zClockwise rotation of the NinePatch, in degrees.

        The NinePatch will be rotated about its image's (anchor_x, anchor_y)
        position.
        )rg   r   s    r(   rW   zNinePatch.rotation   s     ~r)   rW   c                H    || _         | j         fdz  | j        j        d d <   d S r   )rg   rh   rW   )r&   rW   s     r(   rW   zNinePatch.rotation   s-    !)-(9B(>"111%%%r)   c                     t          d          )Nz,Not supported. Use `width`/`height` instead.NotImplementedErrorr   s    r(   rV   zNinePatch.scale   s    !"PQQQr)   c                     t          d          )Nz#Not supported. Use `width` instead.r   r   s    r(   scale_xzNinePatch.scale_x   s    !"GHHHr)   c                     t          d          )Nz$Not supported. Use `height` instead.r   r   s    r(   scale_yzNinePatch.scale_y   s    !"HIIIr)   c                     t          d          )Nz#Not supported on NinePatch objects.r   )r&   argskwargss      r(   updatezNinePatch.update   s    !"GHHHr)   c                    | j         S )zGThe width of the NinePatch.

        Invariant under rotation.
        )r"   r   s    r(   r   zNinePatch.width   s     {r)   c                <    || _         |                                  d S N)r"   _update_position)r&   r   s     r(   r   zNinePatch.width   s!    r)   c                    | j         S )zHThe height of the NinePatch.

        Invariant under rotation.
        )r#   r   s    r(   r   zNinePatch.height   s     |r)   c                <    || _         |                                  d S r   )r#   r   )r&   r   s     r(   r   zNinePatch.height  s!    r)   c                    | j         d         S )a  Blend opacity.

        This property sets the alpha component of the colour of the sprite's
        vertices.  With the default blend mode (see the constructor), this
        allows the sprite to be drawn with fractional opacity, blending with the
        background.

        An opacity of 255 (the default) has no effect.  An opacity of 128 will
        make the sprite appear translucent.
        r;   r`   r   s    r(   opacityzNinePatch.opacity  s     z!}r)   r   c                f    | j         \  }}}}||||f| _         | j         dz  | j        j        d d <   d S r   r`   rh   rT   )r&   r   rgb_s         r(   r   zNinePatch.opacity  sA    Z
1a1g%
&*j2o ###r)   tuple[int, int, int, int]c                    | j         S )a?  Blend color.

        This property sets the color of the sprite's vertices. This allows the
        sprite to be drawn with a color tint.

        The color is specified as either an RGBA tuple of integers
        '(red, green, blue, opacity)' or an RGB tuple of integers
        `(red, blue, green)`.

        If there are fewer than three components, a :py:func`ValueError`
        will be raised. Each color component must be an int in the range
        0 (dark) to 255 (saturated). If any component is not an int, a
        :py:class:`TypeError` will be raised.
        r   r   s    r(   colorzNinePatch.color   s      zr)   rgba0tuple[int, int, int, int] | tuple[int, int, int]c                    |^}}}}||||r|d         ndf}|| j         k    r|| _         |dz  | j        j        d d <   d S d S )Nr      rP   r   )r&   r   r   r   r   a	new_colors          r(   r   zNinePatch.color2  sh     1a!q!Q/QqTTC/	 
"""DJ*3b.D$QQQ''' #"r)   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r*   r   r+   r   r   r   r   r   r   r   r   r   )r4   r5   )r4   rn   )r4   r   )rS   r   r4   r5   )r4   r   )rW   r   )r   r   )r   r   )r4   r   )r   r   )r4   r   )r   r   )__name__
__module____qualname____doc__r   r   r%   classmethodr3   rm   r_   propertyrS   setterr   r   r   rW   rV   r   r   r   r   r   r   r   __classcell__)r'   s   @r(   r   r      s        ( !%)".#9'+'+%L %L %L %L %L %L %LN  ,-.:/E3737(U (U (U (U [(UT# # # #B@ @ @ @2 ) ) ) X) _7 7 7 _7    X XD D XD    X XD D XD    X XD D XD    X _? ? ? _? R R R XR I I I XI J J XJI I I    X \      \     X ]      ]     X ^6 6 6 ^6
    X" \9 9 9 \9 9 9 9 9r)   r   N)
__future__r   typingr   	pyglet.glr   r   r   pyglet.spriter   pyglet.imager	   r
   pyglet.graphicsr   r   pyglet.text.layoutr   r    r)   r(   <module>r      s    " " " " " "             M M M M M M M M M M             .55555555,,,,,,,,------m9 m9 m9 m9 m9 m9 m9 m9 m9 m9r)   