Commit acdca5da authored by twanvl's avatar twanvl

Moved the AColor type to a gfx/ header, so other code can use it.

parent 77881a72
...@@ -7,7 +7,54 @@ ...@@ -7,7 +7,54 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp> #include <util/prec.hpp>
#include <gfx/gfx.hpp> #include <gfx/color.hpp>
// ----------------------------------------------------------------------------- : 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 // ----------------------------------------------------------------------------- : Color utility functions
......
//+----------------------------------------------------------------------------+
//| 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 <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) {}
};
// ----------------------------------------------------------------------------- : 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
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/real_point.hpp> #include <util/real_point.hpp>
#include <gfx/color.hpp>
// ----------------------------------------------------------------------------- : Resampling // ----------------------------------------------------------------------------- : Resampling
...@@ -198,26 +199,5 @@ class ContourMask { ...@@ -198,26 +199,5 @@ class ContourMask {
int *lefts, *rights; 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 // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <data/format/clipboard.hpp> #include <data/format/clipboard.hpp>
#include <util/tagged_string.hpp> #include <util/tagged_string.hpp>
#include <util/window_id.hpp> #include <util/window_id.hpp>
#include <gfx/gfx.hpp> #include <gfx/color.hpp>
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
DECLARE_TYPEOF_COLLECTION(KeywordP); DECLARE_TYPEOF_COLLECTION(KeywordP);
......
...@@ -209,9 +209,7 @@ void CardsPanel::onCommand(int id) { ...@@ -209,9 +209,7 @@ void CardsPanel::onCommand(int id) {
set->actions.add(new AddCardAction(*set)); set->actions.add(new AddCardAction(*set));
break; break;
case ID_CARD_REMOVE: case ID_CARD_REMOVE:
if (card_list->getCard() != nullptr && set->cards.size() != 1) card_list->doDelete();
//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()));
break; break;
case ID_CARD_ROTATE: case ID_CARD_ROTATE:
case ID_CARD_ROTATE_0: case ID_CARD_ROTATE_90: case ID_CARD_ROTATE_180: case ID_CARD_ROTATE_270: { case ID_CARD_ROTATE_0: case ID_CARD_ROTATE_90: case ID_CARD_ROTATE_180: case ID_CARD_ROTATE_270: {
......
...@@ -2399,6 +2399,9 @@ ...@@ -2399,6 +2399,9 @@
ObjectFile="$(IntDir)/$(InputName)3.obj"/> ObjectFile="$(IntDir)/$(InputName)3.obj"/>
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\gfx\color.hpp">
</File>
<File <File
RelativePath=".\gfx\combine_image.cpp"> RelativePath=".\gfx\combine_image.cpp">
<FileConfiguration <FileConfiguration
......
...@@ -11,34 +11,6 @@ ...@@ -11,34 +11,6 @@
#include <render/symbol/viewer.hpp> #include <render/symbol/viewer.hpp>
#include <gfx/gfx.hpp> #include <gfx/gfx.hpp>
#include <util/error.hpp> #include <util/error.hpp>
#include <script/value.hpp> // for some strange reason the profile build needs this :(
// ----------------------------------------------------------------------------- : Color
template <> void GetDefaultMember::handle(const AColor& col) {
handle((const Color&)col);
}
template <> void Reader::handle(AColor& col) {
UInt r,g,b,a;
String v = getValue();
if (wxSscanf(v.c_str(),_("rgb(%u,%u,%u)"),&r,&g,&b)) {
col.Set(r,g,b);
col.alpha = 255;
} else if (wxSscanf(v.c_str(),_("rgba(%u,%u,%u,%u)"),&r,&g,&b,&a)) {
col.Set(r,g,b);
col.alpha = a;
} else {
col = Color(v);
if (!col.Ok()) col = *wxBLACK;
}
}
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 {
handle(String::Format(_("rgba(%u,%u,%u,%u)"), col.Red(), col.Green(), col.Blue(), col.alpha));
}
}
// ----------------------------------------------------------------------------- : Symbol filtering // ----------------------------------------------------------------------------- : Symbol filtering
......
...@@ -11,21 +11,11 @@ ...@@ -11,21 +11,11 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/reflect.hpp> #include <util/reflect.hpp>
#include <gfx/color.hpp>
DECLARE_POINTER_TYPE(Symbol); DECLARE_POINTER_TYPE(Symbol);
class SymbolFilter; class SymbolFilter;
// ----------------------------------------------------------------------------- : Color
/// 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) {}
};
// ----------------------------------------------------------------------------- : Symbol filtering // ----------------------------------------------------------------------------- : Symbol filtering
/// Filter a symbol-image. /// Filter a symbol-image.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <render/text/element.hpp> #include <render/text/element.hpp>
#include <util/tagged_string.hpp> #include <util/tagged_string.hpp>
#include <data/field/text.hpp> #include <data/field/text.hpp>
#include <gfx/color.hpp>
DECLARE_TYPEOF_COLLECTION(TextElementP); DECLARE_TYPEOF_COLLECTION(TextElementP);
DECLARE_POINTER_TYPE(FontTextElement); DECLARE_POINTER_TYPE(FontTextElement);
......
...@@ -367,19 +367,6 @@ template <> void Reader::handle(Vector2D& vec) { ...@@ -367,19 +367,6 @@ template <> void Reader::handle(Vector2D& vec) {
} }
} }
template <> void Reader::handle(Color& col) {
col = parse_color(getValue());
if (!col.Ok()) col = *wxBLACK;
}
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);
}
}
template <> void Reader::handle(FileName& f) { template <> void Reader::handle(FileName& f) {
if (clipboard_package()) { if (clipboard_package()) {
String str = getValue(); String str = getValue();
......
...@@ -251,9 +251,6 @@ void Reader::handle(IndexMap<K,V>& m) { ...@@ -251,9 +251,6 @@ void Reader::handle(IndexMap<K,V>& m) {
// ----------------------------------------------------------------------------- : Reflection for enumerations // ----------------------------------------------------------------------------- : Reflection for enumerations
/// Parse a color
Color parse_color(const String& value);
/// Implement enum reflection as used by Reader /// Implement enum reflection as used by Reader
#define REFLECT_ENUM_READER(Enum) \ #define REFLECT_ENUM_READER(Enum) \
template<> void Reader::handle<Enum>(Enum& enum_) { \ template<> void Reader::handle<Enum>(Enum& enum_) { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment