A bit of refactoring:

- common code of ChoiceValueViewer and MultipleChoiceValueViewer put into functions
 - RotatedDC can now draw text with shadow.
 - DECLARE_STYLE_TYPE macro and friends do slightly more.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@788 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-12-26 17:46:40 +00:00
parent 2fb7de196e
commit 8d86e4a25c
19 changed files with 125 additions and 233 deletions
+10 -1
View File
@@ -247,6 +247,7 @@ inline String type_name(const Value&) {
// ----------------------------------------------------------------------------- : Utilities
#define DECLARE_FIELD_TYPE(Type) \
DECLARE_REFLECTION(); public: \
virtual ValueP newValue(const FieldP& thisP) const; \
virtual StyleP newStyle(const FieldP& thisP) const; \
virtual String typeName() const
@@ -269,10 +270,18 @@ inline String type_name(const Value&) {
}
#define DECLARE_STYLE_TYPE(Type) \
DECLARE_REFLECTION(); public: \
DECLARE_HAS_FIELD(Type) \
virtual StyleP clone() const; \
virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP); \
virtual ValueViewerP makeEditor(DataEditor& parent, const StyleP& thisP);
virtual ValueViewerP makeEditor(DataEditor& parent, const StyleP& thisP)
#define DECLARE_VALUE_TYPE(Type,ValueType_) \
DECLARE_REFLECTION(); public: \
DECLARE_HAS_FIELD(Type) \
virtual ValueP clone() const; \
virtual String toString() const; \
typedef ValueType_ ValueType
// implement field() which returns a field with the right (derived) type
#define DECLARE_HAS_FIELD(Type) \
-3
View File
@@ -25,9 +25,6 @@ class BooleanField : public ChoiceField {
DECLARE_FIELD_TYPE(Boolean);
// no extra data
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : BooleanStyle
+1 -13
View File
@@ -42,9 +42,6 @@ class ChoiceField : public Field {
map<String,Color> choice_colors_cardlist; ///< Colors for the various choices, for in the card list
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
@@ -166,9 +163,6 @@ class ChoiceStyle : public Style {
virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
virtual void invalidate();
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : ChoiceValue
@@ -181,17 +175,11 @@ class ChoiceValue : public Value {
an explicit initial value
*/
ChoiceValue(const ChoiceFieldP& field, bool initial_first_choice = true);
DECLARE_HAS_FIELD(Choice)
DECLARE_VALUE_TYPE(Choice, Defaultable<String>);
typedef Defaultable<String> ValueType;
ValueType value; /// The name of the selected choice
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&);
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : EOF
+1 -13
View File
@@ -37,9 +37,6 @@ class ColorField : public Field {
String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
/// A color that can be chosen for this field
@@ -67,9 +64,6 @@ class ColorStyle : public Style {
Scriptable<String> mask_filename; ///< Filename of an additional mask over the images
virtual int update(Context&);
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : ColorValue
@@ -78,17 +72,11 @@ class ColorStyle : public Style {
class ColorValue : public Value {
public:
ColorValue(const ColorFieldP& field);
DECLARE_HAS_FIELD(Color)
DECLARE_VALUE_TYPE(Color, Defaultable<Color>);
typedef Defaultable<Color> ValueType;
ValueType value; ///< The value
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&);
private:
DECLARE_REFLECTION();
};
+1 -13
View File
@@ -25,9 +25,6 @@ class ImageField : public Field {
public:
// no extra data
DECLARE_FIELD_TYPE(Image);
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : ImageStyle
@@ -42,9 +39,6 @@ class ImageStyle : public Style {
ScriptableImage default_image; ///< Placeholder
virtual int update(Context&);
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : ImageValue
@@ -53,16 +47,10 @@ class ImageStyle : public Style {
class ImageValue : public Value {
public:
inline ImageValue(const ImageFieldP& field) : Value(field) {}
DECLARE_VALUE_TYPE(Image, FileName);
typedef FileName ValueType;
ValueType filename; ///< Filename of the image (in the current package), or ""
Age last_update; ///< When was the image last changed?
virtual ValueP clone() const;
virtual String toString() const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : EOF
+2 -13
View File
@@ -32,9 +32,6 @@ class InfoField : public Field {
OptionalScript script; ///< Script to apply to all values
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : InfoStyle
@@ -53,9 +50,6 @@ class InfoStyle : public Style {
virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : InfoValue
@@ -64,16 +58,11 @@ class InfoStyle : public Style {
class InfoValue : public Value {
public:
inline InfoValue(const InfoFieldP& field) : Value(field) {}
DECLARE_HAS_FIELD(Info)
DECLARE_VALUE_TYPE(Info, String);
String value;
ValueType value;
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&);
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : EOF
-6
View File
@@ -26,9 +26,6 @@ class MultipleChoiceField : public ChoiceField {
UInt minimum_selection, maximum_selection; ///< How many choices can be selected simultaniously?
String empty_choice; ///< Name to use when nothing is selected
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : MultipleChoiceStyle
@@ -41,9 +38,6 @@ class MultipleChoiceStyle : public ChoiceStyle {
Direction direction; ///< In what direction are choices layed out?
double spacing; ///< Spacing between choices (images) in pixels
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : MultipleChoiceValue
+2 -14
View File
@@ -25,11 +25,9 @@ DECLARE_POINTER_TYPE(SymbolValue);
/// A field for image values
class SymbolField : public Field {
public:
// no extra data
DECLARE_FIELD_TYPE(Symbol);
private:
DECLARE_REFLECTION();
// no extra data
};
// ----------------------------------------------------------------------------- : SymbolStyle
@@ -46,9 +44,6 @@ class SymbolStyle : public Style {
double max_aspect_ratio; ///< Bounds for the symbol's aspect ratio
vector<SymbolVariationP> variations; ///< Different variantions of the same symbol
private:
DECLARE_REFLECTION();
};
/// Styling for a symbol variation, defines color, border, etc.
@@ -71,17 +66,10 @@ class SymbolVariation : public IntrusivePtrBase<SymbolVariation> {
class SymbolValue : public Value {
public:
inline SymbolValue(const SymbolFieldP& field) : Value(field) {}
DECLARE_HAS_FIELD(Symbol)
DECLARE_VALUE_TYPE(Symbol, FileName);
typedef FileName ValueType;
ValueType filename; ///< Filename of the symbol (in the current package)
Age last_update; ///< When was the symbol last changed?
virtual ValueP clone() const;
virtual String toString() const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : EOF
+1 -13
View File
@@ -41,9 +41,6 @@ class TextField : public Field {
String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : TextStyle
@@ -83,9 +80,6 @@ class TextStyle : public Style {
/// Stretch factor to use
double getStretch() const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : TextValue
@@ -94,18 +88,12 @@ class TextStyle : public Style {
class TextValue : public Value {
public:
inline TextValue(const TextFieldP& field) : Value(field), last_update(1) {}
DECLARE_HAS_FIELD(Text)
DECLARE_VALUE_TYPE(Text, Defaultable<String>);
typedef Defaultable<String> ValueType;
ValueType value; ///< The text of this value
Age last_update; ///< When was the text last changed?
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&);
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : TextValue
+3 -1
View File
@@ -54,7 +54,9 @@ class Font : public IntrusivePtrBase<Font> {
void initDependencies(Context&, const Dependency&) const;
/// Does this font have a shadow?
inline bool hasShadow() { return shadow_displacement.width != 0 || shadow_displacement.height != 0; }
inline bool hasShadow() const {
return shadow_displacement.width != 0 || shadow_displacement.height != 0;
}
/// Add style to a font, and optionally change the color
FontP make(int add_flags, Color* other_color) const;
+2 -12
View File
@@ -338,12 +338,7 @@ void SymbolFont::drawWithText(RotatedDC& dc, const RealRect& rect, double font_s
// align text
RealPoint text_pos = align_in_rect(text_alignment, ts, sym_rect);
// draw text
if (text_font->hasShadow()) {
dc.SetTextForeground(text_font->shadow_color);
dc.DrawText(text, text_pos + text_font->shadow_displacement * font_size, 0, 1, stretch);
}
dc.SetTextForeground(text_font->color);
dc.DrawText(text, text_pos, 0, 1, stretch);
dc.DrawTextWithShadow(text, *text_font, text_pos, font_size, stretch);
}
Image SymbolFont::getImage(double font_size, const DrawableSymbol& sym) {
@@ -388,12 +383,7 @@ Image SymbolFont::getImage(double font_size, const DrawableSymbol& sym) {
// align text
RealPoint text_pos = align_in_rect(text_alignment, ts, sym_rect);
// draw text
if (text_font->hasShadow()) {
rdc.SetTextForeground(text_font->shadow_color);
rdc.DrawText(sym.text, text_pos + text_font->shadow_displacement * font_size, 0, 1, stretch);
}
rdc.SetTextForeground(text_font->color);
rdc.DrawText(sym.text, text_pos, 0, 1, stretch);
rdc.DrawTextWithShadow(sym.text, *text_font, text_pos, font_size, stretch);
// done
dc.SelectObject(wxNullBitmap);
return bmp.ConvertToImage();