mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
add store_in_metadata image style property
This commit is contained in:
+27
-14
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <data/field.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <script/scriptable.hpp>
|
||||
#include <script/image.hpp>
|
||||
#include <util/io/package.hpp>
|
||||
@@ -30,19 +31,6 @@ public:
|
||||
DECLARE_FIELD_TYPE(Image);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageStyle
|
||||
|
||||
/// The Style for a ImageField
|
||||
class ImageStyle : public Style {
|
||||
public:
|
||||
inline ImageStyle(const ImageFieldP& field) : Style(field) {}
|
||||
DECLARE_STYLE_TYPE(Image);
|
||||
|
||||
ScriptableImage default_image; ///< Placeholder
|
||||
|
||||
int update(Context&) override;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageValue
|
||||
|
||||
/// The Value in a ImageField, i.e. an image
|
||||
@@ -50,8 +38,33 @@ class ImageValue : public Value {
|
||||
public:
|
||||
inline ImageValue(const ImageFieldP& field) : Value(field) {}
|
||||
DECLARE_VALUE_TYPE(Image, LocalFileName);
|
||||
|
||||
|
||||
ValueType filename; ///< Filename of the image (in the current package), or ""
|
||||
Age last_update; ///< When was the image last changed?
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageStyle
|
||||
|
||||
/// The Style for an ImageField
|
||||
class ImageStyle : public Style {
|
||||
public:
|
||||
inline ImageStyle(const ImageFieldP& field) : Style(field), store_in_metadata(false) {}
|
||||
DECLARE_STYLE_TYPE(Image);
|
||||
|
||||
ScriptableImage default_image; ///< Placeholder image when the user hasn't set one.
|
||||
Scriptable<bool> store_in_metadata; ///< Is the image stored in full in the metadata when exporting?
|
||||
|
||||
int update(Context&) override;
|
||||
|
||||
inline std::string getExternalImageString(const SetP& set, ImageValue* value) { ///< update the style before calling this
|
||||
auto imageInputStream = set->openIn(value->filename);
|
||||
Image img(*imageInputStream, wxBITMAP_TYPE_PNG);
|
||||
if (!img.IsOk()) throw ScriptError(_ERROR_2_("file not found", value->filename.toStringForKey(), set));
|
||||
String temppath = wxFileName::CreateTempFileName(_("mse")) + _(".png");
|
||||
img.SaveFile(temppath);
|
||||
std::string s = "<mse-image-data>" + fileToUTF8(temppath.ToStdString()) + "</mse-image-data>";
|
||||
wxRemoveFile(temppath);
|
||||
wxRemoveFile(temppath.substr(0, temppath.size() - 4));
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user