added FieldP to values and styles, implemented reflection for IndexMap

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@36 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-19 18:44:27 +00:00
parent 46a6ed39dc
commit ff96f1522a
30 changed files with 290 additions and 122 deletions
+5 -5
View File
@@ -355,8 +355,8 @@ void DuplicateSymbolPartsAction::getParts(set<SymbolPartP>& parts) {
// ----------------------------------------------------------------------------- : Reorder symbol parts
ReorderSymbolPartsAction::ReorderSymbolPartsAction(Symbol& symbol, size_t partId1, size_t partId2)
: symbol(symbol), partId1(partId1), partId2(partId2)
ReorderSymbolPartsAction::ReorderSymbolPartsAction(Symbol& symbol, size_t part_id1, size_t part_id2)
: symbol(symbol), part_id1(part_id1), part_id2(part_id2)
{}
String ReorderSymbolPartsAction::getName(bool to_undo) const {
@@ -364,7 +364,7 @@ String ReorderSymbolPartsAction::getName(bool to_undo) const {
}
void ReorderSymbolPartsAction::perform(bool to_undo) {
assert(partId1 < symbol.parts.size());
assert(partId2 < symbol.parts.size());
swap(symbol.parts[partId1], symbol.parts[partId2]);
assert(part_id1 < symbol.parts.size());
assert(part_id2 < symbol.parts.size());
swap(symbol.parts[part_id1], symbol.parts[part_id2]);
}
+2 -2
View File
@@ -223,7 +223,7 @@ class DuplicateSymbolPartsAction : public SymbolPartListAction {
/// Change the position of a part in a symbol, by swapping two parts.
class ReorderSymbolPartsAction : public SymbolPartListAction {
public:
ReorderSymbolPartsAction(Symbol& symbol, size_t partId1, size_t partId2);
ReorderSymbolPartsAction(Symbol& symbol, size_t part_id1, size_t part_id2);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
@@ -231,7 +231,7 @@ class ReorderSymbolPartsAction : public SymbolPartListAction {
private:
Symbol& symbol; ///< Symbol to swap the parts in
public:
size_t partId1, partId2; ///< Indeces of parts to swap
size_t part_id1, part_id2; ///< Indeces of parts to swap
};
+1
View File
@@ -35,5 +35,6 @@ String Card::identification() const {
IMPLEMENT_REFLECTION(Card) {
REFLECT(notes);
REFLECT_NAMELESS(data);
}
+5 -6
View File
@@ -31,20 +31,19 @@ class Card {
/// Creates a card using the given game
Card(const Game& game);
/// Get an identification of the card, an identification is something like a name, title, etc.
String identification() const;
/// The values on the fields of the card.
/** The indices should correspond to the cardFields in the Game */
/** The indices should correspond to the card_fields in the Game */
IndexMap<FieldP, ValueP> data;
/// Notes for this card
String notes;
/// Alternative style to use for this card
/** Optional; if not set use the card style from the set */
StyleSheetP stylesheet;
/// Get the identification of this card, an identification is something like a name, title, etc.
/** May return "" */
String identification() const;
DECLARE_REFLECTION();
};
+24 -9
View File
@@ -9,6 +9,7 @@
#include <data/field.hpp>
#include <data/field/text.hpp>
#include <data/field/choice.hpp>
#include <data/field/multiple_choice.hpp>
#include <data/field/boolean.hpp>
#include <data/field/image.hpp>
#include <data/field/symbol.hpp>
@@ -56,21 +57,29 @@ shared_ptr<Field> read_new<Field>(Reader& reader) {
// there must be a type specified
String type;
reader.handle(_("type"), type);
if (type == _("text")) return new_shared<TextField>();
else if (type == _("choice")) return new_shared<ChoiceField>();
else if (type == _("boolean")) return new_shared<BooleanField>();
else if (type == _("image")) return new_shared<ImageField>();
else if (type == _("symbol")) return new_shared<SymbolField>();
else if (type == _("color")) return new_shared<ColorField>();
if (type == _("text")) return new_shared<TextField>();
else if (type == _("choice")) return new_shared<ChoiceField>();
else if (type == _("multiple choice")) return new_shared<MultipleChoiceField>();
else if (type == _("boolean")) return new_shared<BooleanField>();
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 {
throw ParseError(_("Unsupported field type: '") + type + _("'"));
}
}
// ----------------------------------------------------------------------------- : Style
Style::Style(const FieldP& field)
: fieldP(field)
, z_index(0)
, left(0), width (1)
, top (0), height(1)
, visible(true)
{}
Style::~Style() {}
IMPLEMENT_REFLECTION(Style) {
@@ -82,9 +91,12 @@ IMPLEMENT_REFLECTION(Style) {
REFLECT(visible);
}
void initObject(const FieldP& field, StyleP& style) {
void init_object(const FieldP& field, StyleP& style) {
style = field->newStyle(field);
}
template <> StyleP read_new<Style>(Reader&) {
throw InternalError(_("IndexMap contains nullptr StyleP the application should have crashed already"));
}
// ----------------------------------------------------------------------------- : Value
@@ -93,7 +105,10 @@ Value::~Value() {}
IMPLEMENT_REFLECTION_NAMELESS(Value) {
}
void initObject(const FieldP& field, ValueP& value) {
void init_object(const FieldP& field, ValueP& value) {
value = field->newValue(field);
}
template <> ValueP read_new<Value>(Reader&) {
throw InternalError(_("IndexMap contains nullptr ValueP the application should have crashed already"));
}
+33 -3
View File
@@ -63,9 +63,11 @@ shared_ptr<Field> read_new<Field>(Reader& reader);
/// Style information needed to display a Value in a Field.
class Style {
public:
Style(const FieldP&);
virtual ~Style();
int z_index; ///< Stacking of values of this field, higher = on top
const FieldP fieldP; ///< Field this style is for, should have the right type!
int z_index; ///< Stacking of values of this field, higher = on top
Scriptable<double> left, top; ///< Position of this field
Scriptable<double> width, height; ///< Position of this field
Scriptable<bool> visible; ///< Is this field visible?
@@ -74,14 +76,20 @@ class Style {
DECLARE_REFLECTION_VIRTUAL();
};
void initObject(const FieldP&, StyleP&);
void init_object(const FieldP&, StyleP&);
inline const FieldP& get_key (const StyleP& s) { return s->fieldP; }
inline const String& get_key_name(const StyleP& s) { return s->fieldP->name; }
template <> StyleP read_new<Style>(Reader&);
// ----------------------------------------------------------------------------- : Value
/// A specific value 'in' a Field.
class Value {
public:
inline Value(const FieldP& field) : fieldP(field) {}
virtual ~Value();
const FieldP fieldP; ///< Field this value is for, should have the right type!
/// Convert this value to a string for use in tables
virtual String toString() const = 0;
@@ -90,7 +98,29 @@ class Value {
DECLARE_REFLECTION_VIRTUAL();
};
void initObject(const FieldP&, ValueP&);
void init_object(const FieldP&, ValueP&);
inline const FieldP& get_key (const ValueP& v) { return v->fieldP; }
inline const String& get_key_name(const ValueP& v) { return v->fieldP->name; }
template <> ValueP read_new<Value>(Reader&);
// ----------------------------------------------------------------------------- : Utilities
// implement newStyle and newValue
#define FIELD_TYPE(Type) \
StyleP Type ## Field::newStyle(const FieldP& thisP) const { \
assert(thisP.get() == this); \
return new_shared1<Type ## Style>(static_pointer_cast<Type ## Field>(thisP)); \
} \
ValueP Type ## Field::newValue(const FieldP& thisP) const { \
assert(thisP.get() == this); \
return new_shared1<Type ## Value>(static_pointer_cast<Type ## Field>(thisP)); \
}
// implement field() which returns a field with the right (derived) type
#define HAS_FIELD(Type) \
inline Type ## Field& field() const { \
return *static_cast<Type ## Field*>(fieldP.get()); \
}
// ----------------------------------------------------------------------------- : EOF
#endif
+1 -7
View File
@@ -16,13 +16,7 @@ BooleanField::BooleanField() {
choices->initIds();
}
StyleP BooleanField::newStyle(const FieldP& thisP) const {
return new_shared<BooleanStyle>();
}
ValueP BooleanField::newValue(const FieldP& thisP) const {
return new_shared<BooleanValue>();
}
FIELD_TYPE(Boolean)
String BooleanField::typeName() const {
return _("boolean");
+8
View File
@@ -14,6 +14,8 @@
// ----------------------------------------------------------------------------- : BooleanField
DECLARE_POINTER_TYPE(BooleanField);
/// A field whos value is either true or false
class BooleanField : public ChoiceField {
public:
@@ -34,6 +36,9 @@ class BooleanField : public ChoiceField {
/// The Style for a BooleanField
class BooleanStyle : public ChoiceStyle {
public:
inline BooleanStyle(const ChoiceFieldP& field) : ChoiceStyle(field) {}
HAS_FIELD(Boolean)
// no extra data
private:
@@ -45,6 +50,9 @@ class BooleanStyle : public ChoiceStyle {
/// The Value in a BooleanField
class BooleanValue : public ChoiceValue {
public:
inline BooleanValue(const ChoiceFieldP& field) : ChoiceValue(field) {}
HAS_FIELD(Boolean)
// no extra data
private:
+8 -10
View File
@@ -17,13 +17,7 @@ ChoiceField::ChoiceField()
, default_name(_("Default"))
{}
StyleP ChoiceField::newStyle(const FieldP& thisP) const {
return new_shared<ChoiceStyle>();
}
ValueP ChoiceField::newValue(const FieldP& thisP) const {
return new_shared<ChoiceValue>();
}
FIELD_TYPE(Choice)
String ChoiceField::typeName() const {
return _("choice");
@@ -153,8 +147,13 @@ template <> void GetMember::handle(const ChoiceField::Choice& c) {
// ----------------------------------------------------------------------------- : ChoiceStyle
ChoiceStyle::ChoiceStyle()
ChoiceStyle::ChoiceStyle(const ChoiceFieldP& field)
: Style(field)
, popup_style(POPUP_DROPDOWN)
, render_style(RENDER_TEXT)
, combine(COMBINE_NORMAL)
, alignment(ALIGN_STRETCH)
, colors_card_list(false)
{}
IMPLEMENT_REFLECTION_ENUM(ChoicePopupStyle) {
@@ -191,7 +190,6 @@ String ChoiceValue::toString() const {
return value();
}
IMPLEMENT_REFLECTION_NAMELESS(ChoiceValue) {
REFLECT_NAMELESS(value);
}
+7 -1
View File
@@ -17,6 +17,8 @@
// ----------------------------------------------------------------------------- : ChoiceField
DECLARE_POINTER_TYPE(ChoiceField);
/// A field that contains a list of choices
class ChoiceField : public Field {
public:
@@ -108,7 +110,8 @@ enum ChoiceRenderStyle
/// The Style for a ChoiceField
class ChoiceStyle : public Style {
public:
ChoiceStyle();
ChoiceStyle(const ChoiceFieldP& field);
HAS_FIELD(Choice)
ChoicePopupStyle popup_style; ///< Style of popups/menus
ChoiceRenderStyle render_style; ///< Style of rendering
@@ -129,6 +132,9 @@ class ChoiceStyle : public Style {
/// The Value in a ChoiceField
class ChoiceValue : public Value {
public:
inline ChoiceValue(const ChoiceFieldP& field) : Value(field) {}
HAS_FIELD(Choice)
Defaultable<String> value; /// The name of the selected choice
virtual String toString() const;
+8 -13
View File
@@ -17,13 +17,7 @@ ColorField::ColorField()
, allow_custom(true)
{}
StyleP ColorField::newStyle(const FieldP& thisP) const {
return new_shared<ColorStyle>();
}
ValueP ColorField::newValue(const FieldP& thisP) const {
return new_shared<ColorValue>();
}
FIELD_TYPE(Color)
String ColorField::typeName() const {
return _("color");
@@ -47,8 +41,9 @@ IMPLEMENT_REFLECTION(ColorField::Choice) {
// ----------------------------------------------------------------------------- : ColorStyle
ColorStyle::ColorStyle()
: radius(0)
ColorStyle::ColorStyle(const ColorFieldP& field)
: Style(field)
, radius(0)
, left_width(100000), right_width (100000)
, top_width (100000), bottom_width(100000)
{}
@@ -65,12 +60,12 @@ IMPLEMENT_REFLECTION(ColorStyle) {
// ----------------------------------------------------------------------------- : ColorValue
String ColorValue::toString() const {
/* if (value.isDefault()) return field->default_name;
if (value.isDefault()) return field().default_name;
// is this a named color?
FOR_EACH(c, field->choices) {
if (value == c->color) return c->name;
FOR_EACH(c, field().choices) {
if (value() == c->color) return c->name;
}
*/ return _("<color>");
return _("<color>");
}
IMPLEMENT_REFLECTION_NAMELESS(ColorValue) {
+8 -2
View File
@@ -16,6 +16,8 @@
// ----------------------------------------------------------------------------- : ColorField
DECLARE_POINTER_TYPE(ColorField);
/// A field for color values, it contains a list of choices for colors
class ColorField : public Field {
public:
@@ -52,14 +54,15 @@ class ColorField::Choice {
/// The Style for a ColorField
class ColorStyle : public Style {
public:
ColorStyle();
ColorStyle(const ColorFieldP& field);
HAS_FIELD(Color)
int radius; ///< Radius of round corners
UInt left_width; ///< Width of the colored region on the left side
UInt right_width; ///< Width of the colored region on the right side
UInt top_width; ///< Width of the colored region on the top side
UInt bottom_width; ///< Width of the colored region on the bottom side
private:
DECLARE_REFLECTION();
};
@@ -69,6 +72,9 @@ class ColorStyle : public Style {
/// The Value in a ColorField
class ColorValue : public Value {
public:
inline ColorValue(const ColorFieldP& field) : Value(field) {}
HAS_FIELD(Color)
Defaultable<Color> value; ///< The value
virtual String toString() const;
+1 -7
View File
@@ -10,13 +10,7 @@
// ----------------------------------------------------------------------------- : ImageField
StyleP ImageField::newStyle(const FieldP& thisP) const {
return new_shared<ImageStyle>();
}
ValueP ImageField::newValue(const FieldP& thisP) const {
return new_shared<ImageValue>();
}
FIELD_TYPE(Image)
String ImageField::typeName() const {
return _("image");
+7
View File
@@ -15,6 +15,8 @@
// ----------------------------------------------------------------------------- : ImageField
DECLARE_POINTER_TYPE(ImageField);
/// A field for image values
class ImageField : public Field {
public:
@@ -33,7 +35,10 @@ class ImageField : public Field {
/// The Style for a ImageField
class ImageStyle : public Style {
public:
inline ImageStyle(const ImageFieldP& field) : Style(field) {}
Scriptable<String> mask_filename; ///< Filename for a mask image
private:
DECLARE_REFLECTION();
};
@@ -43,6 +48,8 @@ class ImageStyle : public Style {
/// The Value in a ImageField, i.e. an image
class ImageValue : public Value {
public:
inline ImageValue(const ImageFieldP& field) : Value(field) {}
String filename; ///< Filename of the image (in the current package), or ""
virtual String toString() const;
+4 -9
View File
@@ -15,13 +15,7 @@ MultipleChoiceField::MultipleChoiceField()
, maximum_selection(1000000)
{}
StyleP MultipleChoiceField::newStyle(const FieldP& thisP) const {
return new_shared<MultipleChoiceStyle>();
}
ValueP MultipleChoiceField::newValue(const FieldP& thisP) const {
return new_shared<MultipleChoiceValue>();
}
FIELD_TYPE(MultipleChoice)
String MultipleChoiceField::typeName() const {
return _("multiple choice");
@@ -35,8 +29,9 @@ IMPLEMENT_REFLECTION(MultipleChoiceField) {
// ----------------------------------------------------------------------------- : MultipleChoiceStyle
MultipleChoiceStyle::MultipleChoiceStyle()
: direction(HORIZONTAL)
MultipleChoiceStyle::MultipleChoiceStyle(const MultipleChoiceFieldP& field)
: ChoiceStyle(field)
, direction(HORIZONTAL)
, spacing(0)
{}
+7 -1
View File
@@ -14,6 +14,8 @@
// ----------------------------------------------------------------------------- : MultipleChoiceField
DECLARE_POINTER_TYPE(MultipleChoiceField);
/// A ChoiceField where multiple choices can be selected simultaniously
class MultipleChoiceField : public ChoiceField {
public:
@@ -38,7 +40,8 @@ enum Direction {
/// The Style for a MultipleChoiceField
class MultipleChoiceStyle : public ChoiceStyle {
public:
MultipleChoiceStyle();
MultipleChoiceStyle(const MultipleChoiceFieldP& field);
HAS_FIELD(MultipleChoice)
Direction direction; ///< In what direction are choices layed out?
double spacing; ///< Spacing between choices (images) in pixels
@@ -55,6 +58,9 @@ class MultipleChoiceStyle : public ChoiceStyle {
*/
class MultipleChoiceValue : public ChoiceValue {
public:
inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field) {}
HAS_FIELD(MultipleChoice)
// no extra data
/// Splits the value, stores the selected choices in the out parameter
+1 -7
View File
@@ -10,13 +10,7 @@
// ----------------------------------------------------------------------------- : SymbolField
StyleP SymbolField::newStyle(const FieldP& thisP) const {
return new_shared<SymbolStyle>();
}
ValueP SymbolField::newValue(const FieldP& thisP) const {
return new_shared<SymbolValue>();
}
FIELD_TYPE(Symbol)
String SymbolField::typeName() const {
return _("symbol");
+8
View File
@@ -17,6 +17,8 @@ DECLARE_POINTER_TYPE(SymbolFilter);
// ----------------------------------------------------------------------------- : SymbolField
DECLARE_POINTER_TYPE(SymbolField);
/// A field for image values
class SymbolField : public Field {
public:
@@ -35,6 +37,9 @@ class SymbolField : public Field {
/// The Style for a SymbolField
class SymbolStyle : public Style {
public:
inline SymbolStyle(const SymbolFieldP& field) : Style(field) {}
HAS_FIELD(Symbol)
class Variation;
typedef shared_ptr<Variation> VariationP;
vector<VariationP> variations; ///< Different variantions of the same symbol
@@ -58,6 +63,9 @@ class SymbolStyle::Variation {
/// The Value in a SymbolField, i.e. a symbol
class SymbolValue : public Value {
public:
inline SymbolValue(const SymbolFieldP& field) : Value(field) {}
HAS_FIELD(Symbol)
String filename; ///< Filename of the symbol (in the current package)
virtual String toString() const;
+33 -9
View File
@@ -16,15 +16,7 @@ TextField::TextField()
, default_name(_("Default"))
{}
StyleP TextField::newStyle(const FieldP& thisP) const {
assert(thisP.get() == this);
return new_shared<TextStyle>();
}
ValueP TextField::newValue(const FieldP& thisP) const {
assert(thisP.get() == this);
return new_shared<TextValue>();
}
FIELD_TYPE(Text)
String TextField::typeName() const {
return _("text");
@@ -42,8 +34,40 @@ IMPLEMENT_REFLECTION(TextField) {
// ----------------------------------------------------------------------------- : TextStyle
TextStyle::TextStyle(const TextFieldP& field)
: Style(field)
, always_symbol(false), allow_formating(true)
, alignment(ALIGN_TOP_LEFT)
, angle(0)
, padding_left (0), padding_left_min (10000)
, padding_right (0), padding_right_min (10000)
, padding_top (0), padding_top_min (10000)
, padding_bottom(0), padding_bottom_min(10000)
, line_height_soft(1.0)
, line_height_hard(1.0)
, line_height_line(1.0)
{}
IMPLEMENT_REFLECTION(TextStyle) {
REFLECT_BASE(Style);
// REFLECT(font);
// REFLECT(symbol_font);
REFLECT(always_symbol);
REFLECT(allow_formating);
REFLECT(alignment);
REFLECT(angle);
REFLECT(padding_left);
REFLECT(padding_right);
REFLECT(padding_top);
REFLECT(padding_bottom);
REFLECT(padding_left_min);
REFLECT(padding_right_min);
REFLECT(padding_top_min);
REFLECT(padding_bottom_min);
REFLECT(line_height_soft);
REFLECT(line_height_hard);
REFLECT(line_height_line);
REFLECT_N("mask", mask_filename);
}
// ----------------------------------------------------------------------------- : TextValue
+14 -6
View File
@@ -16,6 +16,8 @@
// ----------------------------------------------------------------------------- : TextField
DECLARE_POINTER_TYPE(TextField);
/// A field for values containing tagged text
class TextField : public Field {
public:
@@ -40,16 +42,19 @@ class TextField : public Field {
/// The Style for a TextField
class TextStyle : public Style {
public:
TextStyle(const TextFieldP&);
HAS_FIELD(Text)
// FontInfo font; ///< Font to use for the text
// SymbolFontInfo symbol_font; ///< Symbol font for symbols in the text
bool always_symbol; ///< Should everything be drawn as symbols?
bool allow_formatting; ///< Is formating (bold/italic/..) allowed?
bool allow_formating; ///< Is formating (bold/italic/..) allowed?
Alignment alignment; ///< Alignment inside the box
int angle; ///< Angle of the text inside the box
int padding_left, padding_left_min; ///< Padding
int padding_right, padding_right_min; ///< Padding
int padding_top, padding_top_min; ///< Padding
int padding_bottom, padding_bottom_min; ///< Padding
double padding_left, padding_left_min; ///< Padding
double padding_right, padding_right_min; ///< Padding
double padding_top, padding_top_min; ///< Padding
double padding_bottom, padding_bottom_min; ///< Padding
double line_height_soft; ///< Line height for soft linebreaks
double line_height_hard; ///< Line height for hard linebreaks
double line_height_line; ///< Line height for <line> tags
@@ -63,7 +68,10 @@ class TextStyle : public Style {
/// The Value in a TextField
class TextValue : public Value {
public:
public:
inline TextValue(const TextFieldP& field) : Value(field) {}
HAS_FIELD(Text)
Defaultable<String> value; ///< The text of this value
virtual String toString() const;
+1 -1
View File
@@ -22,7 +22,7 @@ String Set::typeName() const { return _("set"); }
IMPLEMENT_REFLECTION(Set) {
WITH_DYNAMIC_ARG(game_for_new_cards, game.get()) {
REFLECT_N("card", cards);
REFLECT(cards);
}
}
+6 -4
View File
@@ -17,17 +17,22 @@
DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(Set);
DECLARE_POINTER_TYPE(Game);
DECLARE_POINTER_TYPE(Stylesheet);
// ----------------------------------------------------------------------------- : Set
/// A set of cards
class Set : public Packaged {
public:
/// Create a set, the set should be open()ed later
Set();
/// Create a set using the given game
Set(const GameP& game);
/// The game this set uses
GameP game;
/// The default stylesheet
StylesheetP stylesheet;
/// The cards in the set
vector<CardP> cards;
/// Actions performed on this set and the cards in it
@@ -35,10 +40,7 @@ class Set : public Packaged {
protected:
String typeName() const;
// default constructor accessible to Reader
Set();
DECLARE_REFLECTION();
};