reading alignments

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@123 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-12-19 16:45:55 +00:00
parent f09f610e7c
commit 7d205f318f
+16 -6
View File
@@ -34,13 +34,23 @@ RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRec
// ----------------------------------------------------------------------------- : Reflection stuff
/// Convert a String to an Alignment
Alignment fromString(const String& str) {
int al = 0;
Alignment from_string(const String& s) {
int al = ALIGN_TOP_LEFT;
if (s.find(_("left")) !=String::npos) al = ALIGN_LEFT | (al & ALIGN_VERTICAL);
if (s.find(_("center")) !=String::npos) al = ALIGN_CENTER | (al & ALIGN_VERTICAL);
if (s.find(_("right")) !=String::npos) al = ALIGN_RIGHT | (al & ALIGN_VERTICAL);
if (s.find(_("justify")) !=String::npos) al = ALIGN_JUSTIFY | (al & ALIGN_VERTICAL);
if (s.find(_("justify-words")) !=String::npos) al = ALIGN_JUSTIFY_WORDS | (al & ALIGN_VERTICAL);
if (s.find(_("shrink-overflow"))!=String::npos) al = ALIGN_JUSTIFY_OVERFLOW | (al & ~ALIGN_JUSTIFY_OVERFLOW);
if (s.find(_("top")) !=String::npos) al = ALIGN_TOP | (al & ALIGN_HORIZONTAL);
if (s.find(_("middle")) !=String::npos) al = ALIGN_MIDDLE | (al & ALIGN_HORIZONTAL);
if (s.find(_("bottom")) !=String::npos) al = ALIGN_BOTTOM | (al & ALIGN_HORIZONTAL);
if (s.find(_("stretch")) !=String::npos) al = ALIGN_STRETCH;
return static_cast<Alignment>(al);
}
/// Convert an Alignment to a String
String toString(Alignment align) {
String to_string(Alignment align) {
String ret;
// vertical
if (align & ALIGN_TOP) ret += _(" top");
@@ -61,11 +71,11 @@ String toString(Alignment align) {
// we need custom io, because there can be both a horizontal and a vertical component
template <> void Reader::handle(Alignment& align) {
align = fromString(value);
align = from_string(value);
}
template <> void Writer::handle(const Alignment& align) {
handle(toString(align));
handle(to_string(align));
}
template <> void GetDefaultMember::handle(const Alignment& align) {
handle(toString(align));
handle(to_string(align));
}