diff --git a/src/data/font.cpp b/src/data/font.cpp index ea16d53b..04c98ba7 100644 --- a/src/data/font.cpp +++ b/src/data/font.cpp @@ -17,10 +17,10 @@ Font::Font() , underline(false) , scale_down_to(100000) , max_stretch(1.0) - , color(AColor(0,0,0)) + , color(Color(0,0,0)) , shadow_displacement(0,0) , shadow_blur(0) - , separator_color(AColor(0,0,0,128)) + , separator_color(Color(0,0,0,128)) , flags(FONT_NORMAL) {} @@ -50,7 +50,7 @@ void Font::initDependencies(Context& ctx, const Dependency& dep) const { shadow_color.initDependencies(ctx, dep); } -FontP Font::make(int add_flags, AColor* other_color, double* other_size) const { +FontP Font::make(int add_flags, Color* other_color, double* other_size) const { FontP f(new Font(*this)); f->flags |= add_flags; if (add_flags & FONT_CODE_STRING) { diff --git a/src/data/font.hpp b/src/data/font.hpp index 314c436e..da906426 100644 --- a/src/data/font.hpp +++ b/src/data/font.hpp @@ -34,19 +34,19 @@ enum FontFlags /** Contains additional information about scaling, color and shadow */ class Font : public IntrusivePtrBase { public: - Scriptable name; ///< Name of the font - Scriptable italic_name; ///< Font name for italic text (optional) - Scriptable size; ///< Size of the font - Scriptable weight, style; ///< Weight and style of the font (bold/italic) - Scriptable underline; ///< Underlined? - double scale_down_to; ///< Smallest size to scale down to - double max_stretch; ///< How much should the font be stretched before scaling down? - Scriptable color; ///< Color to use - Scriptable shadow_color; ///< Color for shadow + Scriptable name; ///< Name of the font + Scriptable italic_name; ///< Font name for italic text (optional) + Scriptable size; ///< Size of the font + Scriptable weight, style; ///< Weight and style of the font (bold/italic) + Scriptable underline; ///< Underlined? + double scale_down_to; ///< Smallest size to scale down to + double max_stretch; ///< How much should the font be stretched before scaling down? + Scriptable color; ///< Color to use + Scriptable shadow_color; ///< Color for shadow RealSize shadow_displacement; ///< Position of the shadow - double shadow_blur; ///< Blur radius of the shadow - AColor separator_color; ///< Color for text - int flags; ///< FontFlags for this font + double shadow_blur; ///< Blur radius of the shadow + Color separator_color; ///< Color for text + int flags; ///< FontFlags for this font Font(); @@ -61,7 +61,7 @@ class Font : public IntrusivePtrBase { } /// Add style to a font, and optionally change the color and size - FontP make(int add_flags, AColor* other_color, double* other_size) const; + FontP make(int add_flags, Color* other_color, double* other_size) const; /// Convert this font to a wxFont wxFont toWxFont(double scale) const; diff --git a/src/data/keyword.cpp b/src/data/keyword.cpp index 05dfac10..8b9324b4 100644 --- a/src/data/keyword.cpp +++ b/src/data/keyword.cpp @@ -736,7 +736,7 @@ KeywordParamValue::operator String() const { KeywordParamValue::operator int() const { return *to_script(value); } // a bit of a hack KeywordParamValue::operator double() const { return *to_script(value); } KeywordParamValue::operator bool() const { return *to_script(value); } -KeywordParamValue::operator AColor() const { return *to_script(value); } +KeywordParamValue::operator Color() const { return *to_script(value); } int KeywordParamValue::itemCount() const { return to_script(value)->itemCount(); } ScriptValueP KeywordParamValue::getMember(const String& name) const { diff --git a/src/data/keyword.hpp b/src/data/keyword.hpp index 32999166..9ea82131 100644 --- a/src/data/keyword.hpp +++ b/src/data/keyword.hpp @@ -197,7 +197,7 @@ class KeywordParamValue : public ScriptValue { virtual operator int() const; virtual operator bool() const; virtual operator double() const; - virtual operator AColor() const; + virtual operator Color() const; virtual int itemCount() const; virtual ScriptValueP getMember(const String& name) const; }; diff --git a/src/gfx/color.cpp b/src/gfx/color.cpp index 8aabea6f..6ddd10d8 100644 --- a/src/gfx/color.cpp +++ b/src/gfx/color.cpp @@ -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( a.Red() + (b.Red() - a.Red() ) * t ), static_cast( a.Green() + (b.Green() - a.Green()) * t ), - static_cast( a.Blue() + (b.Blue() - a.Blue() ) * t )); + static_cast( a.Blue() + (b.Blue() - a.Blue() ) * t ), + static_cast( a.Alpha() + (b.Alpha() - a.Alpha()) * t )); } diff --git a/src/gfx/color.hpp b/src/gfx/color.hpp index 10acb1d1..c4a2f372 100644 --- a/src/gfx/color.hpp +++ b/src/gfx/color.hpp @@ -16,22 +16,6 @@ #include -// ----------------------------------------------------------------------------- : 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(*this) == static_cast(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); diff --git a/src/gfx/gfx.hpp b/src/gfx/gfx.hpp index d502a9d7..87a48c48 100644 --- a/src/gfx/gfx.hpp +++ b/src/gfx/gfx.hpp @@ -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; diff --git a/src/gfx/resample_text.cpp b/src/gfx/resample_text.cpp index 6648fbcf..777a8dbd 100644 --- a/src/gfx/resample_text.cpp +++ b/src/gfx/resample_text.cpp @@ -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(rect.width) + 3 + 2 * blur_radius, h = static_cast(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) { diff --git a/src/gui/set/console_panel.cpp b/src/gui/set/console_panel.cpp index fc0f425b..21d22ea8 100644 --- a/src/gui/set/console_panel.cpp +++ b/src/gui/set/console_panel.cpp @@ -510,10 +510,10 @@ void ConsolePanel::exec(String const& command) { message->bitmap = wxBitmap(image); } else if (type == SCRIPT_COLOR) { message->text = result->toCode(); - AColor color = (AColor)*result; + Color color = (Color)*result; wxImage image(30,20); fill_image(image,color); - set_alpha(image, color.alpha / 255.0); + set_alpha(image, color.Alpha() / 255.0); message->bitmap = wxBitmap(image); } else { message->text = result->toCode(); diff --git a/src/gui/symbol/part_list.cpp b/src/gui/symbol/part_list.cpp index d37bb31d..c4b028d6 100644 --- a/src/gui/symbol/part_list.cpp +++ b/src/gui/symbol/part_list.cpp @@ -517,7 +517,7 @@ const Image& SymbolPartList::itemPreview(int i, const SymbolPartP& part) { } const Image& SymbolPartList::symbolPreview() { if (!symbol_preview.up_to_date) { - SolidFillSymbolFilter filter(AColor(0,0,0,40), AColor(255,255,255,40)); + SolidFillSymbolFilter filter(Color(0,0,0,40), Color(255,255,255,40)); Image img = render_symbol(symbol, filter, 0.06, ITEM_HEIGHT * 4); resample(img, symbol_preview.image); symbol_preview.up_to_date = true; diff --git a/src/render/symbol/filter.cpp b/src/render/symbol/filter.cpp index 3b9aec01..8d90ba5f 100644 --- a/src/render/symbol/filter.cpp +++ b/src/render/symbol/filter.cpp @@ -34,12 +34,12 @@ void filter_symbol(Image& symbol, const SymbolFilter& filter) { } else { SymbolSet point = data[1] ? (data[0] ? SYMBOL_BORDER : SYMBOL_OUTSIDE) : SYMBOL_INSIDE; // Call filter - AColor result = filter.color((double)x / width, (double)y / height, point); + Color result = filter.color((double)x / width, (double)y / height, point); // Store color data[0] = result.Red(); data[1] = result.Green(); data[2] = result.Blue(); - alpha[0] = result.alpha; + alpha[0] = result.Alpha(); } // next data += 3; @@ -87,10 +87,10 @@ intrusive_ptr read_new(Reader& reader) { String SolidFillSymbolFilter::fillType() const { return _("solid"); } -AColor SolidFillSymbolFilter::color(double x, double y, SymbolSet point) const { +Color SolidFillSymbolFilter::color(double x, double y, SymbolSet point) const { if (point == SYMBOL_INSIDE) return fill_color; else if (point == SYMBOL_BORDER) return border_color; - else return AColor(0,0,0,0); + else return Color(0,0,0,0); } bool SolidFillSymbolFilter::operator == (const SymbolFilter& that) const { @@ -108,10 +108,10 @@ IMPLEMENT_REFLECTION(SolidFillSymbolFilter) { // ----------------------------------------------------------------------------- : GradientSymbolFilter template -AColor GradientSymbolFilter::color(double x, double y, SymbolSet point, const T* t) const { +Color GradientSymbolFilter::color(double x, double y, SymbolSet point, const T* t) const { if (point == SYMBOL_INSIDE) return lerp(fill_color_1, fill_color_2, t->t(x,y)); else if (point == SYMBOL_BORDER) return lerp(border_color_1, border_color_2, t->t(x,y)); - else return AColor(0,0,0,0); + else return Color(0,0,0,0); } bool GradientSymbolFilter::equal(const GradientSymbolFilter& that) const { @@ -149,7 +149,7 @@ LinearGradientSymbolFilter::LinearGradientSymbolFilter , end_x(end_x), end_y(end_y) {} -AColor LinearGradientSymbolFilter::color(double x, double y, SymbolSet point) const { +Color LinearGradientSymbolFilter::color(double x, double y, SymbolSet point) const { len = sqr(end_x - center_x) + sqr(end_y - center_y); if (len == 0) len = 1; // prevent div by 0 return GradientSymbolFilter::color(x,y,point,this); @@ -177,7 +177,7 @@ IMPLEMENT_REFLECTION(LinearGradientSymbolFilter) { String RadialGradientSymbolFilter::fillType() const { return _("radial gradient"); } -AColor RadialGradientSymbolFilter::color(double x, double y, SymbolSet point) const { +Color RadialGradientSymbolFilter::color(double x, double y, SymbolSet point) const { return GradientSymbolFilter::color(x,y,point,this); } diff --git a/src/render/symbol/filter.hpp b/src/render/symbol/filter.hpp index f682bbba..e7d5ddcd 100644 --- a/src/render/symbol/filter.hpp +++ b/src/render/symbol/filter.hpp @@ -42,7 +42,7 @@ class SymbolFilter : public IntrusivePtrVirtualBase { virtual ~SymbolFilter() {} /// What color should the symbol have at location (x, y)? /** x,y are in the range [0...1) */ - virtual AColor color(double x, double y, SymbolSet point) const = 0; + virtual Color color(double x, double y, SymbolSet point) const = 0; /// Name of this fill type virtual String fillType() const = 0; /// Comparision @@ -60,14 +60,14 @@ intrusive_ptr read_new(Reader& reader); class SolidFillSymbolFilter : public SymbolFilter { public: inline SolidFillSymbolFilter() {} - inline SolidFillSymbolFilter(const AColor& fill_color, const AColor& border_color) + inline SolidFillSymbolFilter(const Color& fill_color, const Color& border_color) : fill_color(fill_color), border_color(border_color) {} - virtual AColor color(double x, double y, SymbolSet point) const; + virtual Color color(double x, double y, SymbolSet point) const; virtual String fillType() const; virtual bool operator == (const SymbolFilter& that) const; private: - AColor fill_color, border_color; + Color fill_color, border_color; DECLARE_REFLECTION(); }; @@ -83,7 +83,7 @@ class GradientSymbolFilter : public SymbolFilter { Color fill_color_1, border_color_1; Color fill_color_2, border_color_2; template - AColor color(double x, double y, SymbolSet point, const T* t) const; + Color color(double x, double y, SymbolSet point, const T* t) const; bool equal(const GradientSymbolFilter& that) const; DECLARE_REFLECTION(); @@ -96,7 +96,7 @@ class LinearGradientSymbolFilter : public GradientSymbolFilter { LinearGradientSymbolFilter(const Color& fill_color_1, const Color& border_color_1, const Color& fill_color_2, const Color& border_color_2 ,double center_x, double center_y, double end_x, double end_y); - virtual AColor color(double x, double y, SymbolSet point) const; + virtual Color color(double x, double y, SymbolSet point) const; virtual String fillType() const; virtual bool operator == (const SymbolFilter& that) const; @@ -118,7 +118,7 @@ class RadialGradientSymbolFilter : public GradientSymbolFilter { : GradientSymbolFilter(fill_color_1, border_color_1, fill_color_2, border_color_2) {} - virtual AColor color(double x, double y, SymbolSet point) const; + virtual Color color(double x, double y, SymbolSet point) const; virtual String fillType() const; virtual bool operator == (const SymbolFilter& that) const; diff --git a/src/render/text/element.cpp b/src/render/text/element.cpp index 1dc2a6d2..ac626be4 100644 --- a/src/render/text/element.cpp +++ b/src/render/text/element.cpp @@ -60,13 +60,13 @@ double TextElements::scaleStep() const { } // Colors for tags -AColor param_colors[] = - { AColor(0,170,0) - , AColor(0,0,200) - , AColor(200,0,100) - , AColor(200,200,0) - , AColor(0,170,170) - , AColor(200,0,0) +Color param_colors[] = + { Color(0,170,0) + , Color(0,0,200) + , Color(200,0,100) + , Color(200,200,0) + , Color(0,170,170) + , Color(200,0,0) }; const size_t param_colors_count = sizeof(param_colors) / sizeof(param_colors[0]); @@ -77,7 +77,7 @@ struct TextElementsFromString { int soft, kwpph, param, line, soft_line; int code, code_kw, code_string, param_ref, error; int param_id; - vector colors; + vector colors; vector sizes; /// put angle brackets around the text? bool bracket; @@ -128,7 +128,7 @@ struct TextElementsFromString { else if (is_substr(text, tag_start, _( ":"), tag_start); if (colon < pos - 1 && text.GetChar(colon) == _(':')) { - AColor c = parse_acolor(text.substr(colon+1, pos-colon-2)); + Color c = parse_color(text.substr(colon+1, pos-colon-2)); if (!c.Ok()) c = style.font.color; colors.push_back(c); } diff --git a/src/script/context.cpp b/src/script/context.cpp index 8f5c2fb8..169cbbb5 100644 --- a/src/script/context.cpp +++ b/src/script/context.cpp @@ -556,7 +556,7 @@ void instrTernary(TernaryInstructionType i, ScriptValueP& a, const ScriptValueP& void instrQuaternary(QuaternaryInstructionType i, ScriptValueP& a, const ScriptValueP& b, const ScriptValueP& c, const ScriptValueP& d) { switch (i) { case I_RGBA: - a = to_script(AColor((int)*a, (int)*b, (int)*c, (int)*d)); + a = to_script(Color((int)*a, (int)*b, (int)*c, (int)*d)); break; } } diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index dc227201..fd9d9516 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -112,7 +112,7 @@ SCRIPT_FUNCTION(to_int) { if (t == SCRIPT_BOOL) { result = (bool)*input ? 1 : 0; } else if (t == SCRIPT_COLOR) { - AColor c = (AColor)*input; + Color c = (Color)*input; result = (c.Red() + c.Blue() + c.Green()) / 3; } else if (t == SCRIPT_STRING) { long l; @@ -141,7 +141,7 @@ SCRIPT_FUNCTION(to_real) { if (t == SCRIPT_BOOL) { result = (bool)*input ? 1.0 : 0.0; } else if (t == SCRIPT_COLOR) { - AColor c = (AColor)*input; + Color c = (Color)*input; result = (c.Red() + c.Blue() + c.Green()) / 3.0; } else if (t == SCRIPT_STRING) { String str = input->toString(); @@ -166,7 +166,7 @@ SCRIPT_FUNCTION(to_number) { if (t == SCRIPT_BOOL) { SCRIPT_RETURN((bool)*input ? 1 : 0); } else if (t == SCRIPT_COLOR) { - AColor c = (AColor)*input; + Color c = (Color)*input; SCRIPT_RETURN( (c.Red() + c.Blue() + c.Green()) / 3 ); } else if (t == SCRIPT_DOUBLE) { SCRIPT_RETURN((double)*input); @@ -208,7 +208,7 @@ SCRIPT_FUNCTION(to_boolean) { SCRIPT_FUNCTION(to_color) { try { - SCRIPT_PARAM_C(AColor, input); + SCRIPT_PARAM_C(Color, input); SCRIPT_RETURN(input); } catch (const ScriptError& e) { return delay_error(e); diff --git a/src/script/functions/construction.cpp b/src/script/functions/construction.cpp index 446ee477..88db1462 100644 --- a/src/script/functions/construction.cpp +++ b/src/script/functions/construction.cpp @@ -44,7 +44,7 @@ SCRIPT_FUNCTION(new_card) { } else if (PackageChoiceValue* pvalue = dynamic_cast(value)) { pvalue->package_name = v->toString(); } else if (ColorValue* cvalue = dynamic_cast(value)) { - cvalue->value = (AColor)*v; + cvalue->value = (Color)*v; } else { throw ScriptError(format_string(_("Can not set value '%s', it is not of the right type"),name)); } diff --git a/src/script/scriptable.cpp b/src/script/scriptable.cpp index 43a704a7..3fc476bb 100644 --- a/src/script/scriptable.cpp +++ b/src/script/scriptable.cpp @@ -25,11 +25,9 @@ void store(const ScriptValueP& val, String& var) { var = val->toStr void store(const ScriptValueP& val, int& var) { var = *val; } void store(const ScriptValueP& val, double& var) { var = *val; } void store(const ScriptValueP& val, bool& var) { var = *val; } -void store(const ScriptValueP& val, Color& var) { var = (AColor)*val; } -void store(const ScriptValueP& val, AColor& var) { var = *val; } +void store(const ScriptValueP& val, Color& var) { var = *val; } void store(const ScriptValueP& val, Defaultable& var) { var.assign(*val); } -void store(const ScriptValueP& val, Defaultable& var) { var.assign((AColor)*val); } -void store(const ScriptValueP& val, Defaultable& var) { var.assign(*val); } +void store(const ScriptValueP& val, Defaultable& var) { var.assign(*val); } void store(const ScriptValueP& val, Alignment& var) { var = from_string(val->toString()); } void store(const ScriptValueP& val, Direction& var) { parse_enum(val->toString(),var); } diff --git a/src/script/scriptable.hpp b/src/script/scriptable.hpp index 58bc3c94..4086f4c8 100644 --- a/src/script/scriptable.hpp +++ b/src/script/scriptable.hpp @@ -18,7 +18,6 @@ #include