mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
Scripts depending on content_something are re-updating after updating the content properties
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@480 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+2
-2
@@ -53,8 +53,8 @@ Context& Set::getContext(const CardP& card) {
|
|||||||
assert(wxThread::IsMain());
|
assert(wxThread::IsMain());
|
||||||
return script_manager->getContext(card);
|
return script_manager->getContext(card);
|
||||||
}
|
}
|
||||||
void Set::updateStyles(const CardP& card) {
|
void Set::updateStyles(const CardP& card, bool only_content_dependent) {
|
||||||
script_manager->updateStyles(card);
|
script_manager->updateStyles(card, only_content_dependent);
|
||||||
}
|
}
|
||||||
void Set::updateDelayed() {
|
void Set::updateDelayed() {
|
||||||
script_manager->updateDelayed();
|
script_manager->updateDelayed();
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ class Set : public Packaged {
|
|||||||
/** Should only be used from the main thread! */
|
/** Should only be used from the main thread! */
|
||||||
Context& getContext(const CardP& card);
|
Context& getContext(const CardP& card);
|
||||||
/// Update styles and extra_card_fields for a card
|
/// Update styles and extra_card_fields for a card
|
||||||
void updateStyles(const CardP& card);
|
void updateStyles(const CardP& card, bool only_content_dependent);
|
||||||
/// Update scripts that were delayed
|
/// Update scripts that were delayed
|
||||||
void updateDelayed();
|
void updateDelayed();
|
||||||
/// A context for performing scripts
|
/// A context for performing scripts
|
||||||
|
|||||||
+27
-15
@@ -40,30 +40,23 @@ void DataViewer::draw(RotatedDC& dc, const Color& background) {
|
|||||||
// fill with background color
|
// fill with background color
|
||||||
clearDC(dc.getDC(), background);
|
clearDC(dc.getDC(), background);
|
||||||
// update style scripts
|
// update style scripts
|
||||||
try {
|
updateStyles(false);
|
||||||
if (card) {
|
|
||||||
set->updateStyles(card);
|
|
||||||
} else {
|
|
||||||
Context& ctx = getContext();
|
|
||||||
FOR_EACH(v, viewers) {
|
|
||||||
if (v->getStyle()->update(ctx)) {
|
|
||||||
v->getStyle()->tellListeners();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (const Error& e) {
|
|
||||||
handle_error(e, false, false);
|
|
||||||
}
|
|
||||||
// prepare viewers
|
// prepare viewers
|
||||||
|
bool changed_content_properties = false;
|
||||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||||
if (v->getStyle()->visible) {
|
if (v->getStyle()->visible) {
|
||||||
try {
|
try {
|
||||||
v->prepare(dc);
|
if (v->prepare(dc)) {
|
||||||
|
changed_content_properties = true;
|
||||||
|
}
|
||||||
} catch (const Error& e) {
|
} catch (const Error& e) {
|
||||||
handle_error(e, false, false);
|
handle_error(e, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (changed_content_properties) {
|
||||||
|
updateStyles(true);
|
||||||
|
}
|
||||||
// draw viewers
|
// draw viewers
|
||||||
FOR_EACH(v, viewers) { // draw low z index fields first
|
FOR_EACH(v, viewers) { // draw low z index fields first
|
||||||
if (v->getStyle()->visible) {// visible
|
if (v->getStyle()->visible) {// visible
|
||||||
@@ -80,6 +73,25 @@ void DataViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
|||||||
v.draw(dc);
|
v.draw(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataViewer::updateStyles(bool only_content_dependent) {
|
||||||
|
try {
|
||||||
|
if (card) {
|
||||||
|
set->updateStyles(card, only_content_dependent);
|
||||||
|
} else {
|
||||||
|
Context& ctx = getContext();
|
||||||
|
FOR_EACH(v, viewers) {
|
||||||
|
Style& s = *v->getStyle();
|
||||||
|
if (only_content_dependent && !s.content_dependent) continue;
|
||||||
|
if (s.update(ctx)) {
|
||||||
|
s.tellListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const Error& e) {
|
||||||
|
handle_error(e, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Utility for ValueViewers
|
// ----------------------------------------------------------------------------- : Utility for ValueViewers
|
||||||
|
|
||||||
bool DataViewer::nativeLook() const { return false; }
|
bool DataViewer::nativeLook() const { return false; }
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ class DataViewer : public SetView {
|
|||||||
private:
|
private:
|
||||||
/// Create some viewers for the given styles
|
/// Create some viewers for the given styles
|
||||||
void addStyles(IndexMap<FieldP,StyleP>& styles);
|
void addStyles(IndexMap<FieldP,StyleP>& styles);
|
||||||
|
/// Update style scripts
|
||||||
|
void updateStyles(bool only_content_dependent);
|
||||||
protected:
|
protected:
|
||||||
/// Set the styles for the data to be shown, recreating the viewers
|
/// Set the styles for the data to be shown, recreating the viewers
|
||||||
void setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles, IndexMap<FieldP,StyleP>* extra_styles = nullptr);
|
void setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles, IndexMap<FieldP,StyleP>* extra_styles = nullptr);
|
||||||
|
|||||||
@@ -131,12 +131,15 @@ void TextViewer::drawSeparators(RotatedDC& dc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextViewer::prepare(RotatedDC& dc, const String& text, TextStyle& style, Context& ctx) {
|
bool TextViewer::prepare(RotatedDC& dc, const String& text, TextStyle& style, Context& ctx) {
|
||||||
if (lines.empty()) {
|
if (lines.empty()) {
|
||||||
// not prepared yet
|
// not prepared yet
|
||||||
Rotater r(dc, style.getRotation());
|
Rotater r(dc, style.getRotation());
|
||||||
prepareElements(text, style, ctx);
|
prepareElements(text, style, ctx);
|
||||||
prepareLines(dc, text, style, ctx);
|
prepareLines(dc, text, style, ctx);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void TextViewer::reset() {
|
void TextViewer::reset() {
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ class TextViewer {
|
|||||||
void drawSeparators(RotatedDC& dc);
|
void drawSeparators(RotatedDC& dc);
|
||||||
|
|
||||||
/// Prepare the text for drawing, if it is not already prepared
|
/// Prepare the text for drawing, if it is not already prepared
|
||||||
void prepare(RotatedDC& dc, const String& text, TextStyle& style, Context&);
|
/** Returns true if something has been done */
|
||||||
|
bool prepare(RotatedDC& dc, const String& text, TextStyle& style, Context&);
|
||||||
/// Reset the cached data, at a new call to draw it will be recalculated
|
/// Reset the cached data, at a new call to draw it will be recalculated
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : TextValueViewer
|
// ----------------------------------------------------------------------------- : TextValueViewer
|
||||||
|
|
||||||
void TextValueViewer::prepare(RotatedDC& dc) {
|
bool TextValueViewer::prepare(RotatedDC& dc) {
|
||||||
if (!style().mask_filename.empty() && !style().mask.ok()) {
|
if (!style().mask_filename.empty() && !style().mask.ok()) {
|
||||||
// load contour mask
|
// load contour mask
|
||||||
Image image;
|
Image image;
|
||||||
@@ -22,6 +22,7 @@ void TextValueViewer::prepare(RotatedDC& dc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.prepare(dc, value().value(), style(), viewer.getContext());
|
v.prepare(dc, value().value(), style(), viewer.getContext());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextValueViewer::draw(RotatedDC& dc) {
|
void TextValueViewer::draw(RotatedDC& dc) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class TextValueViewer : public ValueViewer {
|
|||||||
public:
|
public:
|
||||||
DECLARE_VALUE_VIEWER(Text) : ValueViewer(parent,style) {}
|
DECLARE_VALUE_VIEWER(Text) : ValueViewer(parent,style) {}
|
||||||
|
|
||||||
virtual void prepare(RotatedDC& dc);
|
virtual bool prepare(RotatedDC& dc);
|
||||||
virtual void draw(RotatedDC& dc);
|
virtual void draw(RotatedDC& dc);
|
||||||
virtual void onValueChange();
|
virtual void onValueChange();
|
||||||
virtual void onStyleChange();
|
virtual void onStyleChange();
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ class ValueViewer : public StyleListener {
|
|||||||
inline const ValueP& getValue() const { return valueP; }
|
inline const ValueP& getValue() const { return valueP; }
|
||||||
|
|
||||||
/// Prepare before drawing.
|
/// Prepare before drawing.
|
||||||
/** Scripts are updated after preparing, allowing */
|
/** Should return true if a content property has changed
|
||||||
virtual void prepare(RotatedDC& dc) {};
|
* Scripts are re-updated after preparing if they depend on content properties. */
|
||||||
|
virtual bool prepare(RotatedDC& dc) { return false; };
|
||||||
/// Draw this value
|
/// Draw this value
|
||||||
virtual void draw(RotatedDC& dc) = 0;
|
virtual void draw(RotatedDC& dc) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -139,6 +139,12 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
|
|||||||
s->checkContentDependencies(ctx, test);
|
s->checkContentDependencies(ctx, test);
|
||||||
if (test.index) s->content_dependent = true;
|
if (test.index) s->content_dependent = true;
|
||||||
}
|
}
|
||||||
|
FOR_EACH(s, stylesheet.extra_card_style) {
|
||||||
|
// are there dependencies of this style on other style properties?
|
||||||
|
Dependency test(DEP_DUMMY, false);
|
||||||
|
s->checkContentDependencies(ctx, test);
|
||||||
|
if (test.index) s->content_dependent = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : ScriptManager : updating
|
// ----------------------------------------------------------------------------- : ScriptManager : updating
|
||||||
@@ -199,21 +205,24 @@ void SetScriptManager::onAction(const Action& action, bool undone) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetScriptManager::updateStyles(const CardP& card) {
|
void SetScriptManager::updateStyles(const CardP& card, bool only_content_dependent) {
|
||||||
assert(card);
|
assert(card);
|
||||||
const StyleSheet& stylesheet = set.stylesheetFor(card);
|
const StyleSheet& stylesheet = set.stylesheetFor(card);
|
||||||
Context& ctx = getContext(card);
|
Context& ctx = getContext(card);
|
||||||
// update extra card fields
|
if (!only_content_dependent) {
|
||||||
IndexMap<FieldP,ValueP>& extra_data = card->extraDataFor(stylesheet);
|
// update extra card fields
|
||||||
FOR_EACH(v, extra_data) {
|
IndexMap<FieldP,ValueP>& extra_data = card->extraDataFor(stylesheet);
|
||||||
v->update(ctx);
|
FOR_EACH(v, extra_data) {
|
||||||
|
v->update(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// update all styles
|
// update all styles
|
||||||
updateStyles(ctx, stylesheet.card_style);
|
updateStyles(ctx, stylesheet.card_style, only_content_dependent);
|
||||||
updateStyles(ctx, stylesheet.extra_card_style);
|
updateStyles(ctx, stylesheet.extra_card_style, only_content_dependent);
|
||||||
}
|
}
|
||||||
void SetScriptManager::updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles) {
|
void SetScriptManager::updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles, bool only_content_dependent) {
|
||||||
FOR_EACH_CONST(s, styles) {
|
FOR_EACH_CONST(s, styles) {
|
||||||
|
if (only_content_dependent && !s->content_dependent) continue;
|
||||||
try {
|
try {
|
||||||
if (s->update(ctx)) {
|
if (s->update(ctx)) {
|
||||||
// style has changed, tell listeners
|
// style has changed, tell listeners
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class SetScriptManager : public SetScriptContext, public ActionListener {
|
|||||||
~SetScriptManager();
|
~SetScriptManager();
|
||||||
|
|
||||||
/// Update all styles for a particular card
|
/// Update all styles for a particular card
|
||||||
void updateStyles(const CardP& card);
|
void updateStyles(const CardP& card, bool only_content_dependent);
|
||||||
|
|
||||||
/// Update expensive things that were previously delayed
|
/// Update expensive things that were previously delayed
|
||||||
void updateDelayed();
|
void updateDelayed();
|
||||||
@@ -79,7 +79,7 @@ class SetScriptManager : public SetScriptContext, public ActionListener {
|
|||||||
void initDependencies(Context&, StyleSheet&);
|
void initDependencies(Context&, StyleSheet&);
|
||||||
|
|
||||||
/// Update a map of styles
|
/// Update a map of styles
|
||||||
void updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles);
|
void updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>& styles, bool only_content_dependent);
|
||||||
/// Updates scripts, starting at some value
|
/// Updates scripts, starting at some value
|
||||||
/** if the value changes any dependend values are updated as well */
|
/** if the value changes any dependend values are updated as well */
|
||||||
void updateValue(Value& value, const CardP& card);
|
void updateValue(Value& value, const CardP& card);
|
||||||
|
|||||||
Reference in New Issue
Block a user