mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37: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) {
|
bool ChoiceStyle::update(Context& ctx) {
|
||||||
// Don't update the choice images, leave that to invalidate()
|
// 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 {
|
void ChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
|
||||||
Style::initDependencies(ctx, dep);
|
Style::initDependencies(ctx, dep);
|
||||||
@@ -199,7 +200,7 @@ void ChoiceStyle::invalidate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChoiceStyle::loadMask(Package& pkg) {
|
void ChoiceStyle::loadMask(Package& pkg) {
|
||||||
if (mask.Ok() || mask_filename.empty()) return;
|
if (mask.Ok() || mask_filename().empty()) return;
|
||||||
// load file
|
// load file
|
||||||
InputStreamP image_file = pkg.openIn(mask_filename);
|
InputStreamP image_file = pkg.openIn(mask_filename);
|
||||||
mask.LoadFile(*image_file);
|
mask.LoadFile(*image_file);
|
||||||
|
|||||||
+12
-12
@@ -121,18 +121,18 @@ class ChoiceStyle : public Style {
|
|||||||
DECLARE_STYLE_TYPE(Choice);
|
DECLARE_STYLE_TYPE(Choice);
|
||||||
~ChoiceStyle();
|
~ChoiceStyle();
|
||||||
|
|
||||||
ChoicePopupStyle popup_style; ///< Style of popups/menus
|
ChoicePopupStyle popup_style; ///< Style of popups/menus
|
||||||
ChoiceRenderStyle render_style; ///< Style of rendering
|
ChoiceRenderStyle render_style; ///< Style of rendering
|
||||||
Font font; ///< Font for drawing text (when RENDER_TEXT)
|
Font font; ///< Font for drawing text (when RENDER_TEXT)
|
||||||
map<String,ScriptableImage> choice_images; ///< Images for the various choices (when RENDER_IMAGE)
|
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)
|
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?
|
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
|
Scriptable<String> mask_filename; ///< Filename of an additional mask over the images
|
||||||
ImageCombine combine; ///< Combining mode for drawing the images
|
ImageCombine combine; ///< Combining mode for drawing the images
|
||||||
Alignment alignment; ///< Alignment of images
|
Alignment alignment; ///< Alignment of images
|
||||||
Image mask; ///< The actual mask image
|
Image mask; ///< The actual mask image
|
||||||
wxImageList* thumbnails; ///< Thumbnails for the choices
|
wxImageList* thumbnails; ///< Thumbnails for the choices
|
||||||
Age thumbnail_age; ///< Age the thumbnails were generated
|
Age thumbnail_age; ///< Age the thumbnails were generated
|
||||||
bool invalidated_images; ///< Have the images been invalidated?
|
bool invalidated_images; ///< Have the images been invalidated?
|
||||||
|
|
||||||
/// Load the mask image, if it's not already done
|
/// Load the mask image, if it's not already done
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ IMPLEMENT_REFLECTION(ImageStyle) {
|
|||||||
REFLECT_N("mask", mask_filename);
|
REFLECT_N("mask", mask_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImageStyle::update(Context& ctx) {
|
||||||
|
return Style ::update(ctx)
|
||||||
|
| mask_filename.update(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : ImageValue
|
// ----------------------------------------------------------------------------- : ImageValue
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ class ImageStyle : public Style {
|
|||||||
|
|
||||||
Scriptable<String> mask_filename; ///< Filename for a mask image
|
Scriptable<String> mask_filename; ///< Filename for a mask image
|
||||||
|
|
||||||
|
virtual bool update(Context&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
// ----------------------------------------------------------------------------- : Includes
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
#include <gui/image_slice_window.hpp>
|
#include <gui/image_slice_window.hpp>
|
||||||
|
#include <gui/util.hpp>
|
||||||
#include <util/window_id.hpp>
|
#include <util/window_id.hpp>
|
||||||
|
#include <util/rotation.hpp>
|
||||||
#include <gfx/gfx.hpp>
|
#include <gfx/gfx.hpp>
|
||||||
#include <wx/spinctrl.h>
|
#include <wx/spinctrl.h>
|
||||||
#include <wx/dcbuffer.h>
|
#include <wx/dcbuffer.h>
|
||||||
@@ -72,7 +74,7 @@ DEFINE_EVENT_TYPE(EVENT_SLICE_CHANGED);
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : ImageSliceWindow
|
// ----------------------------------------------------------------------------- : 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)
|
: wxDialog(parent,wxID_ANY,_TITLE_("slice image"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE)
|
||||||
, slice(source, target_size)
|
, slice(source, target_size)
|
||||||
{
|
{
|
||||||
@@ -80,7 +82,7 @@ ImageSliceWindow::ImageSliceWindow(Window* parent, const Image& source, const wx
|
|||||||
const wxPoint defPos = wxDefaultPosition;
|
const wxPoint defPos = wxDefaultPosition;
|
||||||
const wxSize spinSize(80,-1);
|
const wxSize spinSize(80,-1);
|
||||||
selector = new ImageSliceSelector(this, ID_SELECTOR, slice);
|
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")
|
String sizes[] = { _("&Original Size")
|
||||||
, _("Size to &Fit")
|
, _("Size to &Fit")
|
||||||
@@ -331,9 +333,10 @@ END_EVENT_TABLE ()
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : ImageSlicePreview
|
// ----------------------------------------------------------------------------- : ImageSlicePreview
|
||||||
|
|
||||||
ImageSlicePreview::ImageSlicePreview(Window* parent, int id, ImageSlice& slice)
|
ImageSlicePreview::ImageSlicePreview(Window* parent, int id, ImageSlice& slice, const AlphaMaskP& mask)
|
||||||
: wxControl(parent, id)
|
: wxControl(parent, id)
|
||||||
, slice(slice)
|
, slice(slice)
|
||||||
|
, mask(mask)
|
||||||
, mouse_down(false)
|
, mouse_down(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -356,7 +359,21 @@ void ImageSlicePreview::onPaint(wxPaintEvent&) {
|
|||||||
}
|
}
|
||||||
void ImageSlicePreview::draw(DC& dc) {
|
void ImageSlicePreview::draw(DC& dc) {
|
||||||
if (!bitmap.Ok()) {
|
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()) {
|
if (bitmap.Ok()) {
|
||||||
dc.DrawBitmap(bitmap, 0, 0);
|
dc.DrawBitmap(bitmap, 0, 0);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
class ImageSlicePreview;
|
class ImageSlicePreview;
|
||||||
class ImageSliceSelector;
|
class ImageSliceSelector;
|
||||||
class wxSpinEvent;
|
class wxSpinEvent;
|
||||||
|
DECLARE_POINTER_TYPE(AlphaMask);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : ImageSlice
|
// ----------------------------------------------------------------------------- : ImageSlice
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ class ImageSlice {
|
|||||||
/// Dialog for selecting a slice of an image
|
/// Dialog for selecting a slice of an image
|
||||||
class ImageSliceWindow : public wxDialog {
|
class ImageSliceWindow : public wxDialog {
|
||||||
public:
|
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
|
/// Return the sliced image
|
||||||
Image getImage() const;
|
Image getImage() const;
|
||||||
@@ -106,7 +107,7 @@ class ImageSliceWindow : public wxDialog {
|
|||||||
/// A preview of the sliced image
|
/// A preview of the sliced image
|
||||||
class ImageSlicePreview : public wxControl {
|
class ImageSlicePreview : public wxControl {
|
||||||
public:
|
public:
|
||||||
ImageSlicePreview(Window* parent, int id, ImageSlice& slice);
|
ImageSlicePreview(Window* parent, int id, ImageSlice& slice, const AlphaMaskP& mask);
|
||||||
|
|
||||||
/// Notify that the slice was updated
|
/// Notify that the slice was updated
|
||||||
void update();
|
void update();
|
||||||
@@ -115,6 +116,7 @@ class ImageSlicePreview : public wxControl {
|
|||||||
private:
|
private:
|
||||||
Bitmap bitmap;
|
Bitmap bitmap;
|
||||||
ImageSlice& slice;
|
ImageSlice& slice;
|
||||||
|
AlphaMaskP mask;
|
||||||
|
|
||||||
bool mouse_down;
|
bool mouse_down;
|
||||||
int mouseX, mouseY; ///< starting mouse position
|
int mouseX, mouseY; ///< starting mouse position
|
||||||
|
|||||||
+14
-1
@@ -10,6 +10,7 @@
|
|||||||
#include <gui/image_slice_window.hpp>
|
#include <gui/image_slice_window.hpp>
|
||||||
#include <data/format/clipboard.hpp>
|
#include <data/format/clipboard.hpp>
|
||||||
#include <data/action/value.hpp>
|
#include <data/action/value.hpp>
|
||||||
|
#include <data/stylesheet.hpp>
|
||||||
#include <wx/clipbrd.h>
|
#include <wx/clipbrd.h>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : ImageValueEditor
|
// ----------------------------------------------------------------------------- : ImageValueEditor
|
||||||
@@ -28,8 +29,20 @@ bool ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
|
|||||||
|
|
||||||
void ImageValueEditor::sliceImage(const Image& image) {
|
void ImageValueEditor::sliceImage(const Image& image) {
|
||||||
if (!image.Ok()) return;
|
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
|
// slice
|
||||||
ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, style().getSize());
|
ImageSliceWindow s(wxGetTopLevelParent(&editor()), image, style().getSize(), mask);
|
||||||
|
// clicked ok?
|
||||||
if (s.ShowModal() == wxID_OK) {
|
if (s.ShowModal() == wxID_OK) {
|
||||||
// store the image into the set
|
// store the image into the set
|
||||||
FileName new_image_file = getSet().newFileName(field().name,_("")); // a new unique name in the package
|
FileName new_image_file = getSet().newFileName(field().name,_("")); // a new unique name in the package
|
||||||
|
|||||||
Reference in New Issue
Block a user