
    ~d>                       S SK Jr  S SKJrJrJr  S SKJr  S SKJ	r	  S SK
JrJrJrJr  S SKrSSKJr  \\\\\4   r " S	 S
\5      r " S S\5      r\" SS9              SS j5       r        SS jr " S S5      rg)    )annotations)EnumIntEnumauto)	lru_cache)TracebackType)OptionalTupleTypeUnionN   )FontRenderInfoc                  >    \ rS rSr\" 5       r\" 5       r\" 5       rSrg)HorizontalAlign    N)	__name__
__module____qualname____firstlineno__r   LEFTCENTERRIGHT__static_attributes__r       [Z:\mnt\Skyabridged\SteamLibrary\steamapps\common\Borderlands 2\sdk_mods\canvaslib\canvas.pyr   r      s    6DVFFEr   r   c                  >    \ rS rSr\" 5       r\" 5       r\" 5       rSrg)VerticalAlign   r   N)	r   r   r   r   r   TOPr   BOTTOMr   r   r   r   r   r      s    
&CVFVFr   r      )maxsizec                d   U[         R                  :X  a  O@U[         R                  :X  a  XS-  -  n O$U[         R                  :X  a  X-  n O[	        S5      eU[
        R                  :X  a   X4$ U[
        R                  :X  a
  XS-  -  nX4$ U[
        R                  :X  a  X-  nX4$ [	        S5      e)N   zInvalid horizontal alignzInvalid vertical align)r   r   r   r   
ValueErrorr   r    r!   )xywidthheighthalignvaligns         r   get_aligned_posr-      s     %%%	?))	)	aZ	?((	(	
344""" 4K 
=''	'	q[
 4K	 
=''	'	 4K 122r   c                :    XR                   -  X R                  -  4$ )zConverts relative coordinates to screen coordinates.

Args:
    canvas: The canvas to use for the conversion.
    x: The relative x coordinate. Between 0 and 1.
    y: The relative y coordinate. Between 0 and 1.
)ClipXClipY)canvasr'   r(   s      r   relative_to_screen_coordinatesr2   5   s     ||Q---r   c                  V   \ rS rSrSrSSS jjrSS jr      SS jrSSS jjrSS	 jr	SS\
R                  \R                  S\" 5       4                   SS
 jjr\
R                  \R                   S4               SS jjr  S             SS jjrSrg)CanvasB   a  
Context manager for drawing text on the canvas.
Upon leaving the context, the font will be restored to the previous one.

Example:

>>> with Canvas(canvas) as c:
>>>     # Draw text with the default font, centered on the screen
>>>     c.draw_text("Hello World!", 0.5, 0.5,
>>>                 horizontal_align=HorizontalAlign.CENTER,
>>>                 vertical_align=VerticalAlign.CENTER)
>>> # Draw text with a custom font, aligned to the top right corner
>>> with Canvas(canvas, uefont=Fonts.Font_Willowbody_18pt_TWN) as c:
>>>     c.draw_text("Hello World!", 1.0, 0.0,
 >>>                horizontal_align=HorizontalAlign.RIGHT,
>>>                 vertical_align=VerticalAlign.TOP)
Nc                `    Xl         X l        U R                   R                  U l        SU l        g )N)r      r   r7   )r1   fontFontbackup_font
draw_color)selfr1   ufonts      r   __init__Canvas.__init__U   s%    )/16	.2kk.>.> 0r   c                b    U R                   =(       d    U R                  U R                  l        U $ N)r8   r:   r1   r9   )r<   s    r   	__enter__Canvas.__enter__[   s"    998(8(8r   c                :    U R                   U R                  l        g rA   )r:   r1   r9   )r<   exc_typeexc_valexc_tbs       r   __exit__Canvas.__exit___   s    
  ++r         ?c                L    U R                   R                  U5      u  pEXB-  XS-  4$ )z3Returns the width and height of the text in pixels.)r1   TextSize)r<   textscale_xscale_yr'   r(   s         r   	text_sizeCanvas.text_sizef   s'    {{##D){AK''r   c                    X2X4U l         U $ )z3Sets the draw color of the Thext. Values are 0-255.)r;   )r<   rgbas        r   set_draw_colorCanvas.set_draw_colork   s    ,r   c
                   U R                   n
U
R                  nU
R                  nUS::  a  X-  nUS::  a  X-  nU R                  =(       d    U R                  U
l        U R                  XU5      u  p[        X#XXg5      u  p#U
R                  U=(       d    U R                  5        U
R                  X#5        U
R                  USXEU	R                  5       5        X--   X>-   4$ )zDraws text on the canvas.
If x or y is [0.0-1.0], it will be treated as a percentage of the screen width or height.

Returns the x and y position of the bottom right corner of the text.
r   F)r1   SizeXSizeYr8   r:   r9   rP   r-   SetDrawColorStructr;   SetPosDrawTextas_tuple)r<   rM   r'   r(   rN   rO   horizontal_alignvertical_aligncolorfont_render_infor1   screen_widthscreen_heightr)   r*   s                  r   	draw_textCanvas.draw_textp   s    " "LL#\\6 A6!Aii34#3#3tg>qU4DU!!%":4??;aeW7G7P7P7RSy!*$$r   c                   U R                   nUS::  a  UR                  U-  nUS::  a  UR                  U-  nUS::  a  UR                  U-  nUS::  a  UR                  U-  n[        XX4XV5      u  pUR	                  U=(       d    U R
                  5        UR                  X5        UR                  X4UR                  5        X-   X$-   4$ )Nr   )	r1   rZ   r[   r-   r\   r;   r]   DrawRectDefaultTexture)	r<   r'   r(   r)   r*   r`   ra   rb   r1   s	            r   	draw_rectCanvas.draw_rect   s     6q A6q AA:LL5(EQ;\\F*FqU4DU!!%":4??;av'<'<=y!*$$r   c                4   U R                   nUS::  a  UR                  U-  nUS::  a  UR                  U-  nUS::  a  UR                  U-  nUS::  a  UR                  U-  nUR                  XS4X4S4SXV=(       d    U R                  UR
                  SSSSS9
  g )Nr   r   )

StartPointEndPointPercWidth	LineColorLineTextureUVULVL)r1   rZ   r[   DrawTextureLiner;   rj   )r<   x1y1x2y2r)   rb   r1   s           r   	draw_lineCanvas.draw_line   s     7"B7"B7"B7"B{ba[qYqbfbqbq--aA! 	 	
r   )r:   r1   r;   r8   rA   )r1   unrealsdk.UObjectr=   zOptional[unrealsdk.UObject])returnr4   )rE   zOptional[Type[BaseException]]rF   zOptional[BaseException]rG   zOptional[TracebackType])rJ   rJ   )rM   strrN   floatrO   r   r   Tuple[float, float])
rS   r   rT   r   rU   r   rV   r   r   r4   )rM   r   r'   Union[int, float]r(   r   rN   r   rO   r   r`   r   ra   r   rb   Optional[BGRA]rc   r   r   r   )r'   r   r(   r   r)   r   r*   r   r`   r   ra   r   rb   r   r   r   )r   N)ry   r   rz   r   r{   r   r|   r   r)   r   rb   r   r   None)r   r   r   r   __doc__r>   rB   rH   rP   rW   r   r   r   r   rf   r   r    rk   r}   r   r   r   r   r4   r4   B   s   $1,8,1, 1,(
 ! 0?0F0F,9,@,@$(/=/? % % ! % !	 %
  %  % . % * % " % - % 
 %P 1@0D0D,9,=,=$(% % !% %	%
 &% .% *% "% 
%> ()$(
!
 "
 "	

 "
 %
 "
 

 
r   r4   )r'   r   r(   r   r)   r   r*   r   r+   r   r,   r   r   r   )r1   r   r'   r   r(   r   r   r   )
__future__r   enumr   r   r   	functoolsr   typesr   typingr	   r
   r   r   	unrealsdkfontsr   r   BGRAr   r   r-   r2   r4   r   r   r   <module>r      s    " $ $   / /  !UE5%'(d D  3!2 *;   *7 	 2
.!
.&7
.<M
.
.
 
r   