@@ -157,3 +157,124 @@ pub fn write_normal_comment(
157157 }
158158 "" . to_owned ( )
159159}
160+
161+ #[ allow( clippy:: too_many_arguments) ]
162+ pub fn write_comment_with_animation (
163+ comment : & Comment ,
164+ width : u32 ,
165+ height : u32 ,
166+ rotate_y : f64 ,
167+ rotate_z : f64 ,
168+ from_x : f64 ,
169+ from_y : f64 ,
170+ to_x : f64 ,
171+ to_y : f64 ,
172+ from_alpha : u8 ,
173+ to_alpha : u8 ,
174+ text : & str ,
175+ delay : f64 ,
176+ lifetime : f64 ,
177+ duration : f64 ,
178+ fontface : & str ,
179+ is_border : bool ,
180+ styleid : & str ,
181+ zoom_factor : ( f32 , f32 , f32 ) ,
182+ ) -> String {
183+ let from_rotarg = utils:: convert_flash_rotation (
184+ rotate_y,
185+ rotate_z,
186+ from_x,
187+ from_y,
188+ width as f64 ,
189+ height as f64 ,
190+ ) ;
191+ let to_rotarg =
192+ utils:: convert_flash_rotation ( rotate_y, rotate_z, to_x, to_y, width as f64 , height as f64 ) ;
193+ if vec ! [
194+ from_rotarg. 0 ,
195+ from_rotarg. 1 ,
196+ from_rotarg. 2 ,
197+ from_rotarg. 3 ,
198+ from_rotarg. 4 ,
199+ from_rotarg. 5 ,
200+ to_rotarg. 0 ,
201+ to_rotarg. 1 ,
202+ to_rotarg. 2 ,
203+ to_rotarg. 3 ,
204+ to_rotarg. 4 ,
205+ to_rotarg. 5 ,
206+ ]
207+ . into_iter ( )
208+ . any ( |x| x. is_nan ( ) )
209+ {
210+ // eprintln!(
211+ // "Invalid rotation arguments: {:?}",
212+ // (rotate_y, rotate_z, from_x, from_y)
213+ // );
214+ return "" . to_owned ( ) ;
215+ }
216+ let mut styles = vec ! [ format!( "\\ org({}, {})" , width / 2 , height / 2 ) ] ;
217+ if ( from_rotarg. 0 , from_rotarg. 1 ) == ( to_rotarg. 0 , to_rotarg. 1 ) {
218+ styles. push ( format ! ( "\\ pos({:.0}, {:.0})" , from_rotarg. 0 , from_rotarg. 1 ) ) ;
219+ } else {
220+ styles. push ( format ! (
221+ "\\ move({:.0}, {:.0}, {:.0}, {:.0}, {:.0}, {:.0})" ,
222+ from_rotarg. 0 ,
223+ from_rotarg. 1 ,
224+ to_rotarg. 0 ,
225+ to_rotarg. 1 ,
226+ delay,
227+ delay + duration
228+ ) ) ;
229+ }
230+ styles. push ( format ! (
231+ "\\ frx{:.0}\\ fry{:.0}\\ frz{:.0}\\ fscx{:.0}\\ fscy{:.0}" ,
232+ from_rotarg. 2 , from_rotarg. 3 , from_rotarg. 4 , from_rotarg. 5 , from_rotarg. 6
233+ ) ) ;
234+ if ( from_x, from_y) != ( to_x, to_y) {
235+ styles. push ( format ! (
236+ "\\ t({}, {}, " ,
237+ delay as i32 ,
238+ ( delay + duration) as i32
239+ ) ) ;
240+ styles. push ( format ! (
241+ "\\ frx{:.0}\\ fry{:.0}\\ frz{:.0}\\ fscx{:.0}\\ fscy{:.0}" ,
242+ to_rotarg. 2 , to_rotarg. 3 , to_rotarg. 4 , to_rotarg. 5 , to_rotarg. 6
243+ ) ) ;
244+ styles. push ( ")" . to_owned ( ) ) ;
245+ }
246+ if !fontface. is_empty ( ) {
247+ styles. push ( format ! ( "\\ fn{}" , utils:: ass_escape( fontface) ) ) ;
248+ }
249+ styles. push ( format ! ( "\\ fs{:.0}" , comment. size * zoom_factor. 0 ) ) ;
250+ if comment. color != 0xFFFFFF {
251+ styles. push ( format ! (
252+ "\\ c&H{}&" ,
253+ utils:: convert_color( comment. color, None , None )
254+ ) ) ;
255+ if comment. color == 0x000000 {
256+ styles. push ( "\\ 3c&HFFFFFF&" . to_owned ( ) ) ;
257+ }
258+ }
259+ if from_alpha == to_alpha {
260+ styles. push ( format ! ( "\\ alpha&H{from_alpha:02X}" ) ) ;
261+ } else if ( from_alpha, to_alpha) == ( 255 , 0 ) {
262+ styles. push ( format ! ( "\\ fad({:.0},0)" , lifetime * 1000. ) )
263+ } else if ( from_alpha, to_alpha) == ( 0 , 255 ) {
264+ styles. push ( format ! ( "\\ fad(0, {:.0})" , lifetime * 1000. ) ) ;
265+ } else {
266+ let lifetime = lifetime * 1000. ;
267+ styles. push (
268+ format ! (
269+ "\\ fade({from_alpha}, {to_alpha}, {to_alpha}, 0, {lifetime:.0}, {lifetime:.0}, {lifetime:.0})"
270+ )
271+ )
272+ }
273+ if !is_border {
274+ styles. push ( "\\ bord0" . to_owned ( ) )
275+ }
276+ let start = utils:: convert_timestamp ( comment. timeline ) ;
277+ let end = utils:: convert_timestamp ( comment. timeline + lifetime) ;
278+ let styles = styles. join ( "" ) ;
279+ format ! ( "Dialogue: -1,{start},{end},{styleid},,0,0,0,,{{{styles}}}{text}\n " )
280+ }
0 commit comments