mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 21:27:01 -04:00
implemented resampled text ("high quality")
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@87 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -26,8 +26,8 @@ double align_delta_y(Alignment align, double box_height, double obj_height) {
|
||||
|
||||
RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRect& outer) {
|
||||
return RealPoint(
|
||||
outer.position.x + align_delta_x(align, outer.size.width, to_align.width),
|
||||
outer.position.y + align_delta_y(align, outer.size.height, to_align.height)
|
||||
outer.x + align_delta_x(align, outer.width, to_align.width),
|
||||
outer.y + align_delta_y(align, outer.height, to_align.height)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,11 @@ enum Alignment
|
||||
, ALIGN_STRETCH = 0x2000
|
||||
// common combinations
|
||||
, ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT
|
||||
, ALIGN_TOP_CENTER = ALIGN_TOP | ALIGN_CENTER
|
||||
, ALIGN_TOP_RIGHT = ALIGN_TOP | ALIGN_RIGHT
|
||||
, ALIGN_MIDDLE_LEFT = ALIGN_MIDDLE | ALIGN_LEFT
|
||||
, ALIGN_MIDDLE_CENTER = ALIGN_MIDDLE | ALIGN_CENTER
|
||||
, ALIGN_MIDDLE_RIGHT = ALIGN_MIDDLE | ALIGN_RIGHT
|
||||
};
|
||||
|
||||
|
||||
|
||||
+36
-18
@@ -117,33 +117,51 @@ inline RealSize addDiagonal(const RealSize& a, const RealSize& b) {
|
||||
// ----------------------------------------------------------------------------- : Rectangle using doubles
|
||||
|
||||
/// A rectangle (postion and size) using real (double) coordinats
|
||||
class RealRect {
|
||||
class RealRect : private RealPoint, private RealSize {
|
||||
public:
|
||||
/// Position of the top left corner
|
||||
RealPoint position;
|
||||
/// Size of the rectangle
|
||||
RealSize size;
|
||||
|
||||
using RealPoint::x;
|
||||
using RealPoint::y;
|
||||
using RealSize::width;
|
||||
using RealSize::height;
|
||||
|
||||
inline RealRect(const wxRect& rect)
|
||||
: position(rect.x, rect.y), size(rect.width, rect.height)
|
||||
: RealPoint(rect.x, rect.y), RealSize(rect.width, rect.height)
|
||||
{}
|
||||
inline RealRect(const RealPoint& position, const RealSize& size)
|
||||
: position(position), size(size)
|
||||
: RealPoint(position), RealSize(size)
|
||||
{}
|
||||
inline RealRect(double x, double y, double w, double h)
|
||||
: position(x,y), size(w,h)
|
||||
: RealPoint(x,y), RealSize(w,h)
|
||||
{}
|
||||
|
||||
inline operator wxRect() const {
|
||||
return wxRect(position.x, position.y, size.width, size.height);
|
||||
}
|
||||
/// Position of the top left corner
|
||||
inline RealPoint& position() { return *this; }
|
||||
inline const RealPoint& position() const { return *this; }
|
||||
/// Size of the rectangle
|
||||
inline RealSize& size() { return *this; }
|
||||
inline const RealSize& size() const { return *this; }
|
||||
|
||||
inline double left() const { return x; }
|
||||
inline double right() const { return x + width; }
|
||||
inline double top() const { return y; }
|
||||
inline double bottom() const { return y + height; }
|
||||
|
||||
inline RealPoint topLeft () const { return *this; }
|
||||
inline RealPoint topRight () const { return RealPoint(x + width, y); }
|
||||
inline RealPoint bottomLeft () const { return RealPoint(x, y + height); }
|
||||
inline RealPoint bottomRight() const { return RealPoint(x + width, y + height); }
|
||||
|
||||
/// Return a rectangle that is amount larger to all sides
|
||||
inline RealRect grow(double amount) {
|
||||
return RealRect(position.x - amount, position.y - amount, size.width + 2 * amount, size.height + 2 * amount);
|
||||
return RealRect(x - amount, y - amount, width + 2 * amount, height + 2 * amount);
|
||||
}
|
||||
/// Move the coordinates by some amount
|
||||
inline RealRect move(double dx, double dy, double dw, double dh) {
|
||||
return RealRect(position.x + dx, position.y + dy, size.width + dw, size.height + dh);
|
||||
inline RealRect move(double dx, double dy, double dw, double dh) const {
|
||||
return RealRect(x + dx, y + dy, width + dw, height + dh);
|
||||
}
|
||||
|
||||
inline operator wxRect() const {
|
||||
return wxRect(x, y, width, height);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,9 +178,9 @@ class RealRect {
|
||||
* +----+-------+
|
||||
*/
|
||||
inline RealRect split_left(RealRect& r, double w) {
|
||||
RealRect result(r.position.x, r.position.y, w, r.size.height);
|
||||
r.size.width -= w;
|
||||
r.position.x += w;
|
||||
RealRect result(r.x, r.y, w, r.height);
|
||||
r.width -= w;
|
||||
r.x += w;
|
||||
return result;
|
||||
}
|
||||
/// Split a rectangle horizontally
|
||||
|
||||
+29
-26
@@ -19,8 +19,8 @@ int constrain_angle(int angle) {
|
||||
|
||||
Rotation::Rotation(int angle, const RealRect& rect, double zoom)
|
||||
: angle(constrain_angle(angle))
|
||||
, size(rect.size)
|
||||
, origin(rect.position)
|
||||
, size(rect.size())
|
||||
, origin(rect.position())
|
||||
, zoom(zoom)
|
||||
{
|
||||
// set origin
|
||||
@@ -43,7 +43,7 @@ RealSize Rotation::tr(const RealSize& s) const {
|
||||
}
|
||||
}
|
||||
RealRect Rotation::tr(const RealRect& r) const {
|
||||
return RealRect(tr(r.position), tr(r.size));
|
||||
return RealRect(tr(r.position()), tr(r.size()));
|
||||
}
|
||||
|
||||
RealSize Rotation::trNoNeg(const RealSize& s) const {
|
||||
@@ -54,12 +54,12 @@ RealSize Rotation::trNoNeg(const RealSize& s) const {
|
||||
}
|
||||
}
|
||||
RealRect Rotation::trNoNeg(const RealRect& r) const {
|
||||
RealSize s = (sideways() ? RealSize(r.size.height, r.size.width) : r.size) * zoom;
|
||||
return RealRect(tr(r.position) - RealSize(revX()?s.width:0, revY()?s.height:0), s);
|
||||
RealSize s = (sideways() ? RealSize(r.height, r.width) : r.size()) * zoom;
|
||||
return RealRect(tr(r.position()) - RealSize(revX()?s.width:0, revY()?s.height:0), s);
|
||||
}
|
||||
RealRect Rotation::trNoNegNoZoom(const RealRect& r) const {
|
||||
RealSize s = sideways() ? RealSize(r.size.height, r.size.width) : r.size;
|
||||
return RealRect(tr(r.position) - RealSize(revX()?s.width:0, revY()?s.height:0), s);
|
||||
RealSize s = sideways() ? RealSize(r.height, r.width) : r.size();
|
||||
return RealRect(tr(r.position()) - RealSize(revX()?s.width:0, revY()?s.height:0), s);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,8 +90,8 @@ Rotater::Rotater(Rotation& rot, const Rotation& by)
|
||||
RealRect new_ext = rot.trNoNeg(by.getExternalRect());
|
||||
rot.angle = constrain_angle(rot.angle + by.angle);
|
||||
rot.zoom *= by.zoom;
|
||||
rot.size = new_ext.size;
|
||||
rot.origin = new_ext.position + RealSize(rot.revX() ? rot.size.width : 0, rot.revY() ? rot.size.height : 0);
|
||||
rot.size = new_ext.size();
|
||||
rot.origin = new_ext.position() + RealSize(rot.revX() ? rot.size.width : 0, rot.revY() ? rot.size.height : 0);
|
||||
}
|
||||
|
||||
Rotater::~Rotater() {
|
||||
@@ -107,26 +107,21 @@ RotatedDC::RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool
|
||||
|
||||
RotatedDC::RotatedDC(DC& dc, const Rotation& rotation, bool high_quality = false)
|
||||
: Rotation(rotation)
|
||||
, dc(dc), high_quality(high_quality)
|
||||
, dc(dc), high_quality(high_quality&&false)
|
||||
{}
|
||||
|
||||
// ----------------------------------------------------------------------------- : RotatedDC : Drawing
|
||||
|
||||
void RotatedDC::DrawText (const String& text, const RealPoint& pos) {
|
||||
if (text.empty()) return;
|
||||
// if (high_quality) {
|
||||
/* RealRect r(p, getTextExtent(text));
|
||||
//dc.getTextExtent(text, &r.width, &r.height)
|
||||
if (high_quality) {
|
||||
RealRect r(pos, GetTextExtent(text));
|
||||
RealRect r_ext = trNoNeg(r);
|
||||
drawResampledText( {
|
||||
dc, r_ext.x, r_ext.y, r_ext.width, r_ext.height,
|
||||
revX(), revY(),
|
||||
angle, text);
|
||||
}
|
||||
draw_resampled_text(dc, r_ext, revX(), revY(), angle, text);
|
||||
} else {
|
||||
*/ RealPoint p_ext = tr(pos);
|
||||
RealPoint p_ext = tr(pos);
|
||||
dc.DrawRotatedText(text, p_ext.x, p_ext.y, angle);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void RotatedDC::DrawBitmap(const Bitmap& bitmap, const RealPoint& pos) {
|
||||
@@ -165,22 +160,30 @@ void RotatedDC::SetBrush(const wxBrush& brush) { dc.SetBrush(brush); }
|
||||
void RotatedDC::SetTextForeground(const Color& color) { dc.SetTextForeground(color); }
|
||||
void RotatedDC::SetLogicalFunction(int function) { dc.SetLogicalFunction(function); }
|
||||
|
||||
void RotatedDC::SetFont(const wxFont& font) { SetFont(font, font.GetPointSize()); }
|
||||
void RotatedDC::SetFont(const wxFont& font) {
|
||||
SetFont(font, font.GetPointSize());
|
||||
}
|
||||
void RotatedDC::SetFont(wxFont font, double size) {
|
||||
font.SetPointSize(trS(size));
|
||||
font.SetPointSize(trS(size) * (high_quality ? text_scaling : 1));
|
||||
dc.SetFont(font);
|
||||
}
|
||||
|
||||
double RotatedDC::getFontSizeStep() const {
|
||||
return 1; // TODO
|
||||
// return 1. / (high_quality ? text_scaling : 1);
|
||||
return 1. / (high_quality ? text_scaling : 1);
|
||||
}
|
||||
|
||||
RealSize RotatedDC::GetTextExtent(const String& text) const {
|
||||
int w, h;
|
||||
dc.GetTextExtent(text, &w, &h);
|
||||
return RealSize(w,h) / zoom;
|
||||
return RealSize(w,h) / zoom / (high_quality ? text_scaling : 1);
|
||||
}
|
||||
double RotatedDC::GetCharHeight() const {
|
||||
return dc.GetCharHeight() / zoom;
|
||||
return dc.GetCharHeight() / zoom / (high_quality ? text_scaling : 1);
|
||||
}
|
||||
|
||||
void RotatedDC::SetClippingRegion(const RealRect& rect) {
|
||||
dc.SetClippingRegion(trNoNeg(rect));
|
||||
}
|
||||
void RotatedDC::DestroyClippingRegion() {
|
||||
dc.DestroyClippingRegion();
|
||||
}
|
||||
|
||||
@@ -139,17 +139,20 @@ class RotatedDC : public Rotation {
|
||||
void SetBrush(const wxBrush&);
|
||||
void SetTextForeground(const Color&);
|
||||
void SetLogicalFunction(int function);
|
||||
|
||||
void SetFont(const wxFont& font);
|
||||
/// Set the font, scales for zoom and high_quality
|
||||
/** The font will get the given (internal) point size */
|
||||
void SetFont(wxFont font, double size);
|
||||
|
||||
/// Steps to use when decrementing font size
|
||||
double getFontSizeStep() const;
|
||||
|
||||
RealSize GetTextExtent(const String& text) const;
|
||||
double GetCharHeight() const;
|
||||
|
||||
void SetClippingRegion(const RealRect& rect);
|
||||
void DestroyClippingRegion();
|
||||
|
||||
inline wxDC& getDC() { return dc; }
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user