Commit e3411494 authored by twanvl's avatar twanvl

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.
parent cea9b94d
...@@ -247,6 +247,7 @@ inline String type_name(const Value&) { ...@@ -247,6 +247,7 @@ inline String type_name(const Value&) {
// ----------------------------------------------------------------------------- : Utilities // ----------------------------------------------------------------------------- : Utilities
#define DECLARE_FIELD_TYPE(Type) \ #define DECLARE_FIELD_TYPE(Type) \
DECLARE_REFLECTION(); public: \
virtual ValueP newValue(const FieldP& thisP) const; \ virtual ValueP newValue(const FieldP& thisP) const; \
virtual StyleP newStyle(const FieldP& thisP) const; \ virtual StyleP newStyle(const FieldP& thisP) const; \
virtual String typeName() const virtual String typeName() const
...@@ -269,10 +270,18 @@ inline String type_name(const Value&) { ...@@ -269,10 +270,18 @@ inline String type_name(const Value&) {
} }
#define DECLARE_STYLE_TYPE(Type) \ #define DECLARE_STYLE_TYPE(Type) \
DECLARE_REFLECTION(); public: \
DECLARE_HAS_FIELD(Type) \ DECLARE_HAS_FIELD(Type) \
virtual StyleP clone() const; \ virtual StyleP clone() const; \
virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP); \ 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 // implement field() which returns a field with the right (derived) type
#define DECLARE_HAS_FIELD(Type) \ #define DECLARE_HAS_FIELD(Type) \
......
...@@ -25,9 +25,6 @@ class BooleanField : public ChoiceField { ...@@ -25,9 +25,6 @@ class BooleanField : public ChoiceField {
DECLARE_FIELD_TYPE(Boolean); DECLARE_FIELD_TYPE(Boolean);
// no extra data // no extra data
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : BooleanStyle // ----------------------------------------------------------------------------- : BooleanStyle
......
...@@ -42,9 +42,6 @@ class ChoiceField : public Field { ...@@ -42,9 +42,6 @@ class ChoiceField : public Field {
map<String,Color> choice_colors_cardlist; ///< Colors for the various choices, for in the card list map<String,Color> choice_colors_cardlist; ///< Colors for the various choices, for in the card list
virtual void initDependencies(Context&, const Dependency&) const; virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
}; };
...@@ -166,9 +163,6 @@ class ChoiceStyle : public Style { ...@@ -166,9 +163,6 @@ class ChoiceStyle : public Style {
virtual int update(Context&); virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const; virtual void initDependencies(Context&, const Dependency&) const;
virtual void invalidate(); virtual void invalidate();
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : ChoiceValue // ----------------------------------------------------------------------------- : ChoiceValue
...@@ -181,17 +175,11 @@ class ChoiceValue : public Value { ...@@ -181,17 +175,11 @@ class ChoiceValue : public Value {
an explicit initial value an explicit initial value
*/ */
ChoiceValue(const ChoiceFieldP& field, bool initial_first_choice = true); 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 ValueType value; /// The name of the selected choice
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&); virtual bool update(Context&);
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -37,9 +37,6 @@ class ColorField : public Field { ...@@ -37,9 +37,6 @@ class ColorField : public Field {
String default_name; ///< Name of "default" value String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const; virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
}; };
/// A color that can be chosen for this field /// A color that can be chosen for this field
...@@ -67,9 +64,6 @@ class ColorStyle : public Style { ...@@ -67,9 +64,6 @@ class ColorStyle : public Style {
Scriptable<String> mask_filename; ///< Filename of an additional mask over the images Scriptable<String> mask_filename; ///< Filename of an additional mask over the images
virtual int update(Context&); virtual int update(Context&);
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : ColorValue // ----------------------------------------------------------------------------- : ColorValue
...@@ -78,17 +72,11 @@ class ColorStyle : public Style { ...@@ -78,17 +72,11 @@ class ColorStyle : public Style {
class ColorValue : public Value { class ColorValue : public Value {
public: public:
ColorValue(const ColorFieldP& field); ColorValue(const ColorFieldP& field);
DECLARE_HAS_FIELD(Color) DECLARE_VALUE_TYPE(Color, Defaultable<Color>);
typedef Defaultable<Color> ValueType;
ValueType value; ///< The value ValueType value; ///< The value
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&); virtual bool update(Context&);
private:
DECLARE_REFLECTION();
}; };
......
...@@ -25,9 +25,6 @@ class ImageField : public Field { ...@@ -25,9 +25,6 @@ class ImageField : public Field {
public: public:
// no extra data // no extra data
DECLARE_FIELD_TYPE(Image); DECLARE_FIELD_TYPE(Image);
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : ImageStyle // ----------------------------------------------------------------------------- : ImageStyle
...@@ -42,9 +39,6 @@ class ImageStyle : public Style { ...@@ -42,9 +39,6 @@ class ImageStyle : public Style {
ScriptableImage default_image; ///< Placeholder ScriptableImage default_image; ///< Placeholder
virtual int update(Context&); virtual int update(Context&);
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : ImageValue // ----------------------------------------------------------------------------- : ImageValue
...@@ -53,16 +47,10 @@ class ImageStyle : public Style { ...@@ -53,16 +47,10 @@ class ImageStyle : public Style {
class ImageValue : public Value { class ImageValue : public Value {
public: public:
inline ImageValue(const ImageFieldP& field) : Value(field) {} 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 "" ValueType filename; ///< Filename of the image (in the current package), or ""
Age last_update; ///< When was the image last changed? Age last_update; ///< When was the image last changed?
virtual ValueP clone() const;
virtual String toString() const;
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -32,9 +32,6 @@ class InfoField : public Field { ...@@ -32,9 +32,6 @@ class InfoField : public Field {
OptionalScript script; ///< Script to apply to all values OptionalScript script; ///< Script to apply to all values
virtual void initDependencies(Context&, const Dependency&) const; virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : InfoStyle // ----------------------------------------------------------------------------- : InfoStyle
...@@ -53,9 +50,6 @@ class InfoStyle : public Style { ...@@ -53,9 +50,6 @@ class InfoStyle : public Style {
virtual int update(Context&); virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const; virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : InfoValue // ----------------------------------------------------------------------------- : InfoValue
...@@ -64,16 +58,11 @@ class InfoStyle : public Style { ...@@ -64,16 +58,11 @@ class InfoStyle : public Style {
class InfoValue : public Value { class InfoValue : public Value {
public: public:
inline InfoValue(const InfoFieldP& field) : Value(field) {} 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&); virtual bool update(Context&);
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -26,9 +26,6 @@ class MultipleChoiceField : public ChoiceField { ...@@ -26,9 +26,6 @@ class MultipleChoiceField : public ChoiceField {
UInt minimum_selection, maximum_selection; ///< How many choices can be selected simultaniously? UInt minimum_selection, maximum_selection; ///< How many choices can be selected simultaniously?
String empty_choice; ///< Name to use when nothing is selected String empty_choice; ///< Name to use when nothing is selected
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : MultipleChoiceStyle // ----------------------------------------------------------------------------- : MultipleChoiceStyle
...@@ -41,9 +38,6 @@ class MultipleChoiceStyle : public ChoiceStyle { ...@@ -41,9 +38,6 @@ class MultipleChoiceStyle : public ChoiceStyle {
Direction direction; ///< In what direction are choices layed out? Direction direction; ///< In what direction are choices layed out?
double spacing; ///< Spacing between choices (images) in pixels double spacing; ///< Spacing between choices (images) in pixels
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : MultipleChoiceValue // ----------------------------------------------------------------------------- : MultipleChoiceValue
......
...@@ -25,11 +25,9 @@ DECLARE_POINTER_TYPE(SymbolValue); ...@@ -25,11 +25,9 @@ DECLARE_POINTER_TYPE(SymbolValue);
/// A field for image values /// A field for image values
class SymbolField : public Field { class SymbolField : public Field {
public: public:
// no extra data
DECLARE_FIELD_TYPE(Symbol); DECLARE_FIELD_TYPE(Symbol);
private: // no extra data
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : SymbolStyle // ----------------------------------------------------------------------------- : SymbolStyle
...@@ -46,9 +44,6 @@ class SymbolStyle : public Style { ...@@ -46,9 +44,6 @@ class SymbolStyle : public Style {
double max_aspect_ratio; ///< Bounds for the symbol's aspect ratio double max_aspect_ratio; ///< Bounds for the symbol's aspect ratio
vector<SymbolVariationP> variations; ///< Different variantions of the same symbol vector<SymbolVariationP> variations; ///< Different variantions of the same symbol
private:
DECLARE_REFLECTION();
}; };
/// Styling for a symbol variation, defines color, border, etc. /// Styling for a symbol variation, defines color, border, etc.
...@@ -71,17 +66,10 @@ class SymbolVariation : public IntrusivePtrBase<SymbolVariation> { ...@@ -71,17 +66,10 @@ class SymbolVariation : public IntrusivePtrBase<SymbolVariation> {
class SymbolValue : public Value { class SymbolValue : public Value {
public: public:
inline SymbolValue(const SymbolFieldP& field) : Value(field) {} 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) ValueType filename; ///< Filename of the symbol (in the current package)
Age last_update; ///< When was the symbol last changed? Age last_update; ///< When was the symbol last changed?
virtual ValueP clone() const;
virtual String toString() const;
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -41,9 +41,6 @@ class TextField : public Field { ...@@ -41,9 +41,6 @@ class TextField : public Field {
String default_name; ///< Name of "default" value String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const; virtual void initDependencies(Context&, const Dependency&) const;
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : TextStyle // ----------------------------------------------------------------------------- : TextStyle
...@@ -83,9 +80,6 @@ class TextStyle : public Style { ...@@ -83,9 +80,6 @@ class TextStyle : public Style {
/// Stretch factor to use /// Stretch factor to use
double getStretch() const; double getStretch() const;
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : TextValue // ----------------------------------------------------------------------------- : TextValue
...@@ -94,18 +88,12 @@ class TextStyle : public Style { ...@@ -94,18 +88,12 @@ class TextStyle : public Style {
class TextValue : public Value { class TextValue : public Value {
public: public:
inline TextValue(const TextFieldP& field) : Value(field), last_update(1) {} 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 ValueType value; ///< The text of this value
Age last_update; ///< When was the text last changed? Age last_update; ///< When was the text last changed?
virtual ValueP clone() const;
virtual String toString() const;
virtual bool update(Context&); virtual bool update(Context&);
private:
DECLARE_REFLECTION();
}; };
// ----------------------------------------------------------------------------- : TextValue // ----------------------------------------------------------------------------- : TextValue
......
...@@ -54,7 +54,9 @@ class Font : public IntrusivePtrBase<Font> { ...@@ -54,7 +54,9 @@ class Font : public IntrusivePtrBase<Font> {
void initDependencies(Context&, const Dependency&) const; void initDependencies(Context&, const Dependency&) const;
/// Does this font have a shadow? /// 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 /// Add style to a font, and optionally change the color
FontP make(int add_flags, Color* other_color) const; FontP make(int add_flags, Color* other_color) const;
......
...@@ -338,12 +338,7 @@ void SymbolFont::drawWithText(RotatedDC& dc, const RealRect& rect, double font_s ...@@ -338,12 +338,7 @@ void SymbolFont::drawWithText(RotatedDC& dc, const RealRect& rect, double font_s
// align text // align text
RealPoint text_pos = align_in_rect(text_alignment, ts, sym_rect); RealPoint text_pos = align_in_rect(text_alignment, ts, sym_rect);
// draw text // draw text
if (text_font->hasShadow()) { dc.DrawTextWithShadow(text, *text_font, text_pos, font_size, stretch);
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);
} }
Image SymbolFont::getImage(double font_size, const DrawableSymbol& sym) { Image SymbolFont::getImage(double font_size, const DrawableSymbol& sym) {
...@@ -388,12 +383,7 @@ Image SymbolFont::getImage(double font_size, const DrawableSymbol& sym) { ...@@ -388,12 +383,7 @@ Image SymbolFont::getImage(double font_size, const DrawableSymbol& sym) {
// align text // align text
RealPoint text_pos = align_in_rect(text_alignment, ts, sym_rect); RealPoint text_pos = align_in_rect(text_alignment, ts, sym_rect);
// draw text // draw text
if (text_font->hasShadow()) { rdc.DrawTextWithShadow(sym.text, *text_font, text_pos, font_size, stretch);
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);
// done // done
dc.SelectObject(wxNullBitmap); dc.SelectObject(wxNullBitmap);
return bmp.ConvertToImage(); return bmp.ConvertToImage();
......
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
Optimization="2" Optimization="2"
GlobalOptimizations="TRUE" GlobalOptimizations="TRUE"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
ImproveFloatingPointConsistency="TRUE"
OmitFramePointers="TRUE" OmitFramePointers="TRUE"
OptimizeForProcessor="0" OptimizeForProcessor="0"
OptimizeForWindowsApplication="TRUE" OptimizeForWindowsApplication="TRUE"
...@@ -225,6 +226,7 @@ ...@@ -225,6 +226,7 @@
Optimization="3" Optimization="3"
GlobalOptimizations="TRUE" GlobalOptimizations="TRUE"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
ImproveFloatingPointConsistency="TRUE"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="TRUE" OmitFramePointers="TRUE"
OptimizeForProcessor="3" OptimizeForProcessor="3"
...@@ -300,6 +302,7 @@ ...@@ -300,6 +302,7 @@
Optimization="3" Optimization="3"
GlobalOptimizations="TRUE" GlobalOptimizations="TRUE"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
ImproveFloatingPointConsistency="TRUE"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="TRUE" OmitFramePointers="TRUE"
OptimizeForProcessor="3" OptimizeForProcessor="3"
...@@ -375,6 +378,7 @@ ...@@ -375,6 +378,7 @@
Optimization="3" Optimization="3"
GlobalOptimizations="TRUE" GlobalOptimizations="TRUE"
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
ImproveFloatingPointConsistency="TRUE"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
OmitFramePointers="TRUE" OmitFramePointers="TRUE"
OptimizeForProcessor="3" OptimizeForProcessor="3"
...@@ -2172,12 +2176,6 @@ ...@@ -2172,12 +2176,6 @@
<Filter <Filter
Name="base" Name="base"
Filter=""> Filter="">
<File
RelativePath=".\util\atomic.hpp">
</File>
<File
RelativePath=".\util\dynamic_arg.hpp">
</File>
<File <File
RelativePath=".\util\error.cpp"> RelativePath=".\util\error.cpp">
</File> </File>
...@@ -2187,9 +2185,6 @@ ...@@ -2187,9 +2185,6 @@
<File <File
RelativePath=".\util\for_each.hpp"> RelativePath=".\util\for_each.hpp">
</File> </File>
<File
RelativePath=".\util\order_cache.hpp">
</File>
<File <File
RelativePath=".\util\platform.hpp"> RelativePath=".\util\platform.hpp">
</File> </File>
...@@ -2208,12 +2203,6 @@ ...@@ -2208,12 +2203,6 @@
<File <File
RelativePath=".\util\smart_ptr.hpp"> RelativePath=".\util\smart_ptr.hpp">
</File> </File>
<File
RelativePath=".\util\spec_sort.cpp">
</File>
<File
RelativePath=".\util\spec_sort.hpp">
</File>
<File <File
RelativePath=".\util\string.cpp"> RelativePath=".\util\string.cpp">
<FileConfiguration <FileConfiguration
...@@ -2253,6 +2242,25 @@ ...@@ -2253,6 +2242,25 @@
<File <File
RelativePath=".\util\window_id.hpp"> RelativePath=".\util\window_id.hpp">
</File> </File>
<Filter
Name="aux"
Filter="">
<File
RelativePath=".\util\atomic.hpp">
</File>
<File
RelativePath=".\util\dynamic_arg.hpp">
</File>
<File
RelativePath=".\util\order_cache.hpp">
</File>
<File
RelativePath=".\util\spec_sort.cpp">
</File>
<File
RelativePath=".\util\spec_sort.hpp">
</File>
</Filter>
</Filter> </Filter>
</Filter> </Filter>
<Filter <Filter
......
...@@ -13,19 +13,14 @@ ...@@ -13,19 +13,14 @@
void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const { void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const {
if ((what & draw_as) != draw_as) return; // don't draw if ((what & draw_as) != draw_as) return; // don't draw
dc.SetFont(*font, scale); // text
// draw shadow
String text = content.substr(start - this->start, end - start); String text = content.substr(start - this->start, end - start);
if (!text.empty() && text.GetChar(text.size() - 1) == _('\n')) { if (!text.empty() && text.GetChar(text.size() - 1) == _('\n')) {
text = text.substr(0, text.size() - 1); // don't draw last \n text = text.substr(0, text.size() - 1); // don't draw last \n
} }
if (font->hasShadow()) {
dc.SetTextForeground(font->shadow_color);
dc.DrawText(text, rect.position() + font->shadow_displacement);
}
// draw // draw
dc.SetTextForeground(font->color); dc.SetFont(*font, scale);
dc.DrawText(text, rect.position()); dc.DrawTextWithShadow(text, *font, rect.position());
} }
void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const { void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const {
......
...@@ -12,27 +12,38 @@ ...@@ -12,27 +12,38 @@
// ----------------------------------------------------------------------------- : ChoiceValueViewer // ----------------------------------------------------------------------------- : ChoiceValueViewer
void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts);
bool ChoiceValueViewer::prepare(RotatedDC& dc) { bool ChoiceValueViewer::prepare(RotatedDC& dc) {
if (style().render_style & RENDER_IMAGE) { return prepare_choice_viewer(dc, viewer, style(), value().value());
style().initImage(); }
CachedScriptableImage& img = style().image; void ChoiceValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc);
if (style().render_style & RENDER_HIDDEN) return;
draw_choice_viewer(dc, viewer, style(), value().value());
}
bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value) {
if (style.render_style & RENDER_IMAGE) {
style.initImage();
CachedScriptableImage& img = style.image;
Context& ctx = viewer.getContext(); Context& ctx = viewer.getContext();
ctx.setVariable(SCRIPT_VAR_input, to_script(value().value())); ctx.setVariable(SCRIPT_VAR_input, to_script(value));
// generate to determine the size // generate to determine the size
if (img.update(ctx) && img.isReady()) { if (img.update(ctx) && img.isReady()) {
GeneratedImage::Options img_options; GeneratedImage::Options img_options;
getOptions(dc, img_options); get_options(dc, viewer, style, img_options);
// Generate image/bitmap (whichever is available) // Generate image/bitmap (whichever is available)
// don't worry, we cache the image // don't worry, we cache the image
ImageCombine combine = style().combine; ImageCombine combine = style.combine;
style().loadMask(*viewer.stylesheet); style.loadMask(*viewer.stylesheet);
Bitmap bitmap; Image image; Bitmap bitmap; Image image;
RealSize size; RealSize size;
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image, &size); img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size);
// store content properties // store content properties
if (style().content_width != size.width || style().content_height != size.height) { if (style.content_width != size.width || style.content_height != size.height) {
style().content_width = size.width; style.content_width = size.width;
style().content_height = size.height; style.content_height = size.height;
return true; return true;
} }
} }
...@@ -40,25 +51,23 @@ bool ChoiceValueViewer::prepare(RotatedDC& dc) { ...@@ -40,25 +51,23 @@ bool ChoiceValueViewer::prepare(RotatedDC& dc) {
return false; return false;
} }
void ChoiceValueViewer::draw(RotatedDC& dc) { void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value) {
drawFieldBorder(dc); if (value.empty()) return;
if (style().render_style & RENDER_HIDDEN) return;
if (value().value().empty()) return;
double margin = 0; double margin = 0;
if (style().render_style & RENDER_IMAGE) { if (style.render_style & RENDER_IMAGE) {
// draw image // draw image
CachedScriptableImage& img = style().image; CachedScriptableImage& img = style.image;
if (img.isReady()) { if (img.isReady()) {
GeneratedImage::Options img_options; GeneratedImage::Options img_options;
getOptions(dc, img_options); get_options(dc, viewer, style, img_options);
// Generate image/bitmap // Generate image/bitmap
ImageCombine combine = style().combine; ImageCombine combine = style.combine;
style().loadMask(*viewer.stylesheet); style.loadMask(*viewer.stylesheet);
Bitmap bitmap; Image image; Bitmap bitmap; Image image;
RealSize size; RealSize size;
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image, &size); img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size);
size = dc.trInvS(size); size = dc.trInvS(size);
RealRect rect(align_in_rect(style().alignment, size, dc.getInternalRect()), size); RealRect rect(align_in_rect(style.alignment, size, dc.getInternalRect()), size);
if (bitmap.Ok()) { if (bitmap.Ok()) {
// just draw it // just draw it
dc.DrawPreRotatedBitmap(bitmap,rect); dc.DrawPreRotatedBitmap(bitmap,rect);
...@@ -67,42 +76,36 @@ void ChoiceValueViewer::draw(RotatedDC& dc) { ...@@ -67,42 +76,36 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
dc.DrawPreRotatedImage(image,rect,combine); dc.DrawPreRotatedImage(image,rect,combine);
} }
margin = size.width + 1; margin = size.width + 1;
} else if (nativeLook()) { } else if (viewer.nativeLook()) {
// always have the margin // always have the margin
margin = 17; margin = 17;
} }
} }
if (style().render_style & RENDER_TEXT) { if (style.render_style & RENDER_TEXT) {
// draw text String text = tr(*viewer.stylesheet, value, capitalize(value));
dc.SetFont(style().font, 1.0); dc.SetFont(style.font, 1.0);
String text = tr(*viewer.stylesheet, value().value(), capitalize(value().value()));
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0); RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0);
if (style().font.hasShadow()) { dc.DrawTextWithShadow(text, style.font, pos);
dc.SetTextForeground(style().font.shadow_color);
dc.DrawText(text, pos + style().font.shadow_displacement);
}
dc.SetTextForeground(style().font.color());
dc.DrawText(text, pos);
} }
} }
void ChoiceValueViewer::onStyleChange(int changes) { void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts) {
if (changes & CHANGE_MASK) style().image.clearCache();
ValueViewer::onStyleChange(changes);
}
void ChoiceValueViewer::getOptions(Rotation& rot, GeneratedImage::Options& opts) {
opts.package = viewer.stylesheet.get(); opts.package = viewer.stylesheet.get();
opts.local_package = &getSet(); opts.local_package = viewer.getSet().get();
opts.angle = rot.trAngle(0); opts.angle = rot.trAngle(0);
if (nativeLook()) { if (viewer.nativeLook()) {
opts.width = opts.height = 16; opts.width = opts.height = 16;
opts.preserve_aspect = ASPECT_BORDER; opts.preserve_aspect = ASPECT_BORDER;
} else if(style().render_style & RENDER_TEXT) { } else if(style.render_style & RENDER_TEXT) {
// also drawing text, use original size // also drawing text, use original size
} else { } else {
opts.width = (int) rot.trX(style().width); opts.width = (int) rot.trX(style.width);
opts.height = (int) rot.trY(style().height); opts.height = (int) rot.trY(style.height);
opts.preserve_aspect = (style().alignment & ALIGN_STRETCH) ? ASPECT_STRETCH : ASPECT_FIT; opts.preserve_aspect = (style.alignment & ALIGN_STRETCH) ? ASPECT_STRETCH : ASPECT_FIT;
} }
} }
void ChoiceValueViewer::onStyleChange(int changes) {
if (changes & CHANGE_MASK) style().image.clearCache();
ValueViewer::onStyleChange(changes);
}
\ No newline at end of file
...@@ -23,9 +23,10 @@ class ChoiceValueViewer : public ValueViewer { ...@@ -23,9 +23,10 @@ class ChoiceValueViewer : public ValueViewer {
virtual bool prepare(RotatedDC& dc); virtual bool prepare(RotatedDC& dc);
virtual void draw(RotatedDC& dc); virtual void draw(RotatedDC& dc);
virtual void onStyleChange(int); virtual void onStyleChange(int);
private:
void getOptions(Rotation& rot, GeneratedImage::Options& opts);
}; };
bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value);
void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value);
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <render/value/multiple_choice.hpp> #include <render/value/multiple_choice.hpp>
#include <render/value/choice.hpp>
#include <render/card/viewer.hpp> #include <render/card/viewer.hpp>
#include <data/stylesheet.hpp> #include <data/stylesheet.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
...@@ -15,6 +16,11 @@ DECLARE_TYPEOF_COLLECTION(String); ...@@ -15,6 +16,11 @@ DECLARE_TYPEOF_COLLECTION(String);
// ----------------------------------------------------------------------------- : MultipleChoiceValueViewer // ----------------------------------------------------------------------------- : MultipleChoiceValueViewer
bool MultipleChoiceValueViewer::prepare(RotatedDC& dc) {
if (style().render_style & (RENDER_CHECKLIST | RENDER_LIST)) return false;
return prepare_choice_viewer(dc, viewer, style(), value().value());
}
void MultipleChoiceValueViewer::draw(RotatedDC& dc) { void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc); drawFieldBorder(dc);
if (style().render_style & RENDER_HIDDEN) return; if (style().render_style & RENDER_HIDDEN) return;
...@@ -38,44 +44,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) { ...@@ -38,44 +44,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
drawChoice(dc, pos, choice); drawChoice(dc, pos, choice);
} }
} else { } else {
// COPY FROM ChoiceValueViewer draw_choice_viewer(dc, viewer, style(), value().value());
if (value().value().empty()) return;
double margin = 0;
if (style().render_style & RENDER_IMAGE) {
// draw image
style().initImage();
CachedScriptableImage& img = style().image;
Context& ctx = viewer.getContext();
ctx.setVariable(SCRIPT_VAR_input, to_script(value().value()));
img.update(ctx);
if (img.isReady()) {
GeneratedImage::Options img_options;
getOptions(dc, img_options);
// Generate image/bitmap
ImageCombine combine = style().combine;
style().loadMask(*viewer.stylesheet);
Bitmap bitmap; Image image;
RealSize size;
img.generateCached(img_options, &style().mask, &combine, &bitmap, &image, &size);
size = dc.trInvS(size);
RealRect rect(align_in_rect(style().alignment, size, dc.getInternalRect()), size);
if (bitmap.Ok()) {
// just draw it
dc.DrawPreRotatedBitmap(bitmap,rect);
} else {
// use combine mode
dc.DrawPreRotatedImage(image,rect,combine);
}
margin = size.width + 1;
}
}
if (style().render_style & RENDER_TEXT) {
// draw text
dc.DrawText(tr(*viewer.stylesheet, value().value(), capitalize(value().value())),
align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0)
);
}
// COPY ENDS HERE
} }
} }
...@@ -111,20 +80,3 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const ...@@ -111,20 +80,3 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
// next position // next position
pos = move_in_direction(style().direction, pos, size, style().spacing); pos = move_in_direction(style().direction, pos, size, style().spacing);
} }
// COPY from ChoiceValueViewer
void MultipleChoiceValueViewer::getOptions(Rotation& rot, GeneratedImage::Options& opts) {
opts.package = viewer.stylesheet.get();
opts.local_package = &getSet();
opts.angle = rot.trAngle(0); //%%
if (nativeLook()) {
opts.width = opts.height = 16;
opts.preserve_aspect = ASPECT_BORDER;
} else if(style().render_style & RENDER_TEXT) {
// also drawing text, use original size
} else {
opts.width = (int) rot.trX(style().width);
opts.height = (int) rot.trY(style().height);
opts.preserve_aspect = (style().alignment & ALIGN_STRETCH) ? ASPECT_STRETCH : ASPECT_FIT;
}
}
...@@ -20,12 +20,12 @@ class MultipleChoiceValueViewer : public ValueViewer { ...@@ -20,12 +20,12 @@ class MultipleChoiceValueViewer : public ValueViewer {
public: public:
DECLARE_VALUE_VIEWER(MultipleChoice) : ValueViewer(parent,style), item_height(0) {} DECLARE_VALUE_VIEWER(MultipleChoice) : ValueViewer(parent,style), item_height(0) {}
virtual bool prepare(RotatedDC& dc);
virtual void draw(RotatedDC& dc); virtual void draw(RotatedDC& dc);
protected: protected:
double item_height; ///< Height of a single item, or 0 if non uniform double item_height; ///< Height of a single item, or 0 if non uniform
private: private:
void drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active = true); void drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active = true);
void getOptions(Rotation& rot, GeneratedImage::Options& opts);
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -216,6 +216,15 @@ void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_ra ...@@ -216,6 +216,15 @@ void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_ra
} }
} }
void RotatedDC::DrawTextWithShadow(const String& text, const Font& font, const RealPoint& pos, double scale, double stretch) {
if (font.hasShadow()) {
SetTextForeground(font.shadow_color);
DrawText(text, pos + font.shadow_displacement * scale, 0, 1, stretch);
}
SetTextForeground(font.color);
DrawText(text, pos, 0, 1, stretch);
}
void RotatedDC::DrawBitmap(const Bitmap& bitmap, const RealPoint& pos) { void RotatedDC::DrawBitmap(const Bitmap& bitmap, const RealPoint& pos) {
if (angle == 0) { if (angle == 0) {
RealPoint p_ext = tr(pos); RealPoint p_ext = tr(pos);
......
...@@ -163,7 +163,10 @@ class RotatedDC : public Rotation { ...@@ -163,7 +163,10 @@ class RotatedDC : public Rotation {
// --------------------------------------------------- : Drawing // --------------------------------------------------- : Drawing
/// Draw text
void DrawText (const String& text, const RealPoint& pos, int blur_radius = 0, int boldness = 1, double stretch = 1.0); void DrawText (const String& text, const RealPoint& pos, int blur_radius = 0, int boldness = 1, double stretch = 1.0);
/// Draw text with the shadow and color settings of the given font
void DrawTextWithShadow(const String& text, const Font& font, const RealPoint& pos, double scale = 1.0, double stretch = 1.0);
/// Draw abitmap, it must already be zoomed! /// Draw abitmap, it must already be zoomed!
void DrawBitmap(const Bitmap& bitmap, const RealPoint& pos); void DrawBitmap(const Bitmap& bitmap, const RealPoint& pos);
/// Draw an image using the given combining mode, the image must already be zoomed! /// Draw an image using the given combining mode, the image must already be zoomed!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment