
    ^jy%                       d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZ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 d dlmZ d d	lmZ d d
lmZ  G d dej                  Z G d dej                  Z  G d de          Z!dS )    )annotations)TYPE_CHECKINGClassVar)graphics)	GL_BLENDGL_ONE_MINUS_SRC_ALPHAGL_SRC_ALPHAGL_TEXTURE0glActiveTextureglBindTextureglBlendFunc	glDisableglEnable)
TextLayout)AnchorXAnchorY)Batch)ShaderProgram)Texture)AbstractDocumentc                  b     e Zd ZU dZdZded<   	 	 dd fdZddZddZddZ	ddZ
d dZ xZS )!ScrollableTextLayoutGroupa  Default rendering group for :py:class:`~pyglet.text.layout.ScrollableTextLayout`.

    The group maintains internal state for specifying the viewable
    area, and for scrolling. Because the group has internal state
    specific to the text layout, the group is never shared.
    r   r   r   r   #ClassVar[tuple[int, int, int, int]]scissor_area   Ntexturer   programr   orderintparentgraphics.Group | NonereturnNonec                j    t                                          ||           || _        || _        d S N)r   r!   )super__init__r   r   )selfr   r   r   r!   	__class__s        W/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/text/layout/scrolling.pyr(   z"ScrollableTextLayoutGroup.__init__$   s4     	uV444    c                6   | j                                          d| j         d<   | j        | j         d<   t          t                     t          | j        j        | j        j                   t          t                     t          t          t                     d S NTscissorr   )r   user   r   r
   r   r   targetidr   r   r   r	   r   r)   s    r+   	set_statez#ScrollableTextLayoutGroup.set_state+   s}    "&Y'+'8^$$$$dl)4<?;;;L"899999r,   c                `    t          t                     | j                                         d S Nr   r   r   stopr3   s    r+   unset_statez%ScrollableTextLayoutGroup.unset_state6   *    (r,   strc                0    | j         j         d| j         dS )N())r*   __name__r   r3   s    r+   __repr__z"ScrollableTextLayoutGroup.__repr__:   s     .);;DL;;;;r,   otherobjectboolc                
    | |u S r6    r)   rA   s     r+   __eq__z ScrollableTextLayoutGroup.__eq__=       u}r,   c                     t          |           S r6   r2   r3   s    r+   __hash__z"ScrollableTextLayoutGroup.__hash__@       $xxr,   )r   N)
