@@ -8,7 +8,7 @@ use tdlib::types::Sticker as TdSticker;
88
99use super :: VectorPath ;
1010use crate :: session:: Session ;
11- use crate :: utils:: { decode_image_from_path, spawn} ;
11+ use crate :: utils:: { color_matrix_from_color , decode_image_from_path, spawn} ;
1212
1313mod imp {
1414 use super :: * ;
@@ -19,6 +19,8 @@ mod imp {
1919 pub ( crate ) struct Sticker {
2020 pub ( super ) file_id : Cell < i32 > ,
2121 pub ( super ) aspect_ratio : Cell < f64 > ,
22+ pub ( super ) recolor : Cell < bool > ,
23+ pub ( super ) is_loaded : Cell < bool > ,
2224 pub ( super ) child : RefCell < Option < gtk:: Widget > > ,
2325
2426 #[ property( get, set = Self :: set_longer_side_size) ]
@@ -84,6 +86,17 @@ mod imp {
8486 child. allocate ( width, height, baseline, None ) ;
8587 }
8688 }
89+
90+ fn snapshot ( & self , snapshot : & gtk:: Snapshot ) {
91+ if self . recolor . get ( ) && self . is_loaded . get ( ) {
92+ let ( color_matrix, color_offset) = color_matrix_from_color ( self . obj ( ) . color ( ) ) ;
93+ snapshot. push_color_matrix ( & color_matrix, & color_offset) ;
94+ self . parent_snapshot ( snapshot) ;
95+ snapshot. pop ( ) ;
96+ } else {
97+ self . parent_snapshot ( snapshot) ;
98+ }
99+ }
87100 }
88101
89102 impl Sticker {
@@ -108,11 +121,15 @@ impl Sticker {
108121 return ;
109122 }
110123
111- self . set_child ( Some ( VectorPath :: new ( & sticker. outline ) . upcast ( ) ) ) ;
124+ self . set_child ( VectorPath :: new ( & sticker. outline ) . upcast ( ) , false ) ;
112125
113126 let aspect_ratio = sticker. width as f64 / sticker. height as f64 ;
114127 imp. aspect_ratio . set ( aspect_ratio) ;
115128
129+ let recolor = matches ! ( & sticker. full_type,
130+ tdlib:: enums:: StickerFullType :: CustomEmoji ( data) if data. needs_repainting) ;
131+ imp. recolor . set ( recolor) ;
132+
116133 let format = sticker. format ;
117134
118135 spawn ( clone ! ( @weak self as obj, @weak session => async move {
@@ -185,18 +202,17 @@ impl Sticker {
185202
186203 // Skip if widget was recycled by ListView
187204 if self . imp ( ) . file_id . get ( ) == file_id {
188- self . set_child ( Some ( widget) ) ;
205+ self . set_child ( widget, true ) ;
189206 }
190207 }
191208
192- fn set_child ( & self , child : Option < gtk:: Widget > ) {
209+ fn set_child ( & self , child : gtk:: Widget , is_loaded : bool ) {
193210 let imp = self . imp ( ) ;
211+ imp. is_loaded . set ( is_loaded) ;
194212
195- if let Some ( ref child) = child {
196- child. set_parent ( self ) ;
197- }
213+ child. set_parent ( self ) ;
198214
199- if let Some ( old) = imp. child . replace ( child) {
215+ if let Some ( old) = imp. child . replace ( Some ( child) ) {
200216 old. unparent ( )
201217 }
202218 }
0 commit comments