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:
twanvl
2007-07-04 17:15:08 +00:00
parent 95d4ca89f9
commit b3d04fe192
11 changed files with 63 additions and 34 deletions
+27 -15
View File
@@ -40,30 +40,23 @@ void DataViewer::draw(RotatedDC& dc, const Color& background) {
// fill with background color
clearDC(dc.getDC(), background);
// update style scripts
try {
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);
}
updateStyles(false);
// prepare viewers
bool changed_content_properties = false;
FOR_EACH(v, viewers) { // draw low z index fields first
if (v->getStyle()->visible) {
try {
v->prepare(dc);
if (v->prepare(dc)) {
changed_content_properties = true;
}
} catch (const Error& e) {
handle_error(e, false, false);
}
}
}
if (changed_content_properties) {
updateStyles(true);
}
// draw viewers
FOR_EACH(v, viewers) { // draw low z index fields first
if (v->getStyle()->visible) {// visible
@@ -80,6 +73,25 @@ void DataViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
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
bool DataViewer::nativeLook() const { return false; }
+2
View File
@@ -75,6 +75,8 @@ class DataViewer : public SetView {
private:
/// Create some viewers for the given styles
void addStyles(IndexMap<FieldP,StyleP>& styles);
/// Update style scripts
void updateStyles(bool only_content_dependent);
protected:
/// 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);
+4 -1
View File
@@ -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()) {
// not prepared yet
Rotater r(dc, style.getRotation());
prepareElements(text, style, ctx);
prepareLines(dc, text, style, ctx);
return true;
} else {
return false;
}
}
void TextViewer::reset() {
+2 -1
View File
@@ -54,7 +54,8 @@ class TextViewer {
void drawSeparators(RotatedDC& dc);
/// 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
void reset();
+2 -1
View File
@@ -12,7 +12,7 @@
// ----------------------------------------------------------------------------- : TextValueViewer
void TextValueViewer::prepare(RotatedDC& dc) {
bool TextValueViewer::prepare(RotatedDC& dc) {
if (!style().mask_filename.empty() && !style().mask.ok()) {
// load contour mask
Image image;
@@ -22,6 +22,7 @@ void TextValueViewer::prepare(RotatedDC& dc) {
}
}
v.prepare(dc, value().value(), style(), viewer.getContext());
return true;
}
void TextValueViewer::draw(RotatedDC& dc) {
+1 -1
View File
@@ -21,7 +21,7 @@ class TextValueViewer : public ValueViewer {
public:
DECLARE_VALUE_VIEWER(Text) : ValueViewer(parent,style) {}
virtual void prepare(RotatedDC& dc);
virtual bool prepare(RotatedDC& dc);
virtual void draw(RotatedDC& dc);
virtual void onValueChange();
virtual void onStyleChange();
+3 -2
View File
@@ -40,8 +40,9 @@ class ValueViewer : public StyleListener {
inline const ValueP& getValue() const { return valueP; }
/// Prepare before drawing.
/** Scripts are updated after preparing, allowing */
virtual void prepare(RotatedDC& dc) {};
/** Should return true if a content property has changed
* Scripts are re-updated after preparing if they depend on content properties. */
virtual bool prepare(RotatedDC& dc) { return false; };
/// Draw this value
virtual void draw(RotatedDC& dc) = 0;