Added support for informational headings in native look editor.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@212 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-03-18 14:50:44 +00:00
parent 074ff12816
commit d30e0f7bc5
14 changed files with 395 additions and 15 deletions
+2
View File
@@ -14,6 +14,7 @@
#include <data/field/image.hpp>
#include <data/field/symbol.hpp>
#include <data/field/color.hpp>
#include <data/field/information.hpp>
#include <util/error.hpp>
// ----------------------------------------------------------------------------- : Field
@@ -69,6 +70,7 @@ shared_ptr<Field> read_new<Field>(Reader& reader) {
else if (type == _("image")) return new_shared<ImageField>();
else if (type == _("symbol")) return new_shared<SymbolField>();
else if (type == _("color")) return new_shared<ColorField>();
else if (type == _("info")) return new_shared<InfoField>();
else {
throw ParseError(_("Unsupported field type: '") + type + _("'"));
}
+77
View File
@@ -0,0 +1,77 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <data/field/information.hpp>
#include <util/tagged_string.hpp>
#include <script/script.hpp>
// ----------------------------------------------------------------------------- : InfoField
IMPLEMENT_FIELD_TYPE(Info)
String InfoField::typeName() const {
return _("info");
}
void InfoField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
script. initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(InfoField) {
REFLECT_BASE(Field);
REFLECT(script);
}
// ----------------------------------------------------------------------------- : InfoStyle
InfoStyle::InfoStyle(const InfoFieldP& field)
: Style(field)
, alignment(ALIGN_TOP_LEFT)
, padding_left (2)
, padding_right (2)
, padding_top (2)
, padding_bottom(2)
, background_color(255,255,255)
{}
bool InfoStyle::update(Context& ctx) {
return Style ::update(ctx)
| font .update(ctx);
}
void InfoStyle::initDependencies(Context& ctx, const Dependency& dep) const {
Style ::initDependencies(ctx, dep);
// font .initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(InfoStyle) {
REFLECT_BASE(Style);
REFLECT(font);
REFLECT(alignment);
REFLECT(padding_left);
REFLECT(padding_right);
REFLECT(padding_top);
REFLECT(padding_bottom);
REFLECT(background_color);
}
// ----------------------------------------------------------------------------- : InfoValue
String InfoValue::toString() const {
return value;
}
bool InfoValue::update(Context& ctx) {
Value::update(ctx);
if (value.empty()) value = field().name;
return field().script.invokeOn(ctx, value);
}
IMPLEMENT_REFLECTION_NAMELESS(InfoValue) {
// never save
}
+79
View File
@@ -0,0 +1,79 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_FIELD_INFORMATION
#define HEADER_DATA_FIELD_INFORMATION
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/defaultable.hpp>
#include <data/field.hpp>
#include <data/font.hpp>
#include <script/scriptable.hpp>
// ----------------------------------------------------------------------------- : InfoField
DECLARE_POINTER_TYPE(InfoField);
DECLARE_POINTER_TYPE(InfoStyle);
DECLARE_POINTER_TYPE(InfoValue);
/// A field for informational values.
/** These values are not editable, they are just headers, icons, labels, etc.
*/
class InfoField : public Field {
public:
InfoField() {}
DECLARE_FIELD_TYPE(Text);
OptionalScript script; ///< Script to apply to all values
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : InfoStyle
/// The Style for a InfoField
class InfoStyle : public Style {
public:
InfoStyle(const InfoFieldP&);
DECLARE_STYLE_TYPE(Info);
Font font; ///< Font to use for the text
Alignment alignment; ///< Alignment inside the box
double padding_left, padding_right; ///< Padding
double padding_top, padding_bottom;
Color background_color;
virtual bool update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : InfoValue
/// The Value in a InfoField
class InfoValue : public Value {
public:
inline InfoValue(const InfoFieldP& field) : Value(field) {}
DECLARE_HAS_FIELD(Info)
String value;
virtual String toString() const;
virtual bool update(Context&);
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : EOF
#endif