New class CachedScriptableMask: like CachedScriptableImage, only containing an AlphaMask instead of an Image/Bitmap.

Use CachedScriptableMask for all masks.

TODO: This introduces some duplicate code in ValueViewers that could be fixed by moving mask to the Style base class.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1182 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-08-30 21:51:38 +00:00
parent acb3493b59
commit a183ecc9a6
23 changed files with 306 additions and 159 deletions
+40 -8
View File
@@ -10,6 +10,8 @@
#include <render/value/choice.hpp>
#include <render/card/viewer.hpp>
DECLARE_TYPEOF_COLLECTION(wxPoint);
// ----------------------------------------------------------------------------- : ChoiceValueViewer
IMPLEMENT_VALUE_VIEWER(Choice);
@@ -20,11 +22,48 @@ bool ChoiceValueViewer::prepare(RotatedDC& dc) {
return prepare_choice_viewer(dc, *this, style(), value().value());
}
void ChoiceValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc);
int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height));
const AlphaMask& alpha_mask = getMask(w,h);
drawFieldBorder(dc, alpha_mask);
if (style().render_style & RENDER_HIDDEN) return;
draw_choice_viewer(dc, *this, style(), value().value());
}
void ChoiceValueViewer::drawFieldBorder(RotatedDC& dc, const AlphaMask& alpha_mask) {
if (!alpha_mask.isLoaded()) {
ValueViewer::drawFieldBorder(dc);
} else if (setFieldBorderPen(dc)) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
vector<wxPoint> points;
alpha_mask.convexHull(points);
if (points.size() < 3) return;
FOR_EACH(p, points) p = dc.trPixelNoZoom(RealPoint(p.x,p.y));
dc.getDC().DrawPolygon((int)points.size(), &points[0]);
}
}
bool ChoiceValueViewer::containsPoint(const RealPoint& p) const {
// check against mask
return getMask(0,0).isOpaque(p, style().getSize());
}
void ChoiceValueViewer::onStyleChange(int changes) {
if (changes & CHANGE_MASK) style().image.clearCache();
ValueViewer::onStyleChange(changes);
}
const AlphaMask& ChoiceValueViewer::getMask(int w, int h) const {
GeneratedImage::Options opts;
opts.package = &viewer.getStylePackage();
opts.local_package = &viewer.getLocalPackage();
opts.angle = 0;
opts.width = w;
opts.height = h;
return style().mask.get(opts);
}
// ----------------------------------------------------------------------------- : Generic draw/prepare
bool prepare_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value) {
if (style.render_style & RENDER_IMAGE) {
style.initImage();
@@ -38,7 +77,6 @@ bool prepare_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& styl
// Generate image/bitmap (whichever is available)
// don't worry, we cache the image
ImageCombine combine = style.combine;
style.loadMask(viewer.getStylePackage());
Bitmap bitmap; Image image;
RealSize size;
img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size);
@@ -70,7 +108,6 @@ void draw_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style,
get_options(dc, viewer, style, img_options);
// Generate image/bitmap
ImageCombine combine = style.combine;
style.loadMask(viewer.getStylePackage());
Bitmap bitmap; Image image;
RealSize size;
img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size);
@@ -112,8 +149,3 @@ void get_options(Rotation& rot, ValueViewer& viewer, const ChoiceStyle& style, G
opts.preserve_aspect = (style.alignment & ALIGN_STRETCH) ? ASPECT_STRETCH : ASPECT_FIT;
}
}
void ChoiceValueViewer::onStyleChange(int changes) {
if (changes & CHANGE_MASK) style().image.clearCache();
ValueViewer::onStyleChange(changes);
}