@@ -289,6 +289,8 @@ class GridColumnCPS final : public GridColumn {
289
289
const agi::OptionValue *cps_warn = OPT_GET(" Subtitle/Character Counter/CPS Warning Threshold" );
290
290
const agi::OptionValue *cps_error = OPT_GET(" Subtitle/Character Counter/CPS Error Threshold" );
291
291
const agi::OptionValue *bg_color = OPT_GET(" Colour/Subtitle Grid/CPS Error" );
292
+ const agi::OptionValue *disp_fmt = OPT_GET(" Subtitle/Character Counter/Display Format" );
293
+ const agi::OptionValue *col_align = OPT_GET(" Subtitle/Character Counter/Column Alignment" );
292
294
293
295
public:
294
296
COLUMN_HEADER (_(" CPS" ))
@@ -300,7 +302,7 @@ class GridColumnCPS final : public GridColumn {
300
302
return wxS (" " );
301
303
}
302
304
303
- int CPS (const AssDialogue *d) const {
305
+ double CPS (const AssDialogue *d) const {
304
306
int duration = d->End - d->Start ;
305
307
auto const & text = d->Text .get ();
306
308
@@ -313,32 +315,60 @@ class GridColumnCPS final : public GridColumn {
313
315
if (ignore_punctuation->GetBool ())
314
316
ignore |= agi::IGNORE_PUNCTUATION;
315
317
316
- return agi::CharacterCount (text, ignore) * 1000 / duration;
318
+ return agi::CharacterCount (text, ignore) * 1000 . / duration;
317
319
}
318
320
319
321
int Width (const agi::Context *c, WidthHelper &helper) const override {
320
- return helper (wxS (" 999 " ));
322
+ return helper (wxS (" 99.9 " ));
321
323
}
322
324
323
325
void Paint (wxDC &dc, int x, int y, const AssDialogue *d, const agi::Context *) const override {
324
- int cps = CPS (d);
325
- if (cps < 0 || cps > 100 ) return ;
326
+ double cps = CPS (d);
327
+ if (cps < 0 ) return ;
328
+
329
+ double round_cps;
330
+ wxString str;
331
+ if (disp_fmt->GetInt () == 0 || (disp_fmt->GetInt () == 2 && cps >= 10 )) {
332
+ round_cps = std::lround (cps);
333
+ if (round_cps >= 100 ) return ;
334
+ str = std::to_wstring (int (round_cps));
335
+ } else {
336
+ round_cps = std::round (cps*10 ) / 10.0 ;
337
+ if (round_cps >= 100 ) return ;
338
+ if (round_cps >= 10 )
339
+ str = std::to_wstring (round_cps).substr (0 , 4 );
340
+ else
341
+ str = std::to_wstring (round_cps).substr (0 , 3 );
342
+ }
343
+
344
+ wxSize ext;
345
+ int w0 = dc.GetTextExtent (wxString (L" 0" )).GetWidth ();
346
+ if (col_align->GetInt () == 0 || (disp_fmt->GetInt () != 2 && round_cps >= 10 ))
347
+ ext = dc.GetTextExtent (str);
348
+ else {
349
+ wxString str0;
350
+ if (cps >= 10 )
351
+ str0 = str + wxString (L" .0" );
352
+ else
353
+ str0 = wxString (L" 0" ) + str;
354
+ ext = dc.GetTextExtent (str0);
355
+ }
326
356
327
- wxString str = std::to_wstring (cps);
328
- wxSize ext = dc.GetTextExtent (str);
329
357
auto tc = dc.GetTextForeground ();
330
358
331
- int cps_min = cps_warn->GetInt ();
332
- int cps_max = std::max<int >(cps_min, cps_error->GetInt ());
359
+ double cps_min = cps_warn->GetDouble ();
360
+ double cps_max = std::max<float >(cps_min, cps_error->GetDouble ());
333
361
if (cps > cps_min) {
334
- double alpha = std::min ((double )( cps - cps_min + 1 ) / (cps_max - cps_min + 1 ), 1.0 );
362
+ double alpha = std::min ((cps - cps_min + 1 ) / (cps_max - cps_min + 1 ), 1.0 );
335
363
dc.SetBrush (wxBrush (blend (to_wx (bg_color->GetColor ()), dc.GetBrush ().GetColour (), alpha)));
336
364
dc.SetPen (*wxTRANSPARENT_PEN);
337
365
dc.DrawRectangle (x, y + 1 , width, ext.GetHeight () + 3 );
338
366
dc.SetTextForeground (blend (*wxBLACK, tc, alpha));
339
367
}
340
368
341
369
x += (width + 2 - ext.GetWidth ()) / 2 ;
370
+ if (col_align->GetInt () == 1 && round_cps < 10 )
371
+ x += w0;
342
372
dc.DrawText (str, x, y + 2 );
343
373
dc.SetTextForeground (tc);
344
374
}
0 commit comments