mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 13:17:00 -04:00
Remove AColor class, because wxColour now supports alpha values.
This commit is contained in:
+12
-24
@@ -13,47 +13,34 @@
|
||||
|
||||
template <> void Reader::handle(Color& col) {
|
||||
col = parse_color(getValue());
|
||||
if (!col.Ok()) col = *wxBLACK;
|
||||
if (!col.Ok()) col = Color(0,0,0,0);
|
||||
}
|
||||
|
||||
template <> void Reader::handle(AColor& col) {
|
||||
col = parse_acolor(getValue());
|
||||
if (!col.Ok()) col = AColor(0,0,0,0);
|
||||
}
|
||||
template <> void Writer::handle(const AColor& col) {
|
||||
handle(format_acolor(col));
|
||||
template <> void Writer::handle(const Color& col) {
|
||||
handle(format_color(col));
|
||||
}
|
||||
|
||||
|
||||
Color parse_color(const String& v) {
|
||||
UInt r,g,b;
|
||||
if (wxSscanf(v.c_str(),_("rgb(%u,%u,%u)"),&r,&g,&b)) {
|
||||
return Color(r, g, b);
|
||||
} else {
|
||||
return Color(v);
|
||||
}
|
||||
}
|
||||
|
||||
AColor parse_acolor(const String& v) {
|
||||
UInt r,g,b,a;
|
||||
if (wxSscanf(v.c_str(),_("rgb(%u,%u,%u)"),&r,&g,&b)) {
|
||||
return AColor(r, g, b);
|
||||
return Color(r, g, b);
|
||||
} else if (wxSscanf(v.c_str(),_("rgba(%u,%u,%u,%u)"),&r,&g,&b,&a)) {
|
||||
return AColor(r, g, b, a);
|
||||
return Color(r, g, b, a);
|
||||
} else if (v == _("transparent")) {
|
||||
return AColor(0,0,0,0);
|
||||
return Color(0,0,0,0);
|
||||
} else {
|
||||
return Color(v);
|
||||
}
|
||||
}
|
||||
|
||||
String format_acolor(AColor col) {
|
||||
if (col.alpha == 255) {
|
||||
String format_color(Color col) {
|
||||
if (col.Alpha() == 255) {
|
||||
return String::Format(_("rgb(%u,%u,%u)"), col.Red(), col.Green(), col.Blue());
|
||||
} else if (col.alpha == 0) {
|
||||
} else if (col.Alpha() == 0) {
|
||||
return _("transparent");
|
||||
} else {
|
||||
return String::Format(_("rgba(%u,%u,%u,%u)"), col.Red(), col.Green(), col.Blue(), col.alpha);
|
||||
return String::Format(_("rgba(%u,%u,%u,%u)"), col.Red(), col.Green(), col.Blue(), col.Alpha());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +49,8 @@ String format_acolor(AColor col) {
|
||||
Color lerp(const Color& a, const Color& b, double t) {
|
||||
return Color(static_cast<int>( a.Red() + (b.Red() - a.Red() ) * t ),
|
||||
static_cast<int>( a.Green() + (b.Green() - a.Green()) * t ),
|
||||
static_cast<int>( a.Blue() + (b.Blue() - a.Blue() ) * t ));
|
||||
static_cast<int>( a.Blue() + (b.Blue() - a.Blue() ) * t ),
|
||||
static_cast<int>( a.Alpha() + (b.Alpha() - a.Alpha()) * t ));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-23
@@ -16,22 +16,6 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Color with alpha
|
||||
|
||||
/// Color with alpha channel
|
||||
class AColor : public Color {
|
||||
public:
|
||||
Byte alpha; ///< The alpha value, in the range [0..255]
|
||||
inline AColor() : alpha(0) {}
|
||||
inline AColor(Byte r, Byte g, Byte b, Byte a = 255) : Color(r,g,b), alpha(a) {}
|
||||
inline AColor(const Color& color, Byte a = 255) : Color(color), alpha(a) {}
|
||||
|
||||
inline bool operator == (const AColor& that) const {
|
||||
return static_cast<const Color&>(*this) == static_cast<const Color&>(that) && alpha == that.alpha;
|
||||
}
|
||||
inline bool operator != (const AColor& that) const { return ! (*this == that); }
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// RGB Color, packed into 3 bytes
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -84,11 +68,8 @@ struct RGB {
|
||||
/// Parse a color
|
||||
Color parse_color(const String& value);
|
||||
|
||||
/// Parse a color with alpha
|
||||
AColor parse_acolor(const String& value);
|
||||
|
||||
/// Convert an AColor to a string
|
||||
String format_acolor(AColor col);
|
||||
/// Convert a Color to a string
|
||||
String format_color(Color col);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Color utility functions
|
||||
|
||||
@@ -98,8 +79,6 @@ inline int col(int x) { return top(bot(x)); } ///< top and bottom range check fo
|
||||
|
||||
/// Linear interpolation between colors
|
||||
Color lerp(const Color& a, const Color& b, double t);
|
||||
/// Linear interpolation between colors
|
||||
AColor lerp(const AColor& a, const AColor& b, double t);
|
||||
|
||||
/// convert HSL to RGB, h,s,l must be in range [0...1)
|
||||
Color hsl2rgb(double h, double s, double l);
|
||||
|
||||
+1
-1
@@ -53,7 +53,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)
|
||||
* 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, Radians angle, AColor color, const String& text, int blur_radius = 0, int repeat = 1);
|
||||
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, Radians angle, Color color, const String& text, int blur_radius = 0, int repeat = 1);
|
||||
|
||||
// scaling factor to use when drawing resampled text
|
||||
extern const int text_scaling;
|
||||
|
||||
@@ -165,9 +165,9 @@ void blur_image_alpha(Image& img) {
|
||||
|
||||
// Draw text by first drawing it using a larger font and then downsampling it
|
||||
// optionally rotated by an angle
|
||||
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, Radians angle, AColor color, const String& text, int blur_radius, int repeat) {
|
||||
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, Radians angle, Color color, const String& text, int blur_radius, int repeat) {
|
||||
// transparent text can be ignored
|
||||
if (color.alpha == 0) return;
|
||||
if (color.Alpha() == 0) return;
|
||||
// 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;
|
||||
// determine sub-pixel position
|
||||
@@ -194,8 +194,8 @@ void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, dou
|
||||
fill_image(img_small, color);
|
||||
downsample_to_alpha(buffer, img_small);
|
||||
// multiply alpha
|
||||
if (color.alpha != 255) {
|
||||
set_alpha(img_small, color.alpha / 255.);
|
||||
if (color.Alpha() != 255) {
|
||||
set_alpha(img_small, color.Alpha() / 255.);
|
||||
}
|
||||
// blur
|
||||
for (int i = 0 ; i < blur_radius ; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user