Remove AColor class, because wxColour now supports alpha values.

This commit is contained in:
Twan van Laarhoven
2020-04-23 22:59:29 +02:00
parent 1fe145864e
commit 4258ce1c6c
25 changed files with 94 additions and 140 deletions
+3 -3
View File
@@ -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) {
+13 -13
View File
@@ -34,19 +34,19 @@ enum FontFlags
/** Contains additional information about scaling, color and shadow */
class Font : public IntrusivePtrBase<Font> {
public:
Scriptable<String> name; ///< Name of the font
Scriptable<String> italic_name; ///< Font name for italic text (optional)
Scriptable<double> size; ///< Size of the font
Scriptable<String> weight, style; ///< Weight and style of the font (bold/italic)
Scriptable<bool> 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<AColor> color; ///< Color to use
Scriptable<AColor> shadow_color; ///< Color for shadow
Scriptable<String> name; ///< Name of the font
Scriptable<String> italic_name; ///< Font name for italic text (optional)
Scriptable<double> size; ///< Size of the font
Scriptable<String> weight, style; ///< Weight and style of the font (bold/italic)
Scriptable<bool> 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; ///< Color to use
Scriptable<Color> 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 <sep> text
int flags; ///< FontFlags for this font
double shadow_blur; ///< Blur radius of the shadow
Color separator_color; ///< Color for <sep> text
int flags; ///< FontFlags for this font
Font();
@@ -61,7 +61,7 @@ class Font : public IntrusivePtrBase<Font> {
}
/// 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;
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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;
};
+12 -24
View File
@@ -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
View File
@@ -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
View File
@@ -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;
+4 -4
View File
@@ -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) {
+2 -2
View File
@@ -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();
+1 -1
View File
@@ -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;
+8 -8
View File
@@ -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<SymbolFilter> read_new<SymbolFilter>(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 <typename T>
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);
}
+7 -7
View File
@@ -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<SymbolFilter> read_new<SymbolFilter>(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 <typename T>
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;
+9 -9
View File
@@ -60,13 +60,13 @@ double TextElements::scaleStep() const {
}
// Colors for <atom-param> 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<AColor> colors;
vector<Color> colors;
vector<double> sizes;
/// put angle brackets around the text?
bool bracket;
@@ -128,7 +128,7 @@ struct TextElementsFromString {
else if (is_substr(text, tag_start, _( "<color"))) {
size_t colon = text.find_first_of(_(">:"), 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);
}
+1 -1
View File
@@ -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;
}
}
+4 -4
View File
@@ -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);
+1 -1
View File
@@ -44,7 +44,7 @@ SCRIPT_FUNCTION(new_card) {
} else if (PackageChoiceValue* pvalue = dynamic_cast<PackageChoiceValue*>(value)) {
pvalue->package_name = v->toString();
} else if (ColorValue* cvalue = dynamic_cast<ColorValue*>(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));
}
+2 -4
View File
@@ -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<String>& var) { var.assign(*val); }
void store(const ScriptValueP& val, Defaultable<Color>& var) { var.assign((AColor)*val); }
void store(const ScriptValueP& val, Defaultable<AColor>& var) { var.assign(*val); }
void store(const ScriptValueP& val, Defaultable<Color>& 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); }
-2
View File
@@ -18,7 +18,6 @@
#include <script/parser.hpp>
#include <script/to_value.hpp>
class AColor;
DECLARE_POINTER_TYPE(Script);
// ----------------------------------------------------------------------------- : Store
@@ -29,7 +28,6 @@ void store(const ScriptValueP& val, int& var);
void store(const ScriptValueP& val, double& var);
void store(const ScriptValueP& val, bool& var);
void store(const ScriptValueP& val, Color& var);
void store(const ScriptValueP& val, AColor& var);
void store(const ScriptValueP& val, Defaultable<String>& var);
void store(const ScriptValueP& val, Defaultable<Color>& var);
void store(const ScriptValueP& val, Alignment& var);
+3 -5
View File
@@ -78,7 +78,7 @@ class ScriptDelayedError : public ScriptValue {
virtual operator double() const;
virtual operator int() const;
virtual operator bool() const;
virtual operator AColor() const;
virtual operator Color() const;
virtual int itemCount() const;
virtual CompareWhat compareAs(String&, void const*&) const;
// these can propagate the error
@@ -279,7 +279,7 @@ class ScriptObject : public ScriptValue {
virtual operator double() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator double(); }
virtual operator int() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator int(); }
virtual operator bool() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator bool(); }
virtual operator AColor() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator AColor(); }
virtual operator Color() const { ScriptValueP d = getDefault(); return d ? *d : ScriptValue::operator Color(); }
virtual String toCode() const { ScriptValueP d = getDefault(); return d ? d->toCode() : to_code(*value); }
virtual GeneratedImageP toImage(const ScriptValueP& thisP) const {
ScriptValueP d = getDefault(); return d ? d->toImage(d) : ScriptValue::toImage(thisP);
@@ -399,7 +399,6 @@ inline ScriptValueP to_script(long v) { return to_script((int) v); }
ScriptValueP to_script(double v);
ScriptValueP to_script(const String& v);
ScriptValueP to_script(Color v);
ScriptValueP to_script(AColor v);
ScriptValueP to_script(wxDateTime v);
inline ScriptValueP to_script(bool v) { return v ? script_true : script_false; }
template <typename T>
@@ -428,8 +427,7 @@ template <> inline String from_script<String> (const ScriptValueP& va
template <> inline int from_script<int> (const ScriptValueP& value) { return *value; }
template <> inline double from_script<double> (const ScriptValueP& value) { return *value; }
template <> inline bool from_script<bool> (const ScriptValueP& value) { return *value; }
template <> inline Color from_script<Color> (const ScriptValueP& value) { return (AColor)*value; }
template <> inline AColor from_script<AColor> (const ScriptValueP& value) { return *value; }
template <> inline Color from_script<Color> (const ScriptValueP& value) { return *value; }
template <> inline wxDateTime from_script<wxDateTime> (const ScriptValueP& value) { return *value; }
// ----------------------------------------------------------------------------- : EOF
+14 -17
View File
@@ -23,7 +23,7 @@ ScriptValue::operator String() const { throw Script
ScriptValue::operator int() const { throw ScriptErrorConversion(typeName(), _TYPE_("integer" )); }
ScriptValue::operator bool() const { throw ScriptErrorConversion(typeName(), _TYPE_("boolean" )); }
ScriptValue::operator double() const { throw ScriptErrorConversion(typeName(), _TYPE_("double" )); }
ScriptValue::operator AColor() const { throw ScriptErrorConversion(typeName(), _TYPE_("color" )); }
ScriptValue::operator Color() const { throw ScriptErrorConversion(typeName(), _TYPE_("color" )); }
ScriptValue::operator wxDateTime() const { throw ScriptErrorConversion(typeName(), _TYPE_("date" )); }
ScriptValueP ScriptValue::do_eval(Context&, bool) const { return delay_error(ScriptErrorConversion(typeName(), _TYPE_("function"))); }
ScriptValueP ScriptValue::next(ScriptValueP* key_out) { throw InternalError(_("Can't convert from ")+typeName()+_(" to iterator")); }
@@ -108,7 +108,7 @@ ScriptDelayedError::operator String() const { throw error; }
ScriptDelayedError::operator double() const { throw error; }
ScriptDelayedError::operator int() const { throw error; }
ScriptDelayedError::operator bool() const { throw error; }
ScriptDelayedError::operator AColor() const { throw error; }
ScriptDelayedError::operator Color() const { throw error; }
int ScriptDelayedError::itemCount() const { throw error; }
CompareWhat ScriptDelayedError::compareAs(String&, void const*&) const { throw error; }
ScriptValueP ScriptDelayedError::getMember(const String&) const { return intrusive(new ScriptDelayedError(error)); }
@@ -270,8 +270,8 @@ class ScriptString : public ScriptValue {
throw ScriptErrorConversion(value, typeName(), _TYPE_("boolean"));
}
}
virtual operator AColor() const {
AColor c = parse_acolor(value);
virtual operator Color() const {
Color c = parse_color(value);
if (!c.Ok()) {
throw ScriptErrorConversion(value, typeName(), _TYPE_("color"));
}
@@ -313,26 +313,23 @@ ScriptValueP to_script(const String& v) {
// ----------------------------------------------------------------------------- : Color
// AColor values
class ScriptAColor : public ScriptValue {
public:
ScriptAColor(const AColor& v) : value(v) {}
// Color values
class ScriptColor : public ScriptValue {
public:
ScriptColor(const Color& v) : value(v) {}
virtual ScriptType type() const { return SCRIPT_COLOR; }
virtual String typeName() const { return _TYPE_("color"); }
virtual operator AColor() const { return value; }
virtual operator Color() const { return value; }
// colors don't auto convert to int, use to_int to force
virtual operator String() const {
return format_acolor(value);
return format_color(value);
}
private:
AColor value;
private:
Color value;
};
ScriptValueP to_script(Color v) {
return intrusive(new ScriptAColor(v));
}
ScriptValueP to_script(AColor v) {
return intrusive(new ScriptAColor(v));
return intrusive(new ScriptColor(v));
}
@@ -368,7 +365,7 @@ public:
operator double() const override { return 0.0; }
operator int() const override { return 0; }
operator bool() const override { return false; }
operator AColor() const override { return AColor(); }
operator Color() const override { return wxTransparentColour; }
GeneratedImageP toImage(const ScriptValueP&) const {
return intrusive(new BlankImage());
}
+1 -1
View File
@@ -67,7 +67,7 @@ class ScriptValue : public IntrusivePtrBaseWithDelete {
/// Convert this value to a boolean
virtual operator bool() const;
/// Convert this value to a color
virtual operator AColor() const;
virtual operator Color() const;
/// Convert this value to a wxDateTime
virtual operator wxDateTime() const;
-1
View File
@@ -26,7 +26,6 @@ template <> void GetDefaultMember::handle(const bool& v) { value = to_sc
template <> void GetDefaultMember::handle(const tribool& v) { value = to_script((bool)v); }
template <> void GetDefaultMember::handle(const Vector2D& v) { value = to_script(String::Format(_("(%.10lf,%.10lf)"), v.x, v.y)); }
template <> void GetDefaultMember::handle(const Color& v) { value = to_script(v); }
template <> void GetDefaultMember::handle(const AColor& v) { value = to_script(v); }
template <> void GetDefaultMember::handle(const wxDateTime& v) { value = to_script(v); }
void GetDefaultMember::handle(const ScriptValueP& v) { value = v; }
void GetDefaultMember::handle(const ScriptP& v) { value = v; }
-3
View File
@@ -130,9 +130,6 @@ template <> void Writer::handle(const wxDateTime& date) {
template <> void Writer::handle(const Vector2D& vec) {
handle(String::Format(_("(%.10lf,%.10lf)"), vec.x, vec.y));
}
template <> void Writer::handle(const Color& col) {
handle(String::Format(_("rgb(%u,%u,%u)"), col.Red(), col.Green(), col.Blue()));
}
template <> void Writer::handle(const FileName& value) {
if (clipboard_package() && !value.empty()) {
+2 -2
View File
@@ -186,9 +186,9 @@ void RotatedDC::DrawText (const String& text, const RealPoint& pos, int blur_ra
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_) {
void RotatedDC::DrawText (const String& text, const RealPoint& pos, Color color, int blur_radius, int boldness, double stretch_) {
if (text.empty()) return;
if (color.alpha == 0) return;
if (color.Alpha() == 0) return;
if (quality >= QUALITY_AA) {
RealRect r(pos, GetTextExtent(text));
RealRect r_ext = trRectToBB(r);
+2 -2
View File
@@ -158,8 +158,8 @@ class RotatedDC : public Rotation {
// --------------------------------------------------- : Drawing
/// 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, AColor color, 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, Color color, int blur_radius = 0, int boldness = 1, double stretch = 1.0);
/// 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);
/// Draw abitmap, it must already be zoomed!