+
    KiZ  c                   sD   ^ RI H t ^ RIHt ^ RIt^ RIHt ^ RIHt ]P                  ! RR4       ^ RI
t
^ RIHtHtHtHtHt ^ R	IHtHtHtHtHt ^ R
IHt ^ RIHt ^ s ! R R]P8                  4      t ! R R]P<                  4      tR R lt ]PB                  ! ] 4       R# )    )gettext)floorN)schedule_at_idle)logger
PangoCairoz1.0)GdkGObjectGtkPangor   )MEDIA_CACHE_INVALIDATEDget_default_icon_pathget_runtime_icon_pathget_scaled_surface_by_pathget_surface_size)resolve_media_path)MISSING_GAMESc                   sZ   a a ] tR t^t oRtV 3R ltR tR tR tR t	R t
R tR	tVtV ;t# )
GridViewCellRendererTextzCellRendererText adjusted for grid view display, removes extra padding
and caches cell metrics for improved resize performance.c                s:  < \         SV `  ! V/ VB  \        P                  P                  V P
                  n        \        P                  P                  V P
                  n	        R V P
                  n
        ^ V P
                  n        RV n        / V n        / V n        R# )g      ?N)super__init__r	   Z	AlignmentZCENTERpropsZ	alignmentZWrapModeZWORDZ	wrap_modeZxalignZyalignfixed_widthcached_heightcached_widthselfZargsZkwargs	__class__   &*,E/usr/lib/python3.14/site-packages/lutris/gui/widgets/cellrenderers.pyr   Z!GridViewCellRendererText.__init__"   sq    $)&)$55

$~~22





    c                sR    Wn         WP                  n        V P                  4        R # N)r   r   Z
wrap_widthclear_caches)r   width   &&r   	set_widthZ"GridViewCellRendererText.set_width,   s      %

r   c                sn    V P                   P                  4        V P                  P                  4        R # r   )r   clearr   r      &r   r   Z%GridViewCellRendererText.clear_caches1   s&      "!r   c                   V P                   P                  pV P                  '       d$   W P                  9   d   V P                  V,          # \        P
                  P                  W4      pV P                  '       d   W0P                  V&   V# r   )r   textr   r   r   CellRendererTextdo_get_preferred_width)r   widgetr'   r       &&  r   r)   Z/GridViewCellRendererText.do_get_preferred_width5   sl    zz(9(9 9$$T**$$;;DI&+d#r   c                s   V P                   P                  pV P                  '       d$   W0P                  9   d   V P                  V,          # \        P
                  P                  WV4      pV P                  '       d   W P                  V&   V# r   )r   r'   r   r   r   r(   !do_get_preferred_width_for_height)r   r*   r    r'   s   &&& r   r,   Z:GridViewCellRendererText.do_get_preferred_width_for_heightA   so    zz(9(9 9$$T**$$FFtUZ[&+d#r   c                r&   r   )r   r'   r   r   r   r(   do_get_preferred_height)r   r*   r'   heightr+   r   r-   Z0GridViewCellRendererText.do_get_preferred_heightM   sl    zz(:(: :%%d++%%==dK'-t$r   c                s   V P                   P                  pV P                  '       d$   W0P                  9   d   V P                  V,          # \        P
                  P                  WV4      pV P                  '       d   W@P                  V&   V# r   )r   r'   r   r   r   r(   !do_get_preferred_height_for_width)r   r*   r    r'   r.   s   &&&  r   r/   Z:GridViewCellRendererText.do_get_preferred_height_for_widthY   so    zz(:(: :%%d++%%GGV[\'-t$r   )r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r"   r   r)   r,   r-   r/   __static_attributes____classdictcell____classcell__r   __classdict__   @@r   r   r      s3     @
"



 
r   r   c                   s  a a ] tR t^ft oRtV 3R ltV3R lR ltR tR t]	P                  ! ]R7      R 4       t]P                  R	 4       t]	P                  ! ]	P                  R7      R
 4       t]P                  R 4       t]	P                  ! ]	P                  R7      R 4       t]P                  R 4       t]	P                  ! ]RR7      R 4       t]P                  R 4       t]	P                  ! ]R7      R 4       t]P                  R 4       t]	P                  ! ]RR7      R 4       t]P                  R 4       tR tR tR tR tR t]R 4       tR tR tR tR t]R  4       t / t!R! t"R" t#R# t$V3R$ lR% lt%R)R& lt&R)R' lt'R(t(Vt)V ;t*# )*GridViewCellRendererImagezA pixbuf cell renderer that takes not the pixbuf but a path to an image file;
it loads that image only when rendering. It also has properties for its width
and height, so it need not load the pixbuf to know its size.c                s  < \         SV `  ! V/ VB  R V n        R V n        . V n        RV n        R V n        RV n        / V n        / V n	        ^ V n
        ^ V n        RV n        RV n        RV n        RV n        / V n        R V n        R V n        R # )NTg333333?r    r    )   r=   r=   )r    r    r    )r   r   _game_id_service_media_paths_show_badges	_platform_is_installedcached_surfaces_newcached_surfaces_oldcached_surfaces_loadedcached_surface_generation
badge_sizebadge_alphabadge_fore_colorbadge_back_color_inset_fractions_expected_width_expected_heightr   r   r   r   Z"GridViewCellRendererImage.__init__k   s    $)&) !#% #% &'#)*& ' ' "# $r   c                s,   < V ^8  d   QhRS[ RS[RS[/# )   game_idfractionreturn)strZfloatboolformatr9      "r   __annotate__&GridViewCellRendererImage.__annotate__   s"      #  4 r   c                s    VR8  d3   W P                   P                  V4      8w  d   W P                   V&   R#  R# WP                   9   d   V P                   V R# R# )aJ  This function indicates that a particular game should be displayed inset by a certain fraction of
its total size; 0 is full size, 0.1 would show it at 90% size, but centered.

This is not bound as an attribute; it's used for an ephemeral animation, and we wouldn't want
to mess with the GameStore to do it. Instead, the cell renderer tracks these per game ID, and
the caller uses queue_draw() to trigger a redraw.

Set the fraction to 0 for a game to remove the effect when done.

This returns True if it alters the inset of a game, and False if not because it was
already set that way.        TF)rL   get)r   rP   rQ      &&&r   
inset_gameZ$GridViewCellRendererImage.inset_game   s_     c>0044W==19%%g. > 	 ---%%g.r   c                s    V P                   RJ # )zKReturns True if this is rendering for the library view (not a service view)N)servicer$   r%   r   is_library_viewZ)GridViewCellRendererImage.is_library_view   s    ||t##r   c                s    Wn         W n        R# )zNSets the expected dimensions for library view based on the selected zoom levelN)rM   rN   )r   r    r.   r\   r   set_expected_sizeZ+GridViewCellRendererImage.set_expected_size   s    $ &r   )typec                    V P                   # z3This is the path to the media file to be displayed.r>   r$   r%   r   rP   !GridViewCellRendererImage.game_id   s     }}r   c                    Wn         R # r   rd   r   Zvaluer!   r   rP   re          r   c                rb   r   r?   r$   r%   r   r^   !GridViewCellRendererImage.service   s    }}r   c                rf   r   ri   rg   r!   r   r^   rj      rh   r   c                rb   )zAThis is the list of paths where the media to be displayed may be.r@   r$   r%   r   media_paths%GridViewCellRendererImage.media_paths           r   c                rf   r   rk   rg   r!   r   rl   rm          !r   T)ra   Zdefaultc                rb   rc   rA   r$   r%   r   show_badges%GridViewCellRendererImage.show_badges   rn   r   c                rf   r   rp   rg   r!   r   rq   rr      ro   r   c                rb   )zhThis is the platform text, a comma separated list; we try to convert
this into icons, if it is not None.rB   r$   r%   r   platform"GridViewCellRendererImage.platform   s     ~~r   c                rf   r   rs   rg   r!   r   rt   ru      s    r   c                rb   )zRThis flag indicates if the game is installed; if not the media is shown
faded out.rC   r$   r%   r   is_installed&GridViewCellRendererImage.is_installed   s     !!!r   c                rf   r   rv   rg   r!   r   rw   rx      s    "r   c                sp    V P                   pV'       d"   V^ ,          pVP                  VP                  3# R# )r    r<   )rl   r    r.   )r   Zpathspaths   &  r   _get_preferred_sizeZ-GridViewCellRendererImage._get_preferred_size   s1      8D::t{{**r   c                s    V P                  4       '       d+   V P                  '       d   V P                  V P                  3# V P                  4       pV^ ,          V^ ,          3# )r    )r_   rM   rz   r   r*   size   && r   r)   Z0GridViewCellRendererImage.do_get_preferred_width   sT    !!d&:&:&:'')=)==='')AwQr   c                s    V P                  4       '       d+   V P                  '       d   V P                  V P                  3# V P                  4       pV^,          V^,          3# )r=   )r_   rN   rz   r{   r}   r   r-   Z1GridViewCellRendererImage.do_get_preferred_height   sT    !!d&;&;&;(($*?*???'')AwQr   c                sV   V P                   '       d   \        V P                   4      MR pV'       g   R # VP                  pVP                  pVP                  p	V P
                  '       d   ^MRp
