mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Moved the AColor type to a gfx/ header, so other code can use it.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@847 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+48
-1
@@ -7,7 +7,54 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#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
|
||||
|
||||
|
||||
@@ -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 <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
|
||||
+1
-21
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <util/real_point.hpp>
|
||||
#include <gfx/color.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : 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
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <data/format/clipboard.hpp>
|
||||
#include <util/tagged_string.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <gfx/gfx.hpp>
|
||||
#include <gfx/color.hpp>
|
||||
#include <wx/clipbrd.h>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(KeywordP);
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -2399,6 +2399,9 @@
|
||||
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gfx\color.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gfx\combine_image.cpp">
|
||||
<FileConfiguration
|
||||
|
||||
@@ -11,34 +11,6 @@
|
||||
#include <render/symbol/viewer.hpp>
|
||||
#include <gfx/gfx.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
|
||||
|
||||
|
||||
@@ -11,21 +11,11 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <util/reflect.hpp>
|
||||
#include <gfx/color.hpp>
|
||||
|
||||
DECLARE_POINTER_TYPE(Symbol);
|
||||
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
|
||||
|
||||
/// Filter a symbol-image.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <render/text/element.hpp>
|
||||
#include <util/tagged_string.hpp>
|
||||
#include <data/field/text.hpp>
|
||||
#include <gfx/color.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(TextElementP);
|
||||
DECLARE_POINTER_TYPE(FontTextElement);
|
||||
|
||||
@@ -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) {
|
||||
if (clipboard_package()) {
|
||||
String str = getValue();
|
||||
|
||||
@@ -251,9 +251,6 @@ void Reader::handle(IndexMap<K,V>& m) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Reflection for enumerations
|
||||
|
||||
/// Parse a color
|
||||
Color parse_color(const String& value);
|
||||
|
||||
/// Implement enum reflection as used by Reader
|
||||
#define REFLECT_ENUM_READER(Enum) \
|
||||
template<> void Reader::handle<Enum>(Enum& enum_) { \
|
||||
|
||||
Reference in New Issue
Block a user