mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Symbol resizing using aspect ratio;
TODO: copy code for rarity box to other styles git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@622 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -71,8 +71,8 @@ void filter_symbol(Image& symbol, const SymbolFilter& filter) {
|
||||
}
|
||||
}
|
||||
|
||||
Image render_symbol(const SymbolP& symbol, const SymbolFilter& filter, double border_radius, int width, int height, bool edit_hints) {
|
||||
Image i = render_symbol(symbol, border_radius, width, height, edit_hints);
|
||||
Image render_symbol(const SymbolP& symbol, const SymbolFilter& filter, double border_radius, int width, int height, bool edit_hints, bool allow_smaller) {
|
||||
Image i = render_symbol(symbol, border_radius, width, height, edit_hints, allow_smaller);
|
||||
filter_symbol(i, filter);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class AColor : public Color {
|
||||
void filter_symbol(Image& symbol, const SymbolFilter& filter);
|
||||
|
||||
/// Render a Symbol to an Image and filter it
|
||||
Image render_symbol(const SymbolP& symbol, const SymbolFilter& filter, double border_radius = 0.05, int width = 100, int height = 100, bool edit_hints = false);
|
||||
Image render_symbol(const SymbolP& symbol, const SymbolFilter& filter, double border_radius = 0.05, int width = 100, int height = 100, bool edit_hints = false, bool allow_smaller = false);
|
||||
|
||||
/// Is a point inside a symbol?
|
||||
enum SymbolSet
|
||||
|
||||
@@ -14,14 +14,14 @@ DECLARE_TYPEOF_COLLECTION(SymbolPartP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Simple rendering
|
||||
|
||||
Image render_symbol(const SymbolP& symbol, double border_radius, int width, int height, bool editing_hints) {
|
||||
Image render_symbol(const SymbolP& symbol, double border_radius, int width, int height, bool editing_hints, bool allow_smaller) {
|
||||
SymbolViewer viewer(symbol, editing_hints, width, border_radius);
|
||||
// limit width/height ratio to aspect ratio of symbol
|
||||
double ar = symbol->aspectRatio();
|
||||
double par = (double)width/height;
|
||||
if (par > ar && ar > 1) {
|
||||
if (par > ar && (ar > 1 || (allow_smaller && height < width))) {
|
||||
width = height * ar;
|
||||
} else if (par < ar && ar < 1) {
|
||||
} else if (par < ar && (ar < 1 || (allow_smaller && width < height))) {
|
||||
height = width / ar;
|
||||
}
|
||||
if (width > height) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// ----------------------------------------------------------------------------- : Simple rendering
|
||||
|
||||
/// Render a Symbol to an Image
|
||||
Image render_symbol(const SymbolP& symbol, double border_radius = 0.05, int width = 100, int height = 100, bool editing_hints = false);
|
||||
Image render_symbol(const SymbolP& symbol, double border_radius = 0.05, int width = 100, int height = 100, bool editing_hints = false, bool allow_smaller = false);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Symbol Viewer
|
||||
|
||||
|
||||
@@ -12,6 +12,40 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : ChoiceValueViewer
|
||||
|
||||
bool ChoiceValueViewer::prepare(RotatedDC& dc) {
|
||||
if (style().render_style & RENDER_IMAGE) {
|
||||
style().initImage();
|
||||
ScriptableImage& img = style().image;
|
||||
Context& ctx = viewer.getContext();
|
||||
ctx.setVariable(_("input"), to_script(value().value()));
|
||||
img.update(ctx);
|
||||
//generate
|
||||
if (img.isReady()) {
|
||||
GeneratedImage::Options img_options(0,0, viewer.stylesheet.get(), &getSet());
|
||||
if (nativeLook()) {
|
||||
img_options.width = img_options.height = 16;
|
||||
img_options.preserve_aspect = ASPECT_BORDER;
|
||||
} else if(style().render_style & RENDER_TEXT) {
|
||||
// also drawing text, use original size
|
||||
} else {
|
||||
img_options.width = (int) dc.trX(style().width);
|
||||
img_options.height = (int) dc.trY(style().height);
|
||||
img_options.preserve_aspect = (style().alignment & ALIGN_STRETCH) ? ASPECT_STRETCH : ASPECT_FIT;
|
||||
}
|
||||
// don't worry we cache the image
|
||||
Image image = img.generate(img_options, true);
|
||||
// store content properties
|
||||
if (style().content_width != image.GetWidth() ||
|
||||
style().content_height != image.GetHeight()) {
|
||||
style().content_width = image.GetWidth();
|
||||
style().content_height = image.GetHeight();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
drawFieldBorder(dc);
|
||||
if (style().render_style & RENDER_HIDDEN) return;
|
||||
@@ -19,14 +53,7 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
double margin = 0;
|
||||
if (style().render_style & RENDER_IMAGE) {
|
||||
// draw image
|
||||
// map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(value().value()));
|
||||
// if (it != style().choice_images.end() && it->second.isReady()) {
|
||||
// ScriptableImage& img = it->second;
|
||||
style().initImage();
|
||||
ScriptableImage& img = style().image;
|
||||
Context& ctx = viewer.getContext();
|
||||
ctx.setVariable(_("input"), to_script(value().value()));
|
||||
img.update(ctx);
|
||||
if (img.isReady()) {
|
||||
GeneratedImage::Options img_options(0,0, viewer.stylesheet.get(), &getSet());
|
||||
if (nativeLook()) {
|
||||
|
||||
@@ -20,6 +20,7 @@ class ChoiceValueViewer : public ValueViewer {
|
||||
public:
|
||||
DECLARE_VALUE_VIEWER(Choice) : ValueViewer(parent,style) {}
|
||||
|
||||
virtual bool prepare(RotatedDC& dc);
|
||||
virtual void draw(RotatedDC& dc);
|
||||
virtual void onStyleChange(bool);
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ void SymbolValueViewer::draw(RotatedDC& dc) {
|
||||
ar = min(style().max_aspect_ratio, max(style().min_aspect_ratio, ar));
|
||||
// render and filter variations
|
||||
FOR_EACH(variation, style().variations) {
|
||||
Image img = render_symbol(symbol, *variation->filter, variation->border_radius, 100 * ar, 100);
|
||||
Image img = render_symbol(symbol, *variation->filter, variation->border_radius, 200 * ar, 200);
|
||||
Image resampled((int) (wh * ar), (int) wh, false);
|
||||
resample(img, resampled);
|
||||
symbols.push_back(Bitmap(resampled));
|
||||
|
||||
Reference in New Issue
Block a user