V^ 8  Ed   V^ 8  Ed   V	'       Ed   V P                  W)Wx3R7      pV'       g"   \        Wx34      p	V P                  W)Wx3RR7      pV'       EdB   V P                  W4      pV P                  WV4       VP                  4        V P                  '       d0   V P                  P                  V P                  4      ;'       g    RMRpV^ 8  d   V;P                  VP                  V,          ^,          ,          un        V;P                  VP                  V,          ^,          ,          un        VP!                  VP                  VP                  4       VP#                  ^V,
          ^V,
          4       M&VP!                  VP                  VP                  4       ^ Vn        ^ Vn        V
^8  d:   V P%                  WV^ ^ 4       V P&                  '       d   V P)                  WW4       MiVP+                  4        V P%                  WV^ ^ 4       V P&                  '       d   V P)                  WW4       VP-                  4        VP/                  V
4       VP1                  4        V^ 8  d(   VP3                  R4      p\4        P6                  ! W4       \9        V P:                  4       R # R # R # R # )Nr|   F)r|   preserve_aspect_ratiorZ   Z g?)rl   r   r    r.   ry   rw   _get_cached_surface_by_pathr   get_media_areaselect_badge_metricssaverP   rL   r[   xy	translatescalerender_mediarq   _render_badgesZ
push_groupZpop_group_to_sourceZpaint_with_alpharestorecreate_pango_layoutr   update_layoutr   cycle_cache)r   crr*   Zbackground_area	cell_areaZflagsZ
media_pathmedia_widthmedia_heightry   alphasurface
media_areaZinset_fractionlayouts   &&&&&&         r   	do_renderZ#GridViewCellRendererImage.do_render   s   =A=M=M=M'(8(89SW
 &&!((&&&I?|a/DD66v;Je6fG,k-HI::'BZ_ ;  w!00D
))'M	 TXS_S_S_!6!6!:!:4<<!H!O!OCeh!A%LLZ%5%5%F!$KKLLLZ%6%6%G1$LLLLLz||<HHQ/^1CDLLz||< 
 
A:%%b'1a@'''++BLMMO%%b'1a@'''++BL**,''.

