mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
support for masks in choice styles
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@148 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
// ----------------------------------------------------------------------------- : Includes
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
#include <data/field/choice.hpp>
|
#include <data/field/choice.hpp>
|
||||||
|
#include <util/io/package.hpp>
|
||||||
|
|
||||||
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
|
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
|
||||||
typedef map<String,ScriptableImage> map_String_ScriptableImage;
|
typedef map<String,ScriptableImage> map_String_ScriptableImage;
|
||||||
@@ -185,6 +186,13 @@ void ChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChoiceStyle::loadMask(Package& pkg) {
|
||||||
|
if (mask.Ok() || mask_filename.empty()) return;
|
||||||
|
// load file
|
||||||
|
InputStreamP image_file = pkg.openIn(mask_filename);
|
||||||
|
mask.LoadFile(*image_file);
|
||||||
|
}
|
||||||
|
|
||||||
IMPLEMENT_REFLECTION_ENUM(ChoicePopupStyle) {
|
IMPLEMENT_REFLECTION_ENUM(ChoicePopupStyle) {
|
||||||
VALUE_N("dropdown", POPUP_DROPDOWN);
|
VALUE_N("dropdown", POPUP_DROPDOWN);
|
||||||
VALUE_N("menu", POPUP_MENU);
|
VALUE_N("menu", POPUP_MENU);
|
||||||
@@ -204,7 +212,7 @@ IMPLEMENT_REFLECTION(ChoiceStyle) {
|
|||||||
REFLECT_BASE(Style);
|
REFLECT_BASE(Style);
|
||||||
REFLECT(popup_style);
|
REFLECT(popup_style);
|
||||||
REFLECT(render_style);
|
REFLECT(render_style);
|
||||||
REFLECT_N("maks",mask_filename);
|
REFLECT_N("mask",mask_filename);
|
||||||
REFLECT(combine);
|
REFLECT(combine);
|
||||||
REFLECT(alignment);
|
REFLECT(alignment);
|
||||||
REFLECT(colors_card_list);
|
REFLECT(colors_card_list);
|
||||||
|
|||||||
@@ -125,6 +125,10 @@ class ChoiceStyle : public Style {
|
|||||||
String mask_filename; ///< Filename of an additional mask over the images
|
String mask_filename; ///< Filename of an additional mask over the images
|
||||||
ImageCombine combine; ///< Combining mode for drawing the images
|
ImageCombine combine; ///< Combining mode for drawing the images
|
||||||
Alignment alignment; ///< Alignment of images
|
Alignment alignment; ///< Alignment of images
|
||||||
|
Image mask; ///< The actual mask image
|
||||||
|
|
||||||
|
/// Load the mask image, if it's not already done
|
||||||
|
void loadMask(Package& pkg);
|
||||||
|
|
||||||
virtual bool update(Context&);
|
virtual bool update(Context&);
|
||||||
virtual void initDependencies(Context&, const Dependency&) const;
|
virtual void initDependencies(Context&, const Dependency&) const;
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ String TextValue::toString() const {
|
|||||||
}
|
}
|
||||||
bool TextValue::update(Context& ctx) {
|
bool TextValue::update(Context& ctx) {
|
||||||
Value::update(ctx);
|
Value::update(ctx);
|
||||||
WITH_DYNAMIC_ARG(last_update_age, last_update.get());
|
WITH_DYNAMIC_ARG(last_update_age, value.isDefault() ? 0 : last_update.get());
|
||||||
bool change = field().default_script.invokeOnDefault(ctx, value)
|
bool change = field().default_script.invokeOnDefault(ctx, value)
|
||||||
| field(). script.invokeOn(ctx, value);
|
| field(). script.invokeOn(ctx, value);
|
||||||
if (change) last_update.update();
|
if (change) last_update.update();
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ void mask_blend(Image& img1, const Image& img2, const Image& mask) {
|
|||||||
|
|
||||||
void set_alpha(Image& img, const Image& img_alpha) {
|
void set_alpha(Image& img, const Image& img_alpha) {
|
||||||
if (img.GetWidth() != img_alpha.GetWidth() || img.GetHeight() != img_alpha.GetHeight()) {
|
if (img.GetWidth() != img_alpha.GetWidth() || img.GetHeight() != img_alpha.GetHeight()) {
|
||||||
throw InternalError(_("Image used with maks must have same size as mask"));
|
throw Error(_("Image must have same size as mask"));
|
||||||
}
|
}
|
||||||
if (!img.HasAlpha()) img.InitAlpha();
|
if (!img.HasAlpha()) img.InitAlpha();
|
||||||
Byte *im = img.GetAlpha(), *al = img_alpha.GetData();
|
Byte *im = img.GetAlpha(), *al = img_alpha.GetData();
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (i) {
|
if (i) {
|
||||||
|
// apply mask?
|
||||||
|
style().loadMask(*viewer.stylesheet);
|
||||||
|
if (style().mask.Ok()) {
|
||||||
|
set_alpha(i->image, style().mask);
|
||||||
|
}
|
||||||
|
// draw
|
||||||
dc.DrawImage(i->image,
|
dc.DrawImage(i->image,
|
||||||
align_in_rect(style().alignment, RealSize(i->image.GetWidth(), i->image.GetHeight()), style().getRect()),
|
align_in_rect(style().alignment, RealSize(i->image.GetWidth(), i->image.GetHeight()), style().getRect()),
|
||||||
i->combine == COMBINE_NORMAL ? style().combine : i->combine
|
i->combine == COMBINE_NORMAL ? style().combine : i->combine
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_ValueP);
|
|||||||
void init_script_functions(Context& ctx);
|
void init_script_functions(Context& ctx);
|
||||||
void init_script_image_functions(Context& ctx);
|
void init_script_image_functions(Context& ctx);
|
||||||
|
|
||||||
#define LOG_UPDATES
|
//#define LOG_UPDATES
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : SetScriptContext : initialization
|
// ----------------------------------------------------------------------------- : SetScriptContext : initialization
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user