Conversion to new ScriptableImage complete, this affected quite a bit, including the evil thumbnail thread;

Added StyleListener, so style changes are only propagated to interested viewers.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@329 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-05-10 00:47:27 +00:00
parent 71adbf8545
commit 00b3e3a3cd
28 changed files with 282 additions and 531 deletions
+4 -2
View File
@@ -35,8 +35,10 @@ BooleanStyle::BooleanStyle(const ChoiceFieldP& field)
: ChoiceStyle(field)
{
render_style = RENDER_BOTH;
choice_images[_("yes")] = ScriptableImage(_("buildin_image(\"bool_yes\")"));
choice_images[_("no")] = ScriptableImage(_("buildin_image(\"bool_no\")"));
//%%choice_images[_("yes")] = ScriptableImage(_("buildin_image(\"bool_yes\")"));
//%%choice_images[_("no")] = ScriptableImage(_("buildin_image(\"bool_no\")"));
choice_images[_("yes")] = ScriptableImage(new_intrusive1<BuiltInImage>(_("bool_yes")));
choice_images[_("no")] = ScriptableImage(new_intrusive1<BuiltInImage>(_("bool_no")));
}
IMPLEMENT_REFLECTION(BooleanStyle) {
+23 -14
View File
@@ -167,8 +167,6 @@ ChoiceStyle::ChoiceStyle(const ChoiceFieldP& field)
, alignment(ALIGN_STRETCH)
, angle(0)
, thumbnails(nullptr)
, thumbnail_age(1) // thumbnails were made before the beginning of time
, invalidated_images(false)
{}
ChoiceStyle::~ChoiceStyle() {
@@ -178,8 +176,15 @@ ChoiceStyle::~ChoiceStyle() {
bool ChoiceStyle::update(Context& ctx) {
// Don't update the choice images, leave that to invalidate()
return Style ::update(ctx)
| mask_filename.update(ctx);
bool change = Style ::update(ctx)
| mask_filename.update(ctx);
FOR_EACH(ci, choice_images) {
if (ci.second.update(ctx)) {
change = true;
// TODO : remove this thumbnail
}
}
return change;
}
void ChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
Style::initDependencies(ctx, dep);
@@ -187,17 +192,21 @@ void ChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
ci.second.initDependencies(ctx, dep);
}
}
void ChoiceStyle::invalidate() {
// rebuild choice images
// TODO: Don't use this; rely on upToDate() instead
FOR_EACH(ci, choice_images) {
// TODO : only invalidate images that actually have dependencies
ci.second.invalidate();
void ChoiceStyle::invalidate(Context& ctx) {
// TODO : this is also done in update(), once should be enough
// Update choice images and thumbnails
bool change = false;
int end = field().choices->lastId();
thumbnails_status.resize(end, THUMB_NOT_MADE);
for (int i = 0 ; i < end ; ++i) {
String name = cannocial_name_form(field().choices->choiceName(i));
ScriptableImage& img = choice_images[name];
if (img.update(ctx)) {
change = true;
thumbnails_status[i] = THUMB_CHANGED;
}
}
if (thumbnails) {
thumbnails->RemoveAll();
}
invalidated_images = true;
if (change) tellListeners();
}
void ChoiceStyle::loadMask(Package& pkg) {
+8 -3
View File
@@ -114,6 +114,12 @@ enum ChoiceRenderStyle
, RENDER_BOTH_CHECKLIST = RENDER_CHECKLIST | RENDER_BOTH
};
enum ThumbnailStatus
{ THUMB_NOT_MADE
, THUMB_OK
, THUMB_CHANGED
};
/// The Style for a ChoiceField
class ChoiceStyle : public Style {
public:
@@ -133,15 +139,14 @@ class ChoiceStyle : public Style {
Image mask; ///< The actual mask image
int angle; ///< Angle by which the images are rotated
wxImageList* thumbnails; ///< Thumbnails for the choices
Age thumbnail_age; ///< Age the thumbnails were generated
bool invalidated_images; ///< Have the images been invalidated?
vector<ThumbnailStatus> thumbnails_status; ///< Which thumbnails are up to date?
/// Load the mask image, if it's not already done
void loadMask(Package& pkg);
virtual bool update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
virtual void invalidate();
virtual void invalidate(Context&);
private:
DECLARE_REFLECTION();
+1 -1
View File
@@ -39,7 +39,7 @@ class ImageStyle : public Style {
DECLARE_STYLE_TYPE(Image);
Scriptable<String> mask_filename; ///< Filename for a mask image
ScriptableImage2 default_image; ///< Placeholder
ScriptableImage default_image; ///< Placeholder
virtual bool update(Context&);