!A% $77;F,,R8 T--.c 59/?r   c                s   aa VV3R lpV! 4       V n         V P                   ;'       d     \        P                  WP                   4      pRpRpV'       d   TMTV n        V'       d	   W`n        R# TV n        R# )zUpdates fields holding data about the appearance of the badges;
this sets self.badge_size to None if no badges should be shown at all.c                 s>   < S^@8  d   R# S ^8  d   R# S R8  d   R# R# )zReturns the size of the badge icons to render, or None to hide them. We check
width for the smallest size because Dolphin has very thin banners, but we only hide
badges for icons, not banners.Ni   )   r   )   r   )    r    )r   r   s   r   get_badge_icon_sizeZKGridViewCellRendererImage.select_badge_metrics.<locals>.get_badge_icon_size)  s/     Rc!c!Mr   N)皙?r   r   )皙?r   r   )rH   r;   is_bright_cornerrJ   rK   )r   r   r   r   r   Zon_bright_surfaceZbright_colorZ
dark_colors   &&ff    r   r   Z.GridViewCellRendererImage.select_badge_metrics%  s^    
	 ./ OOtt0I0Z0Z[bdsds0t$"
.?
\0Azr   c                s  a aa	 S P                  4       pV\        P                  8w  d   R# S P                  4       w  r4\	        V^ ,          V,          4      p\	        V^,          V,          4      pS P                  4       o	S P                  4       oVV	V 3R lpV! S	^,
          S^,
          4      ;'       dV    V! S	V,
          S^,
          4      ;'       d7    V! S	^,
          SV,
          4      ;'       d    V! S	V,
          SV,
          4      # )zTests several pixels near the corner of the surface where the badges
are drawn. If all are 'bright', we'll render the badges differently. This
means all 4 components must be at least 128/255.Fc                 s   < ^ T u;8:  d   S8  dn   M R# ^ Tu;8:  d   S8  d[   M R# S	P                  4       pS	P                  4       pW,          V ^,          ,           pW4V^,            pV F  pV^8  g   K   R# 	  R# R# )r    FT)Z
get_strideZget_data)
r   r   ZstrideZdataZoffsetZpixelZchannelpixel_heightpixel_widthr   s
   &&     r   is_bright_pixelZCGridViewCellRendererImage.is_bright_corner.<locals>.is_bright_pixelQ  s     A##  )*Q(=(=  !++-'')*A-fqj1$G}$  % r   )Z
get_formatcairoZFORMAT_ARGB32Zget_device_scaleZintZ	get_widthZ
get_height)
r   Zcorner_sizeZsurface_formatZdevice_scale_xZdevice_scale_yZcorner_pixel_widthZcorner_pixel_heightr   r   r   s
   f&      @@r   r   Z*GridViewCellRendererImage.is_bright_corner=  s   
 !++- U000 *1)A)A)C& Q.!@A!+a.>"AB'')))+	$ K!O\A-=> f f.@ @,QRBRSf fa@S1STf f  .@ @,QdBde		
r   c                s   \         P                  ! 4       p\        V4      w  rE\        VP                  VP
                  V,
          ^,          ,           4      Vn        V P                  4       '       d;   \        VP                  VP                  V,
          ^,          ,           4      Vn        M2\        VP                  VP                  ,           V,
          4      Vn        WEuVn        Vn        V# )zcComputes the position of the upper left corner where we will render
a surface within the cell area.)	r   Z	Rectangler   roundr   r    r_   r   r.   )r   r   r   r   r    r.   s   &&&   r   r   Z(GridViewCellRendererImage.get_media_areai  s     ]]_
(1 Y[[IOOe,Cq+HHI
!! 	0@0@60IQ/N!NOJL !y/?/?!?&!HIJL.3+
*+r   c                s    \        V4      w  rgVP                  W4V4       VP                  4       P                  \        P
                  P                  4       VP                  WEWg4       VP                  4        R# )zKRenders the media itself, given the surface containing it
and the position.N)	r   Zset_source_surfaceZ
get_sourceZ
set_extendr   ZExtendZPAD	rectanglefill)r   r   r*   r   r   r   r    r.      &&&&&&  r   r   Z&GridViewCellRendererImage.render_media|  sU     )1
g!,
""5<<#3#34
Q5)
	r   c                sR   V P                  WV^ V4       V P                  pV'       d   V P                  '       d   V P                  P                  V4      pV\        P
                  9   d;   V P                  W\        R4      ^ VP                  VP                  ,           4       R# R# R# )r    ZMissingN)
