mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Fixed mask for image fields, added mask support to slice window
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@243 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -177,7 +177,8 @@ ChoiceStyle::~ChoiceStyle() {
|
||||
|
||||
bool ChoiceStyle::update(Context& ctx) {
|
||||
// Don't update the choice images, leave that to invalidate()
|
||||
return Style::update(ctx);
|
||||
return Style ::update(ctx)
|
||||
| mask_filename.update(ctx);
|
||||
}
|
||||
void ChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
|
||||
Style::initDependencies(ctx, dep);
|
||||
@@ -199,7 +200,7 @@ void ChoiceStyle::invalidate() {
|
||||
}
|
||||
|
||||
void ChoiceStyle::loadMask(Package& pkg) {
|
||||
if (mask.Ok() || mask_filename.empty()) return;
|
||||
if (mask.Ok() || mask_filename().empty()) return;
|
||||
// load file
|
||||
InputStreamP image_file = pkg.openIn(mask_filename);
|
||||
mask.LoadFile(*image_file);
|
||||
|
||||
+12
-12
@@ -121,18 +121,18 @@ class ChoiceStyle : public Style {
|
||||
DECLARE_STYLE_TYPE(Choice);
|
||||
~ChoiceStyle();
|
||||
|
||||
ChoicePopupStyle popup_style; ///< Style of popups/menus
|
||||
ChoiceRenderStyle render_style; ///< Style of rendering
|
||||
Font font; ///< Font for drawing text (when RENDER_TEXT)
|
||||
map<String,ScriptableImage> choice_images; ///< Images for the various choices (when RENDER_IMAGE)
|
||||
map<String,Color> choice_colors; ///< Colors for the various choices (when color_cardlist)
|
||||
bool colors_card_list;///< Does this field determine colors of the rows in the card list?
|
||||
String mask_filename; ///< Filename of an additional mask over the images
|
||||
ImageCombine combine; ///< Combining mode for drawing the images
|
||||
Alignment alignment; ///< Alignment of images
|
||||
Image mask; ///< The actual mask image
|
||||
wxImageList* thumbnails; ///< Thumbnails for the choices
|
||||
Age thumbnail_age; ///< Age the thumbnails were generated
|
||||
ChoicePopupStyle popup_style; ///< Style of popups/menus
|
||||
ChoiceRenderStyle render_style; ///< Style of rendering
|
||||
Font font; ///< Font for drawing text (when RENDER_TEXT)
|
||||
map<String,ScriptableImage> choice_images; ///< Images for the various choices (when RENDER_IMAGE)
|
||||
map<String,Color> choice_colors; ///< Colors for the various choices (when color_cardlist)
|
||||
bool colors_card_list; ///< Does this field determine colors of the rows in the card list?
|
||||
Scriptable<String> mask_filename; ///< Filename of an additional mask over the images
|
||||
ImageCombine combine; ///< Combining mode for drawing the images
|
||||
Alignment alignment; ///< Alignment of images
|
||||
Image mask; ///< The actual mask image
|
||||
wxImageList* thumbnails; ///< Thumbnails for the choices
|
||||
Age thumbnail_age; ///< Age the thumbnails were generated
|
||||
bool invalidated_images; ///< Have the images been invalidated?
|
||||
|
||||
/// Load the mask image, if it's not already done
|
||||
|
||||
@@ -28,6 +28,10 @@ IMPLEMENT_REFLECTION(ImageStyle) {
|
||||
REFLECT_N("mask", mask_filename);
|
||||
}
|
||||
|
||||
bool ImageStyle::update(Context& ctx) {
|
||||
return Style ::update(ctx)
|
||||
| mask_filename.update(ctx);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageValue
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ class ImageStyle : public Style {
|
||||
|
||||
Scriptable<String> mask_filename; ///< Filename for a mask image
|
||||
|
||||
virtual bool update(Context&);
|
||||
|
||||
private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/image_slice_window.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <util/rotation.hpp>
|
||||
#include <gfx/gfx.hpp>
|
||||
#include <wx/spinctrl.h>
|
||||
#include <wx/dcbuffer.h>
|
||||
@@ -72,7 +74,7 @@ DEFINE_EVENT_TYPE(EVENT_SLICE_CHANGED);
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageSliceWindow
|
||||
|
||||
ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wxSize& target_size)
|
||||
ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wxSize& target_size, const AlphaMaskP& mask)
|
||||
: wxDialog(parent,wxID_ANY,_TITLE_("slice image"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE)
|
||||
, slice(source, target_size)
|
||||
{
|
||||
@@ -80,7 +82,7 @@ ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wx
|
||||
const wxPoint defPos = wxDefaultPosition;
|
||||
const wxSize spinSize(80,-1);
|
||||
selector = new ImageSliceSelector(this, ID_SELECTOR, slice);
|
||||
preview = new ImageSlicePreview (this, ID_PREVIEW, slice);
|
||||
preview = new ImageSlicePreview (this, ID_PREVIEW, slice, mask);
|
||||
|
||||
String sizes[] = { _("&Original Size")
|
||||
, _("Size to &Fit")
|
||||
@@ -331,9 +333,10 @@ END_EVENT_TABLE ()
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageSlicePreview
|
||||
|
||||
ImageSlicePreview::ImageSlicePreview(Window* parent, int id, ImageSlice& slice)
|
||||
ImageSlicePreview::ImageSlicePreview(Window* parent, int id, ImageSlice& slice, const AlphaMaskP& mask)
|
||||
: wxControl(parent, id)
|
||||
, slice(slice)
|
||||
, mask(mask)
|
||||
, mouse_down(false)
|
||||
{}
|
||||
|
||||
@@ -356,7 +359,21 @@ void ImageSlicePreview::onPaint(wxPaintEvent&) {
|
||||
}
|
||||
void ImageSlicePreview::draw(DC& dc) {
|
||||
if (!bitmap.Ok()) {
|
||||
bitmap = Bitmap(slice.getSlice());
|
||||
Image image = slice.getSlice();
|
||||
if (mask && mask->size == slice.target_size) {
|
||||
mask->setAlpha(image);
|
||||
// create bitmap
|
||||
bitmap = Bitmap(image.GetWidth(), image.GetHeight());
|
||||
wxMemoryDC mdc; mdc.SelectObject(bitmap);
|
||||
// draw checker pattern behind image
|
||||
RealRect rect = GetClientSize();
|
||||
RotatedDC rdc(mdc, 0, rect, 1, false);
|
||||
draw_checker(rdc, rect);
|
||||
rdc.DrawImage(image, RealPoint(0,0));
|
||||
mdc.SelectObject(wxNullBitmap);
|
||||
} else {
|
||||
bitmap = Bitmap(image);
|
||||
}
|
||||
}
|
||||
if (bitmap.Ok()) {
|
||||
dc.DrawBitmap(bitmap, 0, 0);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
class ImageSlicePreview;
|
||||
class ImageSliceSelector;
|
||||
class wxSpinEvent;
|
||||
DECLARE_POINTER_TYPE(AlphaMask);
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageSlice
|
||||
|
||||
@@ -50,7 +51,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);
|
||||
ImageSliceWindow(Window* parent, const Image& source, const wxSize& target_size, const AlphaMaskP& target_mask);
|
||||
|
||||
/// Return the sliced image
|
||||
Image getImage() const;
|
||||
@@ -106,7 +107,7 @@ class ImageSliceWindow : public wxDialog {
|
||||
/// A preview of the sliced image
|
||||
class ImageSlicePreview : public wxControl {
|
||||
public:
|
||||
ImageSlicePreview(Window* parent, int id, ImageSlice& slice);
|
||||
ImageSlicePreview(Window* parent, int id, ImageSlice& slice, const AlphaMaskP& mask);
|
||||
|
||||
/// Notify that the slice was updated
|
||||
void update();
|
||||
@@ -115,6 +116,7 @@ class ImageSlicePreview : public wxControl {
|
||||
private:
|
||||
Bitmap bitmap;
|
||||
ImageSlice& slice;
|
||||
AlphaMaskP mask;
|
||||
|
||||
bool mouse_down;
|
||||
int mouseX, mouseY; ///< starting mouse position
|
||||
|
||||
+14
-1
@@ -10,6 +10,7 @@
|
||||
#include <gui/image_slice_window.hpp>
|
||||
#include <data/format/clipboard.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <wx/clipbrd.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : ImageValueEditor
|
||||
@@ -28,8 +29,20 @@ 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 = viewer.stylesheet->openIn(style().mask_filename);
|
||||
if (mask_image.LoadFile(*image_file)) {
|
||||
Image resampled(style().width, style().height);
|
||||
resample(mask_image, resampled);
|
||||
mask = new_shared1<AlphaMask>(resampled);
|
||||
}
|
||||
}
|
||||
// slice
|
||||
ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, style().getSize());
|
||||
ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, style().getSize(), mask);
|
||||
// clicked ok?
|
||||
if (s.ShowModal() == wxID_OK) {
|
||||
// store the image into the set
|
||||
FileName new_image_file = getSet().newFileName(field().name,_("")); // a new unique name in the package
|
||||
|
||||
Reference in New Issue
Block a user