mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
Removed last of the BeginDrawing/EndDrawing calls;
Added english_number_ordinal script function; Working on symbols with a different aspect ratio (i.e. wider/smaller symbols) git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@558 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -47,8 +47,8 @@ void filter_symbol(Image& symbol, const SymbolFilter& filter) {
|
||||
alpha = (Byte*) malloc(width * height);
|
||||
symbol.SetAlpha(alpha);
|
||||
}
|
||||
for (UInt y = 0 ; y < width ; ++y) {
|
||||
for (UInt x = 0 ; x < height ; ++x) {
|
||||
for (UInt y = 0 ; y < height ; ++y) {
|
||||
for (UInt x = 0 ; x < width ; ++x) {
|
||||
// Determine set
|
||||
// green -> border or outside
|
||||
// green+red=white -> border
|
||||
@@ -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 size, bool edit_hints) {
|
||||
Image i = render_symbol(symbol, border_radius, size, edit_hints);
|
||||
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);
|
||||
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 size = 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);
|
||||
|
||||
/// Is a point inside a symbol?
|
||||
enum SymbolSet
|
||||
|
||||
@@ -14,13 +14,29 @@ DECLARE_TYPEOF_COLLECTION(SymbolPartP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Simple rendering
|
||||
|
||||
Image render_symbol(const SymbolP& symbol, double border_radius, int size, bool editing_hints) {
|
||||
SymbolViewer viewer(symbol, size, border_radius);
|
||||
Bitmap bmp(size, size);
|
||||
Image render_symbol(const SymbolP& symbol, double border_radius, int width, int height, bool editing_hints) {
|
||||
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) {
|
||||
width = height * ar;
|
||||
} else if (par < ar && ar < 1) {
|
||||
height = width / ar;
|
||||
}
|
||||
if (width > height) {
|
||||
viewer.setZoom(width);
|
||||
viewer.setOrigin(Vector2D(0,-(width-height) * 0.5));
|
||||
viewer.border_radius *= (double)height / width;
|
||||
} else {
|
||||
viewer.setZoom(height);
|
||||
viewer.setOrigin(Vector2D(-(height-width) * 0.5,0));
|
||||
viewer.border_radius *= (double)width / height;
|
||||
}
|
||||
Bitmap bmp(width, height);
|
||||
wxMemoryDC dc;
|
||||
dc.SelectObject(bmp);
|
||||
clearDC(dc, Color(0,128,0));
|
||||
viewer.setZoom(size);
|
||||
viewer.draw(dc);
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
return bmp.ConvertToImage();
|
||||
@@ -40,8 +56,13 @@ SymbolViewer::SymbolViewer(const SymbolP& symbol, bool editing_hints, double siz
|
||||
|
||||
void SymbolViewer::setZoom(double zoom) {
|
||||
rotation.setZoom(zoom);
|
||||
rotation.setOrigin(zoom * origin);
|
||||
multiply = Matrix2D(zoom,0, 0,zoom);
|
||||
}
|
||||
void SymbolViewer::setOrigin(const Vector2D& origin) {
|
||||
this->origin = origin;
|
||||
rotation.setOrigin(origin);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Drawing : Combining
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// ----------------------------------------------------------------------------- : Simple rendering
|
||||
|
||||
/// Render a Symbol to an Image
|
||||
Image render_symbol(const SymbolP& symbol, double border_radius = 0.05, int size = 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);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Symbol Viewer
|
||||
|
||||
@@ -41,6 +41,7 @@ class SymbolViewer : public SymbolView {
|
||||
// --------------------------------------------------- : Point translation
|
||||
|
||||
void setZoom(double zoom);
|
||||
void setOrigin(const Vector2D& origin);
|
||||
|
||||
Rotation rotation; ///< Object that handles rotation, scaling and translation
|
||||
Matrix2D multiply; ///< Scaling/rotation of actual parts
|
||||
|
||||
@@ -183,8 +183,10 @@ size_t TextViewer::lineEnd(size_t index) const {
|
||||
}
|
||||
|
||||
struct CompareTop {
|
||||
inline bool operator () (const TextViewer::Line& l, double y) const { return l.top < y; }
|
||||
inline bool operator () (double y, const TextViewer::Line& l) const { return y < l.top; }
|
||||
inline bool operator () (double a, double b) const { return a < b; }
|
||||
inline bool operator () (const TextViewer::Line& a, double b) const { return a.top < b; }
|
||||
inline bool operator () (double a, const TextViewer::Line& b) const { return a < b.top; }
|
||||
inline bool operator () (const TextViewer::Line& a, const TextViewer::Line& b) const { return a.top < b.top; }
|
||||
};
|
||||
size_t TextViewer::indexAt(const RealPoint& pos) const {
|
||||
// 1. find the line
|
||||
|
||||
@@ -27,10 +27,13 @@ void SymbolValueViewer::draw(RotatedDC& dc) {
|
||||
try {
|
||||
// load symbol
|
||||
SymbolP symbol = getSet().readFile<SymbolP>(value().filename);
|
||||
// aspect ratio
|
||||
double ar = symbol->aspectRatio();
|
||||
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);
|
||||
Image resampled((int) wh, (int) wh, false);
|
||||
Image img = render_symbol(symbol, *variation->filter, variation->border_radius, 100 * ar, 100);
|
||||
Image resampled((int) (wh * ar), (int) wh, false);
|
||||
resample(img, resampled);
|
||||
symbols.push_back(Bitmap(resampled));
|
||||
}
|
||||
@@ -39,9 +42,11 @@ void SymbolValueViewer::draw(RotatedDC& dc) {
|
||||
}
|
||||
}
|
||||
// draw image, if any
|
||||
int x = 0;
|
||||
for (size_t i = 0 ; i < symbols.size() ; ++i) {
|
||||
// todo : labels?
|
||||
dc.DrawBitmap(symbols[i], style().getPos() + RealSize(i * (wh + 2), 0));
|
||||
dc.DrawBitmap(symbols[i], style().getPos() + RealSize(x, 0));
|
||||
x += symbols[i].GetWidth() + 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user