Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/grid_column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -470,6 +520,7 @@ std::vector<std::unique_ptr<GridColumn>> GetGridColumns() {
ret.push_back(make<GridColumnStartTime>());
ret.push_back(make<GridColumnEndTime>());
ret.push_back(make<GridColumnCPS>());
ret.push_back(make<GridColumnMaxLength>());
ret.push_back(make<GridColumnStyle>());
ret.push_back(make<GridColumnActor>());
ret.push_back(make<GridColumnEffect>());
Expand Down