Added ValueViewer,DataViewer,CardViewer and made related changes

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@49 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-26 20:33:23 +00:00
parent 46cf4dbb64
commit c8e8dd0220
24 changed files with 515 additions and 57 deletions
+24 -2
View File
@@ -18,6 +18,11 @@ DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Style);
DECLARE_POINTER_TYPE(Value);
// for DataViewer/editor
class DataViewer; class DataEditor;
DECLARE_POINTER_TYPE(ValueViewer);
DECLARE_POINTER_TYPE(ValueEditor);
// ----------------------------------------------------------------------------- : Field
/// Information on how to store a value
@@ -74,6 +79,13 @@ class Style {
Scriptable<double> width, height; ///< Position of this field
Scriptable<bool> visible; ///< Is this field visible?
/// Make a viewer object for values using this style
/** thisP is a smart pointer to this */
virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP) = 0;
/// Make an editor object for values using this style
/** thisP is a smart pointer to this */
virtual ValueEditorP makeEditor(DataEditor& parent, const StyleP& thisP) = 0;
private:
DECLARE_REFLECTION_VIRTUAL();
};
@@ -107,8 +119,13 @@ template <> ValueP read_new<Value>(Reader&);
// ----------------------------------------------------------------------------- : Utilities
#define DECLARE_FIELD_TYPE(Type) \
virtual ValueP newValue(const FieldP& thisP) const; \
virtual StyleP newStyle(const FieldP& thisP) const; \
virtual String typeName() const
// implement newStyle and newValue
#define FIELD_TYPE(Type) \
#define IMPLEMENT_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)); \
@@ -118,8 +135,13 @@ template <> ValueP read_new<Value>(Reader&);
return new_shared1<Type ## Value>(static_pointer_cast<Type ## Field>(thisP)); \
}
#define DECLARE_STYLE_TYPE(Type) \
DECLARE_HAS_FIELD(Type) \
virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP); \
virtual ValueEditorP makeEditor(DataEditor& parent, const StyleP& thisP)
// implement field() which returns a field with the right (derived) type
#define HAS_FIELD(Type) \
#define DECLARE_HAS_FIELD(Type) \
inline Type ## Field& field() const { \
return *static_cast<Type ## Field*>(fieldP.get()); \
}
+1 -1
View File
@@ -16,7 +16,7 @@ BooleanField::BooleanField() {
choices->initIds();
}
FIELD_TYPE(Boolean)
IMPLEMENT_FIELD_TYPE(Boolean)
String BooleanField::typeName() const {
return _("boolean");
+4 -7
View File
@@ -20,13 +20,10 @@ DECLARE_POINTER_TYPE(BooleanField);
class BooleanField : public ChoiceField {
public:
BooleanField();
DECLARE_FIELD_TYPE(Boolean);
// no extra data
virtual ValueP newValue(const FieldP& thisP) const;
virtual StyleP newStyle(const FieldP& thisP) const;
virtual String typeName() const;
private:
DECLARE_REFLECTION();
};
@@ -37,7 +34,7 @@ class BooleanField : public ChoiceField {
class BooleanStyle : public ChoiceStyle {
public:
inline BooleanStyle(const ChoiceFieldP& field) : ChoiceStyle(field) {}
HAS_FIELD(Boolean)
DECLARE_STYLE_TYPE(Boolean);
// no extra data
@@ -51,7 +48,7 @@ class BooleanStyle : public ChoiceStyle {
class BooleanValue : public ChoiceValue {
public:
inline BooleanValue(const ChoiceFieldP& field) : ChoiceValue(field) {}
HAS_FIELD(Boolean)
DECLARE_HAS_FIELD(Boolean);
// no extra data
+1 -1
View File
@@ -17,7 +17,7 @@ ChoiceField::ChoiceField()
, default_name(_("Default"))
{}
FIELD_TYPE(Choice)
IMPLEMENT_FIELD_TYPE(Choice)
String ChoiceField::typeName() const {
return _("choice");
+4 -7
View File
@@ -23,6 +23,7 @@ DECLARE_POINTER_TYPE(ChoiceField);
class ChoiceField : public Field {
public:
ChoiceField();
DECLARE_FIELD_TYPE(Choice);
class Choice;
typedef shared_ptr<Choice> ChoiceP;
@@ -32,11 +33,7 @@ class ChoiceField : public Field {
OptionalScript default_script; ///< Script that generates the default value
String initial; ///< Initial choice of a new value, or ""
String default_name; ///< Name of "default" value
virtual ValueP newValue(const FieldP& thisP) const;
virtual StyleP newStyle(const FieldP& thisP) const;
virtual String typeName() const;
private:
DECLARE_REFLECTION();
};
@@ -111,7 +108,7 @@ enum ChoiceRenderStyle
class ChoiceStyle : public Style {
public:
ChoiceStyle(const ChoiceFieldP& field);
HAS_FIELD(Choice)
DECLARE_STYLE_TYPE(Choice);
ChoicePopupStyle popup_style; ///< Style of popups/menus
ChoiceRenderStyle render_style; ///< Style of rendering
@@ -133,7 +130,7 @@ class ChoiceStyle : public Style {
class ChoiceValue : public Value {
public:
inline ChoiceValue(const ChoiceFieldP& field) : Value(field) {}
HAS_FIELD(Choice)
DECLARE_HAS_FIELD(Choice)
Defaultable<String> value; /// The name of the selected choice
+1 -1
View File
@@ -17,7 +17,7 @@ ColorField::ColorField()
, allow_custom(true)
{}
FIELD_TYPE(Color)
IMPLEMENT_FIELD_TYPE(Color)
String ColorField::typeName() const {
return _("color");
+4 -7
View File
@@ -22,6 +22,7 @@ DECLARE_POINTER_TYPE(ColorField);
class ColorField : public Field {
public:
ColorField();
DECLARE_FIELD_TYPE(Color);
class Choice;
typedef shared_ptr<Choice> ChoiceP;
@@ -31,11 +32,7 @@ class ColorField : public Field {
vector<ChoiceP> choices; ///< Color choices available
bool allow_custom; ///< Are colors not in the list of choices allowed?
String default_name; ///< Name of "default" value
virtual ValueP newValue(const FieldP& thisP) const;
virtual StyleP newStyle(const FieldP& thisP) const;
virtual String typeName() const;
private:
DECLARE_REFLECTION();
};
@@ -55,7 +52,7 @@ class ColorField::Choice {
class ColorStyle : public Style {
public:
ColorStyle(const ColorFieldP& field);
HAS_FIELD(Color)
DECLARE_STYLE_TYPE(Color);
int radius; ///< Radius of round corners
UInt left_width; ///< Width of the colored region on the left side
@@ -73,7 +70,7 @@ class ColorStyle : public Style {
class ColorValue : public Value {
public:
inline ColorValue(const ColorFieldP& field) : Value(field) {}
HAS_FIELD(Color)
DECLARE_HAS_FIELD(Color)
Defaultable<Color> value; ///< The value
+1 -1
View File
@@ -10,7 +10,7 @@
// ----------------------------------------------------------------------------- : ImageField
FIELD_TYPE(Image)
IMPLEMENT_FIELD_TYPE(Image)
String ImageField::typeName() const {
return _("image");
+2 -4
View File
@@ -21,10 +21,7 @@ DECLARE_POINTER_TYPE(ImageField);
class ImageField : public Field {
public:
// no extra data
virtual ValueP newValue(const FieldP& thisP) const;
virtual StyleP newStyle(const FieldP& thisP) const;
virtual String typeName() const;
DECLARE_FIELD_TYPE(Image);
private:
DECLARE_REFLECTION();
@@ -36,6 +33,7 @@ class ImageField : public Field {
class ImageStyle : public Style {
public:
inline ImageStyle(const ImageFieldP& field) : Style(field) {}
DECLARE_STYLE_TYPE(Image);
Scriptable<String> mask_filename; ///< Filename for a mask image
+1 -1
View File
@@ -15,7 +15,7 @@ MultipleChoiceField::MultipleChoiceField()
, maximum_selection(1000000)
{}
FIELD_TYPE(MultipleChoice)
IMPLEMENT_FIELD_TYPE(MultipleChoice)
String MultipleChoiceField::typeName() const {
return _("multiple choice");
+3 -6
View File
@@ -20,13 +20,10 @@ DECLARE_POINTER_TYPE(MultipleChoiceField);
class MultipleChoiceField : public ChoiceField {
public:
MultipleChoiceField();
DECLARE_FIELD_TYPE(MultipleChoiceField);
UInt minimum_selection, maximum_selection; ///< How many choices can be selected simultaniously?
virtual ValueP newValue(const FieldP& thisP) const;
virtual StyleP newStyle(const FieldP& thisP) const;
virtual String typeName() const;
private:
DECLARE_REFLECTION();
};
@@ -41,7 +38,7 @@ enum Direction {
class MultipleChoiceStyle : public ChoiceStyle {
public:
MultipleChoiceStyle(const MultipleChoiceFieldP& field);
HAS_FIELD(MultipleChoice)
DECLARE_STYLE_TYPE(MultipleChoice);
Direction direction; ///< In what direction are choices layed out?
double spacing; ///< Spacing between choices (images) in pixels
@@ -59,7 +56,7 @@ class MultipleChoiceStyle : public ChoiceStyle {
class MultipleChoiceValue : public ChoiceValue {
public:
inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field) {}
HAS_FIELD(MultipleChoice)
DECLARE_HAS_FIELD(MultipleChoice);
// no extra data
+1 -1
View File
@@ -10,7 +10,7 @@
// ----------------------------------------------------------------------------- : SymbolField
FIELD_TYPE(Symbol)
IMPLEMENT_FIELD_TYPE(Symbol)
String SymbolField::typeName() const {
return _("symbol");
+3 -6
View File
@@ -23,10 +23,7 @@ DECLARE_POINTER_TYPE(SymbolField);
class SymbolField : public Field {
public:
// no extra data
virtual ValueP newValue(const FieldP& thisP) const;
virtual StyleP newStyle(const FieldP& thisP) const;
virtual String typeName() const;
DECLARE_FIELD_TYPE(Symbol);
private:
DECLARE_REFLECTION();
@@ -38,7 +35,7 @@ class SymbolField : public Field {
class SymbolStyle : public Style {
public:
inline SymbolStyle(const SymbolFieldP& field) : Style(field) {}
HAS_FIELD(Symbol)
DECLARE_STYLE_TYPE(Symbol);
class Variation;
typedef shared_ptr<Variation> VariationP;
@@ -64,7 +61,7 @@ class SymbolStyle::Variation {
class SymbolValue : public Value {
public:
inline SymbolValue(const SymbolFieldP& field) : Value(field) {}
HAS_FIELD(Symbol)
DECLARE_HAS_FIELD(Symbol)
String filename; ///< Filename of the symbol (in the current package)
+1 -1
View File
@@ -16,7 +16,7 @@ TextField::TextField()
, default_name(_("Default"))
{}
FIELD_TYPE(Text)
IMPLEMENT_FIELD_TYPE(Text)
String TextField::typeName() const {
return _("text");
+4 -7
View File
@@ -22,17 +22,14 @@ DECLARE_POINTER_TYPE(TextField);
class TextField : public Field {
public:
TextField();
DECLARE_FIELD_TYPE(Text);
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
bool multi_line; ///< Are newlines allowed in the text?
bool move_cursor_with_sort; ///< When the text is reordered by a script should the cursor position be updated?
String default_name; ///< Name of "default" value
virtual ValueP newValue(const FieldP& thisP) const;
virtual StyleP newStyle(const FieldP& thisP) const;
virtual String typeName() const;
private:
DECLARE_REFLECTION();
};
@@ -43,7 +40,7 @@ class TextField : public Field {
class TextStyle : public Style {
public:
TextStyle(const TextFieldP&);
HAS_FIELD(Text)
DECLARE_STYLE_TYPE(Text);
// FontInfo font; ///< Font to use for the text
// SymbolFontInfo symbol_font; ///< Symbol font for symbols in the text
@@ -70,7 +67,7 @@ class TextStyle : public Style {
class TextValue : public Value {
public:
inline TextValue(const TextFieldP& field) : Value(field) {}
HAS_FIELD(Text)
DECLARE_HAS_FIELD(Text)
Defaultable<String> value; ///< The text of this value
+2
View File
@@ -20,6 +20,8 @@ DECLARE_POINTER_TYPE(Game);
class StyleSheet : public Packaged {
public:
GameP game;
double card_width; ///< The width of a card in pixels
double card_height; ///< The height of a card in pixels
static String typeNameStatic();
virtual String typeName() const;