@@ -68,6 +68,7 @@ pub struct Render {
68
68
coordinates : Coordinates ,
69
69
frames : vec:: IntoIter < RenderFrame > ,
70
70
kork : bool ,
71
+ game_summary : Option < String > ,
71
72
}
72
73
73
74
impl Render {
@@ -91,6 +92,7 @@ impl Render {
91
92
} ]
92
93
. into_iter ( ) ,
93
94
kork : false ,
95
+ game_summary : None ,
94
96
}
95
97
}
96
98
@@ -114,11 +116,12 @@ impl Render {
114
116
highlighted : highlight_uci ( frame. last_move ) ,
115
117
checked : frame. check . to_square ( & frame. fen . 0 ) . into_iter ( ) . collect ( ) ,
116
118
board : frame. fen . 0 . board ,
117
- delay : Some ( frame . delay . unwrap_or ( default_delay ) ) ,
119
+ delay : Some ( 5 ) ,
118
120
} )
119
121
. collect :: < Vec < _ > > ( )
120
122
. into_iter ( ) ,
121
123
kork : true ,
124
+ game_summary : params. game_summary ,
122
125
}
123
126
}
124
127
}
@@ -270,6 +273,59 @@ impl Iterator for Render {
270
273
271
274
self . state = RenderState :: Frame ( frame) ;
272
275
} else {
276
+ if let Some ( game_summary) = & self . game_summary {
277
+ println ! ( "render game summary: {}" , game_summary) ;
278
+ let mut ctrl = block:: GraphicControl :: default ( ) ;
279
+ ctrl. set_disposal_method ( block:: DisposalMethod :: Keep ) ;
280
+ ctrl. set_transparent_color ( Some ( self . theme . transparent_color ( ) ) ) ;
281
+ ctrl. set_delay_time_cs ( 500 ) ;
282
+ blocks. encode ( ctrl) . expect ( "enc graphic control" ) ;
283
+
284
+ let summary_box_height = 100 ;
285
+ let summary_box_width = 400 ;
286
+ let summary_box_left = ( self . theme . width ( ) - summary_box_width) / 2 ;
287
+ let summary_box_top =
288
+ ( self . theme . height ( self . bars . is_some ( ) ) - summary_box_height) / 2 ;
289
+ let summary_font_scale = Scale { x : 32.0 , y : 32.0 } ;
290
+ let v_metrics = self . font . v_metrics ( summary_font_scale) ;
291
+
292
+ blocks
293
+ . encode (
294
+ block:: ImageDesc :: default ( )
295
+ . with_left ( summary_box_left as u16 )
296
+ . with_top ( summary_box_top as u16 )
297
+ . with_height ( summary_box_height as u16 )
298
+ . with_width ( summary_box_width as u16 ) ,
299
+ )
300
+ . expect ( "enc image desc" ) ;
301
+
302
+ let mut view = ArrayViewMut2 :: from_shape (
303
+ ( summary_box_height, summary_box_width) ,
304
+ & mut self . buffer ,
305
+ )
306
+ . expect ( "summary view box view" ) ;
307
+ view. fill ( self . theme . bar_color ( ) ) ;
308
+
309
+ let glyphs = self . font . layout (
310
+ game_summary,
311
+ summary_font_scale,
312
+ rusttype:: point ( 5.0 , 40.0 ) ,
313
+ ) ;
314
+ render_summary (
315
+ & mut view,
316
+ glyphs,
317
+ self . theme ,
318
+ self . theme . text_color ( ) ,
319
+ self . theme . bar_color ( ) ,
320
+ ) ;
321
+
322
+ let mut image_data =
323
+ block:: ImageData :: new ( summary_box_width * summary_box_height) ;
324
+ image_data. data_mut ( ) . extend_from_slice (
325
+ & self . buffer [ ..( summary_box_width * summary_box_height) ] ,
326
+ ) ;
327
+ blocks. encode ( image_data) . expect ( "enc summary box" ) ;
328
+ }
273
329
// Add a black frame at the end, to work around twitter
274
330
// cutting off the last frame.
275
331
if self . kork {
@@ -526,6 +582,31 @@ fn render_coord(
526
582
}
527
583
}
528
584
585
+ fn render_summary (
586
+ square_buffer : & mut ArrayViewMut2 < u8 > ,
587
+ glyphs : LayoutIter ,
588
+ theme : & Theme ,
589
+ text_color : u8 ,
590
+ background_color : u8 ,
591
+ ) {
592
+ for g in glyphs {
593
+ if let Some ( bb) = g. pixel_bounding_box ( ) {
594
+ // Poor man's anti-aliasing.
595
+ g. draw ( |left, top, intensity| {
596
+ let left = left as i32 + bb. min . x ;
597
+ let top = top as i32 + bb. min . y ;
598
+ if 0 <= left && left < theme. width ( ) as i32 && 0 <= top && intensity >= 0.01 {
599
+ if intensity < 0.5 {
600
+ square_buffer[ ( top as usize , left as usize ) ] = background_color;
601
+ } else {
602
+ square_buffer[ ( top as usize , left as usize ) ] = text_color;
603
+ }
604
+ }
605
+ } ) ;
606
+ } ;
607
+ }
608
+ }
609
+
529
610
fn get_square_background_color ( is_highlighted : bool , is_dark : bool , theme : & Theme ) -> u8 {
530
611
match is_highlighted {
531
612
true => match is_dark {
0 commit comments