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
+6 -6
View File
@@ -54,7 +54,7 @@ void ImageSlice::constrain(PreferedProperty prefer) {
Image ImageSlice::getSlice() const {
if (selection.width == target_size.GetWidth() && selection.height == target_size.GetHeight() && selection.x == 0 && selection.y == 0) {
// exactly the right size
return source;
return source.GetSubImage(selection);
}
Image target(target_size.GetWidth(), target_size.GetHeight(), false);
if (sharpen && sharpen_amount > 0 && sharpen_amount <= 100) {
@@ -75,7 +75,7 @@ DEFINE_EVENT_TYPE(EVENT_SLICE_CHANGED);
// ----------------------------------------------------------------------------- : ImageSliceWindow
ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wxSize& target_size, const AlphaMaskP& mask)
ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wxSize& target_size, const AlphaMask& mask)
: wxDialog(parent,wxID_ANY,_TITLE_("slice image"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE)
, slice(source, target_size)
{
@@ -277,6 +277,7 @@ void ImageSliceWindow::updateControls() {
size->SetSelection(2); // force to fit
} else if (slice.selection.width <= slice.source.GetWidth() &&
slice.selection.height <= slice.source.GetHeight() &&
fabs(slice.zoomX() - slice.zoomY()) < 0.01 &&
( (slice.selection.x == 0 && slice.selection.width == slice.source.GetWidth())
||(slice.selection.y == 0 && slice.selection.height == slice.source.GetHeight()))) {
size->SetSelection(1); // size to fit
@@ -334,7 +335,7 @@ END_EVENT_TABLE ()
// ----------------------------------------------------------------------------- : ImageSlicePreview
ImageSlicePreview::ImageSlicePreview(Window* parent, int id, ImageSlice& slice, const AlphaMaskP& mask)
ImageSlicePreview::ImageSlicePreview(Window* parent, int id, ImageSlice& slice, const AlphaMask& mask)
: wxControl(parent, id)
, slice(slice)
, mask(mask)
@@ -359,9 +360,8 @@ void ImageSlicePreview::onPaint(wxPaintEvent&) {
void ImageSlicePreview::draw(DC& dc) {
if (!bitmap.Ok()) {
Image image = slice.getSlice();
if (mask && mask->hasSize(slice.target_size)) {
mask->setAlpha(image);
}
assert(image.GetWidth() == slice.target_size.GetWidth() && image.GetHeight() == slice.target_size.GetHeight());
mask.setAlpha(image);
if (image.HasAlpha()) {
// create bitmap
bitmap = Bitmap(image.GetWidth(), image.GetHeight());
+3 -3
View File
@@ -59,7 +59,7 @@ class ImageSlice {
/// Dialog for selecting a slice of an image
class ImageSliceWindow : public wxDialog {
public:
ImageSliceWindow(Window* parent, const Image& source, const wxSize& target_size, const AlphaMaskP& target_mask);
ImageSliceWindow(Window* parent, const Image& source, const wxSize& target_size, const AlphaMask& target_mask);
/// Return the sliced image
Image getImage() const;
@@ -115,7 +115,7 @@ class ImageSliceWindow : public wxDialog {
/// A preview of the sliced image
class ImageSlicePreview : public wxControl {
public:
ImageSlicePreview(Window* parent, int id, ImageSlice& slice, const AlphaMaskP& mask);
ImageSlicePreview(Window* parent, int id, ImageSlice& slice, const AlphaMask& mask);
/// Notify that the slice was updated
void update();
@@ -124,7 +124,7 @@ class ImageSlicePreview : public wxControl {
private:
Bitmap bitmap;
ImageSlice& slice;
AlphaMaskP mask;
const AlphaMask& mask;
bool mouse_down;
int mouseX, mouseY; ///< starting mouse position
+4 -11
View File
@@ -29,17 +29,10 @@ bool ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
void ImageValueEditor::sliceImage(const Image& image) {
if (!image.Ok()) return;
// mask?
AlphaMaskP mask;
if (!style().mask_filename().empty()) {
Image mask_image;
InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
if (mask_image.LoadFile(*image_file)) {
Image resampled(style().width, style().height);
resample(mask_image, resampled);
mask = new_intrusive1<AlphaMask>(resampled);
}
}
// mask
GeneratedImage::Options options((int)style().width, (int)style().height, &viewer.getStylePackage(), &viewer.getLocalPackage());
AlphaMask mask;
style().mask.getNoCache(options,mask);
// slice
ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, style().getSize(), mask);
// clicked ok?