mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Text drawing now uses an AColor instead of a normal Color, so transparent text is possible.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@848 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ A reference to a normal [[type:font]] for drawing text.
|
|||||||
| @style@ [[type:scriptable]] font style @"normal"@ Style of the font, one of @"normal"@ or @"italic"@. This can be changed locally by [[type:tagged string|tags]].
|
| @style@ [[type:scriptable]] font style @"normal"@ Style of the font, one of @"normal"@ or @"italic"@. This can be changed locally by [[type:tagged string|tags]].
|
||||||
| @underline@ [[type:scriptable]] [[type:boolean]] @false@ Should the font be underlined?
|
| @underline@ [[type:scriptable]] [[type:boolean]] @false@ Should the font be underlined?
|
||||||
| @color@ [[type:scriptable]] [[type:color]] @rgb(0,0,0)@ What color should text be drawn in?
|
| @color@ [[type:scriptable]] [[type:color]] @rgb(0,0,0)@ What color should text be drawn in?
|
||||||
| @shadow color@ [[type:scriptable]] [[type:color]] @rgb(0,0,0)@ Color for a shadow below the text.
|
| @shadow color@ [[type:scriptable]] [[type:color]] @"transparent"@ Color for a shadow below the text.
|
||||||
| @shadow displacement x@ [[type:double]] @0@ Relative position of the shadow in pixels. A shadow is only drawn if the displacement is nonzero.
|
| @shadow displacement x@ [[type:double]] @0@ Relative position of the shadow in pixels. A shadow is only drawn if the displacement is nonzero.
|
||||||
| @shadow displacement y@ [[type:double]] @0@ ^^^
|
| @shadow displacement y@ [[type:double]] @0@ ^^^
|
||||||
| @shadow blur@ [[type:double]] @0@ How much should the shadow be blurred?
|
| @shadow blur@ [[type:double]] @0@ How much should the shadow be blurred?
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ Font::Font()
|
|||||||
, underline(false)
|
, underline(false)
|
||||||
, scale_down_to(100000)
|
, scale_down_to(100000)
|
||||||
, max_stretch(1.0)
|
, max_stretch(1.0)
|
||||||
|
, color(AColor(0,0,0))
|
||||||
, shadow_displacement(0,0)
|
, shadow_displacement(0,0)
|
||||||
, shadow_blur(0)
|
, shadow_blur(0)
|
||||||
, separator_color(128,128,128)
|
, separator_color(128,128,128)
|
||||||
|
|||||||
+3
-2
@@ -12,6 +12,7 @@
|
|||||||
#include <util/prec.hpp>
|
#include <util/prec.hpp>
|
||||||
#include <util/real_point.hpp>
|
#include <util/real_point.hpp>
|
||||||
#include <script/scriptable.hpp>
|
#include <script/scriptable.hpp>
|
||||||
|
#include <gfx/color.hpp>
|
||||||
|
|
||||||
DECLARE_POINTER_TYPE(Font);
|
DECLARE_POINTER_TYPE(Font);
|
||||||
|
|
||||||
@@ -40,8 +41,8 @@ class Font : public IntrusivePtrBase<Font> {
|
|||||||
Scriptable<bool> underline; ///< Underlined?
|
Scriptable<bool> underline; ///< Underlined?
|
||||||
double scale_down_to; ///< Smallest size to scale down to
|
double scale_down_to; ///< Smallest size to scale down to
|
||||||
double max_stretch; ///< How much should the font be stretched before scaling down?
|
double max_stretch; ///< How much should the font be stretched before scaling down?
|
||||||
Scriptable<Color> color; ///< Color to use
|
Scriptable<AColor> color; ///< Color to use
|
||||||
Scriptable<Color> shadow_color; ///< Color for shadow
|
Scriptable<AColor> shadow_color; ///< Color for shadow
|
||||||
RealSize shadow_displacement; ///< Position of the shadow
|
RealSize shadow_displacement; ///< Position of the shadow
|
||||||
double shadow_blur; ///< Blur radius of the shadow
|
double shadow_blur; ///< Blur radius of the shadow
|
||||||
Color separator_color; ///< Color for <sep> text
|
Color separator_color; ///< Color for <sep> text
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ void sharp_resample_and_clip(const Image& img_in, Image& img_out, wxRect rect, i
|
|||||||
* rect = rectangle to draw in (a rectangle somewhere around pos)
|
* rect = rectangle to draw in (a rectangle somewhere around pos)
|
||||||
* stretch = amount to stretch in the direction of the text after drawing
|
* stretch = amount to stretch in the direction of the text after drawing
|
||||||
*/
|
*/
|
||||||
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, int angle, const String& text, int blur_radius = 0, int repeat = 1);
|
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, int angle, AColor color, const String& text, int blur_radius = 0, int repeat = 1);
|
||||||
|
|
||||||
// scaling factor to use when drawing resampled text
|
// scaling factor to use when drawing resampled text
|
||||||
extern const int text_scaling;
|
extern const int text_scaling;
|
||||||
|
|||||||
@@ -165,7 +165,9 @@ void blur_image_alpha(Image& img) {
|
|||||||
|
|
||||||
// Draw text by first drawing it using a larger font and then downsampling it
|
// Draw text by first drawing it using a larger font and then downsampling it
|
||||||
// optionally rotated by an angle
|
// optionally rotated by an angle
|
||||||
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, int angle, const String& text, int blur_radius, int repeat) {
|
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, int angle, AColor color, const String& text, int blur_radius, int repeat) {
|
||||||
|
// transparent text can be ignored
|
||||||
|
if (color.alpha == 0) return;
|
||||||
// enlarge slightly; some fonts are larger then the GetTextExtent tells us (especially italic fonts)
|
// enlarge slightly; some fonts are larger then the GetTextExtent tells us (especially italic fonts)
|
||||||
int w = static_cast<int>(rect.width) + 3 + 2 * blur_radius, h = static_cast<int>(rect.height) + 1 + 2 * blur_radius;
|
int w = static_cast<int>(rect.width) + 3 + 2 * blur_radius, h = static_cast<int>(rect.height) + 1 + 2 * blur_radius;
|
||||||
// determine sub-pixel position
|
// determine sub-pixel position
|
||||||
@@ -188,8 +190,12 @@ void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, dou
|
|||||||
if (!sideways(angle)) w = int(w * stretch); // GCC makes annoying conversion warnings if *= is used here.
|
if (!sideways(angle)) w = int(w * stretch); // GCC makes annoying conversion warnings if *= is used here.
|
||||||
else h = int(h * stretch);
|
else h = int(h * stretch);
|
||||||
Image img_small(w, h, false);
|
Image img_small(w, h, false);
|
||||||
fill_image(img_small, dc.GetTextForeground());
|
fill_image(img_small, color);
|
||||||
downsample_to_alpha(buffer, img_small);
|
downsample_to_alpha(buffer, img_small);
|
||||||
|
// multiply alpha
|
||||||
|
if (color.alpha != 255) {
|
||||||
|
set_alpha(img_small, color.alpha / 255.);
|
||||||
|
}
|
||||||
// blur
|
// blur
|
||||||
for (int i = 0 ; i < blur_radius ; ++i) {
|
for (int i = 0 ; i < blur_radius ; ++i) {
|
||||||
blur_image_alpha(img_small);
|
blur_image_alpha(img_small);
|
||||||
|
|||||||
+10
-7
@@ -199,7 +199,12 @@ RotatedDC::RotatedDC(DC& dc, const Rotation& rotation, RenderQuality quality)
|
|||||||
// ----------------------------------------------------------------------------- : RotatedDC : Drawing
|
// ----------------------------------------------------------------------------- : RotatedDC : Drawing
|
||||||
|
|
||||||
void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_radius, int boldness, double stretch_) {
|
void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_radius, int boldness, double stretch_) {
|
||||||
|
DrawText(text, pos, dc.GetTextForeground(), blur_radius, boldness, stretch_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RotatedDC::DrawText (const String& text, const RealPoint& pos, AColor color, int blur_radius, int boldness, double stretch_) {
|
||||||
if (text.empty()) return;
|
if (text.empty()) return;
|
||||||
|
if (color.alpha == 0) return;
|
||||||
if (quality >= QUALITY_AA) {
|
if (quality >= QUALITY_AA) {
|
||||||
RealRect r(pos, GetTextExtent(text));
|
RealRect r(pos, GetTextExtent(text));
|
||||||
RealRect r_ext = trRectToBB(r);
|
RealRect r_ext = trRectToBB(r);
|
||||||
@@ -212,27 +217,25 @@ void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_ra
|
|||||||
r_ext.x = r_ext2.x;
|
r_ext.x = r_ext2.x;
|
||||||
r_ext.y = r_ext2.y;
|
r_ext.y = r_ext2.y;
|
||||||
}
|
}
|
||||||
draw_resampled_text(dc, pos2, r_ext, stretch_ * getStretch(), angle, text, blur_radius, boldness);
|
draw_resampled_text(dc, pos2, r_ext, stretch_ * getStretch(), angle, color, text, blur_radius, boldness);
|
||||||
} else if (quality >= QUALITY_SUB_PIXEL) {
|
} else if (quality >= QUALITY_SUB_PIXEL) {
|
||||||
RealPoint p_ext = tr(pos)*text_scaling;
|
RealPoint p_ext = tr(pos)*text_scaling;
|
||||||
double usx,usy;
|
double usx,usy;
|
||||||
dc.GetUserScale(&usx, &usy);
|
dc.GetUserScale(&usx, &usy);
|
||||||
dc.SetUserScale(usx/text_scaling, usy/text_scaling);
|
dc.SetUserScale(usx/text_scaling, usy/text_scaling);
|
||||||
|
dc.SetTextForeground(color);
|
||||||
dc.DrawRotatedText(text, (int) p_ext.x, (int) p_ext.y, angle);
|
dc.DrawRotatedText(text, (int) p_ext.x, (int) p_ext.y, angle);
|
||||||
dc.SetUserScale(usx, usy);
|
dc.SetUserScale(usx, usy);
|
||||||
} else {
|
} else {
|
||||||
RealPoint p_ext = tr(pos);
|
RealPoint p_ext = tr(pos);
|
||||||
|
dc.SetTextForeground(color);
|
||||||
dc.DrawRotatedText(text, (int) p_ext.x, (int) p_ext.y, angle);
|
dc.DrawRotatedText(text, (int) p_ext.x, (int) p_ext.y, angle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotatedDC::DrawTextWithShadow(const String& text, const Font& font, const RealPoint& pos, double scale, double stretch) {
|
void RotatedDC::DrawTextWithShadow(const String& text, const Font& font, const RealPoint& pos, double scale, double stretch) {
|
||||||
if (font.hasShadow()) {
|
DrawText(text, pos + font.shadow_displacement * scale, font.shadow_color, font.shadow_blur * scale, 1, stretch);
|
||||||
SetTextForeground(font.shadow_color);
|
DrawText(text, pos, font.color, 0, 1, stretch);
|
||||||
DrawText(text, pos + font.shadow_displacement * scale, font.shadow_blur * scale, 1, stretch);
|
|
||||||
}
|
|
||||||
SetTextForeground(font.color);
|
|
||||||
DrawText(text, pos, 0, 1, stretch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotatedDC::DrawBitmap(const Bitmap& bitmap, const RealPoint& pos) {
|
void RotatedDC::DrawBitmap(const Bitmap& bitmap, const RealPoint& pos) {
|
||||||
|
|||||||
@@ -164,7 +164,8 @@ class RotatedDC : public Rotation {
|
|||||||
// --------------------------------------------------- : Drawing
|
// --------------------------------------------------- : Drawing
|
||||||
|
|
||||||
/// Draw text
|
/// Draw text
|
||||||
void DrawText (const String& text, const RealPoint& pos, int blur_radius = 0, int boldness = 1, double stretch = 1.0);
|
void DrawText (const String& text, const RealPoint& pos, int blur_radius = 0, int boldness = 1, double stretch = 1.0);
|
||||||
|
void DrawText (const String& text, const RealPoint& pos, AColor color, int blur_radius = 0, int boldness = 1, double stretch = 1.0);
|
||||||
/// Draw text with the shadow and color settings of the given font
|
/// Draw text with the shadow and color settings of the given font
|
||||||
void DrawTextWithShadow(const String& text, const Font& font, const RealPoint& pos, double scale = 1.0, double stretch = 1.0);
|
void DrawTextWithShadow(const String& text, const Font& font, const RealPoint& pos, double scale = 1.0, double stretch = 1.0);
|
||||||
/// Draw abitmap, it must already be zoomed!
|
/// Draw abitmap, it must already be zoomed!
|
||||||
|
|||||||
Reference in New Issue
Block a user