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
+25 -22
View File
@@ -20,34 +20,33 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
if (style().render_style & RENDER_IMAGE) {
// draw image
map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(value().value()));
if (it != style().choice_images.end()) {
if (it != style().choice_images.end() && it->second.isReady()) {
ScriptableImage& img = it->second;
ScriptImageP i;
GeneratedImage::Options img_options(0,0, viewer.stylesheet.get(), &getSet());
if (nativeLook()) {
i = img.update(viewer.getContext(), *viewer.stylesheet, 16, 16, ASPECT_BORDER, false);
img_options.width = img_options.height = 16;
img_options.preserve_aspect = ASPECT_BORDER;
} else if(style().render_style & RENDER_TEXT) {
// also drawing text
i = img.update(viewer.getContext(), *viewer.stylesheet, 0, 0);
// also drawing text, use original size
} else {
i = img.update(viewer.getContext(), *viewer.stylesheet,
(int) dc.trS(style().width), (int) dc.trS(style().height),
style().alignment == ALIGN_STRETCH ? ASPECT_STRETCH : ASPECT_FIT
);
img_options.width = (int) dc.trS(style().width);
img_options.height = (int) dc.trS(style().height);
img_options.preserve_aspect = style().alignment == ALIGN_STRETCH ? ASPECT_STRETCH : ASPECT_FIT;
}
if (i) {
// apply mask?
style().loadMask(*viewer.stylesheet);
if (style().mask.Ok()) {
set_alpha(i->image, style().mask);
}
// draw
dc.DrawImage(i->image,
align_in_rect(style().alignment, RealSize(i->image.GetWidth(), i->image.GetHeight()), style().getRect()),
i->combine == COMBINE_NORMAL ? style().combine : i->combine,
style().angle
);
margin = dc.trInvS(i->image.GetWidth()) + 1;
Image image = img.generate(img_options, true);
ImageCombine combine = img.combine();
// apply mask?
style().loadMask(*viewer.stylesheet);
if (style().mask.Ok()) {
set_alpha(image, style().mask);
}
// draw
dc.DrawImage(image,
align_in_rect(style().alignment, RealSize(image.GetWidth(), image.GetHeight()), style().getRect()),
combine == COMBINE_NORMAL ? style().combine : combine,
style().angle
);
margin = dc.trInvS(image.GetWidth()) + 1;
}
}
if (style().render_style & RENDER_TEXT) {
@@ -57,3 +56,7 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
);
}
}
void ChoiceValueViewer::onStyleChange() {
viewer.redraw(*this);
}
+1
View File
@@ -21,6 +21,7 @@ class ChoiceValueViewer : public ValueViewer {
DECLARE_VALUE_VIEWER(Choice) : ValueViewer(parent,style) {}
virtual void draw(RotatedDC& dc);
virtual void onStyleChange();
};
// ----------------------------------------------------------------------------- : EOF
+1
View File
@@ -88,6 +88,7 @@ bool ColorValueViewer::containsPoint(const RealPoint& p) const {
void ColorValueViewer::onStyleChange() {
alpha_mask = AlphaMaskP();
viewer.redraw(*this);
}
void ColorValueViewer::loadMask(const Rotation& rot) const {
+1
View File
@@ -80,6 +80,7 @@ void ImageValueViewer::onValueChange() {
void ImageValueViewer::onStyleChange() {
bitmap = Bitmap();
alpha_mask = AlphaMaskP(); // TODO: only reload whatever has changed
viewer.redraw(*this);
}
void ImageValueViewer::loadMask(const Rotation& rot) const {
+6 -7
View File
@@ -49,13 +49,12 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
}
if (style().render_style & RENDER_IMAGE) {
map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(choice));
if (it != style().choice_images.end()) {
ScriptImageP i = it->second.update(viewer.getContext(), *viewer.stylesheet, 0, 0);
if (i) {
// TODO : alignment?
dc.DrawImage(i->image, pos + RealSize(size.width, 0), i->combine == COMBINE_NORMAL ? style().combine : i->combine);
size = add_horizontal(size, dc.trInv(RealSize(i->image.GetWidth() + 1, i->image.GetHeight())));
}
if (it != style().choice_images.end() && it->second.isReady()) {
Image image = it->second.generate(GeneratedImage::Options(0,0, viewer.stylesheet.get(),&getSet()), true);
ImageCombine combine = it->second.combine();
// TODO : alignment?
dc.DrawImage(image, pos + RealSize(size.width, 0), combine == COMBINE_NORMAL ? style().combine : combine);
size = add_horizontal(size, dc.trInv(RealSize(image.GetWidth() + 1, image.GetHeight())));
}
}
if (style().render_style & RENDER_TEXT) {
+1
View File
@@ -36,4 +36,5 @@ void TextValueViewer::onValueChange() {
void TextValueViewer::onStyleChange() {
v.reset();
viewer.redraw(*this);
}
+1 -1
View File
@@ -19,7 +19,7 @@
// ----------------------------------------------------------------------------- : ValueViewer
ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style)
: viewer(parent), styleP(style)
: StyleListener(style), viewer(parent)
{}
Set& ValueViewer::getSet() const { return *viewer.getSet(); }
+1 -2
View File
@@ -24,7 +24,7 @@ DECLARE_POINTER_TYPE(Value);
/// The virtual viewer control for a single field on a card (or in the set data)
/** A viewer can only display a value, not edit it, ValueEditor is used for that */
class ValueViewer {
class ValueViewer : public StyleListener{
public:
/// Construct a ValueViewer, set the value at a later time
ValueViewer(DataViewer& parent, const StyleP& style);
@@ -62,7 +62,6 @@ class ValueViewer {
DataViewer& viewer; ///< Our parent object
protected:
StyleP styleP; ///< The style of this viewer
ValueP valueP; ///< The value we are currently viewing
/// Should this viewer render using a platform native look?