r   r   r   r   r   r    r!   r"   r#   r$   r#   r$   r#   r;   rA   rB   r#   rC   r#   r    r?   
__module____qualname____doc__r   __annotations__r(   r4   r9   r@   rG   rK   __classcell__r*   s   @r+   r   r      s           9CLBBBBNO15      	: 	: 	: 	:   < < < <          r,   r   c                  ^     e Zd ZU dZdZded<   dd fdZddZddZddZ	ddZ
ddZ xZS )ScrollableTextDecorationGroupzCreate a text decoration rendering group.

    The group is created internally when a :py:class:`~pyglet.text.Label`
    is created; applications usually do not need to explicitly create it.
    r   r   r   r   Nr   r   r   r    r!   r"   r#   r$   c                \    t                                          ||           || _        d S r&   )r'   r(   r   )r)   r   r   r!   r*   s       r+   r(   z&ScrollableTextDecorationGroup.__init__M   s+    uV444r,   c                    | j                                          d| j         d<   | j        | j         d<   t          t                     t          t          t                     d S r.   )r   r0   r   r   r   r   r	   r   r3   s    r+   r4   z'ScrollableTextDecorationGroup.set_stateQ   sV    "&Y'+'8^$L"899999r,   c                `    t          t                     | j                                         d S r6   r7   r3   s    r+   r9   z)ScrollableTextDecorationGroup.unset_stateY   r:   r,   r;   c                0    | j         j         d| j         dS )Nz	(scissor=r>   )r*   r?   r   r3   s    r+   r@   z&ScrollableTextDecorationGroup.__repr__]   s!    .)HHD4EHHHHr,   rA   rB   rC   c                
    | |u S r6   rE   rF   s     r+   rG   z$ScrollableTextDecorationGroup.__eq__`   rH   r,   c                     t          |           S r6   rJ   r3   s    r+   rK   z&ScrollableTextDecorationGroup.__hash__c   rL   r,   )r   N)r   r   r   r    r!   r"   r#   r$   rM   rN   rO   rP   rQ   rW   s   @r+   rY   rY   D   s           9CLBBBB      : : : :   I I I I          r,   rY   c                  n    e Zd ZU dZeZded<   eZded<   dZ	ded<   dZ
ded	<   	 	 	 	 	 dBdC fd)ZdDd*ZdD fd+ZedEd,            Zej        dF fd-            ZedEd.            Zej        dG fd/            ZedEd0            Zej        dH fd1            ZedId3            Zej        dJ fd5            ZedKd6            Zej        dLd7            ZedMd8            Zej        dNd9            ZdEd:ZdDd;ZedOd<            Zej        dPd>            ZedOd?            Zej        dQdA            Z xZS )RScrollableTextLayouta  Display text in a scrollable viewport.

    This class does not display a scrollbar or handle scroll events; it merely
    clips the text that would be drawn in :py:func:`~pyglet.text.layout.TextLayout`
    to the bounds of the layout given by ``x``, ``y``, ``width`` and ``height``;
    and offsets the text by a scroll offset.

    Use ``view_x`` and ``view_y`` to scroll the text within the viewport.

    Attributes:
        group_class:
            Default group used to set the state for all glyphs.
        decoration_class:
            Default group used to set the state for all decorations including background colors and underlines.
    z)ClassVar[type[ScrollableTextLayoutGroup]]group_classz-ClassVar[type[ScrollableTextDecorationGroup]]decoration_classr   r    _translate_x_translate_yNleftbottomFTdocumentr   xfloatyzwidthheightanchor_xr   anchor_yr   rotation	multilinerC   dpifloat | NonebatchBatch | Nonegroupr"   r   ShaderProgram | None
wrap_linesr#   r$   c                    ||d}t          |          t                                          |||||||||	|
|||||           d S )NzBInvalid size. ScrollableTextLayout width or height cannot be None.)	Exceptionr'   r(   )r)   rh   ri   rk   rl   rm   rn   ro   rp   rq   rr   rs   ru   rw   r   ry   msgr*   s                    r+   r(   zScrollableTextLayout.__init__~   sh     =FNVCC.. 1aE68XxYbdginpu *	. 	. 	. 	. 	.r,   c                    | j         j        sd S | j        | j        | j        | j        f}| j                                        D ]	}||_        
|| j	        _        || j
        _        d S r6   )rh   textrf   rg   _width_heightgroup_cachevaluesr   background_decoration_groupforeground_decoration_group)r)   arearw   s      r+   _update_scissor_areaz)ScrollableTextLayout._update_scissor_area   so    }! 	F	4;T\B%,,.. 	& 	&E!%E8<(58<(555r,   c                p    t                                                       |                                  d S r6   )r'   _updater   )r)   r*   s    r+   r   zScrollableTextLayout._update   s/    !!#####r,   c                    | j         S r6   )_xr3   s    r+   ri   zScrollableTextLayout.x   	    wr,   c                r    t                                          |           |                                  d S r6   )r'   _set_xr   )r)   ri   r*   s     r+   ri   zScrollableTextLayout.x   1    q!!#####r,   c                    | j         S r6   )_yr3   s    r+   rk   zScrollableTextLayout.y   r   r,   c                r    t                                          |           |                                  d S r6   )r'   _set_yr   )r)   rk   r*   s     r+   rk   zScrollableTextLayout.y   r   r,   c                    | j         S r6   )_zr3   s    r+   rl   zScrollableTextLayout.z   r   r,   c                r    t                                          |           |                                  d S r6   )r'   _set_zr   )r)   rl   r*   s     r+   rl   zScrollableTextLayout.z   r   r,   tuple[float, float, float]c                *    | j         | j        | j        fS r6   )r   r   r   r3   s    r+   positionzScrollableTextLayout.position   s    w((r,   r   c                r    t                                          |           |                                  d S r6   )r'   _set_positionr   )r)   r   r*   s     r+   r   zScrollableTextLayout.position   s3    h'''!!#####r,   c                    | j         S r6   )	_anchor_xr3   s    r+   ro   zScrollableTextLayout.anchor_x   
    ~r,   c                    || _         |                                  |                                  |                                  d S r6   )r   _update_anchorr   _update_view_translation)r)   ro   s     r+   ro   zScrollableTextLayout.anchor_x   E    !!!###%%'''''r,   c                    | j         S r6   )	_anchor_yr3   s    r+   rp   zScrollableTextLayout.anchor_y   r   r,   c                    || _         |                                  |                                  |                                  d S r6   )r   r   r   r   )r)   rp   s     r+   rp   zScrollableTextLayout.anchor_y   r   r,   c                   | j         }| j        dk    rt          d| j                   }nC| j        dk    rd}n5| j        dk    rt          d| j                   dz  }nd}t          |          | j        dk    r| |z   S | j        dk    r| | j        z   S | j        dk    rdS | j        dk    r2| j        dk    r| j         | j        dz  | j        d
z  z
  |z
  S ||dz  z
  S d}t          |          )z2Returns the anchor for the Y axis from the bottom.topr   rg   center   z=`content_valign` must be either "top", "bottom", or "center".baseliner   N   zC`anchor_y` must be either "top", "bottom", "center", or "baseline".)r   _content_valignminr{   r   _ascent_line_count_descent)r)   rn   offsetr|   s       r+   _get_bottom_anchorz'ScrollableTextLayout._get_bottom_anchor   s   5((DL))FF!X--FF!X--DL))Q.FFQCC.. >U""7V##>Z''7T\))>X%%1>X%%1$$)=)DMQ,>>&HHFaK''Snnr,   c                `    | j         D ]%}| j         | j         df|j        z  |j        d d <   &d S Nr   )_vertex_listsrd   re   countview_translation)r)   _vertex_lists     r+   r   z-ScrollableTextLayout._update_view_translation   sS     . 	p 	pL151B0BTEVDVXY/Z]i]o/oL)!!!,,	p 	pr,   c                    | j         S )a4  Horizontal scroll offset.

        The initial value is 0, and the left edge of the text will touch the left
        side of the layout bounds.  A positive value causes the text to "scroll"
        to the right.  Values are automatically clipped into the range
        ``[0, content_width - width]``
        )rd   r3   s    r+   view_xzScrollableTextLayout.view_x   s       r,   r   c                    t          dt          | j        | j        z
  |                    }|| j        k    r|| _        |                                  d S d S r   )maxr   _content_widthr   rd   r   )r)   r   translations      r+   r   zScrollableTextLayout.view_x  s[    !S!4t{!BFKKLL$+++ +D))+++++ ,+r,   c                    | j         S )a  Vertical scroll offset.

        The initial value is 0, and the top of the text will touch the top of the
        layout bounds (unless the content height is less than the layout height,
        in which case `content_valign` is used).

        A negative value causes the text to "scroll" upwards.  Values outside of
        the range ``[height - content_height, 0]`` are automatically clipped in
        range.
        )re   r3   s    r+   view_yzScrollableTextLayout.view_y  s       r,   r   c                    t          dt          | j        | j        z
  |                    }|| j        k    r|| _        |                                  d S d S r   )r   r   rn   _content_heightre   r   )r)   r   r   s      r+   r   zScrollableTextLayout.view_y  s]     !St/C!CVLLMM$+++ +D))+++++ ,+r,   )r   r   r   NNrf   rg   r   FNNNNT) rh   r   ri   rj   rk   rj   rl   rj   rm   r    rn   r    ro   r   rp   r   rq   rj   rr   rC   rs   rt   ru   rv   rw   r"   r   rx   ry   rC   r#   r$   rM   )r#   rj   )ri   rj   r#   r$   )rk   rj   r#   r$   )rl   rj   r#   r$   )r#   r   )r   r   r#   r$   )r#   r   )ro   r   r#   r$   )r#   r   )rp   r   r#   r$   rP   )r   r    r#   r$   )r   r    r#   r$   )r?   rR   rS   rT   r   rb   rU   rY   rc   rd   re   r(   r   r   propertyri   setterrk   rl   r   ro   rp   r   r   r   r   rV   rW   s   @r+   ra   ra   g   s=           >WKVVVVFcccccLL 9:26rwfjJN. . . . . . .
= 
= 
= 
=$ $ $ $ $ $    X X$ $ $ $ $ X$    X X$ $ $ $ $ X$    X X$ $ $ $ $ X$ ) ) ) X) _$ $ $ $ $ _$    X _( ( ( _(    X _( ( ( _(   :p p p p
 ! ! ! X! ], , , ], ! ! ! X! ], , , ], , , , ,r,   ra   N)"
__future__r   typingr   r   pygletr   	pyglet.glr   r   r	   r
   r   r   r   r   r   pyglet.text.layout.baser   pyglet.customtypesr   r   pyglet.graphicsr   pyglet.graphics.shaderr   pyglet.imager   pyglet.text.documentr   Groupr   rY   ra   rE   r,   r+   <module>r      s   " " " " " " * * * * * * * *      
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 / . . . . . 633333333%%%%%%444444$$$$$$555555& & & & & & & &R         HN      Fy, y, y, y, y,: y, y, y, y, y,r,   