render_platformsrP   r^   Zresolve_game_idr   Zmissing_game_idsrender_text_badge_r   r.   )r   r   r*   r   r   rP   s   &&&&& r   r   Z(GridViewCellRendererImage._render_badges  s    b'1jA,,|||,,66w?-888&&r1Y<JLLS]SdSdDde 9	 r   c                s    V P                   pV'       dE   V P                  '       d1   V P                  V4      pV'       d   V P                  WW4Wu4       R# R# R# R# )z$Renders the stack of platform icons.N)rt   rH   get_platform_icon_pathsrender_badge_stack)r   r   r*   r   	surface_xr   rt   
icon_pathsr   r   r   Z*GridViewCellRendererImage.render_platforms  sG    ==55h?J''G
_  (8r   c                s,   V \         P                  9   d   \         P                  V ,          # R V 9   d   V P                  R 4      pMV .p. pV F0  p\        VR,           4      pV'       g   K  VP	                  V4       K2  	  V\         P                  V &   V# )Z,z	-symbolic)r;   _platform_icon_pathsZsplitr   Zappend)rt   Z	platformsr   Zp	icon_paths   &    r   r   Z1GridViewCellRendererImage.get_platform_icon_paths  s    0EEE,AA(KK(? s+I!
I
A-a+o>Iy!!), 
 DN!66x@r   c                s  a aaaaaaa S P                   ^ ,          oS P                   ^,          oS P                  oS P                  oS P                  oVVVVVVV V3R lpV\	        V4      ^ ,          ,           pVS,
          p	VP
                  S\        V4      ,          ,
          \        ^\        V4      ^,
          4      ,          p
\        V
^4      p
\        SV
,           4      pVP                  VP
                  ,           S,
          V\        V4      ^,
          ,          ,
          pV F  pV! WV4       W,           pK  	  R# )zRenders a vertical stack of badges, placed at the edge of the media, just to the left
of 'media_area.right'. The icons in icon_paths are drawn from top to bottom, and spaced
to fit in 'media_area', even if they overlap because of this.c                 sR  < SP                  WSS4       SP                  S^ ,          S^,          S^,          S4       SP                  4        S
P                  SVS
P                  R7      pSP                  S	^ ,          S	^,          S	^,          S4       SP                  W0V4       R# )r    r~   N)r   set_source_rgbar   r   rH   Zmask_surface)Zbadge_xZbadge_yry   Ziconr   
back_colorbadge_heightbadge_widthr   
fore_colorr   r*   s   &&& r   render_badgeZBGridViewCellRendererImage.render_badge_stack.<locals>.render_badge  s    LL;Ez!}jmZ]ERGGI33FDt3WDz!}jmZ]EROOD73r   N)rH   rI   rJ   rK   r   r.   ZlenZmaxZminr   r   )r   r   r*   r   r   r   r   r   Zmedia_rightr   ZspacingZy_offsetr   r   r   r   r   r   r   s   fff&&&&       @@@@@r   r   Z,GridViewCellRendererImage.render_badge_stack  s   
 ooa(q)  **
**
	4 	4  "27";A">>+%$$|c*o'EEQPST^P_bcPcIddgq//0LL:,,,|;h#j/\]J]>^^#Iy)A $r   c                sD  aa VV3R lpV P                   '       Ed   V P                  pV P                  pV P                  p	V! 4       w  rpVP	                  4        V P                   ^,          V,          pV P                   ^,          p\        W,          4      pVP                  WEV,
          V^,           V4       VP                  V	^ ,          V	^,          V	^,          V4       VP                  4        VP                  V^,           W\,
          4       VP                  W4       VP                  V^ ,          V^,          V^,          V4       \        P                  ! W4       \        P                  ! W4       VP                  4        \        P                  ! W4       R# R# )zRDraws a short text in the lower left corner of the media, in the
style of a badge.c                 s~  < SP                  S4      p V P                  4       P                  4       pVP                  \        P
                  P                  4       V P                  V4       V P                  4       w  r#WP                  \        P                  ,          VP                  \        P                  ,          3# )zConstructs a layout with the text to draw, but also returns its size
