mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Implement unique IDs and card linking
This commit is contained in:
+87
-35
@@ -13,6 +13,7 @@
|
||||
#include <data/card.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
#include <wx/filename.h>
|
||||
|
||||
@@ -25,47 +26,47 @@ void export_image(const SetP& set, const CardP& card, const String& filename) {
|
||||
}
|
||||
|
||||
class UnzoomedDataViewer : public DataViewer {
|
||||
public:
|
||||
UnzoomedDataViewer();
|
||||
public:
|
||||
UnzoomedDataViewer();
|
||||
UnzoomedDataViewer(double zoom, double angle);
|
||||
virtual ~UnzoomedDataViewer() {};
|
||||
Rotation getRotation() const override;
|
||||
private:
|
||||
private:
|
||||
double zoom;
|
||||
double angle;
|
||||
double angle;
|
||||
bool declared_values;
|
||||
};
|
||||
|
||||
UnzoomedDataViewer::UnzoomedDataViewer()
|
||||
: zoom(1.0)
|
||||
, angle(0.0)
|
||||
, declared_values(false)
|
||||
{}
|
||||
|
||||
UnzoomedDataViewer::UnzoomedDataViewer(const double zoom, const Radians angle = 0.0)
|
||||
: zoom(zoom)
|
||||
, angle(angle)
|
||||
, declared_values(true)
|
||||
};
|
||||
|
||||
UnzoomedDataViewer::UnzoomedDataViewer()
|
||||
: zoom(1.0)
|
||||
, angle(0.0)
|
||||
, declared_values(false)
|
||||
{}
|
||||
|
||||
UnzoomedDataViewer::UnzoomedDataViewer(const double zoom, const Radians angle = 0.0)
|
||||
: zoom(zoom)
|
||||
, angle(angle)
|
||||
, declared_values(true)
|
||||
{}
|
||||
|
||||
Rotation UnzoomedDataViewer::getRotation() const {
|
||||
if (!stylesheet) stylesheet = set->stylesheet;
|
||||
if (declared_values) {
|
||||
return Rotation(angle, stylesheet->getCardRect(), zoom, 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
}
|
||||
if (!stylesheet) stylesheet = set->stylesheet;
|
||||
if (declared_values) {
|
||||
return Rotation(angle, stylesheet->getCardRect(), zoom, 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
}
|
||||
|
||||
double export_zoom = settings.stylesheetSettingsFor(set->stylesheetFor(card)).export_zoom();
|
||||
bool use_viewer_rotation = !settings.stylesheetSettingsFor(set->stylesheetFor(card)).card_normal_export();
|
||||
|
||||
if (use_viewer_rotation) {
|
||||
double export_zoom = settings.stylesheetSettingsFor(set->stylesheetFor(card)).export_zoom();
|
||||
bool use_viewer_rotation = !settings.stylesheetSettingsFor(set->stylesheetFor(card)).card_normal_export();
|
||||
|
||||
if (use_viewer_rotation) {
|
||||
return Rotation(DataViewer::getRotation().getAngle(), stylesheet->getCardRect(), export_zoom, 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
} else {
|
||||
return Rotation(angle, stylesheet->getCardRect(), export_zoom, 1.0, ROTATION_ATTACH_TOP_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
Bitmap export_bitmap(const SetP& set, const CardP& card) {
|
||||
if (!set) throw Error(_("no set"));
|
||||
}
|
||||
|
||||
Bitmap export_bitmap(const SetP& set, const CardP& card) {
|
||||
if (!set) throw Error(_("no set"));
|
||||
UnzoomedDataViewer viewer = UnzoomedDataViewer();
|
||||
viewer.setSet(set);
|
||||
viewer.setCard(card);
|
||||
@@ -79,11 +80,11 @@ Bitmap export_bitmap(const SetP& set, const CardP& card) {
|
||||
// draw
|
||||
viewer.draw(dc);
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, const Radians angle = 0.0) {
|
||||
if (!set) throw Error(_("no set"));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, const Radians angle = 0.0) {
|
||||
if (!set) throw Error(_("no set"));
|
||||
UnzoomedDataViewer viewer = UnzoomedDataViewer(zoom, angle);
|
||||
viewer.setSet(set);
|
||||
viewer.setCard(card);
|
||||
@@ -97,8 +98,59 @@ Bitmap export_bitmap(const SetP& set, const CardP& card, const double zoom, cons
|
||||
// draw
|
||||
viewer.draw(dc);
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
return bitmap;
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (!set) throw Error(_("no set"));
|
||||
vector<Bitmap> bitmaps;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
double lowest_dpi = 1200.0;
|
||||
if (scale_to_lowest_dpi) {
|
||||
FOR_EACH(card, cards) {
|
||||
lowest_dpi = min(lowest_dpi, set->stylesheetFor(card).card_dpi);
|
||||
}
|
||||
lowest_dpi = max(lowest_dpi, 150.0);
|
||||
}
|
||||
// Draw card bitmaps
|
||||
FOR_EACH(card, cards) {
|
||||
double scaled_zoom = 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);
|
||||
viewer.setSet(set);
|
||||
viewer.setCard(card);
|
||||
RealSize size = viewer.getRotation().getExternalSize();
|
||||
Bitmap bitmap((int)size.width, (int)size.height);
|
||||
if (!bitmap.Ok()) throw InternalError(_("Unable to create bitmap"));
|
||||
wxMemoryDC bufferDC;
|
||||
bufferDC.SelectObject(bitmap);
|
||||
clearDC(bufferDC, *wxWHITE_BRUSH);
|
||||
viewer.draw(bufferDC);
|
||||
bufferDC.SelectObject(wxNullBitmap);
|
||||
width += (int)size.width;
|
||||
height = max(height, (int)size.height);
|
||||
bitmaps.push_back(bitmap);
|
||||
}
|
||||
// Draw global bitmap
|
||||
Bitmap global_bitmap(width + (bitmaps.size()-1) * padding, height);
|
||||
if (!global_bitmap.Ok()) throw InternalError(_("Unable to create bitmap"));
|
||||
wxMemoryDC globalDC;
|
||||
globalDC.SelectObject(global_bitmap);
|
||||
clearDC(globalDC, *wxWHITE_BRUSH);
|
||||
int offset = 0;
|
||||
FOR_EACH(bitmap, bitmaps) {
|
||||
globalDC.SetDeviceOrigin(offset, 0);
|
||||
globalDC.DrawBitmap(bitmap, 0, 0);
|
||||
offset += bitmap.GetWidth() + padding;
|
||||
}
|
||||
globalDC.SelectObject(wxNullBitmap);
|
||||
return global_bitmap;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Multiple card export
|
||||
|
||||
|
||||
Reference in New Issue
Block a user