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
+57 -4
View File
@@ -94,7 +94,7 @@ template <> void GetDefaultMember::handle(const ScriptableImage& s) {
// ----------------------------------------------------------------------------- : CachedScriptableImage
void CachedScriptableImage::generateCached(const GeneratedImage::Options& options,
Image* mask,
CachedScriptableMask* mask,
ImageCombine* combine, wxBitmap* bitmap, wxImage* image, RealSize* size) {
// ready?
if (!isReady()) {
@@ -137,13 +137,24 @@ void CachedScriptableImage::generateCached(const GeneratedImage::Options& option
}
}
}
// hack: temporarily set angle to 0, do actual rotation after applying mask
int a = options.angle;
const_cast<GeneratedImage::Options&>(options).angle = 0;
// generate
cached_i = generate(options);
cached_angle = options.angle;
const_cast<GeneratedImage::Options&>(options).angle = cached_angle = a;
*size = cached_size = RealSize(options.width, options.height);
if (mask && mask->Ok()) {
if (mask) {
// apply mask
set_alpha(cached_i, *mask);
GeneratedImage::Options mask_opts(options);
mask_opts.width = cached_i.GetWidth();
mask_opts.height = cached_i.GetHeight();
mask_opts.angle = 0;
mask->get(mask_opts).setAlpha(cached_i);
}
if (options.angle != 0) {
// hack(pt2) do the actual rotation now
cached_i = rotate_image(cached_i, options.angle);
}
if (*combine <= COMBINE_NORMAL) {
*bitmap = cached_b = Bitmap(cached_i);
@@ -176,3 +187,45 @@ template <> void Writer::handle(const CachedScriptableImage& s) {
template <> void GetDefaultMember::handle(const CachedScriptableImage& s) {
handle((const ScriptableImage&)s);
}
// ----------------------------------------------------------------------------- : CachedScriptableMask
bool CachedScriptableMask::update(Context& ctx) {
if (script.update(ctx)) {
mask.clear();
return true;
} else {
return false;
}
}
const AlphaMask& CachedScriptableMask::get(const GeneratedImage::Options& img_options) {
if (mask.isLoaded()) {
// already loaded?
if (img_options.width == 0 && img_options.height == 0) return mask;
if (mask.hasSize(wxSize(img_options.width,img_options.height))) return mask;
}
// load?
getNoCache(img_options,mask);
return mask;
}
void CachedScriptableMask::getNoCache(const GeneratedImage::Options& img_options, AlphaMask& other_mask) {
if (script.isBlank()) {
other_mask.clear();
} else {
Image image = script.generate(img_options);
other_mask.load(image);
}
}
template <> void Reader::handle(CachedScriptableMask& i) {
handle(i.script);
}
template <> void Writer::handle(const CachedScriptableMask& i) {
handle(i.script);
}
template <> void GetDefaultMember::handle(const CachedScriptableMask& i) {
handle(i.script);
}