mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
restore ability to paste in Paint
This commit is contained in:
@@ -161,23 +161,29 @@ KeywordP KeywordDataObject::getKeyword(const SetP& set) {
|
||||
// ----------------------------------------------------------------------------- : Card on clipboard
|
||||
|
||||
CardsOnClipboard::CardsOnClipboard(const SetP& set, const String id, const vector<CardP>& cards) {
|
||||
wxBusyCursor busy;
|
||||
// Conversion to image file
|
||||
if (cards.size() < 6) {
|
||||
Bitmap bmp;
|
||||
Image img;
|
||||
if (cards.size() == 1) {
|
||||
img = export_image(set, cards[0]);
|
||||
img = export_image(set, cards[0], true, 1.0, 0.0, 0.0, &bmp);
|
||||
}
|
||||
else {
|
||||
img = export_image(set, cards);
|
||||
bmp = Bitmap(img);
|
||||
}
|
||||
String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png");
|
||||
img.SaveFile(temp_path, wxBITMAP_TYPE_PNG);
|
||||
wxFileDataObject* fileData = new wxFileDataObject();
|
||||
fileData->AddFile(temp_path);
|
||||
Add(fileData);
|
||||
wxImageDataObject* imgData = new wxImageDataObject();
|
||||
//wxFileDataObject* fileData = new wxFileDataObject(); // needed for pasting on desktop, but slow
|
||||
//String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png");
|
||||
//img.SaveFile(temp_path, wxBITMAP_TYPE_PNG);
|
||||
//fileData->AddFile(temp_path);
|
||||
//Add(fileData);
|
||||
wxImageDataObject* imgData = new wxImageDataObject(); // needed for metadata
|
||||
imgData->SetImage(img);
|
||||
Add(imgData);
|
||||
wxBitmapDataObject* bmpData = new wxBitmapDataObject(); // needed for pasting in MSPaint
|
||||
bmpData->SetBitmap(bmp);
|
||||
Add(bmpData);
|
||||
}
|
||||
// Conversion to serialized card format
|
||||
Add(new CardsDataObject(set, id, cards), true);
|
||||
|
||||
@@ -89,7 +89,7 @@ FileFormatP mtg_editor_file_format();
|
||||
// ----------------------------------------------------------------------------- : Other ways to export
|
||||
|
||||
/// Generate a wxImage of one or more cards
|
||||
Image export_image(const SetP& set, const CardP& card, bool write_metadata = true, double zoom = 1.0, Radians angle_radians = 0.0, double bleed_pixels = 0.0);
|
||||
Image export_image(const SetP& set, const CardP& card, bool write_metadata = true, double zoom = 1.0, Radians angle_radians = 0.0, double bleed_pixels = 0.0, Bitmap* out_bitmap = nullptr);
|
||||
Image export_image(const SetP& set, const vector<CardP>& cards, int padding = 2, double global_zoom = 1.0, bool use_zoom_setting = true, bool use_rotation_setting = true, bool use_bleed_setting = false);
|
||||
|
||||
/// Export the image of one or more cards to a given filename, using the app's zoom, rotation and bleed settings, and including metadata
|
||||
|
||||
@@ -35,7 +35,7 @@ Rotation ZoomedUnrotatedDataViewer::getRotation() const {
|
||||
|
||||
// ----------------------------------------------------------------------------- : wxImage export
|
||||
|
||||
Image export_image(const SetP& set, const CardP& card, bool write_metadata, double zoom, Radians angle_radians, double bleed_pixels) {
|
||||
Image export_image(const SetP& set, const CardP& card, bool write_metadata, double zoom, Radians angle_radians, double bleed_pixels, Bitmap* out_bitmap) {
|
||||
if (!set) throw Error(_("no set"));
|
||||
/// create and zoom
|
||||
ZoomedUnrotatedDataViewer viewer = ZoomedUnrotatedDataViewer(zoom);
|
||||
@@ -52,6 +52,9 @@ Image export_image(const SetP& set, const CardP& card, bool write_metadata, doub
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
Image img = bitmap.ConvertToImage();
|
||||
|
||||
/// return bitmap if needed
|
||||
if (out_bitmap) *out_bitmap = std::move(bitmap);
|
||||
|
||||
/// rotate
|
||||
img = rotate_image(img, angle_radians);
|
||||
|
||||
@@ -218,8 +221,7 @@ void export_image(const SetP& set, const CardP& card, const String& filename) {
|
||||
img.SaveFile(filename);
|
||||
}
|
||||
|
||||
void export_image(const SetP& set, const vector<CardP>& cards, const String& path, const String& filename_template, FilenameConflicts conflicts)
|
||||
{
|
||||
void export_image(const SetP& set, const vector<CardP>& cards, const String& path, const String& filename_template, FilenameConflicts conflicts) {
|
||||
wxBusyCursor busy;
|
||||
// Script
|
||||
ScriptP filename_script = parse(filename_template, nullptr, true);
|
||||
|
||||
@@ -166,6 +166,7 @@ bool CardListBase::doCopy() {
|
||||
// put on clipboard
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, _(""), cards_to_copy)); // ignore result
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
@@ -192,6 +193,7 @@ bool CardListBase::doCopyCardAndLinkedCards() {
|
||||
}
|
||||
}
|
||||
bool ok = wxTheClipboard->SetData(new CardsOnClipboard(set, _(""), cards_to_copy)); // ignore result
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
@@ -200,6 +202,7 @@ bool CardListBase::doPaste() {
|
||||
if (!canPaste()) return false;
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
bool ok = wxTheClipboard->GetData(*drop_target->data_object);
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
if (ok) return parseData(false);
|
||||
return false;
|
||||
|
||||
@@ -109,6 +109,7 @@ bool KeywordList::doCopy() {
|
||||
if (!canCopy()) return false;
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
bool ok = wxTheClipboard->SetData(new KeywordDataObject(set, getKeyword())); // ignore result
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
@@ -125,6 +126,7 @@ bool KeywordList::doPaste() {
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
KeywordDataObject data;
|
||||
bool ok = wxTheClipboard->GetData(data);
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
if (!ok) return false;
|
||||
// add keyword to set
|
||||
|
||||
@@ -107,6 +107,7 @@ public:
|
||||
} else {
|
||||
ok = wxTheClipboard->SetData(new wxTextDataObject(msg.text));
|
||||
}
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ bool ImageValueEditor::doCopy() {
|
||||
// set data
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
bool ok = wxTheClipboard->SetData(new wxBitmapDataObject(image));
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
@@ -102,6 +103,7 @@ bool ImageValueEditor::doPaste() {
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
wxBitmapDataObject data;
|
||||
bool ok = wxTheClipboard->GetData(data);
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
if (!ok) return false;
|
||||
// slice
|
||||
|
||||
@@ -783,6 +783,7 @@ bool TextValueEditor::doPaste() {
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
wxTextDataObject data;
|
||||
bool ok = wxTheClipboard->GetData(data);
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
if (!ok) return false;
|
||||
// paste
|
||||
@@ -801,6 +802,7 @@ bool TextValueEditor::doCopy() {
|
||||
// set data
|
||||
if (!wxTheClipboard->Open()) return false;
|
||||
bool ok = wxTheClipboard->SetData(new wxTextDataObject(str));
|
||||
wxTheClipboard->Flush();
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user