mirror of https://github.com/odrling/Aegisub
Templatize VariableData's getters and setters
Originally committed to SVN as r4523.
This commit is contained in:
parent
c7ea710267
commit
166c95975b
|
@ -486,7 +486,7 @@ void AssDialogue::ParseASSTags () {
|
|||
for (curTag = block->Tags.begin();curTag != block->Tags.end();curTag++) {
|
||||
AssOverrideTag *tag = *curTag;
|
||||
if (tag->Name == _T("\\p")) {
|
||||
drawingLevel = tag->Params.at(0)->AsInt();
|
||||
drawingLevel = tag->Params.at(0)->Get<int>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -591,7 +591,7 @@ void AssDialogue::ConvertTagsToSRT () {
|
|||
if (curTag->IsValid()) {
|
||||
// Italics
|
||||
if (curTag->Name == _T("\\i")) {
|
||||
temp = curTag->Params.at(0)->AsBool();
|
||||
temp = curTag->Params.at(0)->Get<bool>();
|
||||
if (temp && !isItalic) {
|
||||
isItalic = true;
|
||||
final += _T("<i>");
|
||||
|
@ -604,7 +604,7 @@ void AssDialogue::ConvertTagsToSRT () {
|
|||
|
||||
// Underline
|
||||
if (curTag->Name == _T("\\u")) {
|
||||
temp = curTag->Params.at(0)->AsBool();
|
||||
temp = curTag->Params.at(0)->Get<bool>();
|
||||
if (temp && !isUnder) {
|
||||
isUnder = true;
|
||||
final += _T("<u>");
|
||||
|
@ -617,7 +617,7 @@ void AssDialogue::ConvertTagsToSRT () {
|
|||
|
||||
// Strikeout
|
||||
if (curTag->Name == _T("\\s")) {
|
||||
temp = curTag->Params.at(0)->AsBool();
|
||||
temp = curTag->Params.at(0)->Get<bool>();
|
||||
if (temp && !isStrike) {
|
||||
isStrike = true;
|
||||
final += _T("<s>");
|
||||
|
@ -630,7 +630,7 @@ void AssDialogue::ConvertTagsToSRT () {
|
|||
|
||||
// Bold
|
||||
if (curTag->Name == _T("\\b")) {
|
||||
temp = curTag->Params.at(0)->AsBool();
|
||||
temp = curTag->Params.at(0)->Get<bool>();
|
||||
if (temp && !isBold) {
|
||||
isBold = true;
|
||||
final += _T("<b>");
|
||||
|
|
|
@ -102,7 +102,7 @@ void ParseAssKaraokeTags(const AssDialogue *line, AssKaraokeVector &syls)
|
|||
syl.unstripped_text = _T("");
|
||||
syl.tag = tag;
|
||||
syl.type = tag->Name;
|
||||
syl.duration = tag->Params[0]->AsInt();
|
||||
syl.duration = tag->Params[0]->Get<int>();
|
||||
|
||||
} else {
|
||||
// not karaoke tag
|
||||
|
|
|
@ -61,15 +61,7 @@ AssOverrideParameter::~AssOverrideParameter () {
|
|||
/// @param param
|
||||
///
|
||||
void AssOverrideParameter::CopyFrom (const AssOverrideParameter ¶m) {
|
||||
switch(param.GetType()) {
|
||||
case VARDATA_INT: SetInt(param.AsInt()); break;
|
||||
case VARDATA_FLOAT: SetFloat(param.AsFloat()); break;
|
||||
case VARDATA_TEXT: SetText(param.AsText()); break;
|
||||
case VARDATA_BOOL: SetBool(param.AsBool()); break;
|
||||
case VARDATA_COLOUR: SetColour(param.AsColour()); break;
|
||||
case VARDATA_BLOCK: SetBlock(param.AsBlock()); break;
|
||||
default: DeleteValue();
|
||||
}
|
||||
*static_cast<VariableData*>(this) = static_cast<const VariableData&>(param);
|
||||
classification = param.classification;
|
||||
ommited = param.ommited;
|
||||
}
|
||||
|
@ -165,7 +157,7 @@ void AssDialogueBlockOverride::ProcessParameters(AssDialogueBlockOverride::Proce
|
|||
|
||||
// Go recursive if it's a block parameter
|
||||
if (curPar->GetType() == VARDATA_BLOCK) {
|
||||
curPar->AsBlock()->ProcessParameters(callback,userData);
|
||||
curPar->Get<AssDialogueBlockOverride*>()->ProcessParameters(callback,userData);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -466,25 +458,25 @@ void AssOverrideTagProto::LoadProtos () {
|
|||
i++;
|
||||
proto[i].name = _T("\\b");
|
||||
proto[i].params.push_back(AssOverrideParamProto(VARDATA_INT,OPTIONAL_1,PARCLASS_NORMAL));
|
||||
proto[i].params.back().defaultValue.SetBool(false);
|
||||
proto[i].params.back().defaultValue.Set<bool>(false);
|
||||
|
||||
// \i<0/1>
|
||||
i++;
|
||||
proto[i].name = _T("\\i");
|
||||
proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL));
|
||||
proto[i].params.back().defaultValue.SetBool(false);
|
||||
proto[i].params.back().defaultValue.Set<bool>(false);
|
||||
|
||||
// \u<0/1>
|
||||
i++;
|
||||
proto[i].name = _T("\\u");
|
||||
proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL));
|
||||
proto[i].params.back().defaultValue.SetBool(false);
|
||||
proto[i].params.back().defaultValue.Set<bool>(false);
|
||||
|
||||
// \s<0/1>
|
||||
i++;
|
||||
proto[i].name = _T("\\s");
|
||||
proto[i].params.push_back(AssOverrideParamProto(VARDATA_BOOL,OPTIONAL_1,PARCLASS_NORMAL));
|
||||
proto[i].params.back().defaultValue.SetBool(false);
|
||||
proto[i].params.back().defaultValue.Set<bool>(false);
|
||||
|
||||
// \a<alignment>
|
||||
i++;
|
||||
|
@ -689,7 +681,7 @@ end_tokenizing:
|
|||
wxChar firstChar = curtok[0];
|
||||
bool auto4 = (firstChar == _T('!') || firstChar == _T('$') || firstChar == _T('%')) && curproto->type != VARDATA_BLOCK;
|
||||
if (auto4) {
|
||||
newparam->SetText(curtok);
|
||||
newparam->Set(curtok);
|
||||
}
|
||||
else {
|
||||
// Determine parameter type and set value
|
||||
|
@ -697,29 +689,29 @@ end_tokenizing:
|
|||
case VARDATA_INT: {
|
||||
long temp = 0;
|
||||
curtok.ToLong(&temp);
|
||||
newparam->SetInt(temp);
|
||||
newparam->Set<int>(temp);
|
||||
break;
|
||||
}
|
||||
case VARDATA_FLOAT: {
|
||||
double temp = 0.0;
|
||||
curtok.ToDouble(&temp);
|
||||
newparam->SetFloat(temp);
|
||||
newparam->Set<double>(temp);
|
||||
break;
|
||||
}
|
||||
case VARDATA_TEXT:
|
||||
newparam->SetText(curtok);
|
||||
newparam->Set(curtok);
|
||||
break;
|
||||
case VARDATA_BOOL: {
|
||||
long temp = false;
|
||||
curtok.ToLong(&temp);
|
||||
newparam->SetBool(temp != 0);
|
||||
newparam->Set<bool>(temp != 0);
|
||||
break;
|
||||
}
|
||||
case VARDATA_BLOCK: {
|
||||
AssDialogueBlockOverride *temp = new AssDialogueBlockOverride;
|
||||
temp->text = curtok;
|
||||
temp->ParseTags();
|
||||
newparam->SetBlock(temp);
|
||||
newparam->Set(temp);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -761,7 +753,7 @@ wxString AssOverrideTag::ToString() {
|
|||
int n = 0;
|
||||
for (std::vector<AssOverrideParameter*>::iterator cur=Params.begin();cur!=Params.end();cur++) {
|
||||
if ((*cur)->GetType() != VARDATA_NONE && (*cur)->ommited == false) {
|
||||
result += (*cur)->AsText();
|
||||
result += (*cur)->Get<wxString>();
|
||||
result += _T(",");
|
||||
n++;
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ void AudioKaraoke::Commit() {
|
|||
// Some weird people have text before the first karaoke tag on a line.
|
||||
// Check that a karaoke tag actually exists for the (non-)syllable to avoid a crash.
|
||||
if (syl->tag && syl->tag->Params.size()>0)
|
||||
syl->tag->Params[0]->SetInt(syl->duration);
|
||||
syl->tag->Params[0]->Set<int>(syl->duration);
|
||||
// Of course, if the user changed the duration of such a non-syllable, its timing can't be updated and will stay zero.
|
||||
// There is no way to check for that right now, and I can't bother to fix it.
|
||||
}
|
||||
|
|
|
@ -932,11 +932,11 @@ namespace Automation4 {
|
|||
ktag = tag->Name.Mid(1);
|
||||
// check if it's a "set time" tag, special handling for that (depends on previous syllable duration)
|
||||
if (ktag == _T("kt")) {
|
||||
ktime = tag->Params[0]->AsInt() * 10;
|
||||
ktime = tag->Params[0]->Get<int>() * 10;
|
||||
kdur = 0;
|
||||
} else {
|
||||
ktime += kdur; // duration of previous syllable
|
||||
kdur = tag->Params[0]->AsInt() * 10;
|
||||
kdur = tag->Params[0]->Get<int>() * 10;
|
||||
}
|
||||
ktext.clear();
|
||||
ktext_stripped.clear();
|
||||
|
|
|
@ -639,7 +639,7 @@ bool FontsCollectorThread::AttachFont(wxString filename) {
|
|||
///
|
||||
void FontsCollectorThread::GetFonts (wxString tagName,int par_n,AssOverrideParameter *param,void *usr) {
|
||||
if (tagName == _T("\\fn")) {
|
||||
if (instance) instance->AddFont(param->AsText(),1);
|
||||
if (instance) instance->AddFont(param->Get<wxString>(),1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -191,9 +191,9 @@ void DialogResample::DoResampleTags (wxString name,int n,AssOverrideParameter *c
|
|||
case PARCLASS_DRAWING:
|
||||
{
|
||||
AssDialogueBlockDrawing block;
|
||||
block.text = curParam->AsText();
|
||||
block.text = curParam->Get<wxString>();
|
||||
block.TransformCoords(m[0],m[2],rx,ry);
|
||||
curParam->SetText(block.GetText());
|
||||
curParam->Set(block.GetText());
|
||||
}
|
||||
return;
|
||||
|
||||
|
@ -203,16 +203,16 @@ void DialogResample::DoResampleTags (wxString name,int n,AssOverrideParameter *c
|
|||
|
||||
VariableDataType curType = curParam->GetType();
|
||||
if (curType == VARDATA_FLOAT) {
|
||||
float par = curParam->AsFloat();
|
||||
float par = curParam->Get<double>();
|
||||
if (isX) par += m[0];
|
||||
if (isY) par += m[2];
|
||||
curParam->SetFloat(par * resizer);
|
||||
curParam->Set<double>(par * resizer);
|
||||
}
|
||||
if (curType == VARDATA_INT) {
|
||||
int par = curParam->AsInt();
|
||||
int par = curParam->Get<int>();
|
||||
if (isX) par += m[0];
|
||||
if (isY) par += m[2];
|
||||
curParam->SetInt(int(double(par) * resizer + 0.5));
|
||||
curParam->Set<int>(int(double(par) * resizer + 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -510,8 +510,8 @@ void ReplaceStyle(wxString tag,int n,AssOverrideParameter* param,void *userData)
|
|||
wxArrayString strings = *((wxArrayString*)userData);
|
||||
if (tag == _T("\\r")) {
|
||||
if (param->GetType() == VARDATA_TEXT) {
|
||||
if (param->AsText() == strings[0]) {
|
||||
param->SetText(strings[1]);
|
||||
if (param->Get<wxString>() == strings[0]) {
|
||||
param->Set(strings[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ void AssTransformFramerateFilter::TransformTimeTags (wxString name,int n,AssOver
|
|||
}
|
||||
|
||||
// Parameter value
|
||||
int parVal = curParam->AsInt() * mult;
|
||||
int parVal = curParam->Get<int>() * mult;
|
||||
|
||||
// Karaoke preprocess
|
||||
int curKarPos = 0;
|
||||
|
@ -263,7 +263,7 @@ void AssTransformFramerateFilter::TransformTimeTags (wxString name,int n,AssOver
|
|||
value -= curKarPos;
|
||||
}
|
||||
|
||||
curParam->SetInt(value/mult);
|
||||
curParam->Set<int>(value/mult);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1182,14 +1182,14 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos,b
|
|||
for (size_t j=0;j<override->Tags.size();j++) {
|
||||
tag = override->Tags.at(j);
|
||||
if (tag->Name == tagname || tag->Name == alttagname || tagname == _T("\\fn")) {
|
||||
if (isColor) startcolor = tag->Params.at(0)->AsColour();
|
||||
if (isFlag) state = tag->Params.at(0)->AsBool();
|
||||
if (isColor) startcolor = tag->Params.at(0)->Get<wxColour>();
|
||||
if (isFlag) state = tag->Params.at(0)->Get<bool>();
|
||||
if (isFont) {
|
||||
if (tag->Name == _T("\\fn")) startfont.SetFaceName(tag->Params.at(0)->AsText());
|
||||
if (tag->Name == _T("\\fs")) startfont.SetPointSize(tag->Params.at(0)->AsInt());
|
||||
if (tag->Name == _T("\\b")) startfont.SetWeight((tag->Params.at(0)->AsInt() > 0) ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
|
||||
if (tag->Name == _T("\\i")) startfont.SetStyle(tag->Params.at(0)->AsBool() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
|
||||
if (tag->Name == _T("\\u")) startfont.SetUnderlined(tag->Params.at(0)->AsBool());
|
||||
if (tag->Name == _T("\\fn")) startfont.SetFaceName(tag->Params.at(0)->Get<wxString>());
|
||||
if (tag->Name == _T("\\fs")) startfont.SetPointSize(tag->Params.at(0)->Get<int>());
|
||||
if (tag->Name == _T("\\b")) startfont.SetWeight((tag->Params.at(0)->Get<int>() > 0) ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
|
||||
if (tag->Name == _T("\\i")) startfont.SetStyle(tag->Params.at(0)->Get<bool>() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
|
||||
if (tag->Name == _T("\\u")) startfont.SetUnderlined(tag->Params.at(0)->Get<bool>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
/// @file variable_data.cpp
|
||||
/// @brief A variant-type implementation
|
||||
/// @ingroup utility subs_storage
|
||||
///
|
||||
|
||||
|
||||
////////////
|
||||
// Includes
|
||||
|
@ -44,27 +42,19 @@
|
|||
#include "utils.h"
|
||||
#include "variable_data.h"
|
||||
|
||||
|
||||
/// @brief Constructor
|
||||
///
|
||||
VariableData::VariableData () {
|
||||
type = VARDATA_NONE;
|
||||
value = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Destructor
|
||||
///
|
||||
VariableData::~VariableData () {
|
||||
DeleteValue ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Deletes the stored value
|
||||
/// @return
|
||||
///
|
||||
void VariableData::DeleteValue () {
|
||||
if (!value) return;
|
||||
if (type == VARDATA_NONE) return;
|
||||
|
@ -81,129 +71,88 @@ void VariableData::DeleteValue () {
|
|||
value = NULL;
|
||||
}
|
||||
|
||||
template<class T> static inline VariableDataType get_type();
|
||||
|
||||
|
||||
/// @brief Sets to an integer
|
||||
/// @param param
|
||||
///
|
||||
void VariableData::SetInt(int param) {
|
||||
DeleteValue();
|
||||
type = VARDATA_INT;
|
||||
value_int = new int(param);
|
||||
template<> inline VariableDataType get_type<int>() {
|
||||
return VARDATA_INT;
|
||||
}
|
||||
template<> inline VariableDataType get_type<double>() {
|
||||
return VARDATA_FLOAT;
|
||||
}
|
||||
template<> inline VariableDataType get_type<bool>() {
|
||||
return VARDATA_BOOL;
|
||||
}
|
||||
template<> inline VariableDataType get_type<wxString>() {
|
||||
return VARDATA_TEXT;
|
||||
}
|
||||
template<> inline VariableDataType get_type<wxColour>() {
|
||||
return VARDATA_COLOUR;
|
||||
}
|
||||
template<> inline VariableDataType get_type<AssDialogueBlockOverride *>() {
|
||||
return VARDATA_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Sets to a float
|
||||
/// @param param
|
||||
///
|
||||
void VariableData::SetFloat(double param) {
|
||||
template<class T>
|
||||
void VariableData::Set(T param) {
|
||||
DeleteValue();
|
||||
type = VARDATA_FLOAT;
|
||||
value_float = new double(param);
|
||||
type = get_type<T>();
|
||||
value = new T(param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Sets to a boolean
|
||||
/// @param param
|
||||
///
|
||||
void VariableData::SetBool(bool param) {
|
||||
DeleteValue();
|
||||
type = VARDATA_BOOL;
|
||||
value_bool = new bool(param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Sets to a string
|
||||
/// @param param
|
||||
///
|
||||
void VariableData::SetText(wxString param) {
|
||||
DeleteValue();
|
||||
type = VARDATA_TEXT;
|
||||
value_text = new wxString (param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Sets to a colour
|
||||
/// @param param
|
||||
///
|
||||
void VariableData::SetColour(wxColour param) {
|
||||
DeleteValue();
|
||||
type = VARDATA_COLOUR;
|
||||
value_colour = new wxColour (param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Sets to a block
|
||||
/// @param param
|
||||
///
|
||||
void VariableData::SetBlock(AssDialogueBlockOverride *param) {
|
||||
DeleteValue();
|
||||
type = VARDATA_BLOCK;
|
||||
value_block = param;
|
||||
}
|
||||
|
||||
|
||||
template void VariableData::Set<int>(int param);
|
||||
template void VariableData::Set<double>(double param);
|
||||
template void VariableData::Set<bool>(bool param);
|
||||
template void VariableData::Set(wxString param);
|
||||
template void VariableData::Set<wxColour>(wxColour param);
|
||||
template void VariableData::Set<AssDialogueBlockOverride *>(AssDialogueBlockOverride * param);
|
||||
|
||||
/// @brief Resets a value with a string, preserving current type
|
||||
/// @param value
|
||||
///
|
||||
void VariableData::ResetWith(wxString value) {
|
||||
switch (type) {
|
||||
case VARDATA_INT: {
|
||||
long temp = 0;
|
||||
value.ToLong(&temp);
|
||||
SetInt(temp);
|
||||
Set<int>(temp);
|
||||
break;
|
||||
}
|
||||
case VARDATA_FLOAT: {
|
||||
double temp = 0;
|
||||
value.ToDouble(&temp);
|
||||
SetFloat(temp);
|
||||
Set(temp);
|
||||
break;
|
||||
}
|
||||
case VARDATA_BOOL:
|
||||
if (value == _T("1")) SetBool(true);
|
||||
else SetBool(false);
|
||||
if (value == _T("1")) Set(true);
|
||||
else Set(false);
|
||||
break;
|
||||
case VARDATA_COLOUR: {
|
||||
long r=0,g=0,b=0;
|
||||
value.Mid(1,2).ToLong(&r,16);
|
||||
value.Mid(3,2).ToLong(&g,16);
|
||||
value.Mid(5,2).ToLong(&b,16);
|
||||
SetColour(wxColour(r,g,b));
|
||||
Set(wxColour(r,g,b));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
SetText(value);
|
||||
Set(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Reads as an int
|
||||
/// @return
|
||||
///
|
||||
int VariableData::AsInt() const {
|
||||
template<> int VariableData::Get<int>() const {
|
||||
if (!value) throw _T("Null parameter");
|
||||
if (type == VARDATA_BOOL) return (*value_bool)?1:0;
|
||||
if (type == VARDATA_BOOL) return !!(*value_bool);
|
||||
if (type == VARDATA_INT) return *value_int;
|
||||
if (type == VARDATA_FLOAT) return (int)(*value_float);
|
||||
if (type == VARDATA_TEXT) return 0;
|
||||
throw _T("Wrong parameter type, should be int");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Reads as a float
|
||||
/// @return
|
||||
///
|
||||
double VariableData::AsFloat() const {
|
||||
template<> double VariableData::Get<double>() const {
|
||||
if (!value) throw _T("Null parameter");
|
||||
if (type == VARDATA_FLOAT) return *value_float;
|
||||
if (type == VARDATA_INT) return (float)(*value_int);
|
||||
|
@ -211,12 +160,9 @@ double VariableData::AsFloat() const {
|
|||
throw _T("Wrong parameter type, should be float");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Reads as a bool
|
||||
/// @return
|
||||
///
|
||||
bool VariableData::AsBool() const {
|
||||
template<> bool VariableData::Get<bool>() const {
|
||||
if (!value) throw _T("Null parameter");
|
||||
if (type == VARDATA_BOOL) return *value_bool;
|
||||
if (type == VARDATA_INT) return ((*value_int)!=0);
|
||||
|
@ -225,12 +171,9 @@ bool VariableData::AsBool() const {
|
|||
throw _T("Wrong parameter type, should be bool");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Reads as a colour
|
||||
/// @return
|
||||
///
|
||||
wxColour VariableData::AsColour() const {
|
||||
template<> wxColour VariableData::Get<wxColour>() const {
|
||||
if (!value) throw _T("Null parameter");
|
||||
if (type == VARDATA_COLOUR) return *value_colour;
|
||||
else if (type == VARDATA_TEXT) {
|
||||
|
@ -241,62 +184,45 @@ wxColour VariableData::AsColour() const {
|
|||
else throw _T("Wrong parameter type, should be colour");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Reads as a block
|
||||
/// @return
|
||||
///
|
||||
AssDialogueBlockOverride *VariableData::AsBlock() const {
|
||||
template<> AssDialogueBlockOverride *VariableData::Get<AssDialogueBlockOverride *>() const {
|
||||
if (!value) throw _T("Null parameter");
|
||||
if (type != VARDATA_BLOCK) throw _T("Wrong parameter type, should be block");
|
||||
return value_block;
|
||||
return *value_block;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Reads as a string
|
||||
/// @return
|
||||
///
|
||||
wxString VariableData::AsText() const {
|
||||
template<> wxString VariableData::Get<wxString>() const {
|
||||
if (!value) throw _T("Null parameter");
|
||||
if (type != VARDATA_TEXT) {
|
||||
if (type == VARDATA_INT) return wxString::Format(_T("%i"),*value_int);
|
||||
else if (type == VARDATA_FLOAT) return wxString::Format(_T("%g"),*value_float);
|
||||
else if (type == VARDATA_COLOUR) return wxString::Format(_T("#%02X%02X%02X"),value_colour->Red(),value_colour->Green(),value_colour->Blue());
|
||||
else if (type == VARDATA_BOOL) {
|
||||
if (*value_bool) return _T("1");
|
||||
else return _T("0");
|
||||
}
|
||||
else if (type == VARDATA_BLOCK) return value_block->GetText();
|
||||
if (type == VARDATA_INT) return wxString::Format("%i",*value_int);
|
||||
else if (type == VARDATA_FLOAT) return wxString::Format("%g",*value_float);
|
||||
else if (type == VARDATA_COLOUR) return wxString::Format("#%02X%02X%02X",value_colour->Red(),value_colour->Green(),value_colour->Blue());
|
||||
else if (type == VARDATA_BOOL) return *value_bool ? "1" : "0";
|
||||
else if (type == VARDATA_BLOCK) return (*value_block)->GetText();
|
||||
else throw _T("Wrong parameter type, should be text");
|
||||
}
|
||||
return *value_text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Gets type
|
||||
/// @return
|
||||
///
|
||||
VariableDataType VariableData::GetType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Copy
|
||||
/// @param param
|
||||
///
|
||||
void VariableData::operator= (const VariableData ¶m) {
|
||||
switch(param.GetType()) {
|
||||
case VARDATA_INT: SetInt(param.AsInt()); break;
|
||||
case VARDATA_FLOAT: SetFloat(param.AsFloat()); break;
|
||||
case VARDATA_TEXT: SetText(param.AsText()); break;
|
||||
case VARDATA_BOOL: SetBool(param.AsBool()); break;
|
||||
case VARDATA_COLOUR: SetColour(param.AsColour()); break;
|
||||
case VARDATA_BLOCK: SetBlock(param.AsBlock()); break;
|
||||
case VARDATA_INT: Set(param.Get<int>()); break;
|
||||
case VARDATA_FLOAT: Set(param.Get<double>()); break;
|
||||
case VARDATA_TEXT: Set(param.Get<wxString>()); break;
|
||||
case VARDATA_BOOL: Set(param.Get<bool>()); break;
|
||||
case VARDATA_COLOUR: Set(param.Get<wxColor>()); break;
|
||||
case VARDATA_BLOCK: Set(param.Get<AssDialogueBlockOverride*>()); break;
|
||||
default: DeleteValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -70,13 +70,9 @@ enum VariableDataType {
|
|||
VARDATA_BLOCK
|
||||
};
|
||||
|
||||
|
||||
//////////////
|
||||
// Prototypes
|
||||
class AssDialogueBlockOverride;
|
||||
|
||||
|
||||
|
||||
/// DOCME
|
||||
/// @class VariableData
|
||||
/// @brief DOCME
|
||||
|
@ -85,7 +81,6 @@ class AssDialogueBlockOverride;
|
|||
class VariableData {
|
||||
private:
|
||||
union {
|
||||
|
||||
/// DOCME
|
||||
void *value;
|
||||
|
||||
|
@ -105,7 +100,7 @@ private:
|
|||
wxColour *value_colour;
|
||||
|
||||
/// DOCME
|
||||
AssDialogueBlockOverride *value_block;
|
||||
AssDialogueBlockOverride **value_block;
|
||||
};
|
||||
|
||||
/// DOCME
|
||||
|
@ -119,23 +114,9 @@ public:
|
|||
virtual ~VariableData();
|
||||
|
||||
VariableDataType GetType() const;
|
||||
|
||||
void SetInt(int param);
|
||||
void SetFloat(double param);
|
||||
void SetBool(bool param);
|
||||
void SetText(wxString param);
|
||||
void SetColour(wxColour param);
|
||||
void SetBlock(AssDialogueBlockOverride *param);
|
||||
template<class T> void Set(T param);
|
||||
void ResetWith(wxString value);
|
||||
|
||||
int AsInt() const;
|
||||
double AsFloat() const;
|
||||
bool AsBool() const;
|
||||
wxString AsText() const;
|
||||
wxColour AsColour() const;
|
||||
AssDialogueBlockOverride *AsBlock() const;
|
||||
template<class T> T Get() const;
|
||||
|
||||
void operator= (const VariableData ¶m);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -473,15 +473,15 @@ void VisualTool<FeatureType>::GetLinePosition(AssDialogue *diag,int &x, int &y,
|
|||
// Position
|
||||
if ((tag->Name == L"\\pos" || tag->Name == L"\\move") && tag->Params.size() >= 2) {
|
||||
if (!posSet) {
|
||||
x = tag->Params[0]->AsInt();
|
||||
y = tag->Params[1]->AsInt();
|
||||
x = tag->Params[0]->Get<int>();
|
||||
y = tag->Params[1]->Get<int>();
|
||||
posSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Alignment
|
||||
else if ((tag->Name == L"\\an" || tag->Name == L"\\a") && tag->Params.size() >= 1) {
|
||||
align = tag->Params[0]->AsInt();
|
||||
align = tag->Params[0]->Get<int>();
|
||||
if (tag->Name == L"\\a") {
|
||||
switch(align) {
|
||||
case 1: case 2: case 3:
|
||||
|
@ -501,8 +501,8 @@ void VisualTool<FeatureType>::GetLinePosition(AssDialogue *diag,int &x, int &y,
|
|||
|
||||
// Origin
|
||||
else if (!orgSet && tag->Name == L"\\org" && tag->Params.size() >= 2) {
|
||||
orgx = tag->Params[0]->AsInt();
|
||||
orgy = tag->Params[1]->AsInt();
|
||||
orgx = tag->Params[0]->Get<int>();
|
||||
orgy = tag->Params[1]->Get<int>();
|
||||
parent->FromScriptCoords(&orgx, &orgy);
|
||||
orgSet = true;
|
||||
}
|
||||
|
@ -562,18 +562,18 @@ void VisualTool<FeatureType>::GetLineMove(AssDialogue *diag,bool &hasMove,int &x
|
|||
// Position
|
||||
if (tag->Name == L"\\move" && tag->Params.size() >= 4) {
|
||||
hasMove = true;
|
||||
x1 = tag->Params[0]->AsInt();
|
||||
y1 = tag->Params[1]->AsInt();
|
||||
x2 = tag->Params[2]->AsInt();
|
||||
y2 = tag->Params[3]->AsInt();
|
||||
x1 = tag->Params[0]->Get<int>();
|
||||
y1 = tag->Params[1]->Get<int>();
|
||||
x2 = tag->Params[2]->Get<int>();
|
||||
y2 = tag->Params[3]->Get<int>();
|
||||
parent->FromScriptCoords(&x1, &y1);
|
||||
parent->FromScriptCoords(&x2, &y2);
|
||||
if (tag->Params.size() >= 6 &&
|
||||
!tag->Params[4]->ommited &&
|
||||
!tag->Params[5]->ommited) {
|
||||
|
||||
t1 = tag->Params[4]->AsInt();
|
||||
t2 = tag->Params[5]->AsInt();
|
||||
t1 = tag->Params[4]->Get<int>();
|
||||
t2 = tag->Params[5]->Get<int>();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -617,13 +617,13 @@ void VisualTool<FeatureType>::GetLineRotation(AssDialogue *diag,float &rx,float
|
|||
for (size_t j=0;j<override->Tags.size();j++) {
|
||||
tag = override->Tags.at(j);
|
||||
if (tag->Name == L"\\frx" && tag->Params.size() == 1) {
|
||||
rx = tag->Params[0]->AsFloat();
|
||||
rx = tag->Params[0]->Get<double>();
|
||||
}
|
||||
if (tag->Name == L"\\fry" && tag->Params.size() == 1) {
|
||||
ry = tag->Params[0]->AsFloat();
|
||||
ry = tag->Params[0]->Get<double>();
|
||||
}
|
||||
if ((tag->Name == L"\\frz" || tag->Name == L"\fr") && tag->Params.size() == 1) {
|
||||
rz = tag->Params[0]->AsFloat();
|
||||
rz = tag->Params[0]->Get<double>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -655,10 +655,10 @@ void VisualTool<FeatureType>::GetLineScale(AssDialogue *diag,float &scalX,float
|
|||
for (size_t j=0;j<override->Tags.size();j++) {
|
||||
tag = override->Tags.at(j);
|
||||
if (tag->Name == L"\\fscx" && tag->Params.size() == 1) {
|
||||
scalX = tag->Params[0]->AsFloat();
|
||||
scalX = tag->Params[0]->Get<double>();
|
||||
}
|
||||
if (tag->Name == L"\\fscy" && tag->Params.size() == 1) {
|
||||
scalY = tag->Params[0]->AsFloat();
|
||||
scalY = tag->Params[0]->Get<double>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -698,17 +698,17 @@ void VisualTool<FeatureType>::GetLineClip(AssDialogue *diag,int &x1,int &y1,int
|
|||
for (size_t j=0;j<override->Tags.size();j++) {
|
||||
tag = override->Tags.at(j);
|
||||
if (tag->Name == L"\\clip" && tag->Params.size() == 4) {
|
||||
x1 = tag->Params[0]->AsInt();
|
||||
y1 = tag->Params[1]->AsInt();
|
||||
x2 = tag->Params[2]->AsInt();
|
||||
y2 = tag->Params[3]->AsInt();
|
||||
x1 = tag->Params[0]->Get<int>();
|
||||
y1 = tag->Params[1]->Get<int>();
|
||||
x2 = tag->Params[2]->Get<int>();
|
||||
y2 = tag->Params[3]->Get<int>();
|
||||
inverse = false;
|
||||
}
|
||||
else if (tag->Name == L"\\iclip" && tag->Params.size() == 4) {
|
||||
x1 = tag->Params[0]->AsInt();
|
||||
y1 = tag->Params[1]->AsInt();
|
||||
x2 = tag->Params[2]->AsInt();
|
||||
y2 = tag->Params[3]->AsInt();
|
||||
x1 = tag->Params[0]->Get<int>();
|
||||
y1 = tag->Params[1]->Get<int>();
|
||||
x2 = tag->Params[2]->Get<int>();
|
||||
y2 = tag->Params[3]->Get<int>();
|
||||
inverse = true;
|
||||
}
|
||||
}
|
||||
|
@ -745,17 +745,17 @@ wxString VisualTool<FeatureType>::GetLineVectorClip(AssDialogue *diag,int &scale
|
|||
tag = override->Tags.at(j);
|
||||
if (tag->Name == L"\\clip" || tag->Name == L"\\iclip") {
|
||||
if (tag->Params.size() == 1) {
|
||||
result = tag->Params[0]->AsText();
|
||||
result = tag->Params[0]->Get<wxString>();
|
||||
}
|
||||
else if (tag->Params.size() == 2) {
|
||||
scale = tag->Params[0]->AsInt();
|
||||
result = tag->Params[1]->AsText();
|
||||
scale = tag->Params[0]->Get<int>();
|
||||
result = tag->Params[1]->Get<wxString>();
|
||||
}
|
||||
else if (tag->Params.size() == 4) {
|
||||
int x1 = tag->Params[0]->AsInt(),
|
||||
y1 = tag->Params[1]->AsInt(),
|
||||
x2 = tag->Params[2]->AsInt(),
|
||||
y2 = tag->Params[3]->AsInt();
|
||||
int x1 = tag->Params[0]->Get<int>(),
|
||||
y1 = tag->Params[1]->Get<int>(),
|
||||
x2 = tag->Params[2]->Get<int>(),
|
||||
y2 = tag->Params[3]->Get<int>();
|
||||
result = wxString::Format(L"m %d %d l %d %d %d %d %d %d", x1, y1, x2, y1, x2, y2, x1, y2);
|
||||
}
|
||||
inverse = tag->Name == L"\\iclip";
|
||||
|
|
Loading…
Reference in New Issue