mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
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:
+10
-1
@@ -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) \
|
||||
|
||||
@@ -25,9 +25,6 @@ class BooleanField : public ChoiceField {
|
||||
DECLARE_FIELD_TYPE(Boolean);
|
||||
|
||||
// no extra data
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : BooleanStyle
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
+23
-15
@@ -87,6 +87,7 @@
|
||||
Optimization="2"
|
||||
GlobalOptimizations="TRUE"
|
||||
InlineFunctionExpansion="1"
|
||||
ImproveFloatingPointConsistency="TRUE"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="0"
|
||||
OptimizeForWindowsApplication="TRUE"
|
||||
@@ -225,6 +226,7 @@
|
||||
Optimization="3"
|
||||
GlobalOptimizations="TRUE"
|
||||
InlineFunctionExpansion="1"
|
||||
ImproveFloatingPointConsistency="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="3"
|
||||
@@ -300,6 +302,7 @@
|
||||
Optimization="3"
|
||||
GlobalOptimizations="TRUE"
|
||||
InlineFunctionExpansion="1"
|
||||
ImproveFloatingPointConsistency="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="3"
|
||||
@@ -375,6 +378,7 @@
|
||||
Optimization="3"
|
||||
GlobalOptimizations="TRUE"
|
||||
InlineFunctionExpansion="1"
|
||||
ImproveFloatingPointConsistency="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="3"
|
||||
@@ -2172,12 +2176,6 @@
|
||||
<Filter
|
||||
Name="base"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\util\atomic.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\util\dynamic_arg.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\util\error.cpp">
|
||||
</File>
|
||||
@@ -2187,9 +2185,6 @@
|
||||
<File
|
||||
RelativePath=".\util\for_each.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\util\order_cache.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\util\platform.hpp">
|
||||
</File>
|
||||
@@ -2208,12 +2203,6 @@
|
||||
<File
|
||||
RelativePath=".\util\smart_ptr.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\util\spec_sort.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\util\spec_sort.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\util\string.cpp">
|
||||
<FileConfiguration
|
||||
@@ -2253,6 +2242,25 @@
|
||||
<File
|
||||
RelativePath=".\util\window_id.hpp">
|
||||
</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
|
||||
|
||||
@@ -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 {
|
||||
if ((what & draw_as) != draw_as) return; // don't draw
|
||||
dc.SetFont(*font, scale);
|
||||
// draw shadow
|
||||
// text
|
||||
String text = content.substr(start - this->start, end - start);
|
||||
if (!text.empty() && text.GetChar(text.size() - 1) == _('\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
|
||||
dc.SetTextForeground(font->color);
|
||||
dc.DrawText(text, rect.position());
|
||||
dc.SetFont(*font, scale);
|
||||
dc.DrawTextWithShadow(text, *font, rect.position());
|
||||
}
|
||||
|
||||
void FontTextElement::getCharInfo(RotatedDC& dc, double scale, vector<CharInfo>& out) const {
|
||||
|
||||
+53
-50
@@ -12,27 +12,38 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : ChoiceValueViewer
|
||||
|
||||
void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts);
|
||||
|
||||
bool ChoiceValueViewer::prepare(RotatedDC& dc) {
|
||||
if (style().render_style & RENDER_IMAGE) {
|
||||
style().initImage();
|
||||
CachedScriptableImage& img = style().image;
|
||||
return prepare_choice_viewer(dc, viewer, style(), value().value());
|
||||
}
|
||||
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();
|
||||
ctx.setVariable(SCRIPT_VAR_input, to_script(value().value()));
|
||||
ctx.setVariable(SCRIPT_VAR_input, to_script(value));
|
||||
// generate to determine the size
|
||||
if (img.update(ctx) && img.isReady()) {
|
||||
GeneratedImage::Options img_options;
|
||||
getOptions(dc, img_options);
|
||||
get_options(dc, viewer, style, img_options);
|
||||
// Generate image/bitmap (whichever is available)
|
||||
// don't worry, we cache the image
|
||||
ImageCombine combine = style().combine;
|
||||
style().loadMask(*viewer.stylesheet);
|
||||
ImageCombine combine = style.combine;
|
||||
style.loadMask(*viewer.stylesheet);
|
||||
Bitmap bitmap; Image image;
|
||||
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
|
||||
if (style().content_width != size.width || style().content_height != size.height) {
|
||||
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_height = size.height;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -40,25 +51,23 @@ bool ChoiceValueViewer::prepare(RotatedDC& dc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
if (style().render_style & RENDER_HIDDEN) return;
|
||||
if (value().value().empty()) return;
|
||||
void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value) {
|
||||
if (value.empty()) return;
|
||||
double margin = 0;
|
||||
if (style().render_style & RENDER_IMAGE) {
|
||||
if (style.render_style & RENDER_IMAGE) {
|
||||
// draw image
|
||||
CachedScriptableImage& img = style().image;
|
||||
CachedScriptableImage& img = style.image;
|
||||
if (img.isReady()) {
|
||||
GeneratedImage::Options img_options;
|
||||
getOptions(dc, img_options);
|
||||
get_options(dc, viewer, style, img_options);
|
||||
// Generate image/bitmap
|
||||
ImageCombine combine = style().combine;
|
||||
style().loadMask(*viewer.stylesheet);
|
||||
ImageCombine combine = style.combine;
|
||||
style.loadMask(*viewer.stylesheet);
|
||||
Bitmap bitmap; Image image;
|
||||
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);
|
||||
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()) {
|
||||
// just draw it
|
||||
dc.DrawPreRotatedBitmap(bitmap,rect);
|
||||
@@ -67,42 +76,36 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
dc.DrawPreRotatedImage(image,rect,combine);
|
||||
}
|
||||
margin = size.width + 1;
|
||||
} else if (nativeLook()) {
|
||||
} else if (viewer.nativeLook()) {
|
||||
// always have the margin
|
||||
margin = 17;
|
||||
}
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
// draw text
|
||||
dc.SetFont(style().font, 1.0);
|
||||
String text = tr(*viewer.stylesheet, value().value(), capitalize(value().value()));
|
||||
if (style.render_style & RENDER_TEXT) {
|
||||
String text = tr(*viewer.stylesheet, value, capitalize(value));
|
||||
dc.SetFont(style.font, 1.0);
|
||||
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0);
|
||||
if (style().font.hasShadow()) {
|
||||
dc.SetTextForeground(style().font.shadow_color);
|
||||
dc.DrawText(text, pos + style().font.shadow_displacement);
|
||||
}
|
||||
dc.SetTextForeground(style().font.color());
|
||||
dc.DrawText(text, pos);
|
||||
dc.DrawTextWithShadow(text, style.font, pos);
|
||||
}
|
||||
}
|
||||
|
||||
void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts) {
|
||||
opts.package = viewer.stylesheet.get();
|
||||
opts.local_package = viewer.getSet().get();
|
||||
opts.angle = rot.trAngle(0);
|
||||
if (viewer.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;
|
||||
}
|
||||
}
|
||||
|
||||
void ChoiceValueViewer::onStyleChange(int changes) {
|
||||
if (changes & CHANGE_MASK) style().image.clearCache();
|
||||
ValueViewer::onStyleChange(changes);
|
||||
}
|
||||
|
||||
void ChoiceValueViewer::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,10 @@ class ChoiceValueViewer : public ValueViewer {
|
||||
virtual bool prepare(RotatedDC& dc);
|
||||
virtual void draw(RotatedDC& dc);
|
||||
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
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <render/value/multiple_choice.hpp>
|
||||
#include <render/value/choice.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <gui/util.hpp>
|
||||
@@ -15,6 +16,11 @@ DECLARE_TYPEOF_COLLECTION(String);
|
||||
|
||||
// ----------------------------------------------------------------------------- : 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) {
|
||||
drawFieldBorder(dc);
|
||||
if (style().render_style & RENDER_HIDDEN) return;
|
||||
@@ -38,44 +44,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
drawChoice(dc, pos, choice);
|
||||
}
|
||||
} else {
|
||||
// COPY FROM ChoiceValueViewer
|
||||
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
|
||||
draw_choice_viewer(dc, viewer, style(), value().value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,20 +80,3 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
// next position
|
||||
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 {
|
||||
public:
|
||||
DECLARE_VALUE_VIEWER(MultipleChoice) : ValueViewer(parent,style), item_height(0) {}
|
||||
|
||||
virtual bool prepare(RotatedDC& dc);
|
||||
virtual void draw(RotatedDC& dc);
|
||||
protected:
|
||||
double item_height; ///< Height of a single item, or 0 if non uniform
|
||||
private:
|
||||
void drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active = true);
|
||||
void getOptions(Rotation& rot, GeneratedImage::Options& opts);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -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) {
|
||||
if (angle == 0) {
|
||||
RealPoint p_ext = tr(pos);
|
||||
|
||||
@@ -163,7 +163,10 @@ class RotatedDC : public Rotation {
|
||||
|
||||
// --------------------------------------------------- : Drawing
|
||||
|
||||
/// Draw text
|
||||
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!
|
||||
void DrawBitmap(const Bitmap& bitmap, const RealPoint& pos);
|
||||
/// Draw an image using the given combining mode, the image must already be zoomed!
|
||||
|
||||
Reference in New Issue
Block a user