mirror of https://github.com/odrling/Aegisub
Store AssOverrideParameters directly rather than a vector of pointers to them
This commit is contained in:
parent
851f7f40e6
commit
d2a0a76ca9
|
@ -228,7 +228,7 @@ std::auto_ptr<boost::ptr_vector<AssDialogueBlock>> AssDialogue::ParseTags() cons
|
||||||
// Look for \p in block
|
// Look for \p in block
|
||||||
for (auto tag : block->Tags) {
|
for (auto tag : block->Tags) {
|
||||||
if (tag->Name == "\\p")
|
if (tag->Name == "\\p")
|
||||||
drawingLevel = tag->Params[0]->Get<int>(0);
|
drawingLevel = tag->Params[0].Get<int>(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ void AssKaraoke::ParseSyllables(AssDialogue *line, Syllable &syl) {
|
||||||
|
|
||||||
syl.tag_type = tag->Name;
|
syl.tag_type = tag->Name;
|
||||||
syl.start_time += syl.duration;
|
syl.start_time += syl.duration;
|
||||||
syl.duration = tag->Params[0]->Get(0) * 10;
|
syl.duration = tag->Params[0].Get(0) * 10;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
wxString& otext = syl.ovr_tags[syl.text.size()];
|
wxString& otext = syl.ovr_tags[syl.text.size()];
|
||||||
|
|
|
@ -100,14 +100,14 @@ wxString AssDialogueBlockOverride::GetText() {
|
||||||
|
|
||||||
void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callback, void *userData) {
|
void AssDialogueBlockOverride::ProcessParameters(ProcessParametersCallback callback, void *userData) {
|
||||||
for (auto tag : Tags) {
|
for (auto tag : Tags) {
|
||||||
for (auto par : tag->Params) {
|
for (auto& par : tag->Params) {
|
||||||
if (par->GetType() == VARDATA_NONE || par->omitted) continue;
|
if (par.GetType() == VARDATA_NONE || par.omitted) continue;
|
||||||
|
|
||||||
callback(tag->Name, par, userData);
|
callback(tag->Name, &par, userData);
|
||||||
|
|
||||||
// Go recursive if it's a block parameter
|
// Go recursive if it's a block parameter
|
||||||
if (par->GetType() == VARDATA_BLOCK)
|
if (par.GetType() == VARDATA_BLOCK)
|
||||||
par->Get<AssDialogueBlockOverride*>()->ProcessParameters(callback, userData);
|
par.Get<AssDialogueBlockOverride*>()->ProcessParameters(callback, userData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,12 +269,8 @@ AssOverrideTag::AssOverrideTag(wxString text) {
|
||||||
SetText(text);
|
SetText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
AssOverrideTag::~AssOverrideTag () {
|
|
||||||
delete_clear(Params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssOverrideTag::Clear() {
|
void AssOverrideTag::Clear() {
|
||||||
delete_clear(Params);
|
Params.clear();
|
||||||
Params.reserve(6);
|
Params.reserve(6);
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
|
@ -365,9 +361,9 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto::
|
||||||
unsigned curPar = 0;
|
unsigned curPar = 0;
|
||||||
for (auto& curproto : proto_it->params) {
|
for (auto& curproto : proto_it->params) {
|
||||||
// Create parameter
|
// Create parameter
|
||||||
AssOverrideParameter *newparam = new AssOverrideParameter;
|
Params.emplace_back();
|
||||||
|
AssOverrideParameter *newparam = &Params.back();
|
||||||
newparam->classification = curproto.classification;
|
newparam->classification = curproto.classification;
|
||||||
Params.push_back(newparam);
|
|
||||||
|
|
||||||
// Check if it's optional and not present
|
// Check if it's optional and not present
|
||||||
if (!(curproto.optional & parsFlag) || curPar >= totalPars) {
|
if (!(curproto.optional & parsFlag) || curPar >= totalPars) {
|
||||||
|
@ -423,7 +419,7 @@ void AssOverrideTag::ParseParameters(const wxString &text, AssOverrideTagProto::
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static wxString param_str(AssOverrideParameter *p) { return p->Get<wxString>(); }
|
static wxString param_str(AssOverrideParameter const& p) { return p.Get<wxString>(); }
|
||||||
AssOverrideTag::operator wxString() const {
|
AssOverrideTag::operator wxString() const {
|
||||||
wxString result = Name;
|
wxString result = Name;
|
||||||
|
|
||||||
|
@ -433,7 +429,7 @@ AssOverrideTag::operator wxString() const {
|
||||||
|
|
||||||
// Add parameters
|
// Add parameters
|
||||||
result += join(Params
|
result += join(Params
|
||||||
| filtered([](AssOverrideParameter *p) { return p->GetType() != VARDATA_NONE && !p->omitted; })
|
| filtered([](AssOverrideParameter const& p) { return p.GetType() != VARDATA_NONE && !p.omitted; })
|
||||||
| transformed(param_str),
|
| transformed(param_str),
|
||||||
wxS(","));
|
wxS(","));
|
||||||
|
|
||||||
|
|
|
@ -113,16 +113,15 @@ struct AssOverrideTagProto {
|
||||||
void Set(wxString name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL);
|
void Set(wxString name, VariableDataType type, AssParameterClass classi = PARCLASS_NORMAL, int opt = NOT_OPTIONAL);
|
||||||
};
|
};
|
||||||
|
|
||||||
class AssOverrideTag {
|
class AssOverrideTag : boost::noncopyable {
|
||||||
bool valid;
|
bool valid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxString Name;
|
wxString Name;
|
||||||
std::vector<AssOverrideParameter*> Params;
|
std::vector<AssOverrideParameter> Params;
|
||||||
|
|
||||||
AssOverrideTag();
|
AssOverrideTag();
|
||||||
AssOverrideTag(wxString text);
|
AssOverrideTag(wxString text);
|
||||||
~AssOverrideTag();
|
|
||||||
|
|
||||||
bool IsValid() const { return valid; }
|
bool IsValid() const { return valid; }
|
||||||
/// @brief Parses the parameters for the ass override tag
|
/// @brief Parses the parameters for the ass override tag
|
||||||
|
|
|
@ -171,7 +171,7 @@ T get_value(boost::ptr_vector<AssDialogueBlock> const& blocks, int blockn, T ini
|
||||||
for (auto ovr : blocks | sliced(0, blockn + 1) | reversed | agi::of_type<AssDialogueBlockOverride>()) {
|
for (auto ovr : blocks | sliced(0, blockn + 1) | reversed | agi::of_type<AssDialogueBlockOverride>()) {
|
||||||
for (auto tag : ovr->Tags | reversed) {
|
for (auto tag : ovr->Tags | reversed) {
|
||||||
if (tag->Name == tag_name || tag->Name == alt)
|
if (tag->Name == tag_name || tag->Name == alt)
|
||||||
return tag->Params[0]->Get<T>(initial);
|
return tag->Params[0].Get<T>(initial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return initial;
|
return initial;
|
||||||
|
@ -247,8 +247,8 @@ void set_tag(AssDialogue *line, boost::ptr_vector<AssDialogueBlock> &blocks, wxS
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ovr->Tags[i]->Params[0]->Set(value);
|
ovr->Tags[i]->Params[0].Set(value);
|
||||||
ovr->Tags[i]->Params[0]->omitted = false;
|
ovr->Tags[i]->Params[0].omitted = false;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,19 +60,19 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) {
|
||||||
wxString name = tag->Name;
|
wxString name = tag->Name;
|
||||||
|
|
||||||
if (name == "\\r") {
|
if (name == "\\r") {
|
||||||
style = styles[tag->Params[0]->Get<wxString>(line->Style)];
|
style = styles[tag->Params[0].Get<wxString>(line->Style)];
|
||||||
overriden = false;
|
overriden = false;
|
||||||
}
|
}
|
||||||
else if (name == "\\b") {
|
else if (name == "\\b") {
|
||||||
style.bold = tag->Params[0]->Get(initial.bold);
|
style.bold = tag->Params[0].Get(initial.bold);
|
||||||
overriden = true;
|
overriden = true;
|
||||||
}
|
}
|
||||||
else if (name == "\\i") {
|
else if (name == "\\i") {
|
||||||
style.italic = tag->Params[0]->Get(initial.italic);
|
style.italic = tag->Params[0].Get(initial.italic);
|
||||||
overriden = true;
|
overriden = true;
|
||||||
}
|
}
|
||||||
else if (name == "\\fn") {
|
else if (name == "\\fn") {
|
||||||
style.facename = tag->Params[0]->Get(initial.facename);
|
style.facename = tag->Params[0].Get(initial.facename);
|
||||||
overriden = true;
|
overriden = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,13 +125,13 @@ namespace
|
||||||
for (auto t : ob->Tags)
|
for (auto t : ob->Tags)
|
||||||
{
|
{
|
||||||
if (t->Name == "\\u")
|
if (t->Name == "\\u")
|
||||||
underline = t->Params[0]->Get<bool>(style_underline);
|
underline = t->Params[0].Get<bool>(style_underline);
|
||||||
else if (t->Name == "\\i")
|
else if (t->Name == "\\i")
|
||||||
italic = t->Params[0]->Get<bool>(style_italic);
|
italic = t->Params[0].Get<bool>(style_italic);
|
||||||
else if (t->Name == "\\an")
|
else if (t->Name == "\\an")
|
||||||
align = t->Params[0]->Get<int>(align);
|
align = t->Params[0].Get<int>(align);
|
||||||
else if (t->Name == "\\a" && !t->Params[0]->omitted)
|
else if (t->Name == "\\a" && !t->Params[0].omitted)
|
||||||
align = AssStyle::SsaToAss(t->Params[0]->Get<int>());
|
align = AssStyle::SsaToAss(t->Params[0].Get<int>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -563,7 +563,7 @@ wxString SRTSubtitleFormat::ConvertTags(const AssDialogue *diag) const {
|
||||||
if (tag->IsValid() && tag->Name.size() == 2) {
|
if (tag->IsValid() && tag->Name.size() == 2) {
|
||||||
auto it = tag_states.find(tag->Name[1]);
|
auto it = tag_states.find(tag->Name[1]);
|
||||||
if (it != tag_states.end()) {
|
if (it != tag_states.end()) {
|
||||||
bool temp = tag->Params[0]->Get(false);
|
bool temp = tag->Params[0].Get(false);
|
||||||
if (temp && !it->second)
|
if (temp && !it->second)
|
||||||
final += wxString::Format("<%c>", it->first);
|
final += wxString::Format("<%c>", it->first);
|
||||||
if (!temp && it->second)
|
if (!temp && it->second)
|
||||||
|
|
|
@ -355,7 +355,7 @@ void VisualTool<FeatureType>::RemoveSelection(feature_iterator feat) {
|
||||||
|
|
||||||
//////// PARSERS
|
//////// PARSERS
|
||||||
|
|
||||||
typedef const std::vector<AssOverrideParameter*> * param_vec;
|
typedef const std::vector<AssOverrideParameter> * param_vec;
|
||||||
|
|
||||||
// Find a tag's parameters in a line or return nullptr if it's not found
|
// Find a tag's parameters in a line or return nullptr if it's not found
|
||||||
static param_vec find_tag(boost::ptr_vector<AssDialogueBlock>& blocks, wxString tag_name) {
|
static param_vec find_tag(boost::ptr_vector<AssDialogueBlock>& blocks, wxString tag_name) {
|
||||||
|
@ -373,12 +373,12 @@ static param_vec find_tag(boost::ptr_vector<AssDialogueBlock>& blocks, wxString
|
||||||
static Vector2D vec_or_bad(param_vec tag, size_t x_idx, size_t y_idx) {
|
static Vector2D vec_or_bad(param_vec tag, size_t x_idx, size_t y_idx) {
|
||||||
if (!tag ||
|
if (!tag ||
|
||||||
tag->size() <= x_idx || tag->size() <= y_idx ||
|
tag->size() <= x_idx || tag->size() <= y_idx ||
|
||||||
(*tag)[x_idx]->omitted || (*tag)[y_idx]->omitted ||
|
(*tag)[x_idx].omitted || (*tag)[y_idx].omitted ||
|
||||||
(*tag)[x_idx]->GetType() == VARDATA_NONE || (*tag)[y_idx]->GetType() == VARDATA_NONE)
|
(*tag)[x_idx].GetType() == VARDATA_NONE || (*tag)[y_idx].GetType() == VARDATA_NONE)
|
||||||
{
|
{
|
||||||
return Vector2D();
|
return Vector2D();
|
||||||
}
|
}
|
||||||
return Vector2D((*tag)[x_idx]->Get<float>(), (*tag)[y_idx]->Get<float>());
|
return Vector2D((*tag)[x_idx].Get<float>(), (*tag)[y_idx].Get<float>());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) {
|
Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) {
|
||||||
|
@ -402,10 +402,10 @@ Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) {
|
||||||
|
|
||||||
param_vec align_tag;
|
param_vec align_tag;
|
||||||
int ovr_align = 0;
|
int ovr_align = 0;
|
||||||
if ((align_tag = find_tag(blocks, "\\an")) && !(*align_tag)[0]->omitted)
|
if ((align_tag = find_tag(blocks, "\\an")) && !(*align_tag)[0].omitted)
|
||||||
ovr_align = (*align_tag)[0]->Get<int>();
|
ovr_align = (*align_tag)[0].Get<int>();
|
||||||
else if ((align_tag = find_tag(blocks, "\\a")))
|
else if ((align_tag = find_tag(blocks, "\\a")))
|
||||||
ovr_align = AssStyle::SsaToAss((*align_tag)[0]->Get<int>(2));
|
ovr_align = AssStyle::SsaToAss((*align_tag)[0].Get<int>(2));
|
||||||
|
|
||||||
if (ovr_align > 0 && ovr_align <= 9)
|
if (ovr_align > 0 && ovr_align <= 9)
|
||||||
align = ovr_align;
|
align = ovr_align;
|
||||||
|
@ -448,8 +448,8 @@ bool VisualToolBase::GetLineMove(AssDialogue *diag, Vector2D &p1, Vector2D &p2,
|
||||||
p1 = vec_or_bad(tag, 0, 1);
|
p1 = vec_or_bad(tag, 0, 1);
|
||||||
p2 = vec_or_bad(tag, 2, 3);
|
p2 = vec_or_bad(tag, 2, 3);
|
||||||
// VSFilter actually defaults to -1, but it uses <= 0 to check for default and 0 seems less bug-prone
|
// VSFilter actually defaults to -1, but it uses <= 0 to check for default and 0 seems less bug-prone
|
||||||
t1 = (*tag)[4]->Get<int>(0);
|
t1 = (*tag)[4].Get<int>(0);
|
||||||
t2 = (*tag)[5]->Get<int>(0);
|
t2 = (*tag)[5].Get<int>(0);
|
||||||
|
|
||||||
return p1 && p2;
|
return p1 && p2;
|
||||||
}
|
}
|
||||||
|
@ -463,13 +463,13 @@ void VisualToolBase::GetLineRotation(AssDialogue *diag, float &rx, float &ry, fl
|
||||||
boost::ptr_vector<AssDialogueBlock> blocks(diag->ParseTags());
|
boost::ptr_vector<AssDialogueBlock> blocks(diag->ParseTags());
|
||||||
|
|
||||||
if (param_vec tag = find_tag(blocks, "\\frx"))
|
if (param_vec tag = find_tag(blocks, "\\frx"))
|
||||||
rx = tag->front()->Get<float>(rx);
|
rx = tag->front().Get<float>(rx);
|
||||||
if (param_vec tag = find_tag(blocks, "\\fry"))
|
if (param_vec tag = find_tag(blocks, "\\fry"))
|
||||||
ry = tag->front()->Get<float>(ry);
|
ry = tag->front().Get<float>(ry);
|
||||||
if (param_vec tag = find_tag(blocks, "\\frz"))
|
if (param_vec tag = find_tag(blocks, "\\frz"))
|
||||||
rz = tag->front()->Get<float>(rz);
|
rz = tag->front().Get<float>(rz);
|
||||||
else if ((tag = find_tag(blocks, "\\fr")))
|
else if ((tag = find_tag(blocks, "\\fr")))
|
||||||
rz = tag->front()->Get<float>(rz);
|
rz = tag->front().Get<float>(rz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualToolBase::GetLineScale(AssDialogue *diag, Vector2D &scale) {
|
void VisualToolBase::GetLineScale(AssDialogue *diag, Vector2D &scale) {
|
||||||
|
@ -483,9 +483,9 @@ void VisualToolBase::GetLineScale(AssDialogue *diag, Vector2D &scale) {
|
||||||
boost::ptr_vector<AssDialogueBlock> blocks(diag->ParseTags());
|
boost::ptr_vector<AssDialogueBlock> blocks(diag->ParseTags());
|
||||||
|
|
||||||
if (param_vec tag = find_tag(blocks, "\\fscx"))
|
if (param_vec tag = find_tag(blocks, "\\fscx"))
|
||||||
x = tag->front()->Get<float>(x);
|
x = tag->front().Get<float>(x);
|
||||||
if (param_vec tag = find_tag(blocks, "\\fscy"))
|
if (param_vec tag = find_tag(blocks, "\\fscy"))
|
||||||
y = tag->front()->Get<float>(y);
|
y = tag->front().Get<float>(y);
|
||||||
|
|
||||||
scale = Vector2D(x, y);
|
scale = Vector2D(x, y);
|
||||||
}
|
}
|
||||||
|
@ -524,14 +524,14 @@ wxString VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, bool &
|
||||||
|
|
||||||
if (tag && tag->size() == 4) {
|
if (tag && tag->size() == 4) {
|
||||||
return wxString::Format("m %d %d l %d %d %d %d %d %d",
|
return wxString::Format("m %d %d l %d %d %d %d %d %d",
|
||||||
(*tag)[0]->Get<int>(), (*tag)[1]->Get<int>(),
|
(*tag)[0].Get<int>(), (*tag)[1].Get<int>(),
|
||||||
(*tag)[2]->Get<int>(), (*tag)[1]->Get<int>(),
|
(*tag)[2].Get<int>(), (*tag)[1].Get<int>(),
|
||||||
(*tag)[2]->Get<int>(), (*tag)[3]->Get<int>(),
|
(*tag)[2].Get<int>(), (*tag)[3].Get<int>(),
|
||||||
(*tag)[0]->Get<int>(), (*tag)[3]->Get<int>());
|
(*tag)[0].Get<int>(), (*tag)[3].Get<int>());
|
||||||
}
|
}
|
||||||
if (tag) {
|
if (tag) {
|
||||||
scale = std::max((*tag)[0]->Get(scale), 1);
|
scale = std::max((*tag)[0].Get(scale), 1);
|
||||||
return (*tag)[1]->Get<wxString>("");
|
return (*tag)[1].Get<wxString>("");
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
Loading…
Reference in New Issue