Card data in images (minimum viable)

* remove wxEmptyString

* improve style tab carousel

* create web request window

* add drop target and drop source
This commit is contained in:
GenevensiS
2025-11-28 10:42:30 +01:00
committed by GitHub
parent f5b5c0968d
commit cf0a84a8a7
49 changed files with 815 additions and 399 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ void AddCardAction::perform(bool to_undo) {
FOR_EACH(linked_pair, linked_pairs) {
String& linked_uid = linked_pair.first.get();
String& linked_relation = linked_pair.second.get();
if (linked_uid == wxEmptyString) continue;
if (linked_uid.empty()) continue;
// If it's an added card, replace the link
if (all_added_uids.find(linked_uid) != all_added_uids.end()) {
all_added_uids.at(linked_uid)->updateLink(old_uid, new_uid);
+13 -13
View File
@@ -53,7 +53,7 @@ String Card::identification() const {
if (!data.empty()) {
return data.at(0)->toString();
} else {
return wxEmptyString;
return _("");
}
}
@@ -78,7 +78,7 @@ void Card::link(const Set& set, const vector<CardP>& linked_cards, const String&
FOR_EACH(this_linked_pair, this_linked_pairs) {
String& this_linked_uid = this_linked_pair.first.get();
if (
this_linked_uid == wxEmptyString || // Not a reference
this_linked_uid.empty() || // Not a reference
all_existing_uids.find(this_linked_uid) == all_existing_uids.end() // Reference to nonexistent card
) free_link_count++;
}
@@ -94,7 +94,7 @@ void Card::link(const Set& set, const vector<CardP>& linked_cards, const String&
FOR_EACH(this_linked_pair, this_linked_pairs) {
String& this_linked_uid = this_linked_pair.first.get();
String& this_linked_relation = this_linked_pair.second.get();
if (this_linked_uid == wxEmptyString) {
if (this_linked_uid.empty()) {
this_linked_uid = linked_card->uid;
this_linked_relation = linked_relation;
written = true;
@@ -124,7 +124,7 @@ void Card::link(const Set& set, const vector<CardP>& linked_cards, const String&
FOR_EACH(linked_pair, linked_pairs) {
String& linked_uid = linked_pair.first.get();
String& linked_relation = linked_pair.second.get();
if (linked_uid == wxEmptyString) {
if (linked_uid.empty()) {
linked_uid = uid;
linked_relation = selected_relation;
written = true;
@@ -177,26 +177,26 @@ void Card::unlink(const vector<CardP>& unlinked_cards)
pair<String, String> Card::unlink(CardP& unlinked_card)
{
String old_selected_relation = wxEmptyString;
String old_selected_relation = _("");
THIS_LINKED_PAIRS(this_linked_pairs);
FOR_EACH(this_linked_pair, this_linked_pairs) {
String& this_linked_uid = this_linked_pair.first.get();
String& this_linked_relation = this_linked_pair.second.get();
if (this_linked_uid == unlinked_card->uid) {
old_selected_relation = this_linked_relation;
this_linked_uid = wxEmptyString;
this_linked_relation = wxEmptyString;
this_linked_uid = _("");
this_linked_relation = _("");
}
}
String old_unlinked_relation = wxEmptyString;
String old_unlinked_relation = _("");
OTHER_LINKED_PAIRS(unlinked_pairs, unlinked_card);
FOR_EACH(unlinked_pair, unlinked_pairs) {
String& unlinked_uid = unlinked_pair.first.get();
String& unlinked_relation = unlinked_pair.second.get();
if (unlinked_uid == uid) {
old_unlinked_relation = unlinked_relation;
unlinked_uid = wxEmptyString;
unlinked_relation = wxEmptyString;
unlinked_uid = _("");
unlinked_relation = _("");
}
}
return make_pair(old_selected_relation, old_unlinked_relation);
@@ -204,7 +204,7 @@ pair<String, String> Card::unlink(CardP& unlinked_card)
void Card::copyLink(const Set& set, String old_uid, String new_uid) {
// Find what relation we need to copy
String relation_copy = wxEmptyString;
String relation_copy = _("");
THIS_LINKED_PAIRS(this_linked_pairs);
FOR_EACH(this_linked_pair, this_linked_pairs) {
String& this_linked_uid = this_linked_pair.first.get();
@@ -215,7 +215,7 @@ void Card::copyLink(const Set& set, String old_uid, String new_uid) {
}
}
// Nothing to copy
if (relation_copy == wxEmptyString) {
if (relation_copy.empty()) {
return;
}
@@ -224,7 +224,7 @@ void Card::copyLink(const Set& set, String old_uid, String new_uid) {
FOR_EACH(this_linked_pair, this_linked_pairs) {
String& this_linked_uid = this_linked_pair.first.get();
String& this_linked_relation = this_linked_pair.second.get();
if (this_linked_uid == wxEmptyString) {
if (this_linked_uid.empty()) {
this_linked_uid = new_uid;
this_linked_relation = relation_copy;
written = true;
+2 -20
View File
@@ -113,14 +113,9 @@ Style::Style(const FieldP& field)
, visible(true)
, automatic_side(AUTO_UNKNOWN)
, content_dependent(false)
{
field->styleP = this;
}
{}
Style::~Style()
{
fieldP->styleP = nullptr;
}
Style::~Style() {}
IMPLEMENT_REFLECTION(Style) {
REFLECT(z_index);
@@ -138,7 +133,6 @@ IMPLEMENT_REFLECTION(Style) {
void init_object(const FieldP& field, StyleP& style) {
if (!style) style = field->newStyle();
field->styleP = style;
}
template <> StyleP read_new<Style>(Reader&) {
throw InternalError(_("IndexMap contains nullptr StyleP the application should have crashed already"));
@@ -268,18 +262,6 @@ void mark_dependency_member(const Style& style, const String& name, const Depend
style.markDependencyMember(name,dep);
}
String Style::getRect() {
return _("---") +
wxString::Format(wxT("%i"), (int)(left)) +
_("-") +
wxString::Format(wxT("%i"), (int)(top)) +
_("-") +
wxString::Format(wxT("%i"), (int)(width)) +
_("-") +
wxString::Format(wxT("%i"), (int)(height)) +
_("---");
}
// ----------------------------------------------------------------------------- : StyleListener
void Style::addListener(StyleListener* listener) {
+8 -5
View File
@@ -63,7 +63,6 @@ public:
OptionalScript import_script; ///< The script to apply to the supplied value, when creating a new card.
Dependencies dependent_scripts; ///< Scripts that depend on values of this field
String package_relative_filename;
StyleP styleP; ///< Style for this field, should have the right type! Can be null.
/// Creates a new Value corresponding to this Field
virtual ValueP newValue() = 0;
@@ -126,7 +125,14 @@ public:
inline RealPoint getPos() const { return RealPoint(left, top); }
inline RealSize getSize() const { return RealSize(width, height); }
inline RealRect getExternalRect() const { return RealRect(left, top, width, height); }
inline String getExternalRectString(double scale = 1.0, int offset = 0) { ///< update the style before calling this
return _("---") + wxString::Format(wxT("%i"), (int)std::ceil(scale * left + offset)) +
_("-") + wxString::Format(wxT("%i"), (int)std::ceil(scale * top)) +
_("-") + wxString::Format(wxT("%i"), (int)std::floor(scale * width)) +
_("-") + wxString::Format(wxT("%i"), (int)std::floor(scale * height)) +
_("---");
}
/// Does this style have a non-zero size (or is it scripted)?
bool hasSize() const;
@@ -164,9 +170,6 @@ public:
/** change_info is a subset of StyleChange flags */
void tellListeners(int changes);
/// Store where on the card the field goes, to save it in filenames
String getRect();
private:
DECLARE_REFLECTION_VIRTUAL();
/// Things that are listening to changes in this style
+1 -1
View File
@@ -35,7 +35,7 @@ int ImageStyle::update(Context& ctx) {
// ----------------------------------------------------------------------------- : ImageValue
String ImageValue::toString() const {
return filename.empty() ? wxEmptyString : _("<image>");
return filename.empty() ? _("") : _("<image>");
}
// custom reflection: convert to ScriptImageP for scripting
+1 -1
View File
@@ -48,7 +48,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(SymbolVariation) {
// ----------------------------------------------------------------------------- : SymbolValue
String SymbolValue::toString() const {
return filename.empty() ? wxEmptyString : _("<symbol>");
return filename.empty() ? _("") : _("<symbol>");
}
IMPLEMENT_REFLECTION_NO_GET_MEMBER(SymbolValue) {
+1 -1
View File
@@ -206,7 +206,7 @@ void FakeTextValue::retrieve() {
if (underlying) {
value.assign(untagged ? escape(*underlying) : *underlying);
} else {
value.assign(wxEmptyString);
value.assign(_(""));
}
}
+2 -2
View File
@@ -37,7 +37,7 @@ bool Font::PreloadResourceFonts(bool recursive) {
bool preloadHadErrors = false;
wxString folder;
bool cont = appDir.GetFirst(&folder, wxEmptyString, wxDIR_DIRS);
bool cont = appDir.GetFirst(&folder, _(""), wxDIR_DIRS);
while (cont)
{
if (folder.Lower().Contains("fonts")) {
@@ -65,7 +65,7 @@ bool Font::PreloadResourceFonts(bool recursive) {
void Font::TallyResourceFonts(String fontsDirectoryPath, vector<String>& fontFilePaths, bool recursive) {
wxDir fontsDirectory(fontsDirectoryPath);
String fontFileName = wxEmptyString;
String fontFileName = _("");
bool hasNext = fontsDirectory.GetFirst(&fontFileName);
while (hasNext) {
String fontFilePath = fontsDirectoryPath + fontFileName;
+18 -9
View File
@@ -15,7 +15,8 @@
#include <data/stylesheet.hpp>
#include <data/keyword.hpp>
#include <util/io/package.hpp>
#include <script/scriptable.hpp>
#include <script/scriptable.hpp>
#include <wx/filename.h>
#include <wx/sstream.h>
// ----------------------------------------------------------------------------- : Clipboard serialization
@@ -140,13 +141,21 @@ KeywordP KeywordDataObject::getKeyword(const SetP& set) {
// ----------------------------------------------------------------------------- : Card on clipboard
CardsOnClipboard::CardsOnClipboard(const SetP& set, const vector<CardP>& cards) {
// Conversion to image format
if (cards.size() == 1) {
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)));
}
// Conversion to image file
if (cards.size() < 6) {
Image img;
if (cards.size() == 1) {
img = export_image(set, cards[0]);
}
else {
img = export_image(set, cards, true, 0, 1.0, 0.0);
}
String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png");
img.SaveFile(temp_path, wxBITMAP_TYPE_PNG);
wxFileDataObject* data = new wxFileDataObject();
data->AddFile(temp_path);
Add(data);
}
// Conversion to serialized card format
Add(new CardsDataObject(set, cards), true);
Add(new CardsDataObject(set, cards), true);
}
+4 -6
View File
@@ -89,14 +89,12 @@ FileFormatP mtg_editor_file_format();
// ----------------------------------------------------------------------------- : Other ways to export
/// 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 = 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);
Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom = 1.0, 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, vector<double>& scales_out, vector<int>& offsets_out);
/// 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);
Image export_image(const SetP& set, const CardP& card, const double zoom = 1.0, const Radians angle_radians = 0.0);
Image export_image(const SetP& set, const vector<CardP>& cards, bool scale_to_lowest_dpi = false, int padding = 0, const double zoom = 1.0, const Radians angle_radians = 0.0);
/// Export the image of one or more cards to a given filename
void export_image(const SetP& set, const CardP& card, const String& filename);
+56 -41
View File
@@ -15,6 +15,7 @@
#include <data/card.hpp>
#include <data/stylesheet.hpp>
#include <data/settings.hpp>
#include <script/functions/json.hpp>
#include <gui/util.hpp>
#include <render/card/viewer.hpp>
#include <wx/filename.h>
@@ -63,24 +64,6 @@ Rotation UnzoomedDataViewer::getRotation() const {
// ----------------------------------------------------------------------------- : wxBitmap export
Bitmap export_bitmap(const SetP& set, const CardP& card) {
if (!set) throw Error(_("no set"));
UnzoomedDataViewer viewer = UnzoomedDataViewer();
viewer.setSet(set);
viewer.setCard(card);
// size of cards
RealSize size = viewer.getRotation().getExternalSize();
// create bitmap & dc
Bitmap bitmap((int)size.width, (int)size.height);
if (!bitmap.Ok()) throw InternalError(_("Unable to create bitmap"));
wxMemoryDC dc;
dc.SelectObject(bitmap);
// draw
viewer.draw(dc);
dc.SelectObject(wxNullBitmap);
return bitmap;
}
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_radians);
@@ -99,7 +82,7 @@ Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, cons
return bitmap;
}
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 vector<CardP>& cards, bool scale_to_lowest_dpi, int padding, const double zoom, const Radians angle_radians, vector<double>& scales_out, vector<int>& offsets_out) {
if (!set) throw Error(_("no set"));
vector<Bitmap> bitmaps;
int width = 0;
@@ -113,12 +96,13 @@ Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_
}
// Draw card bitmaps
FOR_EACH(card, cards) {
double scaled_zoom = zoom;
double scale = zoom;
if (scale_to_lowest_dpi) {
double dpi = max(set->stylesheetFor(card).card_dpi, 150.0);
scaled_zoom *= lowest_dpi / dpi;
}
UnzoomedDataViewer viewer = UnzoomedDataViewer(scaled_zoom, angle_radians);
scale *= lowest_dpi / dpi;
}
scales_out.push_back(scale);
UnzoomedDataViewer viewer = UnzoomedDataViewer(scale, angle_radians);
viewer.setSet(set);
viewer.setCard(card);
RealSize size = viewer.getRotation().getExternalSize();
@@ -140,7 +124,8 @@ Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_
globalDC.SelectObject(global_bitmap);
clearDC(globalDC, *wxWHITE_BRUSH);
int offset = 0;
FOR_EACH(bitmap, bitmaps) {
FOR_EACH(bitmap, bitmaps) {
offsets_out.push_back(offset);
globalDC.SetDeviceOrigin(offset, 0);
globalDC.DrawBitmap(bitmap, 0, 0);
offset += bitmap.GetWidth() + padding;
@@ -151,29 +136,59 @@ Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_
// ----------------------------------------------------------------------------- : 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>"));
Image img = bitmap.ConvertToImage();
String data = _("<mse-data-start>[");
IndexMap<FieldP, ValueP>& card_data = card->data;
boost::json::object& cardv = mse_to_json(card, set.get());
boost::json::object& cardv_data = cardv["data"].as_object();
for(IndexMap<FieldP, ValueP>::iterator it = card_data.begin() ; it != card_data.end() ; ++it) {
ImageValue* value = dynamic_cast<ImageValue*>(it->get());
if (value && !value->filename.empty()) {
FieldP field = (*it)->fieldP;
StyleP style = set->stylesheetFor(card).card_style.at(field->index);
if (style) {
style->update(set->getContext(card));
std::string rect = style->getExternalRectString(zoom, 0).ToStdString();
cardv_data[field->name.ToStdString()] = rect;
}
}
}
data += json_ugly_print(cardv) + _("]<mse-data-end>");
img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, data);
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>"));
vector<double> scales;
vector<int> offsets;
Bitmap bitmap = export_bitmap(set, cards, scale_to_lowest_dpi, padding, zoom, angle_radians, scales, offsets);
Image img = bitmap.ConvertToImage();
String data = _("<mse-data-start>[");
for (int i = 0; i < cards.size(); ++i) {
if (i > 0) data += _(",");
CardP card = cards[i];
IndexMap<FieldP, ValueP>& card_data = card->data;
boost::json::object& cardv = mse_to_json(card, set.get());
boost::json::object& cardv_data = cardv["data"].as_object();
for(IndexMap<FieldP, ValueP>::iterator it = card_data.begin() ; it != card_data.end() ; ++it) {
ImageValue* value = dynamic_cast<ImageValue*>(it->get());
if (value && !value->filename.empty()) {
FieldP field = (*it)->fieldP;
StyleSheetP stylesheet = set->stylesheetForP(card);
StyleP style = stylesheet->card_style.at(field->index);
if (style) {
style->update(set->getContext(card));
std::string rect = style->getExternalRectString(scales[i], offsets[i]).ToStdString();
cardv_data[field->name.ToStdString()] = rect;
}
}
}
data += json_ugly_print(cardv);
}
data += _("]<mse-data-end>");
img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, data);
return img;
}
+1 -1
View File
@@ -142,7 +142,7 @@ String Set::identification() const {
return v->toString();
}
}
return wxEmptyString;
return _("");
}
+2 -2
View File
@@ -429,7 +429,7 @@ String SymbolFont::insertSymbolCode(int menu_id) const {
if (insert_symbol_menu) {
return insert_symbol_menu->getCode(menu_id - ID_INSERT_SYMBOL_MENU_MIN, *this);
} else {
return wxEmptyString;
return _("");
}
}
@@ -505,7 +505,7 @@ wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolF
}
if (type == Type::SUBMENU) {
wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, label,
wxEmptyString, wxITEM_NORMAL,
_(""), wxITEM_NORMAL,
makeMenu(first_id, font));
item->SetBitmap(wxNullBitmap);
return item;