in pixels. This is boldfaced, but otherwise in the default font.)r   Zget_contextZget_font_descriptionZ
set_weightr	   ZWeightZBOLDZset_font_descriptionZget_extentsr    ZSCALEr.   )ZloZfontr   Ztext_boundsr'   r*   s       r   
get_layoutZ?GridViewCellRendererImage.render_text_badge.<locals>.get_layout  s     ++D1B>>#88:DOOELL--.##D)^^-NA((5;;68J8JU[[8XXXr   N)rH   rI   rJ   rK   r   r   r   r   r   r   r   r   r   Zshow_layoutr   )r   r   r*   r'   ZleftZbottomr   r   r   r   r   Z
text_widthZtext_heightZ
text_scales   &&ff&&        r   r   Z+GridViewCellRendererImage.render_text_badge  s8   	Y ???$$E..J..J.8l+FGGI
 +k9J//!,Kz67JLL3Z!^[Qz!}jmZ]ERGGILL6#78HHZ,z!}jmZ]ER$$R0""2.JJL $$R0A r   c                sn    V P                   P                  4        V P                  P                  4        R# )zDDiscards all cached surfaces; used when some properties are changed.N)rE   r#   rD   r$   r%   r   clear_cacheZ%GridViewCellRendererImage.clear_cache  s&      &&(  &&(r   c                s   < V ^8  d   QhRR/# rO   rR   Nr   rU   rW   r   rX   rY     s     , ,T ,r   c                sj    V P                   ^ 8  d"   V P                  V n        / V n        ^ V n         R# R# )a\  Is the key cache size control trick. When called, the surfaces cached or used
since the last call are preserved, but those not touched are discarded.

We call this at idle time after rendering a cell; this should keep all the surfaces
rendered at that time, so during scrolling the visible media are kept and scrolling is smooth.
At other times we may discard almost all surfaces, saving memory.

We skip clearing anything if no surfaces have been loaded; this happens if drawing was
serviced entirely from cache. GTK may have redrawn just one image or something, so
let's not disturb the cache for that.N)rF   rD   rE   r$   r%   r   r   Z%GridViewCellRendererImage.cycle_cache  s5     &&*'+'?'?D$')D$*+D' +r   c                s~   V P                   \        8w  d   \        V n         V P                  4        WW43pWPP                  9   d   V P                  V,          # WPP                  9   d   V P                  V,          pM3V P                  WW44      pV'       d   V ;P                  ^,          un        W`P                  V&   V# )a  This obtains the scaled surface to rander for a given media path; this is cached
in this render, but we'll clear that cache when the media generation number is changed,
or certain properties are. We also age surfaces from the cache at idle time after
rendering.)rG   _MEDIA_CACHE_GENERATION_NUMBERr   rD   rE   _get_surface_by_pathrF   )r   r*   ry   r|   r   Zkeyr   s   &&&&&  r   r   Z5GridViewCellRendererImage._get_cached_surface_by_path  s    
 ))-KK-KD*D7***++C00***..s3G//dZG ++q0+(/  %r   c                s    TpV'       d   VP                  4       M^p \        W%WdR7      #   \         d#   p\        P                  ! RY'4        Rp?R# Rp?ii ; i)r=   )r   zUnable to load media '%s': %sN)Zget_scale_factorr   Z	Exceptionr   Z	exception)r   r*   ry   r|   r   Z	cell_sizeZscale_factorZexs   &&&&&   r   r   Z.GridViewCellRendererImage._get_surface_by_path-  sX    	4:v..0	-   	 <dG		s   + AAA)rN   rM   r>   rL   rC   r@   rB   r?   rA   rI   rK   rJ   rH   rG   rF   rD   rE   )T)+r0   r1   r2   r3   r4   r   r]   r_   r`   r   ZPropertyrS   rP   ZsetterZTYPE_PYOBJECTr^   rl   rT   rq   rt   rw   rz   r)   r-   r   r   Zstaticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r5   r6   r7   r8   r:   r   r;   r;   f   s    D%( ,$'
 3   ^^  7001 2 ^^  7001! 2! " " 4.! /! " " 3  
 __  4." /"
 # #  ;/zR0 )
 )
V&	f`  $ @.1`)
, , 4 r   r;   c                s    V ^8  d   QhRR/# r   r   )rV   s   "r   rX   rX   ;  s     ( (d (r   c                  s     \         ^,          s R# )r=   N)r   r   r   r   _on_media_cached_invalidatedr   ;  s    
 #a'"r   )"r   r   Zmathr   ZgiZlutris.util.jobsr   Zlutris.util.logr   Zrequire_versionr   Zgi.repositoryr   r   r   r	   r   Zlutris.gui.widgets.utilsr
   r   r   r   r   Zlutris.services.service_mediar   Zlutris.util.path_cacher   r   r(   r   ZCellRendererr;   r   Zregisterr   r   r   <module>r      s    !  	 - "   < '  > >  = 0!" Es33 EPR 0 0 Rj(     != >r   