mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Added crop image function.
Fixed 'difference' symbol type. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@574 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -185,15 +185,15 @@ bool SetCombineImage::operator == (const GeneratedImage& that) const {
|
||||
Image EnlargeImage::generate(const Options& opt) const {
|
||||
// generate 'sub' image
|
||||
Options sub_opt
|
||||
( opt.width * (border_size < 0.5 ? 1 - 2 * border_size : 0)
|
||||
, opt.height * (border_size < 0.5 ? 1 - 2 * border_size : 0)
|
||||
( int(opt.width * (border_size < 0.5 ? 1 - 2 * border_size : 0))
|
||||
, int(opt.height * (border_size < 0.5 ? 1 - 2 * border_size : 0))
|
||||
, opt.package
|
||||
, opt.local_package
|
||||
, opt.preserve_aspect);
|
||||
Image img = image->generate(sub_opt);
|
||||
// size of generated image
|
||||
int w = img.GetWidth(), h = img.GetHeight(); // original image size
|
||||
int dw = w * border_size, dh = h * border_size; // delta
|
||||
int dw = int(w * border_size), dh = int(h * border_size); // delta
|
||||
int w2 = w + dw + dw, h2 = h + dh + dh; // new image size
|
||||
Image larger(w2,h2);
|
||||
larger.InitAlpha();
|
||||
@@ -221,6 +221,21 @@ bool EnlargeImage::operator == (const GeneratedImage& that) const {
|
||||
&& border_size == that2->border_size;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CropImage
|
||||
|
||||
Image CropImage::generate(const Options& opt) const {
|
||||
return image->generate(opt).Size(wxSize((int)width, (int)height), wxPoint(-(int)offset_x, -(int)offset_y));
|
||||
}
|
||||
ImageCombine CropImage::combine() const {
|
||||
return image->combine();
|
||||
}
|
||||
bool CropImage::operator == (const GeneratedImage& that) const {
|
||||
const CropImage* that2 = dynamic_cast<const CropImage*>(&that);
|
||||
return that2 && *image == *that2->image
|
||||
&& width == that2->width && height == that2->height
|
||||
&& offset_x == that2->offset_x && offset_y == that2->offset_y;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : DropShadowImage
|
||||
|
||||
/// Preform a gaussian blur, from the image in of w*h bytes to out
|
||||
@@ -287,7 +302,7 @@ Image DropShadowImage::generate(const Options& opt) const {
|
||||
UInt total = 255 * gaussian_blur(alpha, shadow, w, h, shadow_blur_radius);
|
||||
// combine
|
||||
Byte* data = img.GetData();
|
||||
int dw = w * offset_x, dh = h * offset_y;
|
||||
int dw = int(w * offset_x), dh = int(h * offset_y);
|
||||
int x_start = max(0, dw), y_start = max(0, dh);
|
||||
int x_end = min(w, w+dw), y_end = min(h, h+dh);
|
||||
int delta = dw + w * dh;
|
||||
|
||||
@@ -180,6 +180,23 @@ class EnlargeImage : public GeneratedImage {
|
||||
double border_size;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : CropImage
|
||||
|
||||
/// Crop an image at a certain point, to a certain size
|
||||
class CropImage : public GeneratedImage {
|
||||
public:
|
||||
inline CropImage(const GeneratedImageP& image, double width, double height, double offset_x, double offset_y)
|
||||
: image(image), width(width), height(height), offset_x(offset_x), offset_y(offset_y)
|
||||
{}
|
||||
virtual Image generate(const Options& opt) const;
|
||||
virtual ImageCombine combine() const;
|
||||
virtual bool operator == (const GeneratedImage& that) const;
|
||||
private:
|
||||
GeneratedImageP image;
|
||||
double width, height;
|
||||
double offset_x, offset_y;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : DropShadowImage
|
||||
|
||||
/// Add a drop shadow to an image
|
||||
|
||||
@@ -246,14 +246,14 @@ void SymbolWindow::onFileExit(wxCommandEvent& ev) {
|
||||
|
||||
|
||||
void SymbolWindow::onEditUndo(wxCommandEvent& ev) {
|
||||
if (!control->isEditing()) {
|
||||
if (!control->isEditing() && control->getSymbol()->actions.canUndo()) {
|
||||
control->getSymbol()->actions.undo();
|
||||
control->Refresh(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SymbolWindow::onEditRedo(wxCommandEvent& ev) {
|
||||
if (!control->isEditing()) {
|
||||
if (!control->isEditing() && control->getSymbol()->actions.canRedo()) {
|
||||
control->getSymbol()->actions.redo();
|
||||
control->Refresh(false);
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ void SymbolViewer::combineSymbolShape(const SymbolShape& shape, DC& border, DC&
|
||||
break;
|
||||
} case SYMBOL_COMBINE_DIFFERENCE: {
|
||||
interior.SetLogicalFunction(wxXOR);
|
||||
drawSymbolShape(shape, &border, &interior, 0, ~interiorCol, directB, true);
|
||||
drawSymbolShape(shape, &border, &interior, 0, interiorCol, directB, true);
|
||||
interior.SetLogicalFunction(wxCOPY);
|
||||
break;
|
||||
} case SYMBOL_COMBINE_BORDER: {
|
||||
|
||||
@@ -84,6 +84,15 @@ SCRIPT_FUNCTION(enlarge) {
|
||||
return new_intrusive2<EnlargeImage>(input, border_size);
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(crop) {
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
SCRIPT_PARAM_N(int, _("width"), width);
|
||||
SCRIPT_PARAM_N(int, _("height"), height);
|
||||
SCRIPT_PARAM_N(double, _("offset x"), offset_x);
|
||||
SCRIPT_PARAM_N(double, _("offset y"), offset_y);
|
||||
return new_intrusive5<CropImage>(input, width, height, offset_x, offset_y);
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(drop_shadow) {
|
||||
SCRIPT_PARAM(GeneratedImageP, input);
|
||||
SCRIPT_OPTIONAL_PARAM_N_(double, _("offset x"), offset_x);
|
||||
@@ -161,6 +170,7 @@ void init_script_image_functions(Context& ctx) {
|
||||
ctx.setVariable(_("set alpha"), script_set_alpha);
|
||||
ctx.setVariable(_("set combine"), script_set_combine);
|
||||
ctx.setVariable(_("enlarge"), script_enlarge);
|
||||
ctx.setVariable(_("crop"), script_crop);
|
||||
ctx.setVariable(_("drop shadow"), script_drop_shadow);
|
||||
ctx.setVariable(_("symbol variation"), script_symbol_variation);
|
||||
ctx.setVariable(_("built in image"), script_built_in_image);
|
||||
|
||||
Reference in New Issue
Block a user