diff --git a/src/grid_column.cpp b/src/grid_column.cpp index 43234f49d5..fd9d3a2021 100644 --- a/src/grid_column.cpp +++ b/src/grid_column.cpp @@ -400,6 +400,56 @@ class GridColumnCPS final : public GridColumn { } }; +class GridColumnMaxLength final : public GridColumn { + const agi::OptionValue *ignore_whitespace = OPT_GET("Subtitle/Character Counter/Ignore Whitespace"); + const agi::OptionValue *ignore_punctuation = OPT_GET("Subtitle/Character Counter/Ignore Punctuation"); + const agi::OptionValue *character_limit = OPT_GET("Subtitle/Character Limit"); + const agi::OptionValue *bg_color = OPT_GET("Colour/Subtitle/Syntax/Background/Error"); + +public: + COLUMN_HEADER(_("Max")) + COLUMN_DESCRIPTION(_("Max Characters Per Line")) + bool Centered() const override { return true; } + bool RefreshOnTextChange() const override { return true; } + + wxString Value(const AssDialogue *d, const agi::Context *) const override { + return wxS(""); + } + + int MaxLength(const AssDialogue *d) const { + auto const& text = d->Text.get(); + + int ignore = agi::IGNORE_BLOCKS; + if (ignore_whitespace->GetBool()) + ignore |= agi::IGNORE_WHITESPACE; + if (ignore_punctuation->GetBool()) + ignore |= agi::IGNORE_PUNCTUATION; + + return agi::MaxLineLength(text, ignore); + } + + int Width(const agi::Context *c, WidthHelper &helper) const override { + return helper(wxS("999")); + } + + void Paint(wxDC &dc, int x, int y, const AssDialogue *d, const agi::Context *) const override { + int maxLength = MaxLength(d); + + wxString str = std::to_wstring(maxLength); + wxSize ext = dc.GetTextExtent(str); + + int limit = character_limit->GetInt(); + if (maxLength > limit) { + dc.SetBrush(wxBrush(to_wx(bg_color->GetColor()))); + dc.SetPen(*wxTRANSPARENT_PEN); + dc.DrawRectangle(x, y + 1, width, ext.GetHeight() + 3); + } + + x += (width + 2 - ext.GetWidth()) / 2; + dc.DrawText(str, x, y + 2); + } +}; + class GridColumnText final : public GridColumn { const agi::OptionValue *override_mode; wxString replace_char; @@ -470,6 +520,7 @@ std::vector> GetGridColumns() { ret.push_back(make()); ret.push_back(make()); ret.push_back(make()); + ret.push_back(make()); ret.push_back(make()); ret.push_back(make()); ret.push_back(make());