mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Images are now cached as wxBitmap, not wxImage. This should improve performance.
Fixed some more corner cases of rotation+zoom. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@630 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+3
-3
@@ -120,7 +120,7 @@ template <> StyleP read_new<Style>(Reader&) {
|
||||
throw InternalError(_("IndexMap contains nullptr StyleP the application should have crashed already"));
|
||||
}
|
||||
|
||||
bool Style::update(Context& ctx) {
|
||||
int Style::update(Context& ctx) {
|
||||
bool changed =
|
||||
left .update(ctx)
|
||||
| width .update(ctx)
|
||||
@@ -196,8 +196,8 @@ void Style::removeListener(StyleListener* listener) {
|
||||
listeners.end()
|
||||
);
|
||||
}
|
||||
void Style::tellListeners(bool already_prepared) {
|
||||
FOR_EACH(l, listeners) l->onStyleChange(already_prepared);
|
||||
void Style::tellListeners(int changes) {
|
||||
FOR_EACH(l, listeners) l->onStyleChange(changes);
|
||||
}
|
||||
|
||||
StyleListener::StyleListener(const StyleP& style)
|
||||
|
||||
+18
-6
@@ -119,9 +119,11 @@ class Style : public IntrusivePtrVirtualBase {
|
||||
/** thisP is a smart pointer to this */
|
||||
virtual ValueViewerP makeEditor(DataEditor& parent, const StyleP& thisP) = 0;
|
||||
|
||||
/// Update scripted values of this style, return true if anything has changed.
|
||||
/** The caller should tellListeners() */
|
||||
virtual bool update(Context&);
|
||||
/// Update scripted values of this style, return nonzero if anything has changed.
|
||||
/** The caller should tellListeners()
|
||||
* The result is a combination of StyleChange flags
|
||||
*/
|
||||
virtual int update(Context&);
|
||||
/// Add the given dependency to the dependent_scripts list for the variables this style depends on
|
||||
/** Only use for things that need invalidate() */
|
||||
virtual void initDependencies(Context&, const Dependency&) const;
|
||||
@@ -140,7 +142,8 @@ class Style : public IntrusivePtrVirtualBase {
|
||||
/// Remove a StyleListener
|
||||
void removeListener(StyleListener*);
|
||||
/// Tell the StyleListeners that this style has changed
|
||||
void tellListeners(bool already_prepared);
|
||||
/** change_info is a subset of StyleChange flags */
|
||||
void tellListeners(int changes);
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION_VIRTUAL();
|
||||
@@ -148,6 +151,15 @@ class Style : public IntrusivePtrVirtualBase {
|
||||
vector<StyleListener*> listeners;
|
||||
};
|
||||
|
||||
/// What changed in a style update?
|
||||
enum StyleChange
|
||||
{ CHANGE_NONE = 0x00 // nothing changed
|
||||
, CHANGE_OTHER = 0x01 // some other change (note: result of casting from bool)
|
||||
, CHANGE_DEFAULT = 0x02 // only the 'default' state is affected
|
||||
, CHANGE_MASK = 0x04 // a mask image changed, must be reloaded
|
||||
, CHANGE_ALREADY_PREPARED = 0x80 // hint that the change was the result of a content property change, viewers are already prepared
|
||||
};
|
||||
|
||||
void init_object(const FieldP&, StyleP&);
|
||||
inline const FieldP& get_key (const StyleP& s) { return s->fieldP; }
|
||||
inline const String& get_key_name(const StyleP& s) { return s->fieldP->name; }
|
||||
@@ -168,8 +180,8 @@ class StyleListener : public IntrusivePtrVirtualBase {
|
||||
virtual ~StyleListener();
|
||||
|
||||
/// Called when a (scripted) property of the viewed style has changed
|
||||
/** already_prepared indicates that this change happend after preparing text for content properties */
|
||||
virtual void onStyleChange(bool already_prepared) {}
|
||||
/** changes is a combination of StyleChange flags */
|
||||
virtual void onStyleChange(int changes) {}
|
||||
protected:
|
||||
const StyleP styleP; ///< The style we are listening to
|
||||
};
|
||||
|
||||
@@ -216,17 +216,17 @@ void ChoiceStyle::initImage() {
|
||||
script.addInstruction(I_RET);
|
||||
}
|
||||
|
||||
bool ChoiceStyle::update(Context& ctx) {
|
||||
int ChoiceStyle::update(Context& ctx) {
|
||||
// Don't update the choice images, leave that to invalidate()
|
||||
bool change = Style ::update(ctx)
|
||||
| font .update(ctx)
|
||||
| mask_filename.update(ctx);
|
||||
int change = Style ::update(ctx)
|
||||
| font .update(ctx) * CHANGE_OTHER
|
||||
| mask_filename.update(ctx) * CHANGE_MASK;
|
||||
if (!choice_images_initialized) {
|
||||
// we only want to do this once because it is rather slow, other updates are handled by dependencies
|
||||
choice_images_initialized = true;
|
||||
FOR_EACH(ci, choice_images) {
|
||||
if (ci.second.update(ctx)) {
|
||||
change = true;
|
||||
change |= CHANGE_OTHER;
|
||||
// TODO : remove this thumbnail
|
||||
}
|
||||
}
|
||||
@@ -253,7 +253,7 @@ void ChoiceStyle::invalidate(Context& ctx) {
|
||||
thumbnails_status[i] = THUMB_CHANGED;
|
||||
}
|
||||
}
|
||||
if (change) tellListeners(false);
|
||||
if (change) tellListeners(CHANGE_OTHER);
|
||||
}
|
||||
|
||||
void ChoiceStyle::loadMask(Package& pkg) {
|
||||
|
||||
@@ -145,7 +145,7 @@ class ChoiceStyle : public Style {
|
||||
ChoicePopupStyle popup_style; ///< Style of popups/menus
|
||||
ChoiceRenderStyle render_style; ///< Style of rendering
|
||||
Font font; ///< Font for drawing text (when RENDER_TEXT)
|
||||
ScriptableImage image; ///< Image to draw (when RENDER_IMAGE)
|
||||
CachedScriptableImage image; ///< Image to draw (when RENDER_IMAGE)
|
||||
map<String,ScriptableImage> choice_images; ///< Images for the various choices (when RENDER_IMAGE)
|
||||
bool choice_images_initialized;
|
||||
Scriptable<String> mask_filename; ///< Filename of an additional mask over the images
|
||||
@@ -163,7 +163,7 @@ class ChoiceStyle : public Style {
|
||||
/// Initialize image from choice_images
|
||||
void initImage();
|
||||
|
||||
virtual bool update(Context&);
|
||||
virtual int update(Context&);
|
||||
virtual void initDependencies(Context&, const Dependency&) const;
|
||||
virtual void invalidate(Context&);
|
||||
|
||||
|
||||
@@ -67,9 +67,9 @@ IMPLEMENT_REFLECTION(ColorStyle) {
|
||||
REFLECT_N("mask", mask_filename);
|
||||
}
|
||||
|
||||
bool ColorStyle::update(Context& ctx) {
|
||||
int ColorStyle::update(Context& ctx) {
|
||||
return Style ::update(ctx)
|
||||
| mask_filename.update(ctx);
|
||||
| mask_filename.update(ctx) * CHANGE_MASK;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ColorValue
|
||||
|
||||
@@ -66,7 +66,7 @@ class ColorStyle : public Style {
|
||||
double bottom_width; ///< Width of the colored region on the bottom side
|
||||
Scriptable<String> mask_filename; ///< Filename of an additional mask over the images
|
||||
|
||||
virtual bool update(Context&);
|
||||
virtual int update(Context&);
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
|
||||
@@ -25,14 +25,16 @@ IMPLEMENT_REFLECTION(ImageField) {
|
||||
|
||||
IMPLEMENT_REFLECTION(ImageStyle) {
|
||||
REFLECT_BASE(Style);
|
||||
REFLECT(angle);
|
||||
REFLECT_N("mask", mask_filename);
|
||||
REFLECT_N("default", default_image);
|
||||
}
|
||||
|
||||
bool ImageStyle::update(Context& ctx) {
|
||||
int ImageStyle::update(Context& ctx) {
|
||||
return Style ::update(ctx)
|
||||
| mask_filename.update(ctx)
|
||||
| default_image.update(ctx);
|
||||
| angle .update(ctx) * CHANGE_OTHER
|
||||
| mask_filename.update(ctx) * CHANGE_MASK
|
||||
| default_image.update(ctx) * CHANGE_DEFAULT;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageValue
|
||||
|
||||
@@ -38,10 +38,11 @@ class ImageStyle : public Style {
|
||||
inline ImageStyle(const ImageFieldP& field) : Style(field) {}
|
||||
DECLARE_STYLE_TYPE(Image);
|
||||
|
||||
Scriptable<int> angle; ///< Rotation of images
|
||||
Scriptable<String> mask_filename; ///< Filename for a mask image
|
||||
ScriptableImage default_image; ///< Placeholder
|
||||
|
||||
virtual bool update(Context&);
|
||||
virtual int update(Context&);
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
|
||||
@@ -40,9 +40,9 @@ InfoStyle::InfoStyle(const InfoFieldP& field)
|
||||
, background_color(255,255,255)
|
||||
{}
|
||||
|
||||
bool InfoStyle::update(Context& ctx) {
|
||||
int InfoStyle::update(Context& ctx) {
|
||||
return Style ::update(ctx)
|
||||
| font .update(ctx);
|
||||
| font .update(ctx) * CHANGE_OTHER;
|
||||
}
|
||||
void InfoStyle::initDependencies(Context& ctx, const Dependency& dep) const {
|
||||
Style ::initDependencies(ctx, dep);
|
||||
|
||||
@@ -51,7 +51,7 @@ class InfoStyle : public Style {
|
||||
double padding_top, padding_bottom;
|
||||
Color background_color;
|
||||
|
||||
virtual bool update(Context&);
|
||||
virtual int update(Context&);
|
||||
virtual void initDependencies(Context&, const Dependency&) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -68,12 +68,12 @@ double TextStyle::getStretch() const {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
bool TextStyle::update(Context& ctx) {
|
||||
int TextStyle::update(Context& ctx) {
|
||||
return Style ::update(ctx)
|
||||
| font .update(ctx)
|
||||
| symbol_font.update(ctx)
|
||||
| alignment .update(ctx)
|
||||
| angle .update(ctx);
|
||||
| font .update(ctx) * CHANGE_OTHER
|
||||
| symbol_font.update(ctx) * CHANGE_OTHER
|
||||
| alignment .update(ctx) * CHANGE_OTHER
|
||||
| angle .update(ctx) * CHANGE_OTHER;
|
||||
}
|
||||
void TextStyle::initDependencies(Context& ctx, const Dependency& dep) const {
|
||||
Style ::initDependencies(ctx, dep);
|
||||
|
||||
@@ -75,7 +75,7 @@ class TextStyle : public Style {
|
||||
double content_width, content_height; ///< Size of the rendered text
|
||||
int content_lines; ///< Number of rendered lines
|
||||
|
||||
virtual bool update(Context&);
|
||||
virtual int update(Context&);
|
||||
virtual void initDependencies(Context&, const Dependency&) const;
|
||||
virtual void checkContentDependencies(Context&, const Dependency&) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user