diff --git a/src/gfx/color.cpp b/src/gfx/color.cpp index 6d201abc..83f75692 100644 --- a/src/gfx/color.cpp +++ b/src/gfx/color.cpp @@ -7,7 +7,54 @@ // ----------------------------------------------------------------------------- : Includes #include -#include +#include + +// ----------------------------------------------------------------------------- : Parsing etc. + +template <> void Reader::handle(Color& col) { + col = parse_color(getValue()); + if (!col.Ok()) col = *wxBLACK; +} + +template <> void GetDefaultMember::handle(const AColor& col) { + handle((const Color&)col); +} +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) { + if (col.alpha == 255) { + handle(String::Format(_("rgb(%u,%u,%u)"), col.Red(), col.Green(), col.Blue())); + } else if (col.alpha == 0) { + handle(_("transparent")); + } else { + handle(String::Format(_("rgba(%u,%u,%u,%u)"), col.Red(), col.Green(), col.Blue(), col.alpha)); + } +} + + +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); + } else if (wxSscanf(v.c_str(),_("rgba(%u,%u,%u,%u)"),&r,&g,&b,&a)) { + return AColor(r, g, b, a); + } else if (v == _("transparent")) { + return AColor(0,0,0,0); + } else { + return Color(v); + } +} // ----------------------------------------------------------------------------- : Color utility functions diff --git a/src/gfx/color.hpp b/src/gfx/color.hpp new file mode 100644 index 00000000..6d1d66a2 --- /dev/null +++ b/src/gfx/color.hpp @@ -0,0 +1,62 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2008 Twan van Laarhoven and "coppro" | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_GFX_COLOR +#define HEADER_GFX_COLOR + +/** @file gfx/color.hpp + * + * Color related functions and types. + */ + +// ----------------------------------------------------------------------------- : Includes + +#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) {} +}; + +// ----------------------------------------------------------------------------- : Parsing + +/// Parse a color +Color parse_color(const String& value); + +/// Parse a color with alpha +AColor parse_acolor(const String& value); + +// ----------------------------------------------------------------------------- : Color utility functions + +inline int bot(int x) { return max(0, x); } ///< bottom range check for color values +inline int top(int x) { return min(255, x); } ///< top range check for color values +inline int col(int x) { return top(bot(x)); } ///< top and bottom range check for color values + +/// 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); + +/// A darker version of a color +Color darken(const Color& c); + +/// A saturated version of a color +Color saturate(const Color& c, double amount); + +/// Fills an image with the specified color +void fill_image(Image& image, const Color& color); + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/gfx/gfx.hpp b/src/gfx/gfx.hpp index b2747dcc..1b70e31a 100644 --- a/src/gfx/gfx.hpp +++ b/src/gfx/gfx.hpp @@ -16,6 +16,7 @@ #include #include +#include // ----------------------------------------------------------------------------- : Resampling @@ -198,26 +199,5 @@ class ContourMask { int *lefts, *rights; }; -// ----------------------------------------------------------------------------- : Color utility functions - -inline int bot(int x) { return max(0, x); } ///< bottom range check for color values -inline int top(int x) { return min(255, x); } ///< top range check for color values -inline int col(int x) { return top(bot(x)); } ///< top and bottom range check for color values - -/// Linear interpolation between colors -Color lerp(const Color& a, const Color& b, double t); - -/// convert HSL to RGB, h,s,l must be in range [0...1) -Color hsl2rgb(double h, double s, double l); - -/// A darker version of a color -Color darken(const Color& c); - -/// A saturated version of a color -Color saturate(const Color& c, double amount); - -/// Fills an image with the specified color -void fill_image(Image& image, const Color& color); - // ----------------------------------------------------------------------------- : EOF #endif diff --git a/src/gui/control/keyword_list.cpp b/src/gui/control/keyword_list.cpp index 69590810..2c3c90ec 100644 --- a/src/gui/control/keyword_list.cpp +++ b/src/gui/control/keyword_list.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include DECLARE_TYPEOF_COLLECTION(KeywordP); diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index b8ca15e4..aded3c91 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -209,9 +209,7 @@ void CardsPanel::onCommand(int id) { set->actions.add(new AddCardAction(*set)); break; case ID_CARD_REMOVE: - if (card_list->getCard() != nullptr && set->cards.size() != 1) - //Don't delete the last card, and certainly don't delete a card if none exists. - set->actions.add(new RemoveCardAction(*set, card_list->getCard())); + card_list->doDelete(); break; case ID_CARD_ROTATE: case ID_CARD_ROTATE_0: case ID_CARD_ROTATE_90: case ID_CARD_ROTATE_180: case ID_CARD_ROTATE_270: { diff --git a/src/mse.vcproj b/src/mse.vcproj index faf68cd1..da1d90f1 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -2399,6 +2399,9 @@ ObjectFile="$(IntDir)/$(InputName)3.obj"/> + + #include #include -#include