Card data in images (start)

* Add uuid implementation

* Simplify uid implementation

* Check for uid conflicts upon adding/copying cards

* Remove unnecessary checks

these are already checked as part of the first loop, since they were added to set.cards

* Implement card linking

* refactor to avoid triple loop

* Start link visualization

* Continue link visualization

* formatting

* add missing locale entries

* improve layout

* improve UI refresh

* copy links when copying cards

* implement second face editor

* refactor using macros

* get references

* pasting multiple cards and links

* start refactoring editors

* continue refactoring editors

* continue refactoring editors again

* finish refactoring editors

* refresh card list on link editor event

* tweak event handling

* Add insert_image script function

* change parameter type

* add script functions to get cards

* add dimensions_of script function

calculate both dimensions simultaneously while rendering the image only once.

* save value even if not editable

* add get_mse_locale script function

* Change zoom scale choices

* bug fixes

* Scale symbol spacing with font size

* sync locales

* standardize line ending

* handle links in new_card

* initial

waiting on wxWidgets 3.3.1

* update comment

* store rect in image filename

* store rect in temp file name

* Update package.cpp

* change line endings
This commit is contained in:
GenevensiS
2025-08-11 16:57:04 +02:00
committed by GitHub
parent 3bf9de18b1
commit 81e9a1e26f
16 changed files with 193 additions and 110 deletions
+6 -5
View File
@@ -71,6 +71,7 @@ CardsDataObject::CardsDataObject(const SetP& set, const vector<CardP>& cards) {
}
WrappedCards data = { set->game.get(), set->game->name(), cards };
SetText(serialize_for_clipboard(*set, data));
queue_message(MESSAGE_WARNING, GetText());
// restore cards
for (size_t i = 0 ; i < cards.size() ; ++i) {
if (has_styling[i]) {
@@ -140,12 +141,12 @@ KeywordP KeywordDataObject::getKeyword(const SetP& set) {
// ----------------------------------------------------------------------------- : Card on clipboard
CardsOnClipboard::CardsOnClipboard(const SetP& set, const vector<CardP>& cards) {
// Conversion to text format
// TODO
//Add( new TextDataObject(_("card")))
// Conversion to bitmap format
// Conversion to image format
if (cards.size() == 1) {
Add(new wxBitmapDataObject(export_bitmap(set, cards[0])));
Add(new wxImageDataObject(export_image(set, cards[0])));
}
else if (cards.size() < 6) {
Add(new wxImageDataObject(export_image(set, cards, true, 0, 1.0, 0.0)));
}
else if (cards.size() < 6) {
Add(new wxBitmapDataObject(export_bitmap(set, cards, true, 0, 1.0, 0.0)));
+11 -13
View File
@@ -88,20 +88,18 @@ FileFormatP mtg_editor_file_format();
// ----------------------------------------------------------------------------- : Other ways to export
/// Export images for each card in a set to a list of files
void export_images(Window* parent, const SetP& set);
/// Export the image for each card in a list of cards
void export_images(const SetP& set, const vector<CardP>& cards,
const String& path, const String& filename_template, FilenameConflicts conflicts);
/// Export the image of a single card
void export_image(const SetP& set, const CardP& card, const String& filename);
/// Generate a bitmap image of a card
/// Generate a wxBitmap of one or more cards
Bitmap export_bitmap(const SetP& set, const CardP& card);
Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, const Radians angle_radians);
Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_lowest_dpi, int padding, const double zoom, const Radians angle_radians);
Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, const Radians angle_radians = 0.0);
Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_lowest_dpi, int padding, const double zoom, const Radians angle_radians = 0.0);
/// Generate a wxImage of one or more cards
Image export_image(const SetP& set, const CardP& card);
Image export_image(const SetP& set, const CardP& card, const double zoom, const Radians angle_radians = 0.0);
Image export_image(const SetP& set, const vector<CardP>& cards, bool scale_to_lowest_dpi, int padding, const double zoom, const Radians angle_radians = 0.0);
/// Export the image of a single card to a given filename
void export_image(const SetP& set, const CardP& card, const String& filename);
/// Export a set to Magic Workstation format
void export_mws(Window* parent, const SetP& set);
+43 -12
View File
@@ -9,6 +9,8 @@
#include <util/prec.hpp>
#include <util/tagged_string.hpp>
#include <data/format/formats.hpp>
#include <data/format/clipboard.hpp>
#include <data/game.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/stylesheet.hpp>
@@ -17,18 +19,14 @@
#include <render/card/viewer.hpp>
#include <wx/filename.h>
// ----------------------------------------------------------------------------- : Single card export
#define wxIMAGE_OPTION_PNG_DESCRIPTION wxString("PngDescription")
void export_image(const SetP& set, const CardP& card, const String& filename) {
Image img = export_bitmap(set, card).ConvertToImage();
img.SaveFile(filename); // can't use Bitmap::saveFile, it wants to know the file type
// but image.saveFile determines it automagicly
}
// ----------------------------------------------------------------------------- : Card export
class UnzoomedDataViewer : public DataViewer {
public:
UnzoomedDataViewer();
UnzoomedDataViewer(double zoom, double angle);
UnzoomedDataViewer(double zoom, Radians angle);
virtual ~UnzoomedDataViewer() {};
Rotation getRotation() const override;
private:
@@ -65,6 +63,8 @@ Rotation UnzoomedDataViewer::getRotation() const {
}
}
// ----------------------------------------------------------------------------- : wxBitmap export
Bitmap export_bitmap(const SetP& set, const CardP& card) {
if (!set) throw Error(_("no set"));
UnzoomedDataViewer viewer = UnzoomedDataViewer();
@@ -83,9 +83,9 @@ Bitmap export_bitmap(const SetP& set, const CardP& card) {
return bitmap;
}
Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, const Radians angle = 0.0) {
Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, const Radians angle_radians) {
if (!set) throw Error(_("no set"));
UnzoomedDataViewer viewer = UnzoomedDataViewer(zoom, angle);
UnzoomedDataViewer viewer = UnzoomedDataViewer(zoom, angle_radians);
viewer.setSet(set);
viewer.setCard(card);
// size of cards
@@ -102,7 +102,7 @@ Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, cons
}
// put multiple card images into one bitmap
Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_lowest_dpi, int padding, const double zoom, const Radians angle = 0.0) {
Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_lowest_dpi, int padding, const double zoom, const Radians angle_radians) {
if (!set) throw Error(_("no set"));
vector<Bitmap> bitmaps;
int width = 0;
@@ -121,7 +121,7 @@ Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_
double dpi = max(set->stylesheetFor(card).card_dpi, 150.0);
scaled_zoom *= lowest_dpi / dpi;
}
UnzoomedDataViewer viewer = UnzoomedDataViewer(scaled_zoom, angle);
UnzoomedDataViewer viewer = UnzoomedDataViewer(scaled_zoom, angle_radians);
viewer.setSet(set);
viewer.setCard(card);
RealSize size = viewer.getRotation().getExternalSize();
@@ -152,8 +152,39 @@ Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_
return global_bitmap;
}
// ----------------------------------------------------------------------------- : Multiple card export
// ----------------------------------------------------------------------------- : wxImage export
Image export_image(const SetP& set, const CardP& card) {
Bitmap bitmap = export_bitmap(set, card);
Image img = bitmap.ConvertToImage();
vector<CardP> cards = { card };
CardsDataObject data(set, cards);
img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, _("<mse-data-start>") + data.GetText() + _("<mse-data-end>"));
return img;
}
Image export_image(const SetP& set, const CardP& card, const double zoom, const Radians angle_radians) {
Bitmap bitmap = export_bitmap(set, card, zoom, angle_radians);
Image img = bitmap.ConvertToImage();
vector<CardP> cards = { card };
CardsDataObject data(set, cards);
img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, _("<mse-data-start>") + data.GetText() + _("<mse-data-end>"));
return img;
}
Image export_image(const SetP& set, const vector<CardP>& cards, bool scale_to_lowest_dpi, int padding, const double zoom, const Radians angle_radians) {
Bitmap bitmap = export_bitmap(set, cards, scale_to_lowest_dpi, padding, zoom, angle_radians);
Image img = bitmap.ConvertToImage();
CardsDataObject data(set, cards);
img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, _("<mse-data-start>") + data.GetText() + _("<mse-data-end>"));
return img;
}
void export_image(const SetP& set, const CardP& card, const String& filename) {
Image img = export_image(set, card);
img.SaveFile(filename); // can't use Bitmap::saveFile, it wants to know the file type
// but image.saveFile determines it automagicly
}
void export_images(const SetP& set, const vector<CardP>& cards,
const String& path, const String& filename_template, FilenameConflicts conflicts)