Replace AssColor with agi::Color

Add agi::Color, and replace AssColor and all uses of wxColor that are
not immediately passed to/from wx with it.
This commit is contained in:
Thomas Goyne 2012-10-26 07:09:14 -07:00
parent 83761d881a
commit ea5428b65f
41 changed files with 628 additions and 626 deletions

View File

@ -283,6 +283,10 @@
RelativePath="..\..\libaegisub\common\charset_ucd.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\common\color.cpp"
>
</File>
<File
RelativePath="..\..\libaegisub\common\hotkey.cpp"
>
@ -418,7 +422,7 @@
>
</File>
<File
RelativePath="..\..\libaegisub\include\libaegisub\colour.h"
RelativePath="..\..\libaegisub\include\libaegisub\color.h"
>
</File>
<File

View File

@ -23,6 +23,7 @@ SRC += \
common/charset_6937.cpp \
common/charset_conv.cpp \
common/charset_ucd.cpp \
common/color.cpp \
common/hotkey.cpp \
common/io.cpp \
common/json.cpp \

View File

@ -0,0 +1,146 @@
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "../config.h"
#include "libaegisub/color.h"
#include <boost/config/warning_disable.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
BOOST_FUSION_ADAPT_STRUCT(
agi::Color,
(unsigned char, r)
(unsigned char, g)
(unsigned char, b)
(unsigned char, a)
)
namespace {
using namespace boost::spirit;
struct unpack_colors : public boost::static_visitor<agi::Color> {
template<typename T> struct result { typedef agi::Color type; };
template<class T> agi::Color operator()(T arg) const {
return boost::apply_visitor(*this, arg);
}
agi::Color operator()(int abgr) const { return (*this)((unsigned)abgr); }
agi::Color operator()(unsigned int abgr) const {
return agi::Color(abgr & 0xFF, (abgr >> 8) & 0xFF, (abgr >> 16) & 0xFF, (abgr >> 24) & 0xFF);
}
};
template<typename Iterator>
struct color_grammar : qi::grammar<Iterator, agi::Color()> {
qi::rule<Iterator, agi::Color()> color;
qi::rule<Iterator, agi::Color()> css_color;
qi::rule<Iterator, agi::Color()> ass_color;
qi::rule<Iterator, unsigned char()> rgb_component;
qi::rule<Iterator, unsigned char()> rgb_percent;
qi::rule<Iterator, unsigned char()> hex_byte;
qi::rule<Iterator, unsigned char()> hex_char;
qi::rule<Iterator> comma;
qi::rule<Iterator> blank;
#define HEX_PARSER(type, len) qi::uint_parser<unsigned type, 16, len, len>()
color_grammar() : color_grammar::base_type(color) {
color = css_color | ass_color;
boost::phoenix::function<unpack_colors> unpack;
ass_color = (
int_
| -lit('&') >> -(lit('H') | lit('h')) >> (HEX_PARSER(int, 8) | HEX_PARSER(int, 6)) >> -lit('&')
)[_val = unpack(_1)] >> blank >> qi::eoi;
css_color
= "rgb(" >> blank >> rgb_component >> comma >> rgb_component >> comma >> rgb_component >> blank >> ')'
| '#' >> hex_byte >> hex_byte >> hex_byte
| '#' >> hex_char >> hex_char >> hex_char
;
hex_char = HEX_PARSER(int, 1)[_val = _1 * 16 + _1];
hex_byte = HEX_PARSER(int, 2);
rgb_component = qi::uint_parser<unsigned char, 10, 1, 3>();
comma = *qi::blank >> "," >> *qi::blank;
blank = *qi::blank;
}
};
}
namespace agi {
Color::Color() : r(0), g(0), b(0), a(0) { }
Color::Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
: r(r), g(g), b(b), a(a)
{ }
Color::Color(std::string const& str)
: r(0), g(0), b(0), a(0)
{
const char *begin = &str[0];
parse(begin, &str[str.size()], color_grammar<const char *>(), *this);
}
Color::Color(const char *str)
: r(0), g(0), b(0), a(0)
{
parse(str, str + strlen(str), color_grammar<const char *>(), *this);
}
std::string Color::GetAssStyleFormatted() const {
return str(boost::format("&H%02X%02X%02X%02X") % (int)a % (int)b % (int)g % (int)r);
}
std::string Color::GetAssOverrideFormatted() const {
return str(boost::format("&H%02X%02X%02X&") % (int)b % (int)g % (int)r);
}
std::string Color::GetSsaFormatted() const {
return boost::lexical_cast<std::string>((a << 24) + (b << 16) + (g << 8) + r);
}
std::string Color::GetHexFormatted() const {
return str(boost::format("#%02X%02X%02X") % (int)r % (int)g % (int)b);
}
std::string Color::GetRgbFormatted() const {
return str(boost::format("rgb(%d, %d, %d)") % (int)r % (int)g % (int)b);
}
bool Color::operator==(Color const& col) const {
return r == col.r && g == col.g && b == col.b && a == col.a;
}
bool Color::operator!=(Color const& col) const {
return !(*this == col);
}
}

View File

@ -63,7 +63,7 @@ namespace {
json::Array array;
for (typename std::vector<T>::const_iterator it = value.begin(); it != value.end(); ++it) {
array.push_back(json::Object());
static_cast<json::Object&>(array.back())[element_key] = *it;
static_cast<json::Object&>(array.back())[element_key] = (json::UnknownElement)*it;
}
put_option(obj, path, array);
@ -151,8 +151,8 @@ void Options::Flush() {
put_option(obj_out, i->first, i->second->GetDouble());
break;
case OptionValue::Type_Colour:
put_option(obj_out, i->first, i->second->GetColour());
case OptionValue::Type_Color:
put_option(obj_out, i->first, i->second->GetColor().GetRgbFormatted());
break;
case OptionValue::Type_Bool:
@ -171,8 +171,8 @@ void Options::Flush() {
put_array(obj_out, i->first, "double", i->second->GetListDouble());
break;
case OptionValue::Type_List_Colour:
put_array(obj_out, i->first, "colour", i->second->GetListColour());
case OptionValue::Type_List_Color:
put_array(obj_out, i->first, "color", i->second->GetListColor());
break;
case OptionValue::Type_List_Bool:

View File

@ -26,7 +26,7 @@
#include <cmath>
#endif
#include <libaegisub/colour.h>
#include <libaegisub/color.h>
#include <libaegisub/log.h>
#include <libaegisub/option_value.h>
#include <libaegisub/scoped_ptr.h>
@ -78,7 +78,7 @@ OptionValue *ConfigVisitor::ReadArray(json::Array const& src, std::string const&
return 0;
}
arr.push_back(obj.begin()->second);
arr.push_back(ValueType(obj.begin()->second));
}
return new OptionValueType(name, arr);
@ -106,8 +106,8 @@ void ConfigVisitor::Visit(const json::Array& array) {
AddOptionValue(ReadArray(array, array_type, &OptionValueListDouble::SetListDouble));
else if (array_type == "bool")
AddOptionValue(ReadArray(array, array_type, &OptionValueListBool::SetListBool));
else if (array_type == "colour")
AddOptionValue(ReadArray(array, array_type, &OptionValueListColour::SetListColour));
else if (array_type == "color")
AddOptionValue(ReadArray(array, array_type, &OptionValueListColor::SetListColor));
else
Error<OptionJsonValueArray>("Array type not handled");
}
@ -121,8 +121,8 @@ void ConfigVisitor::Visit(const json::Double& number) {
}
void ConfigVisitor::Visit(const json::String& string) {
if (string.find("rgb(") == 0) {
AddOptionValue(new OptionValueColour(name, string));
if (string.size() && (string.find("rgb(") == 0 || string[0] == '#' || string[0] == '&')) {
AddOptionValue(new OptionValueColor(name, string));
} else {
AddOptionValue(new OptionValueString(name, string));
}

View File

@ -1,4 +1,4 @@
// Copyright (c) 2010, Amar Takhar <verm@aegisub.org>
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@ -12,18 +12,33 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/// @file colour.h
/// @brief Colourspace class and functions.
/// @ingroup libaegisub
#pragma once
#ifndef LAGI_PRE
#include <string>
#endif
// This file is a stub for now.
namespace agi {
struct Color {
unsigned char r; ///< Red component
unsigned char g; ///< Green component
unsigned char b; ///< Blue component
unsigned char a; ///< Alpha component
typedef std::string Colour;
Color();
Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0);
Color(std::string const& str);
Color(const char *str);
} // namespace agi
bool operator==(Color const& col) const;
bool operator!=(Color const& col) const;
std::string GetAssStyleFormatted() const;
std::string GetAssOverrideFormatted() const;
std::string GetSsaFormatted() const;
std::string GetHexFormatted() const;
std::string GetRgbFormatted() const;
operator std::string() const { return GetRgbFormatted(); }
};
}

View File

@ -23,7 +23,7 @@
#include <vector>
#endif
#include <libaegisub/colour.h>
#include <libaegisub/color.h>
#include <libaegisub/exception.h>
#include <libaegisub/signal.h>
@ -59,12 +59,12 @@ public:
Type_String = 0, ///< String
Type_Int = 1, ///< Integer
Type_Double = 2, ///< Double
Type_Colour = 3, ///< Colour
Type_Color = 3, ///< Color
Type_Bool = 4, ///< Bool
Type_List_String = 100, ///< List of Strings
Type_List_Int = 101, ///< List of Integers
Type_List_Double = 102, ///< List of Doubles
Type_List_Colour = 103, ///< List of Colours
Type_List_Color = 103, ///< List of Colors
Type_List_Bool = 104 ///< List of Bools
};
@ -76,38 +76,38 @@ public:
virtual std::string GetString() const { throw TypeError("string"); }
virtual int64_t GetInt() const { throw TypeError("int"); }
virtual double GetDouble() const { throw TypeError("double"); }
virtual Colour GetColour() const { throw TypeError("colour"); }
virtual Color GetColor() const { throw TypeError("color"); }
virtual bool GetBool() const { throw TypeError("bool"); }
virtual void SetString(const std::string) { throw TypeError("string", " set "); }
virtual void SetInt(const int64_t) { throw TypeError("int", " set "); }
virtual void SetDouble(const double) { throw TypeError("double", " set "); }
virtual void SetColour(const Colour) { throw TypeError("colour", " set "); }
virtual void SetColor(const Color) { throw TypeError("color", " set "); }
virtual void SetBool(const bool) { throw TypeError("bool", " set "); }
virtual std::string GetDefaultString() const { throw TypeError("string"); }
virtual int64_t GetDefaultInt() const { throw TypeError("int"); }
virtual double GetDefaultDouble() const { throw TypeError("double"); }
virtual Colour GetDefaultColour() const { throw TypeError("colour"); }
virtual Color GetDefaultColor() const { throw TypeError("color"); }
virtual bool GetDefaultBool() const { throw TypeError("bool"); }
virtual std::vector<std::string> const& GetListString() const { throw ListTypeError("string"); }
virtual std::vector<int64_t> const& GetListInt() const { throw ListTypeError("int"); }
virtual std::vector<double> const& GetListDouble() const { throw ListTypeError("double"); }
virtual std::vector<Colour> const& GetListColour() const { throw ListTypeError("colour"); }
virtual std::vector<Color> const& GetListColor() const { throw ListTypeError("color"); }
virtual std::vector<bool> const& GetListBool() const { throw ListTypeError("string"); }
virtual void SetListString(const std::vector<std::string>&) { throw ListTypeError("string", " set "); }
virtual void SetListInt(const std::vector<int64_t>&) { throw ListTypeError("int", " set "); }
virtual void SetListDouble(const std::vector<double>&) { throw ListTypeError("double", " set "); }
virtual void SetListColour(const std::vector<Colour>&) { throw ListTypeError("colour", " set "); }
virtual void SetListColor(const std::vector<Color>&) { throw ListTypeError("color", " set "); }
virtual void SetListBool(const std::vector<bool>&) { throw ListTypeError("string", " set "); }
virtual std::vector<std::string> const& GetDefaultListString() const { throw ListTypeError("string"); }
virtual std::vector<int64_t> const& GetDefaultListInt() const { throw ListTypeError("int"); }
virtual std::vector<double> const& GetDefaultListDouble() const { throw ListTypeError("double"); }
virtual std::vector<Colour> const& GetDefaultListColour() const { throw ListTypeError("colour"); }
virtual std::vector<Color> const& GetDefaultListColor() const { throw ListTypeError("color"); }
virtual std::vector<bool> const& GetDefaultListBool() const { throw ListTypeError("string"); }
virtual void Set(const OptionValue *new_value)=0;
@ -136,7 +136,7 @@ public:
CONFIG_OPTIONVALUE(String, std::string)
CONFIG_OPTIONVALUE(Int, int64_t)
CONFIG_OPTIONVALUE(Double, double)
CONFIG_OPTIONVALUE(Colour, Colour)
CONFIG_OPTIONVALUE(Color, Color)
CONFIG_OPTIONVALUE(Bool, bool)
#define CONFIG_OPTIONVALUE_LIST(type_name, type) \
@ -161,7 +161,7 @@ CONFIG_OPTIONVALUE(Bool, bool)
CONFIG_OPTIONVALUE_LIST(String, std::string)
CONFIG_OPTIONVALUE_LIST(Int, int64_t)
CONFIG_OPTIONVALUE_LIST(Double, double)
CONFIG_OPTIONVALUE_LIST(Colour, Colour)
CONFIG_OPTIONVALUE_LIST(Color, Color)
CONFIG_OPTIONVALUE_LIST(Bool, bool)
} // namespace agi

View File

@ -42,91 +42,10 @@
#endif
#include "ass_style.h"
#include "compat.h"
#include "subtitle_format.h"
#include "utils.h"
AssColor::AssColor () {
r=g=b=a=0;
}
AssColor::AssColor(int r, int g, int b, int a)
: r(r)
, g(g)
, b(b)
, a(a)
{
}
AssColor::AssColor(const wxColour &color)
: a(0)
{
SetWXColor(color);
}
void AssColor::Parse(wxString const& value) {
if (value.size() > 0 && value[0] == '#') {
// HTML colour
SetWXColor(wxColor(value));
return;
}
// Prepare
char ostr[12];
int oindex = 11;
bool ishex = false;
ostr[11] = 0;
for(size_t i = value.size(); i > 0 && oindex >= 0; i--) {
unsigned char c = value[i - 1];
if (isxdigit(c) || c == '-') {
ostr[--oindex] = c;
if (c >= 'A')
ishex = true;
}
else if (c == 'H' || c == 'h')
ishex = true;
}
unsigned long outval = strtoul(ostr + oindex, 0, ishex ? 16 : 10);
r = outval & 0xFF;
g = (outval>>8) & 0xFF;
b = (outval>>16) & 0xFF;
a = (outval>>24) & 0xFF;
}
wxColour AssColor::GetWXColor() const {
return wxColour(r,g,b,255-a);
}
void AssColor::SetWXColor(const wxColor &color) {
r = color.Red();
g = color.Green();
b = color.Blue();
}
wxString AssColor::GetAssFormatted(bool alpha,bool stripped,bool isStyle) const {
wxString work;
if (!stripped) work += "&H";
if (alpha) work += wxString::Format("%02X",a);
work += wxString::Format("%02X%02X%02X",b,g,r);
if (!stripped && !isStyle) work += "&";
return work;
}
wxString AssColor::GetSSAFormatted() const {
long color = (a<<24)+(b<<16)+(g<<8)+r;
wxString output=wxString::Format("%li",(long)color);
return output;
}
bool AssColor::operator==(const AssColor &col) const {
return r==col.r && g==col.g && b==col.b && a==col.a;
}
bool AssColor::operator!=(const AssColor &col) const {
return !(*this == col);
}
AssStyle::AssStyle()
: AssEntry(wxString(), wxS("[V4+ Styles]"))
, name("Default")
@ -134,8 +53,6 @@ AssStyle::AssStyle()
, fontsize(20.)
, primary(255, 255, 255)
, secondary(255, 0, 0)
, outline(0, 0, 0)
, shadow(0, 0, 0)
, bold(false)
, italic(false)
, underline(false)
@ -184,20 +101,20 @@ AssStyle::AssStyle(wxString rawData, int version)
fontsize = get_next_double(tkn);
if (version != 0) {
primary.Parse(get_next_string(tkn));
secondary.Parse(get_next_string(tkn));
outline.Parse(get_next_string(tkn));
shadow.Parse(get_next_string(tkn));
primary = from_wx(get_next_string(tkn));
secondary = from_wx(get_next_string(tkn));
outline = from_wx(get_next_string(tkn));
shadow = from_wx(get_next_string(tkn));
}
else {
primary.Parse(get_next_string(tkn));
secondary.Parse(get_next_string(tkn));
primary = from_wx(get_next_string(tkn));
secondary = from_wx(get_next_string(tkn));
// Read and discard tertiary color
get_next_string(tkn);
// Read shadow/outline color
outline.Parse(get_next_string(tkn));
outline = from_wx(get_next_string(tkn));
shadow = outline;
}
@ -257,16 +174,16 @@ AssStyle::AssStyle(wxString rawData, int version)
void AssStyle::UpdateData() {
wxString final;
name.Replace(",",";");
font.Replace(",",";");
//name.Replace(",",";");
//font.Replace(",",";");
final = wxString::Format("Style: %s,%s,%g,%s,%s,%s,%s,%d,%d,%d,%d,%g,%g,%g,%g,%d,%g,%g,%i,%i,%i,%i,%i",
name, font, fontsize,
primary.GetAssFormatted(true,false,true),
secondary.GetAssFormatted(true,false,true),
outline.GetAssFormatted(true,false,true),
shadow.GetAssFormatted(true,false,true),
primary.GetAssStyleFormatted(),
secondary.GetAssStyleFormatted(),
outline.GetAssStyleFormatted(),
shadow.GetAssStyleFormatted(),
(bold? -1 : 0), (italic ? -1 : 0),
(underline?-1:0),(strikeout?-1:0),
scalex,scaley,spacing,angle,
@ -286,9 +203,9 @@ wxString AssStyle::GetSSAText() const {
output = wxString::Format("Style: %s,%s,%g,%s,%s,0,%s,%d,%d,%d,%g,%g,%d,%d,%d,%d,0,%i",
n, f, fontsize,
primary.GetSSAFormatted(),
secondary.GetSSAFormatted(),
shadow.GetSSAFormatted(),
primary.GetSsaFormatted(),
secondary.GetSsaFormatted(),
shadow.GetSsaFormatted(),
(bold? -1 : 0), (italic ? -1 : 0),
borderstyle,outline_w,shadow_w,align,
Margin[0],Margin[1],Margin[2],encoding);

View File

@ -40,25 +40,7 @@
#include "ass_entry.h"
struct AssColor {
int r; ///< Red component
int g; ///< Green component
int b; ///< Blue component
int a; ///< Alpha component
AssColor();
AssColor(int r, int g, int b, int a = 0);
AssColor(const wxColour &color);
bool operator==(const AssColor &col) const;
bool operator!=(const AssColor &col) const;
wxColor GetWXColor() const; // Return as a wxColor
void SetWXColor(const wxColor &color); // Sets from a wxColor
void Parse(wxString const& value); // Parse SSA or ASS-style color
wxString GetAssFormatted(bool alpha,bool stripped=false,bool isStyle=false) const; // Gets color formated in ASS format
wxString GetSSAFormatted() const;
};
#include <libaegisub/color.h>
class AssStyle : public AssEntry {
public:
@ -66,10 +48,10 @@ public:
wxString font; ///< Font face name
double fontsize; ///< Font size
AssColor primary; ///< Default text color
AssColor secondary; ///< Text color for not-yet-reached karaoke syllables
AssColor outline; ///< Outline color
AssColor shadow; ///< Shadow color
agi::Color primary; ///< Default text color
agi::Color secondary; ///< Text color for not-yet-reached karaoke syllables
agi::Color outline; ///< Outline color
agi::Color shadow; ///< Shadow color
bool bold;
bool italic;

View File

@ -86,14 +86,14 @@ public:
void SetColourScheme(std::string const& name)
{
std::string opt_prefix = "Colour/Schemes/" + name + "/UI/";
light_colour = lagi_wxColour(OPT_GET(opt_prefix + "Light")->GetColour());
dark_colour = lagi_wxColour(OPT_GET(opt_prefix + "Dark")->GetColour());
sel_colour = lagi_wxColour(OPT_GET(opt_prefix + "Selection")->GetColour());
light_colour = to_wx(OPT_GET(opt_prefix + "Light")->GetColor());
dark_colour = to_wx(OPT_GET(opt_prefix + "Dark")->GetColor());
sel_colour = to_wx(OPT_GET(opt_prefix + "Selection")->GetColor());
opt_prefix = "Colour/Schemes/" + name + "/UI Focused/";
light_focused_colour = lagi_wxColour(OPT_GET(opt_prefix + "Light")->GetColour());
dark_focused_colour = lagi_wxColour(OPT_GET(opt_prefix + "Dark")->GetColour());
sel_focused_colour = lagi_wxColour(OPT_GET(opt_prefix + "Selection")->GetColour());
light_focused_colour = to_wx(OPT_GET(opt_prefix + "Light")->GetColor());
dark_focused_colour = to_wx(OPT_GET(opt_prefix + "Dark")->GetColor());
sel_focused_colour = to_wx(OPT_GET(opt_prefix + "Selection")->GetColor());
}
/// Set whether to use the focused or unfocused colours

View File

@ -750,8 +750,8 @@ namespace Automation4 {
// LuaFeature
LuaFeature::LuaFeature(lua_State *L)
: L(L)
, myid(0)
: myid(0)
, L(L)
{
}

View File

@ -112,7 +112,7 @@ namespace {
return BadField(std::string("Invalid or missing field '") + name + "' in '" + line_clasee + "' class subtitle line (expected " + expected_type + ")");
}
wxString get_string_field(lua_State *L, const char *name, const char *line_class)
wxString get_wxstring_field(lua_State *L, const char *name, const char *line_class)
{
lua_getfield(L, -1, name);
if (!lua_isstring(L, -1))
@ -122,6 +122,16 @@ namespace {
return ret;
}
std::string get_string_field(lua_State *L, const char *name, const char *line_class)
{
lua_getfield(L, -1, name);
if (!lua_isstring(L, -1))
throw bad_field("string", name, line_class);
std::string ret(lua_tostring(L, -1));
lua_pop(L, 1);
return ret;
}
double get_double_field(lua_State *L, const char *name, const char *line_class)
{
lua_getfield(L, -1, name);
@ -247,10 +257,10 @@ namespace Automation4 {
set_field(L, "fontname", sty->font);
set_field(L, "fontsize", sty->fontsize);
set_field(L, "color1", sty->primary.GetAssFormatted(true));
set_field(L, "color2", sty->secondary.GetAssFormatted(true));
set_field(L, "color3", sty->outline.GetAssFormatted(true));
set_field(L, "color4", sty->shadow.GetAssFormatted(true));
set_field(L, "color1", sty->primary.GetAssStyleFormatted() + "&");
set_field(L, "color2", sty->secondary.GetAssStyleFormatted() + "&");
set_field(L, "color3", sty->outline.GetAssStyleFormatted() + "&");
set_field(L, "color4", sty->shadow.GetAssStyleFormatted() + "&");
set_field(L, "bold", sty->bold);
set_field(L, "italic", sty->italic);
@ -305,16 +315,16 @@ namespace Automation4 {
AssEntry *result = 0;
try {
wxString section = get_string_field(L, "section", "common");
wxString section = get_wxstring_field(L, "section", "common");
if (lclass == "clear")
result = new AssEntry("", "");
else if (lclass == "comment")
result = new AssEntry(";" + get_string_field(L, "text", "comment"), section);
result = new AssEntry(";" + get_wxstring_field(L, "text", "comment"), section);
else if (lclass == "head")
result = new AssEntry(section, section);
else if (lclass == "info") {
result = new AssEntry(wxString::Format("%s: %s", get_string_field(L, "key", "info"), get_string_field(L, "value", "info")), "[Script Info]");
result = new AssEntry(wxString::Format("%s: %s", get_wxstring_field(L, "key", "info"), get_wxstring_field(L, "value", "info")), "[Script Info]");
}
else if (lclass == "format") {
// ohshi- ...
@ -324,13 +334,13 @@ namespace Automation4 {
else if (lclass == "style") {
AssStyle *sty = new AssStyle;
result = sty;
sty->name = get_string_field(L, "name", "style");
sty->font = get_string_field(L, "fontname", "style");
sty->name = get_wxstring_field(L, "name", "style");
sty->font = get_wxstring_field(L, "fontname", "style");
sty->fontsize = get_double_field(L, "fontsize", "style");
sty->primary.Parse(get_string_field(L, "color1", "style"));
sty->secondary.Parse(get_string_field(L, "color2", "style"));
sty->outline.Parse(get_string_field(L, "color3", "style"));
sty->shadow.Parse(get_string_field(L, "color4", "style"));
sty->primary = get_string_field(L, "color1", "style");
sty->secondary = get_string_field(L, "color2", "style");
sty->outline = get_string_field(L, "color3", "style");
sty->shadow = get_string_field(L, "color4", "style");
sty->bold = get_bool_field(L, "bold", "style");
sty->italic = get_bool_field(L, "italic", "style");
sty->underline = get_bool_field(L, "underline", "style");
@ -357,13 +367,13 @@ namespace Automation4 {
dia->Layer = get_int_field(L, "layer", "dialogue");
dia->Start = get_int_field(L, "start_time", "dialogue");
dia->End = get_int_field(L, "end_time", "dialogue");
dia->Style = get_string_field(L, "style", "dialogue");
dia->Actor = get_string_field(L, "actor", "dialogue");
dia->Style = get_wxstring_field(L, "style", "dialogue");
dia->Actor = get_wxstring_field(L, "actor", "dialogue");
dia->Margin[0] = get_int_field(L, "margin_l", "dialogue");
dia->Margin[1] = get_int_field(L, "margin_r", "dialogue");
dia->Margin[2] = get_int_field(L, "margin_t", "dialogue");
dia->Effect = get_string_field(L, "effect", "dialogue");
dia->Text = get_string_field(L, "text", "dialogue");
dia->Effect = get_wxstring_field(L, "effect", "dialogue");
dia->Text = get_wxstring_field(L, "text", "dialogue");
}
else {
luaL_error(L, "Found line with unknown class: %s", lclass.utf8_str().data());

View File

@ -222,7 +222,7 @@ namespace Automation4 {
bool TransferFromWindow()
{
*text = static_cast<ColourButton*>(GetWindow())->GetColour().GetAsString(wxC2S_HTML_SYNTAX);
*text = to_wx(static_cast<ColourButton*>(GetWindow())->GetColor().GetHexFormatted());
return true;
}
};
@ -247,9 +247,8 @@ namespace Automation4 {
wxControl *Create(wxWindow *parent)
{
AssColor colour;
colour.Parse(text);
wxControl *cw = new ColourButton(parent, -1, wxSize(50*width,10*height), colour.GetWXColor());
agi::Color colour(from_wx(text));
wxControl *cw = new ColourButton(parent, -1, wxSize(50*width,10*height), colour);
cw->SetValidator(ColorValidator(&text));
cw->SetToolTip(hint);
return cw;

View File

@ -233,13 +233,13 @@ void BaseGrid::UpdateStyle() {
// Set row brushes
assert(sizeof(rowColors) / sizeof(rowColors[0]) >= COLOR_LEFT_COL);
rowColors[COLOR_DEFAULT].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColour()));
rowColors[COLOR_HEADER].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Header")->GetColour()));
rowColors[COLOR_SELECTION].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColour()));
rowColors[COLOR_COMMENT].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColour()));
rowColors[COLOR_VISIBLE].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColour()));
rowColors[COLOR_SELECTED_COMMENT].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->GetColour()));
rowColors[COLOR_LEFT_COL].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Left Column")->GetColour()));
rowColors[COLOR_DEFAULT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColor()));
rowColors[COLOR_HEADER].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Header")->GetColor()));
rowColors[COLOR_SELECTION].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColor()));
rowColors[COLOR_COMMENT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColor()));
rowColors[COLOR_VISIBLE].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColor()));
rowColors[COLOR_SELECTED_COMMENT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->GetColor()));
rowColors[COLOR_LEFT_COL].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Left Column")->GetColor()));
// Set column widths
std::vector<bool> column_array(OPT_GET("Subtitle/Grid/Column")->GetListBool());
@ -477,12 +477,12 @@ void BaseGrid::DrawImage(wxDC &dc, bool paint_columns[]) {
int maxH = (nDraw+1) * lineHeight;
// Row colors
wxColour text_standard(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Standard")->GetColour()));
wxColour text_selection(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Selection")->GetColour()));
wxColour text_collision(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Collision")->GetColour()));
wxColour text_standard(to_wx(OPT_GET("Colour/Subtitle Grid/Standard")->GetColor()));
wxColour text_selection(to_wx(OPT_GET("Colour/Subtitle Grid/Selection")->GetColor()));
wxColour text_collision(to_wx(OPT_GET("Colour/Subtitle Grid/Collision")->GetColor()));
// First grid row
wxPen grid_pen(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Lines")->GetColour()));
wxPen grid_pen(to_wx(OPT_GET("Colour/Subtitle Grid/Lines")->GetColor()));
dc.SetPen(grid_pen);
dc.DrawLine(0, 0, w, 0);
dc.SetPen(*wxTRANSPARENT_PEN);
@ -580,7 +580,7 @@ void BaseGrid::DrawImage(wxDC &dc, bool paint_columns[]) {
// Draw currently active line border
if (GetActiveLine()) {
dc.SetPen(wxPen(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Active Border")->GetColour())));
dc.SetPen(wxPen(to_wx(OPT_GET("Colour/Subtitle Grid/Active Border")->GetColor())));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
int dy = (line_index_map[GetActiveLine()]+1-yPos) * lineHeight;
dc.DrawRectangle(0,dy,w,lineHeight+1);

View File

@ -363,45 +363,3 @@ void hsl_to_hsv(int iH, int iS, int iL, unsigned char *oH, unsigned char *oS, un
*oS = 2 * 255 * iS * (255 - iL) / (iL*255 + iS*255 - iL*iS);
}
}
wxString color_to_html(wxColour color)
{
return wxString::Format("#%02X%02X%02X", color.Red(), color.Green(), color.Blue());
}
wxColour html_to_color(wxString html)
{
html.Trim(true);
html.Trim(false);
if (html.StartsWith("#")) {
html.Remove(0, 1);
}
if (html.size() == 6) {
// 8 bit per channel
long r, g, b;
wxString sr, sg, sb;
sr = html.Mid(0, 2);
sg = html.Mid(2, 2);
sb = html.Mid(4, 2);
if (sr.ToLong(&r, 16) && sg.ToLong(&g, 16) && sb.ToLong(&b, 16)) {
return wxColour(r, g, b);
} else {
return wxColour(*wxBLACK);
}
} else if (html.size() == 3) {
// 4 bit per channel
long r, g, b;
wxString sr, sg, sb;
sr = html.Mid(0, 1);
sg = html.Mid(1, 1);
sb = html.Mid(2, 1);
if (sr.ToLong(&r, 16) && sg.ToLong(&g, 16) && sb.ToLong(&b, 16)) {
return wxColour(r*16+r, g*16+g, b*16+b);
} else {
return wxColour(*wxBLACK);
}
} else {
// only care about valid colors
return wxColour(*wxBLACK);
}
}

View File

@ -64,10 +64,3 @@ void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
void hsv_to_hsl(int iH, int iS, int iV, unsigned char *oH, unsigned char *oS, unsigned char *oL);
void hsl_to_hsv(int iH, int iS, int iL, unsigned char *oH, unsigned char *oS, unsigned char *oV);
/// Convert a wxColour to a HTML hex string
wxString color_to_html(wxColour color);
/// Convert a HTML hex string to a wxColour
wxColour html_to_color(wxString html);

View File

@ -39,41 +39,34 @@
#endif
#include "colour_button.h"
#include "config.h"
#include "compat.h"
#include "dialog_colorpicker.h"
ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col)
ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, agi::Color col)
: wxBitmapButton(parent, id, wxBitmap(size), wxDefaultPosition, wxSize(size.GetWidth() + 6, size.GetHeight() + 6))
, bmp(GetBitmapLabel())
, colour(col)
{
{
wxMemoryDC dc;
dc.SelectObject(bmp);
dc.SetBrush(wxBrush(colour));
dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight());
}
Paint();
SetBitmapLabel(bmp);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ColourButton::OnClick, this);
}
ColourButton::~ColourButton() {
void ColourButton::Paint() {
wxMemoryDC dc;
dc.SelectObject(bmp);
dc.SetBrush(wxBrush(to_wx(colour)));
dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight());
}
/// @brief Callback for the color picker dialog
/// @param col New color
void ColourButton::SetColour(wxColour col) {
if (!col.IsOk()) return;
void ColourButton::SetColour(agi::Color col) {
colour = col;
// Draw colour
{
wxMemoryDC dc;
dc.SelectObject(bmp);
dc.SetBrush(wxBrush(colour));
dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight());
}
Paint();
SetBitmapLabel(bmp);
// Trigger a click event on this as some stuff relies on that to know
@ -84,18 +77,14 @@ void ColourButton::SetColour(wxColour col) {
AddPendingEvent(evt);
}
wxColour ColourButton::GetColour() {
agi::Color ColourButton::GetColor() {
return colour;
}
/// @brief Click handler
/// @param event
void ColourButton::OnClick(wxCommandEvent &event) {
if (event.GetClientData() == this)
event.Skip();
else {
wxColour initial = colour;
if (!GetColorFromUser<ColourButton, &ColourButton::SetColour>(GetParent(), colour, this).IsOk())
SetColour(initial);
GetColorFromUser<ColourButton, &ColourButton::SetColour>(GetParent(), colour, this);
}
}

View File

@ -36,22 +36,18 @@
#include <wx/bmpbuttn.h>
#endif
#include <libaegisub/color.h>
/// DOCME
/// @class ColourButton
/// @brief DOCME
///
/// DOCME
class ColourButton: public wxBitmapButton {
private:
wxBitmap bmp; /// The button's bitmap label
wxColour colour; /// The current colour
agi::Color colour; /// The current colour
void Paint();
void OnClick(wxCommandEvent &event);
void SetColour(wxColour colour);
void SetColour(agi::Color colour);
public:
ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col=wxColour(0,0,0));
~ColourButton();
ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, agi::Color col = agi::Color());
wxColour GetColour();
agi::Color GetColor();
};

View File

@ -302,19 +302,17 @@ void toggle_override_tag(const agi::Context *c, bool (AssStyle::*field), const c
commit_text(c, undo_msg, sel_start, sel_end);
}
void got_color(const agi::Context *c, const char *tag, int *commit_id, wxColour new_color) {
if (new_color.Ok()) {
int sel_start = c->textSelectionController->GetSelectionStart();
int sel_end = c->textSelectionController->GetSelectionEnd();
set_tag(c, tag, AssColor(new_color).GetAssFormatted(false), sel_start, sel_end);
commit_text(c, _("set color"), sel_start, sel_end, commit_id);
}
void got_color(const agi::Context *c, const char *tag, int *commit_id, agi::Color new_color) {
int sel_start = c->textSelectionController->GetSelectionStart();
int sel_end = c->textSelectionController->GetSelectionEnd();
set_tag(c, tag, new_color.GetAssOverrideFormatted(), sel_start, sel_end);
commit_text(c, _("set color"), sel_start, sel_end, commit_id);
}
void show_color_picker(const agi::Context *c, AssColor (AssStyle::*field), const char *tag, const char *alt) {
void show_color_picker(const agi::Context *c, agi::Color (AssStyle::*field), const char *tag, const char *alt) {
AssDialogue *const line = c->selectionController->GetActiveLine();
AssStyle const* const style = c->ass->GetStyle(line->Style);
wxColor color = (style ? style->*field : AssStyle().*field).GetWXColor();
agi::Color color = (style ? style->*field : AssStyle().*field);
line->ParseAssTags();
@ -324,11 +322,11 @@ void show_color_picker(const agi::Context *c, AssColor (AssStyle::*field), const
color = get_value(*line, blockn, color, tag, alt);
int commit_id = -1;
const wxColor newColor = GetColorFromUser(c->parent, color, bind(got_color, c, tag, &commit_id, std::tr1::placeholders::_1));
bool ok = GetColorFromUser(c->parent, color, bind(got_color, c, tag, &commit_id, std::tr1::placeholders::_1));
line->ClearBlocks();
commit_text(c, _("set color"), -1, -1, &commit_id);
if (!newColor.IsOk()) {
if (!ok) {
c->ass->Undo();
c->textSelectionController->SetSelection(sel_start, sel_end);
}

View File

@ -6,10 +6,15 @@
#include <wx/string.h>
#endif
#include <libaegisub/colour.h>
#include <libaegisub/color.h>
#define STD_STR(x) std::string((x).utf8_str())
inline wxColour lagi_wxColour(const agi::Colour &colour) { return wxColour(colour); }
inline wxColour to_wx(agi::Color color) { return wxColour(color.r, color.g, color.b, 255 - color.a); }
inline wxString to_wx(std::string const& str) { return wxString(str.c_str(), wxConvUTF8); }
inline agi::Color from_wx(wxColour color) { return agi::Color(color.Red(), color.Green(), color.Blue(), 255 - color.Alpha()); }
inline std::string from_wx(wxString const& str) { return std::string(str.utf8_str()); }
inline wxString lagi_wxString(const std::string &str) { return wxString(str.c_str(), wxConvUTF8); }
wxArrayString lagi_MRU_wxAS(const wxString &list);

View File

@ -77,11 +77,6 @@
#include <ApplicationServices/ApplicationServices.h>
#endif
/// DOCME
/// @class ColorPickerSpectrum
/// @brief DOCME
///
/// DOCME
class ColorPickerSpectrum : public wxControl {
public:
enum PickerDirection {
@ -93,10 +88,7 @@ private:
int x;
int y;
/// DOCME
wxBitmap *background;
/// DOCME
PickerDirection direction;
void OnPaint(wxPaintEvent &evt);
@ -113,18 +105,15 @@ public:
void SetBackground(wxBitmap *new_background, bool force = false);
};
/// DOCME
/// @class ColorPickerRecent
/// @brief DOCME
///
/// DOCME
/// @brief A grid of recently used colors which can be selected by clicking on them
class ColorPickerRecent : public wxControl {
int rows; ///< Number of rows of colors
int cols; ///< Number of cols of colors
int cellsize; ///< Width/Height of each cell
/// The colors currently displayed in the control
std::vector<wxColour> colors;
std::vector<agi::Color> colors;
/// Does the background need to be regenerated?
bool background_valid;
@ -141,29 +130,20 @@ class ColorPickerRecent : public wxControl {
public:
ColorPickerRecent(wxWindow *parent, int cols, int rows, int cellsize);
/// Load the colors to show from a string
void LoadFromString(const wxString &recent_string = wxString());
/// Save the colors currently shown to a string
wxString StoreToString();
/// Load the colors to show
void Load(std::vector<agi::Color> const& recent_colors);
/// Get the list of recent colors
std::vector<agi::Color> Save() const;
/// Add a color to the beginning of the recent list
void AddColor(wxColour color);
void AddColor(agi::Color color);
};
/// DOCME
/// @class ColorPickerScreenDropper
/// @brief DOCME
///
/// DOCME
class ColorPickerScreenDropper : public wxControl {
/// DOCME
wxBitmap capture;
/// DOCME
/// DOCME
int resx, resy;
/// DOCME
int magnification;
void OnMouse(wxMouseEvent &evt);
@ -177,15 +157,10 @@ public:
void DropFromScreenXY(int x, int y);
};
/// DOCME
/// @class DialogColorPicker
/// @brief DOCME
///
/// DOCME
class DialogColorPicker : public wxDialog {
agi::scoped_ptr<PersistLocation> persist;
wxColour cur_color; ///< Currently selected colour
agi::Color cur_color; ///< Currently selected colour
bool spectrum_dirty; ///< Does the spectrum image need to be regenerated?
ColorPickerSpectrum *spectrum; ///< The 2D color spectrum
@ -240,7 +215,7 @@ class DialogColorPicker : public wxDialog {
/// Update all other controls as a result of modifying the HTML format control
void UpdateFromHTML();
void SetRGB(unsigned char r, unsigned char g, unsigned char b);
void SetRGB(agi::Color new_color);
void SetHSL(unsigned char r, unsigned char g, unsigned char b);
void SetHSV(unsigned char r, unsigned char g, unsigned char b);
@ -260,22 +235,21 @@ class DialogColorPicker : public wxDialog {
void OnChangeMode(wxCommandEvent &evt);
void OnSpectrumChange(wxCommandEvent &evt);
void OnSliderChange(wxCommandEvent &evt);
void OnRecentSelect(wxCommandEvent &evt); // also handles dropper pick
void OnRecentSelect(wxThreadEvent &evt); // also handles dropper pick
void OnDropperMouse(wxMouseEvent &evt);
void OnMouse(wxMouseEvent &evt);
void OnCaptureLost(wxMouseCaptureLostEvent&);
std::tr1::function<void (wxColour)> callback;
std::tr1::function<void (agi::Color)> callback;
public:
DialogColorPicker(wxWindow *parent, wxColour initial_color, std::tr1::function<void (wxColour)> callback);
DialogColorPicker(wxWindow *parent, agi::Color initial_color, std::tr1::function<void (agi::Color)> callback);
~DialogColorPicker();
void SetColor(wxColour new_color);
wxColour GetColor();
void SetColor(agi::Color new_color);
agi::Color GetColor();
};
/// DOCME
static const int spectrum_horz_vert_arrow_size = 4;
ColorPickerSpectrum::ColorPickerSpectrum(wxWindow *parent, PickerDirection direction, wxSize size)
@ -438,7 +412,7 @@ ColorPickerRecent::ColorPickerRecent(wxWindow *parent, int cols, int rows, int c
, cellsize(cellsize)
, background_valid(false)
{
LoadFromString();
colors.resize(rows * cols);
SetClientSize(cols*cellsize, rows*cellsize);
SetMinSize(GetSize());
SetMaxSize(GetSize());
@ -449,46 +423,33 @@ ColorPickerRecent::ColorPickerRecent(wxWindow *parent, int cols, int rows, int c
Bind(wxEVT_SIZE, &ColorPickerRecent::OnSize, this);
}
void ColorPickerRecent::LoadFromString(const wxString &recent_string)
void ColorPickerRecent::Load(std::vector<agi::Color> const& recent_colors)
{
colors.clear();
wxStringTokenizer toker(recent_string, " ", false);
while (toker.HasMoreTokens()) {
AssColor color;
color.Parse(toker.NextToken());
color.a = 0; // opaque
colors.push_back(color.GetWXColor());
}
while ((int)colors.size() < rows*cols) {
colors.push_back(*wxBLACK);
}
background_valid = false;
colors = recent_colors;
colors.resize(rows * cols);
}
wxString ColorPickerRecent::StoreToString()
std::vector<agi::Color> ColorPickerRecent::Save() const
{
wxString res;
for (int i = 0; i < rows*cols; i++) {
res << AssColor(colors[i]).GetAssFormatted(false, false, false) << " ";
}
return res.Trim(true);
return colors;
}
void ColorPickerRecent::AddColor(wxColour color)
void ColorPickerRecent::AddColor(agi::Color color)
{
std::vector<wxColour>::iterator existing = find(colors.begin(), colors.end(), color);
std::vector<agi::Color>::iterator existing = find(colors.begin(), colors.end(), color);
if (existing != colors.end())
rotate(colors.begin(), existing, existing + 1);
else
else {
colors.insert(colors.begin(), color);
colors.pop_back();
}
background_valid = false;
Refresh(false);
}
wxDEFINE_EVENT(EVT_RECENT_SELECT, wxCommandEvent);
wxDEFINE_EVENT(EVT_RECENT_SELECT, wxThreadEvent);
void ColorPickerRecent::OnClick(wxMouseEvent &evt)
{
@ -499,8 +460,8 @@ void ColorPickerRecent::OnClick(wxMouseEvent &evt)
int i = cols*cy + cx;
if (i >= 0 && i < (int)colors.size()) {
wxCommandEvent evnt(EVT_RECENT_SELECT, GetId());
evnt.SetString(AssColor(colors[i]).GetAssFormatted(false, false, false));
wxThreadEvent evnt(EVT_RECENT_SELECT, GetId());
evnt.SetPayload(colors[i]);
AddPendingEvent(evnt);
}
}
@ -523,7 +484,7 @@ void ColorPickerRecent::OnPaint(wxPaintEvent &)
int x = cx * cellsize;
int y = cy * cellsize;
dc.SetBrush(wxBrush(colors[cy * cols + cx]));
dc.SetBrush(wxBrush(to_wx(colors[cy * cols + cx])));
dc.DrawRectangle(x, y, x+cellsize, y+cellsize);
}
}
@ -561,7 +522,7 @@ ColorPickerScreenDropper::ColorPickerScreenDropper(wxWindow *parent, int resx, i
Bind(wxEVT_LEFT_DOWN, &ColorPickerScreenDropper::OnMouse, this);
}
wxDEFINE_EVENT(EVT_DROPPER_SELECT, wxCommandEvent);
wxDEFINE_EVENT(EVT_DROPPER_SELECT, wxThreadEvent);
void ColorPickerScreenDropper::OnMouse(wxMouseEvent &evt)
{
@ -571,10 +532,10 @@ void ColorPickerScreenDropper::OnMouse(wxMouseEvent &evt)
if (x >= 0 && x < capture.GetWidth() && y >= 0 && y < capture.GetHeight()) {
wxNativePixelData pd(capture, wxRect(x, y, 1, 1));
wxNativePixelData::Iterator pdi(pd.GetPixels());
wxColour color(pdi.Red(), pdi.Green(), pdi.Blue(), wxALPHA_OPAQUE);
agi::Color color(pdi.Red(), pdi.Green(), pdi.Blue(), 0);
wxCommandEvent evnt(EVT_DROPPER_SELECT, GetId());
evnt.SetString(AssColor(color).GetAssFormatted(false, false, false));
wxThreadEvent evnt(EVT_DROPPER_SELECT, GetId());
evnt.SetPayload(color);
AddPendingEvent(evnt);
}
}
@ -622,16 +583,13 @@ void ColorPickerScreenDropper::DropFromScreenXY(int x, int y)
Refresh(false);
}
wxColour GetColorFromUser(wxWindow* parent, wxColour original, std::tr1::function<void (wxColour)> callback)
bool GetColorFromUser(wxWindow* parent, agi::Color original, std::tr1::function<void (agi::Color)> callback)
{
DialogColorPicker dialog(parent, original, callback);
if (dialog.ShowModal() == wxID_OK)
original = dialog.GetColor();
else
original = wxNullColour;
callback(original);
return original;
bool ok = dialog.ShowModal() == wxID_OK;
if (!ok)
callback(original);
return ok;
}
static wxBitmap *make_rgb_image(int width, int offset) {
@ -647,7 +605,7 @@ static wxBitmap *make_rgb_image(int width, int offset) {
return new wxBitmap(img);
}
DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color, std::tr1::function<void (wxColour)> callback)
DialogColorPicker::DialogColorPicker(wxWindow *parent, agi::Color initial_color, std::tr1::function<void (agi::Color)> callback)
: wxDialog(parent, -1, _("Select Color"))
, callback(callback)
{
@ -779,7 +737,7 @@ DialogColorPicker::DialogColorPicker(wxWindow *parent, wxColour initial_color, s
if (mode < 0 || mode > 4) mode = 3; // HSL default
colorspace_choice->SetSelection(mode);
SetColor(initial_color);
recent_box->LoadFromString(lagi_wxString(OPT_GET("Tool/Colour Picker/Recent")->GetString()));
recent_box->Load(OPT_GET("Tool/Colour Picker/Recent Colours")->GetListColor());
using std::tr1::bind;
for (int i = 0; i < 3; ++i) {
@ -823,8 +781,6 @@ wxSizer *DialogColorPicker::MakeColorInputSizer(wxString (&labels)[N], Control *
return sizer;
}
/// @brief Destructor
DialogColorPicker::~DialogColorPicker()
{
delete rgb_spectrum[0];
@ -842,18 +798,18 @@ DialogColorPicker::~DialogColorPicker()
}
/// @brief Sets the currently selected color, and updates all controls
void DialogColorPicker::SetColor(wxColour new_color)
void DialogColorPicker::SetColor(agi::Color new_color)
{
SetRGB(new_color.Red(), new_color.Green(), new_color.Blue());
SetRGB(new_color);
spectrum_dirty = true;
UpdateFromRGB();
}
/// @brief Get the currently selected color
wxColour DialogColorPicker::GetColor()
agi::Color DialogColorPicker::GetColor()
{
recent_box->AddColor(cur_color);
OPT_SET("Tool/Colour Picker/Recent")->SetString(STD_STR(recent_box->StoreToString()));
OPT_SET("Tool/Colour Picker/Recent Colours")->SetListColor(recent_box->Save());
return cur_color;
}
@ -863,12 +819,12 @@ static void change_value(wxSpinCtrl *ctrl, int value)
ctrl->SetValue(value);
}
void DialogColorPicker::SetRGB(unsigned char r, unsigned char g, unsigned char b)
void DialogColorPicker::SetRGB(agi::Color new_color)
{
change_value(rgb_input[0], r);
change_value(rgb_input[1], g);
change_value(rgb_input[2], b);
cur_color = wxColour(r, g, b, wxALPHA_OPAQUE);
change_value(rgb_input[0], new_color.r);
change_value(rgb_input[1], new_color.g);
change_value(rgb_input[2], new_color.b);
cur_color = new_color;
}
void DialogColorPicker::SetHSL(unsigned char r, unsigned char g, unsigned char b)
@ -898,9 +854,9 @@ void DialogColorPicker::UpdateFromRGB(bool dirty)
b = rgb_input[2]->GetValue();
SetHSL(r, g, b);
SetHSV(r, g, b);
cur_color = wxColour(r, g, b, wxALPHA_OPAQUE);
ass_input->ChangeValue(AssColor(cur_color).GetAssFormatted(false, false, false));
html_input->ChangeValue(color_to_html(cur_color));
cur_color = agi::Color(r, g, b);
ass_input->ChangeValue(to_wx(cur_color.GetAssStyleFormatted()));
html_input->ChangeValue(to_wx(cur_color.GetHexFormatted()));
if (dirty)
spectrum_dirty = true;
@ -915,11 +871,11 @@ void DialogColorPicker::UpdateFromHSL(bool dirty)
s = hsl_input[1]->GetValue();
l = hsl_input[2]->GetValue();
hsl_to_rgb(h, s, l, &r, &g, &b);
SetRGB(r, g, b);
SetRGB(agi::Color(r, g, b));
SetHSV(r, g, b);
ass_input->ChangeValue(AssColor(cur_color).GetAssFormatted(false, false, false));
html_input->ChangeValue(color_to_html(cur_color));
ass_input->ChangeValue(to_wx(cur_color.GetAssStyleFormatted()));
html_input->ChangeValue(to_wx(cur_color.GetHexFormatted()));
if (dirty)
spectrum_dirty = true;
@ -934,10 +890,10 @@ void DialogColorPicker::UpdateFromHSV(bool dirty)
s = hsv_input[1]->GetValue();
v = hsv_input[2]->GetValue();
hsv_to_rgb(h, s, v, &r, &g, &b);
SetRGB(r, g, b);
SetRGB(agi::Color(r, g, b));
SetHSL(r, g, b);
ass_input->ChangeValue(AssColor(cur_color).GetAssFormatted(false, false, false));
html_input->ChangeValue(color_to_html(cur_color));
ass_input->ChangeValue(to_wx(cur_color.GetAssStyleFormatted()));
html_input->ChangeValue(to_wx(cur_color.GetHexFormatted()));
if (dirty)
spectrum_dirty = true;
@ -947,16 +903,11 @@ void DialogColorPicker::UpdateFromHSV(bool dirty)
/// @brief Use the value entered in the ASS hex control to update the other controls
void DialogColorPicker::UpdateFromAss()
{
unsigned char r, g, b;
AssColor ass;
ass.Parse(ass_input->GetValue());
r = ass.r;
g = ass.g;
b = ass.b;
SetRGB(r, g, b);
SetHSL(r, g, b);
SetHSV(r, g, b);
html_input->ChangeValue(color_to_html(cur_color));
agi::Color color(from_wx(ass_input->GetValue()));
SetRGB(color);
SetHSL(color.r, color.g, color.b);
SetHSV(color.r, color.g, color.b);
html_input->ChangeValue(to_wx(cur_color.GetHexFormatted()));
spectrum_dirty = true;
UpdateSpectrumDisplay();
@ -965,15 +916,11 @@ void DialogColorPicker::UpdateFromAss()
/// @brief Use the value entered in the HTML hex control to update the other controls
void DialogColorPicker::UpdateFromHTML()
{
unsigned char r, g, b;
cur_color = html_to_color(html_input->GetValue());
r = cur_color.Red();
g = cur_color.Green();
b = cur_color.Blue();
SetRGB(r, g, b);
SetHSL(r, g, b);
SetHSV(r, g, b);
ass_input->ChangeValue(AssColor(cur_color).GetAssFormatted(false, false, false));
agi::Color color(from_wx(html_input->GetValue()));
SetRGB(color);
SetHSL(color.r, color.g, color.b);
SetHSV(color.r, color.g, color.b);
html_input->ChangeValue(to_wx(cur_color.GetHexFormatted()));
spectrum_dirty = true;
UpdateSpectrumDisplay();
@ -1026,7 +973,7 @@ void DialogColorPicker::UpdateSpectrumDisplay()
wxMemoryDC previewdc;
previewdc.SelectObject(tempBmp);
previewdc.SetPen(*wxTRANSPARENT_PEN);
previewdc.SetBrush(wxBrush(cur_color));
previewdc.SetBrush(wxBrush(to_wx(cur_color)));
previewdc.DrawRectangle(0, 0, 40, 40);
}
preview_box->SetBitmap(tempBmp);
@ -1046,7 +993,7 @@ wxBitmap *DialogColorPicker::MakeGBSpectrum()
for (int g = 0; g < 256; g++) {
for (int b = 0; b < 256; b++) {
*spec++ = cur_color.Red();
*spec++ = cur_color.r;
*spec++ = g;
*spec++ = b;
}
@ -1067,7 +1014,7 @@ wxBitmap *DialogColorPicker::MakeRBSpectrum()
for (int r = 0; r < 256; r++) {
for (int b = 0; b < 256; b++) {
*spec++ = r;
*spec++ = cur_color.Green();
*spec++ = cur_color.g;
*spec++ = b;
}
}
@ -1088,7 +1035,7 @@ wxBitmap *DialogColorPicker::MakeRGSpectrum()
for (int g = 0; g < 256; g++) {
*spec++ = r;
*spec++ = g;
*spec++ = cur_color.Blue();
*spec++ = cur_color.b;
}
}
@ -1214,14 +1161,9 @@ void DialogColorPicker::OnSliderChange(wxCommandEvent &)
}
}
void DialogColorPicker::OnRecentSelect(wxCommandEvent &evt)
void DialogColorPicker::OnRecentSelect(wxThreadEvent &evt)
{
// The colour picked is stored in the event string
// Allows this event handler to be shared by recent and dropper controls
// Ugly hack?
AssColor color;
color.Parse(evt.GetString());
SetColor(color.GetWXColor());
SetColor(evt.GetPayload<agi::Color>());
}
void DialogColorPicker::OnDropperMouse(wxMouseEvent &evt)

View File

@ -34,16 +34,17 @@
#ifndef AGI_PRE
#include <tr1/functional>
#include <wx/colour.h>
#endif
namespace agi { struct Color; }
class wxWindow;
/// @brief Get a color from the user via a color picker dialog
/// @param parent Parent window
/// @param original Initial color to select
/// @param callback Function called whenever the selected color changes
/// @return Last selected color when dialog is closed, or wxNullColour if the dialog was canceled
wxColour GetColorFromUser(wxWindow* parent, wxColour original, std::tr1::function<void (wxColour)> callback);
/// @return Did the user accept the new color?
bool GetColorFromUser(wxWindow* parent, agi::Color original, std::tr1::function<void (agi::Color)> callback);
/// @brief Get a color from the user via a color picker dialog
/// @param T Class which the callback method belongs to
@ -51,8 +52,8 @@ wxColour GetColorFromUser(wxWindow* parent, wxColour original, std::tr1::functio
/// @param parent Parent window
/// @param original Initial color to select
/// @param callbackObj Object to call callback method on. Must be of type T.
/// @return Last selected color when dialog is closed, or wxNullColour if the dialog was canceled
template<class T, void (T::*method)(wxColour)>
wxColour GetColorFromUser(wxWindow* parent, wxColour original, T* callbackObj) {
/// @return Did the user accept the new color?
template<class T, void (T::*method)(agi::Color)>
bool GetColorFromUser(wxWindow* parent, agi::Color original, T* callbackObj) {
return GetColorFromUser(parent, original, bind(method, callbackObj, std::tr1::placeholders::_1));
}

View File

@ -90,55 +90,54 @@ static ResolutionShortcut resolutions[] = {
bool DialogDummyVideo::CreateDummyVideo(wxWindow *parent, wxString &out_filename)
{
DialogDummyVideo dlg(parent);
if (dlg.ShowModal() == wxID_OK) {
double fps;
long width, height, length;
wxColour colour;
bool pattern;
// Read back values and check sensibility
if (!dlg.fps->GetValue().ToDouble(&fps) || fps <= 0) {
wxLogWarning("Invalid framerate specified, assuming 23.976");
fps = 24/1.001;
}
if (!dlg.width->GetValue().ToLong(&width) || width <= 0) {
wxLogWarning("Invalid width specified");
width = 0;
}
if (!dlg.height->GetValue().ToLong(&height) || height <= 0) {
wxLogWarning("Invalid height specified");
height = 0;
}
if (width == 0 && height == 0) {
wxLogWarning("Assuming 640x480");
width = 640; height = 480;
} else if (width == 0) {
width = height * 4 / 3;
wxLogWarning("Assuming 4:3 fullscreen, %dx%d", width, height);
} else if (height == 0) {
height = width * 3 / 4;
wxLogWarning("Assuming 4:3 fullscreen, %dx%d", width, height);
}
if ((length = dlg.length->GetValue()) <= 0) {
wxLogWarning("Invalid duration, assuming 2 frames");
length = 2;
}
colour = dlg.colour->GetColour();
pattern = dlg.pattern->GetValue();
// Write to options
OPT_SET("Video/Dummy/FPS")->SetDouble(fps);
OPT_SET("Video/Dummy/Last/Width")->SetInt(width);
OPT_SET("Video/Dummy/Last/Height")->SetInt(height);
OPT_SET("Video/Dummy/Last/Length")->SetInt(length);
OPT_SET("Colour/Video Dummy/Last Colour")->SetColour(STD_STR(colour.GetAsString(wxC2S_CSS_SYNTAX)));
OPT_SET("Video/Dummy/Pattern")->SetBool(pattern);
out_filename = DummyVideoProvider::MakeFilename(fps, length, width, height, colour, pattern);
return true;
} else {
if (dlg.ShowModal() != wxID_OK)
return false;
double fps;
long width, height, length;
agi::Color colour;
bool pattern;
// Read back values and check sensibility
if (!dlg.fps->GetValue().ToDouble(&fps) || fps <= 0) {
wxLogWarning("Invalid framerate specified, assuming 23.976");
fps = 24/1.001;
}
if (!dlg.width->GetValue().ToLong(&width) || width <= 0) {
wxLogWarning("Invalid width specified");
width = 0;
}
if (!dlg.height->GetValue().ToLong(&height) || height <= 0) {
wxLogWarning("Invalid height specified");
height = 0;
}
if (width == 0 && height == 0) {
wxLogWarning("Assuming 640x480");
width = 640; height = 480;
} else if (width == 0) {
width = height * 4 / 3;
wxLogWarning("Assuming 4:3 fullscreen, %dx%d", width, height);
} else if (height == 0) {
height = width * 3 / 4;
wxLogWarning("Assuming 4:3 fullscreen, %dx%d", width, height);
}
if ((length = dlg.length->GetValue()) <= 0) {
wxLogWarning("Invalid duration, assuming 2 frames");
length = 2;
}
colour = dlg.colour->GetColor();
pattern = dlg.pattern->GetValue();
// Write to options
OPT_SET("Video/Dummy/FPS")->SetDouble(fps);
OPT_SET("Video/Dummy/Last/Width")->SetInt(width);
OPT_SET("Video/Dummy/Last/Height")->SetInt(height);
OPT_SET("Video/Dummy/Last/Length")->SetInt(length);
OPT_SET("Colour/Video Dummy/Last Colour")->SetColor(colour);
OPT_SET("Video/Dummy/Pattern")->SetBool(pattern);
out_filename = DummyVideoProvider::MakeFilename(fps, length, width, height, colour, pattern);
return true;
}
DialogDummyVideo::DialogDummyVideo(wxWindow *parent)
@ -151,7 +150,7 @@ DialogDummyVideo::DialogDummyVideo(wxWindow *parent)
resolution_shortcuts = new wxComboBox(this, Dummy_Video_Resolution_Shortcut, "", wxDefaultPosition, wxDefaultSize, 0, 0, wxCB_READONLY);
width = new wxTextCtrl(this, -1);
height = new wxTextCtrl(this, -1);
colour = new ColourButton(this, -1, wxSize(30, 17), lagi_wxColour(OPT_GET("Colour/Video Dummy/Last Colour")->GetColour()));
colour = new ColourButton(this, -1, wxSize(30, 17), OPT_GET("Colour/Video Dummy/Last Colour")->GetColor());
pattern = new wxCheckBox(this, -1, _("Checkerboard &pattern"));
fps = new wxTextCtrl(this, Dummy_Video_FPS, wxString::Format("%f", OPT_GET("Video/Dummy/FPS")->GetDouble()));
length = new wxSpinCtrl(this, Dummy_Video_Length, "", wxDefaultPosition, wxDefaultSize, 4096|wxALIGN_LEFT);
@ -213,7 +212,6 @@ DialogDummyVideo::~DialogDummyVideo()
{
}
BEGIN_EVENT_TABLE(DialogDummyVideo,wxDialog)
EVT_COMBOBOX(Dummy_Video_Resolution_Shortcut, DialogDummyVideo::OnResolutionShortcut)
EVT_TEXT(Dummy_Video_FPS, DialogDummyVideo::OnFpsChange)

View File

@ -191,10 +191,10 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
BoxItalic = new wxCheckBox(this, -1, _("&Italic"));
BoxUnderline = new wxCheckBox(this, -1, _("&Underline"));
BoxStrikeout = new wxCheckBox(this, -1, _("&Strikeout"));
colorButton[0] = new ColourButton(this, -1, wxSize(55, 16), style->primary.GetWXColor());
colorButton[1] = new ColourButton(this, -1, wxSize(55, 16), style->secondary.GetWXColor());
colorButton[2] = new ColourButton(this, -1, wxSize(55, 16), style->outline.GetWXColor());
colorButton[3] = new ColourButton(this, -1, wxSize(55, 16), style->shadow.GetWXColor());
colorButton[0] = new ColourButton(this, -1, wxSize(55, 16), style->primary);
colorButton[1] = new ColourButton(this, -1, wxSize(55, 16), style->secondary);
colorButton[2] = new ColourButton(this, -1, wxSize(55, 16), style->outline);
colorButton[3] = new ColourButton(this, -1, wxSize(55, 16), style->shadow);
colorAlpha[0] = spin_ctrl(this, style->primary.a, 255);
colorAlpha[1] = spin_ctrl(this, style->secondary.a, 255);
colorAlpha[2] = spin_ctrl(this, style->outline.a, 255);
@ -330,8 +330,8 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
ColourButton *previewButton = 0;
if (!SubtitlesProviderFactory::GetClasses().empty()) {
PreviewText = new wxTextCtrl(this, -1, lagi_wxString(OPT_GET("Tool/Style Editor/Preview Text")->GetString()));
previewButton = new ColourButton(this, -1, wxSize(45, 16), lagi_wxColour(OPT_GET("Colour/Style Editor/Background/Preview")->GetColour()));
SubsPreview = new SubtitlesPreview(this, wxSize(100, 60), wxSUNKEN_BORDER, lagi_wxColour(OPT_GET("Colour/Style Editor/Background/Preview")->GetColour()));
previewButton = new ColourButton(this, -1, wxSize(45, 16), OPT_GET("Colour/Style Editor/Background/Preview")->GetColor());
SubsPreview = new SubtitlesPreview(this, wxSize(100, 60), wxSUNKEN_BORDER, OPT_GET("Colour/Style Editor/Background/Preview")->GetColor());
SubsPreview->SetToolTip(_("Preview of current style"));
SubsPreview->SetStyle(*style);
@ -521,27 +521,25 @@ void DialogStyleEditor::UpdateWorkStyle() {
/// @brief Sets color for one of the four color buttons
/// @param n Colour to set
void DialogStyleEditor::OnSetColor (int n, wxCommandEvent& evt) {
void DialogStyleEditor::OnSetColor(int n, wxCommandEvent& evt) {
ColourButton *btn = static_cast<ColourButton*>(evt.GetClientData());
if (!btn) {
evt.Skip();
return;
}
AssColor *modify;
switch (n) {
case 1: modify = &work->primary; break;
case 2: modify = &work->secondary; break;
case 3: modify = &work->outline; break;
case 4: modify = &work->shadow; break;
case 1: work->primary = btn->GetColor(); break;
case 2: work->secondary = btn->GetColor(); break;
case 3: work->outline = btn->GetColor(); break;
case 4: work->shadow = btn->GetColor(); break;
default: throw agi::InternalError("attempted setting colour id outside range", 0);
}
modify->SetWXColor(btn->GetColour());
if (SubsPreview)
SubsPreview->SetStyle(*work);
}
void DialogStyleEditor::OnChildFocus (wxChildFocusEvent &event) {
void DialogStyleEditor::OnChildFocus(wxChildFocusEvent &event) {
UpdateWorkStyle();
if (SubsPreview)
SubsPreview->SetStyle(*work);
@ -559,8 +557,8 @@ void DialogStyleEditor::OnPreviewColourChange (wxCommandEvent &evt) {
if (!btn)
evt.Skip();
else {
SubsPreview->SetColour(btn->GetColour());
OPT_SET("Colour/Style Editor/Background/Preview")->SetColour(STD_STR(btn->GetColour().GetAsString(wxC2S_CSS_SYNTAX)));
SubsPreview->SetColour(btn->GetColor());
OPT_SET("Colour/Style Editor/Background/Preview")->SetColor(btn->GetColor());
}
}

View File

@ -412,7 +412,16 @@
"Tool" : {
"Colour Picker" : {
"Mode" : 4,
"Recent" : "&H000000& &H0000FF& &H00FFFF& &H00FF00& &HFFFF00& &HFF0000& &HFF00FF& &HFFFFFF&",
"Recent Colours" : [
"&H000000&",
"&H0000FF&",
"&H00FFFF&",
"&H00FF00&",
"&HFFFF00&",
"&HFF0000&",
"&HFF00FF&",
"&HFFFFFF&"
],
"Last" : {
"X" : -1,
"Y" : -1

View File

@ -412,7 +412,16 @@
"Tool" : {
"Colour Picker" : {
"Mode" : 4,
"Recent" : "&H000000& &H0000FF& &H00FFFF& &H00FF00& &HFFFF00& &HFF0000& &HFF00FF& &HFFFFFF&",
"Recent Colours" : [
"&H000000&",
"&H0000FF&",
"&H00FFFF&",
"&H00FF00&",
"&HFFFF00&",
"&HFF0000&",
"&HFF00FF&",
"&HFFFFFF&"
],
"Last" : {
"X" : -1,
"Y" : -1

View File

@ -22,7 +22,7 @@
#include "main.h"
void Pen::OnColourChanged(agi::OptionValue const& opt) {
impl.SetColour(lagi_wxColour(opt.GetColour()));
impl.SetColour(to_wx(opt.GetColor()));
}
void Pen::OnWidthChanged(agi::OptionValue const& opt) {
@ -30,14 +30,14 @@ void Pen::OnWidthChanged(agi::OptionValue const& opt) {
}
Pen::Pen(const char *colour_opt, const char *width_opt, wxPenStyle style)
: impl(lagi_wxColour(OPT_GET(colour_opt)->GetColour()), OPT_GET(width_opt)->GetInt(), style)
: impl(to_wx(OPT_GET(colour_opt)->GetColor()), OPT_GET(width_opt)->GetInt(), style)
, colour_con(OPT_SUB(colour_opt, &Pen::OnColourChanged, this))
, width_con(OPT_SUB(width_opt, &Pen::OnWidthChanged, this))
{
}
Pen::Pen(const char *colour_opt, int width, wxPenStyle style)
: impl(lagi_wxColour(OPT_GET(colour_opt)->GetColour()), width, style)
: impl(to_wx(OPT_GET(colour_opt)->GetColor()), width, style)
, colour_con(OPT_SUB(colour_opt, &Pen::OnColourChanged, this))
{
}

View File

@ -71,7 +71,7 @@ public:
void operator()(wxCommandEvent& evt) {
ColourButton *btn = static_cast<ColourButton*>(evt.GetClientData());
if (btn)
parent->SetOption(new agi::OptionValueColour(name, STD_STR(btn->GetColour().GetAsString(wxC2S_CSS_SYNTAX))));
parent->SetOption(new agi::OptionValueColor(name, btn->GetColor()));
evt.Skip();
}
};
@ -162,8 +162,8 @@ wxControl *OptionPage::OptionAdd(wxFlexGridSizer *flex, const wxString &name, co
return text;
}
case agi::OptionValue::Type_Colour: {
ColourButton *cb = new ColourButton(this, -1, wxSize(40,10), lagi_wxColour(opt->GetColour()));
case agi::OptionValue::Type_Color: {
ColourButton *cb = new ColourButton(this, -1, wxSize(40,10), opt->GetColor());
cb->Bind(wxEVT_COMMAND_BUTTON_CLICKED, ColourUpdater(opt_name, parent));
Add(flex, name, cb);
return cb;

View File

@ -248,10 +248,10 @@ enum {
void SubsTextEditCtrl::SetSyntaxStyle(int id, wxFont &font, std::string const& name) {
StyleSetFont(id, font);
StyleSetBold(id, OPT_GET("Colour/Subtitle/Syntax/Bold/" + name)->GetBool());
StyleSetForeground(id, lagi_wxColour(OPT_GET("Colour/Subtitle/Syntax/" + name)->GetColour()));
StyleSetForeground(id, to_wx(OPT_GET("Colour/Subtitle/Syntax/" + name)->GetColor()));
const agi::OptionValue *background = OPT_GET("Colour/Subtitle/Syntax/Background/" + name);
if (background->GetType() == agi::OptionValue::Type_Colour)
StyleSetBackground(id, lagi_wxColour(background->GetColour()));
if (background->GetType() == agi::OptionValue::Type_Color)
StyleSetBackground(id, to_wx(background->GetColor()));
}
void SubsTextEditCtrl::SetStyles() {

View File

@ -48,7 +48,7 @@
#include "include/aegisub/subtitles_provider.h"
#include "video_provider_dummy.h"
SubtitlesPreview::SubtitlesPreview(wxWindow *parent, wxSize size, int winStyle, wxColour col)
SubtitlesPreview::SubtitlesPreview(wxWindow *parent, wxSize size, int winStyle, agi::Color col)
: wxWindow(parent, -1, wxDefaultPosition, size, winStyle)
, style(new AssStyle)
, backColour(col)
@ -92,7 +92,7 @@ void SubtitlesPreview::SetText(wxString text) {
}
}
void SubtitlesPreview::SetColour(wxColour col) {
void SubtitlesPreview::SetColour(agi::Color col) {
if (col != backColour) {
backColour = col;
vid.reset(new DummyVideoProvider(0.0, 10, bmp->GetWidth(), bmp->GetHeight(), backColour, true));

View File

@ -57,7 +57,7 @@ class SubtitlesPreview : public wxWindow {
/// Video provider to render into
agi::scoped_ptr<VideoProvider> vid;
/// Current background color
wxColour backColour;
agi::Color backColour;
/// Subtitle file containing the style and displayed line
agi::scoped_ptr<AssFile> subFile;
/// Line used to render the specified text
@ -76,8 +76,8 @@ public:
/// Set the text to display
void SetText(wxString text);
/// Set the background color
void SetColour(wxColour col);
void SetColour(agi::Color col);
SubtitlesPreview(wxWindow *parent, wxSize size, int style, wxColour colour);
SubtitlesPreview(wxWindow *parent, wxSize size, int style, agi::Color colour);
~SubtitlesPreview();
};

View File

@ -212,9 +212,7 @@ public:
}
else if (attr_name == "color")
{
wxColour wxcl = html_to_color(attr_value);
wxString colorstr = AssColor(wxcl).GetAssFormatted(false, false, false);
new_attribs.color = wxString::Format("{\\c%s}", colorstr);
new_attribs.color = wxString::Format("{\\c%s}", to_wx(agi::Color(from_wx(attr_value)).GetAssOverrideFormatted()));
}
// remove this attribute to prepare for the next
size_t attr_pos, attr_len;

View File

@ -31,29 +31,27 @@
/// @brief A variant-type implementation
/// @ingroup utility subs_storage
////////////
// Includes
#include "config.h"
#include "variable_data.h"
#include "ass_dialogue.h"
#include "ass_style.h"
#include "compat.h"
#include "utils.h"
#include "variable_data.h"
/// @brief Constructor
#include <libaegisub/color.h>
VariableData::VariableData() {
type = VARDATA_NONE;
value = NULL;
}
/// @brief Destructor
VariableData::~VariableData() {
DeleteValue ();
DeleteValue();
}
/// @brief Deletes the stored value
/// @return
void VariableData::DeleteValue () {
void VariableData::DeleteValue() {
if (!value) return;
if (type == VARDATA_NONE) return;
switch (type) {
@ -86,7 +84,7 @@ template<> inline VariableDataType get_type<bool>() {
template<> inline VariableDataType get_type<wxString>() {
return VARDATA_TEXT;
}
template<> inline VariableDataType get_type<wxColour>() {
template<> inline VariableDataType get_type<agi::Color>() {
return VARDATA_COLOUR;
}
template<> inline VariableDataType get_type<AssDialogueBlockOverride *>() {
@ -104,7 +102,7 @@ template void VariableData::Set<float>(float param);
template void VariableData::Set<double>(double param);
template void VariableData::Set<bool>(bool param);
template void VariableData::Set(wxString param);
template void VariableData::Set<wxColour>(wxColour param);
template void VariableData::Set<agi::Color>(agi::Color param);
template void VariableData::Set<AssDialogueBlockOverride *>(AssDialogueBlockOverride * param);
/// @brief Resets a value with a string, preserving current type
@ -128,11 +126,7 @@ void VariableData::ResetWith(wxString value) {
else Set(false);
break;
case VARDATA_COLOUR: {
long r=0,g=0,b=0;
value.Mid(1,2).ToLong(&r,16);
value.Mid(3,2).ToLong(&g,16);
value.Mid(5,2).ToLong(&b,16);
Set(wxColour(r,g,b));
Set(agi::Color(from_wx(value)));
break;
}
default:
@ -141,8 +135,6 @@ void VariableData::ResetWith(wxString value) {
}
}
/// @brief Reads as an int
/// @return
template<> int VariableData::Get<int>() const {
if (!value) throw "Null parameter";
if (type == VARDATA_BOOL) return !!(*value_bool);
@ -152,8 +144,6 @@ template<> int VariableData::Get<int>() const {
throw "Wrong parameter type, should be int";
}
/// @brief Reads as a float
/// @return
template<> float VariableData::Get<float>() const {
if (!value) throw "Null parameter";
if (type == VARDATA_FLOAT) return (float)*value_float;
@ -169,8 +159,6 @@ template<> double VariableData::Get<double>() const {
throw "Wrong parameter type, should be float";
}
/// @brief Reads as a bool
/// @return
template<> bool VariableData::Get<bool>() const {
if (!value) throw "Null parameter";
if (type == VARDATA_BOOL) return *value_bool;
@ -180,35 +168,27 @@ template<> bool VariableData::Get<bool>() const {
throw "Wrong parameter type, should be bool";
}
/// @brief Reads as a colour
/// @return
template<> wxColour VariableData::Get<wxColour>() const {
template<> agi::Color VariableData::Get<agi::Color>() const {
if (!value) throw "Null parameter";
if (type == VARDATA_COLOUR) return *value_colour;
if (type == VARDATA_COLOUR) return *value_colour;
else if (type == VARDATA_TEXT) {
AssColor color;
color.Parse(*value_text);
return color.GetWXColor();
return agi::Color(from_wx(*value_text));
}
else throw "Wrong parameter type, should be colour";
}
/// @brief Reads as a block
/// @return
template<> AssDialogueBlockOverride *VariableData::Get<AssDialogueBlockOverride *>() const {
if (!value) throw "Null parameter";
if (type != VARDATA_BLOCK) throw "Wrong parameter type, should be block";
return *value_block;
}
/// @brief Reads as a string
/// @return
template<> wxString VariableData::Get<wxString>() const {
if (!value) throw "Null parameter";
if (type != VARDATA_TEXT) {
if (type == VARDATA_INT) return wxString::Format("%i",*value_int);
else if (type == VARDATA_FLOAT) return wxString::Format("%g",*value_float);
else if (type == VARDATA_COLOUR) return wxString::Format("#%02X%02X%02X",value_colour->Red(),value_colour->Green(),value_colour->Blue());
else if (type == VARDATA_COLOUR) return to_wx(value_colour->GetHexFormatted());
else if (type == VARDATA_BOOL) return *value_bool ? "1" : "0";
else if (type == VARDATA_BLOCK) return (*value_block)->GetText();
else throw "Wrong parameter type, should be text";
@ -216,21 +196,17 @@ template<> wxString VariableData::Get<wxString>() const {
return *value_text;
}
/// @brief Gets type
/// @return
VariableDataType VariableData::GetType() const {
return type;
}
/// @brief Copy
/// @param param
void VariableData::operator= (const VariableData &param) {
switch(param.GetType()) {
case VARDATA_INT: Set(param.Get<int>()); break;
case VARDATA_FLOAT: Set(param.Get<double>()); break;
case VARDATA_TEXT: Set(param.Get<wxString>()); break;
case VARDATA_BOOL: Set(param.Get<bool>()); break;
case VARDATA_COLOUR: Set(param.Get<wxColor>()); break;
case VARDATA_COLOUR: Set(param.Get<agi::Color>()); break;
case VARDATA_BLOCK: Set(param.Get<AssDialogueBlockOverride*>()); break;
default: DeleteValue();
}

View File

@ -32,76 +32,34 @@
/// @ingroup utility subs_storage
///
#pragma once
namespace agi { struct Color; }
///////////
// Headers
#ifndef AGI_PRE
#include <wx/colour.h>
#endif
/// DOCME
enum VariableDataType {
/// DOCME
VARDATA_NONE,
/// DOCME
VARDATA_INT,
/// DOCME
VARDATA_FLOAT,
/// DOCME
VARDATA_TEXT,
/// DOCME
VARDATA_BOOL,
/// DOCME
VARDATA_COLOUR,
/// DOCME
VARDATA_BLOCK
};
class AssDialogueBlockOverride;
/// DOCME
/// @class VariableData
/// @brief DOCME
///
/// DOCME
class VariableData {
private:
union {
/// DOCME
void *value;
/// DOCME
int *value_int;
/// DOCME
double *value_float;
/// DOCME
bool *value_bool;
/// DOCME
wxString *value_text;
/// DOCME
wxColour *value_colour;
/// DOCME
agi::Color *value_colour;
AssDialogueBlockOverride **value_block;
};
/// DOCME
VariableDataType type;
protected:

View File

@ -160,8 +160,8 @@ void VideoBox::UpdateTimeBoxes() {
VideoPosition->SetValue(wxString::Format("%s - %d", AssTime(time).GetAssFormated(true), frame));
if (binary_search(context->videoController->GetKeyFrames().begin(), context->videoController->GetKeyFrames().end(), frame)) {
// Set the background color to indicate this is a keyframe
VideoPosition->SetBackgroundColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColour()));
VideoPosition->SetForegroundColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Selection")->GetColour()));
VideoPosition->SetBackgroundColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColor()));
VideoPosition->SetForegroundColour(to_wx(OPT_GET("Colour/Subtitle Grid/Selection")->GetColor()));
}
else {
VideoPosition->SetBackgroundColour(wxNullColour);

View File

@ -37,11 +37,11 @@
#include "video_provider_dummy.h"
#ifndef AGI_PRE
#include <wx/colour.h>
#include <wx/tokenzr.h>
#endif
#include "colorspace.h"
#include <libaegisub/color.h>
void DummyVideoProvider::Create(double fps, int frames, int width, int height, unsigned char red, unsigned char green, unsigned char blue, bool pattern) {
this->framecount = frames;
@ -111,14 +111,14 @@ DummyVideoProvider::DummyVideoProvider(wxString const& filename) {
Create(fps, frames, width, height, red, green, blue, pattern);
}
DummyVideoProvider::DummyVideoProvider(double fps, int frames, int width, int height, const wxColour &colour, bool pattern) {
Create(fps, frames, width, height, colour.Red(), colour.Green(), colour.Blue(), pattern);
DummyVideoProvider::DummyVideoProvider(double fps, int frames, int width, int height, agi::Color colour, bool pattern) {
Create(fps, frames, width, height, colour.r, colour.g, colour.b, pattern);
}
DummyVideoProvider::~DummyVideoProvider() {
frame.Clear();
}
wxString DummyVideoProvider::MakeFilename(double fps, int frames, int width, int height, const wxColour &colour, bool pattern) {
return wxString::Format("?dummy:%f:%d:%d:%d:%d:%d:%d:%s", fps, frames, width, height, colour.Red(), colour.Green(), colour.Blue(), pattern ? "c" : "");
wxString DummyVideoProvider::MakeFilename(double fps, int frames, int width, int height, agi::Color colour, bool pattern) {
return wxString::Format("?dummy:%f:%d:%d:%d:%d:%d:%d:%s", fps, frames, width, height, colour.r, colour.g, colour.b, pattern ? "c" : "");
}

View File

@ -35,7 +35,7 @@
#include "include/aegisub/video_provider.h"
#include "video_frame.h"
class wxColour;
namespace agi { struct Color; }
/// @class DummyVideoProvider
/// @brief A dummy video provider for when opening a file is just too much effort
@ -73,14 +73,14 @@ public:
/// @param height Height in pixels of the dummy video
/// @param colour Primary colour of the dummy video
/// @param pattern Use a checkerboard pattern rather than a solid colour
DummyVideoProvider(double fps, int frames, int width, int height, wxColour const& colour, bool pattern);
DummyVideoProvider(double fps, int frames, int width, int height, agi::Color colour, bool pattern);
/// Destructor
~DummyVideoProvider();
/// Make a fake filename which when passed to the constructor taking a
/// string will result in a video with the given parameters
static wxString MakeFilename(double fps, int frames, int width, int height, wxColour const& colour, bool pattern);
static wxString MakeFilename(double fps, int frames, int width, int height, agi::Color colour, bool pattern);
const AegiVideoFrame GetFrame(int n) { return frame; }
int GetFrameCount() const { return framecount; }

View File

@ -19,6 +19,7 @@ SRC = \
util_unix.cpp \
libaegisub_access.cpp \
libaegisub_cajun.cpp \
libaegisub_color.cpp \
libaegisub_hotkey.cpp \
libaegisub_iconv.cpp \
libaegisub_keyframe.cpp \

View File

@ -0,0 +1,99 @@
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// $Id$
#include <libaegisub/color.h>
#include "main.h"
#include "util.h"
class lagi_color : public libagi {
};
namespace agi {
::std::ostream& operator<<(::std::ostream& os, Color const& c) {
return os << "agi::Color(" << (int)c.r << "," << (int)c.g << "," << (int)c.b << "," << (int)c.a << ")";
}
}
TEST(lagi_color, hex) {
EXPECT_EQ(agi::Color(0, 0, 0), agi::Color("#000"));
EXPECT_EQ(agi::Color(0, 0, 0), agi::Color("#000000"));
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("#FFFFFF"));
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("#FFF"));
EXPECT_EQ(agi::Color(255, 0, 127), agi::Color("#FF007F"));
EXPECT_EQ(agi::Color(16, 32, 48), agi::Color("#102030"));
EXPECT_EQ("#000000", agi::Color(0, 0, 0).GetHexFormatted());
EXPECT_EQ("#FFFFFF", agi::Color(255, 255, 255).GetHexFormatted());
EXPECT_EQ("#FF007F", agi::Color(255, 0, 127).GetHexFormatted());
EXPECT_EQ("#102030", agi::Color(16, 32, 48).GetHexFormatted());
}
TEST(lagi_color, rgb) {
EXPECT_EQ(agi::Color(0, 0, 0), "rgb(0, 0, 0)");
EXPECT_EQ(agi::Color(255, 255, 255), "rgb(255, 255, 255)");
EXPECT_EQ(agi::Color(255, 255, 255), "rgb(255,255,255)");
EXPECT_EQ(agi::Color(255, 0, 127), "rgb(255, 0, 127)");
EXPECT_EQ(agi::Color(16, 32, 48), "rgb( 16 , 32 , 48 )");
EXPECT_EQ("rgb(0, 0, 0)", agi::Color(0, 0, 0).GetRgbFormatted());
EXPECT_EQ("rgb(255, 255, 255)", agi::Color(255, 255, 255).GetRgbFormatted());
EXPECT_EQ("rgb(255, 0, 127)", agi::Color(255, 0, 127).GetRgbFormatted());
EXPECT_EQ("rgb(16, 32, 48)", agi::Color(16, 32, 48).GetRgbFormatted());
}
TEST(lagi_color, ass_ovr) {
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("&HFFFFFF"));
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("&HFFFFFF&"));
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("&hFFFFFF&"));
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("HFFFFFF"));
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("hFFFFFF"));
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("FFFFFF"));
EXPECT_EQ(agi::Color(48, 32, 16), agi::Color("&H102030&"));
EXPECT_EQ("&H000000&", agi::Color().GetAssOverrideFormatted());
EXPECT_EQ("&HFFFFFF&", agi::Color(255, 255, 255).GetAssOverrideFormatted());
EXPECT_EQ("&H030201&", agi::Color(1, 2, 3).GetAssOverrideFormatted());
EXPECT_EQ("&H030201&", agi::Color(1, 2, 3, 4).GetAssOverrideFormatted());
}
TEST(lagi_color, ass_style) {
EXPECT_EQ(agi::Color(255, 255, 255, 255), agi::Color("&HFFFFFFFF"));
EXPECT_EQ(agi::Color(255, 255, 255, 255), agi::Color("&HFFFFFFFF&"));
EXPECT_EQ(agi::Color(255, 255, 255, 255), agi::Color("&hFFFFFFFF&"));
EXPECT_EQ(agi::Color(255, 255, 255, 255), agi::Color("HFFFFFFFF"));
EXPECT_EQ(agi::Color(255, 255, 255, 255), agi::Color("hFFFFFFFF"));
EXPECT_EQ(agi::Color(255, 255, 255, 255), agi::Color("FFFFFFFF"));
EXPECT_EQ(agi::Color(4, 3, 2, 1), agi::Color("&H01020304&"));
EXPECT_EQ("&H00000000", agi::Color().GetAssStyleFormatted());
EXPECT_EQ("&H00FFFFFF", agi::Color(255, 255, 255).GetAssStyleFormatted());
EXPECT_EQ("&H00030201", agi::Color(1, 2, 3).GetAssStyleFormatted());
EXPECT_EQ("&H04030201", agi::Color(1, 2, 3, 4).GetAssStyleFormatted());
}
TEST(lagi_color, ssa) {
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("16777215"));
EXPECT_EQ(agi::Color(255, 255, 255), agi::Color("-1"));
EXPECT_EQ(agi::Color(127, 0, 255), agi::Color("16711807"));
EXPECT_EQ(agi::Color(48, 32, 16), agi::Color("1056816"));
EXPECT_EQ("0", agi::Color(0, 0, 0).GetSsaFormatted());
EXPECT_EQ("16777215", agi::Color(255, 255, 255).GetSsaFormatted());
EXPECT_EQ("16711807", agi::Color(127, 0, 255).GetSsaFormatted());
EXPECT_EQ("1056816", agi::Color(48, 32, 16).GetSsaFormatted());
}

View File

@ -132,7 +132,7 @@ TEST_F(lagi_option, flush_roundtrip) {
EXPECT_NO_THROW(opt.Get("Integer")->SetInt(1));
EXPECT_NO_THROW(opt.Get("Double")->SetDouble(1.1));
EXPECT_NO_THROW(opt.Get("String")->SetString("hello"));
EXPECT_NO_THROW(opt.Get("Colour")->SetColour("rgb(255,255,255)"));
EXPECT_NO_THROW(opt.Get("Color")->SetColor("rgb(255,255,255)"));
EXPECT_NO_THROW(opt.Get("Boolean")->SetBool(true));
std::vector<int64_t> int_arr; int_arr.push_back(1);
@ -141,8 +141,8 @@ TEST_F(lagi_option, flush_roundtrip) {
EXPECT_NO_THROW(opt.Get("Array/Double")->SetListDouble(double_arr));
std::vector<std::string> str_arr; str_arr.push_back("hello");
EXPECT_NO_THROW(opt.Get("Array/String")->SetListString(str_arr));
std::vector<agi::Colour> clr_arr; clr_arr.push_back("rgb(255,255,255)");
EXPECT_NO_THROW(opt.Get("Array/Colour")->SetListColour(clr_arr));
std::vector<agi::Color> clr_arr; clr_arr.push_back("rgb(255,255,255)");
EXPECT_NO_THROW(opt.Get("Array/Color")->SetListColor(clr_arr));
std::vector<bool> bool_arr; bool_arr.push_back(true);
EXPECT_NO_THROW(opt.Get("Array/Boolean")->SetListBool(bool_arr));
}
@ -154,19 +154,19 @@ TEST_F(lagi_option, flush_roundtrip) {
EXPECT_EQ(1, opt.Get("Integer")->GetInt());
EXPECT_EQ(1.1, opt.Get("Double")->GetDouble());
EXPECT_STREQ("hello", opt.Get("String")->GetString().c_str());
EXPECT_STREQ("rgb(255,255,255)", opt.Get("Colour")->GetColour().c_str());
EXPECT_STREQ("rgb(255, 255, 255)", opt.Get("Color")->GetColor().GetRgbFormatted().c_str());
EXPECT_EQ(true, opt.Get("Boolean")->GetBool());
EXPECT_EQ(1, opt.Get("Array/Integer")->GetListInt().size());
EXPECT_EQ(1, opt.Get("Array/Double")->GetListDouble().size());
EXPECT_EQ(1, opt.Get("Array/String")->GetListString().size());
EXPECT_EQ(1, opt.Get("Array/Colour")->GetListColour().size());
EXPECT_EQ(1, opt.Get("Array/Color")->GetListColor().size());
EXPECT_EQ(1, opt.Get("Array/Boolean")->GetListBool().size());
EXPECT_EQ(1, opt.Get("Array/Integer")->GetListInt().front());
EXPECT_EQ(1.1, opt.Get("Array/Double")->GetListDouble().front());
EXPECT_STREQ("hello", opt.Get("Array/String")->GetListString().front().c_str());
EXPECT_STREQ("rgb(255,255,255)", opt.Get("Array/Colour")->GetListColour().front().c_str());
EXPECT_STREQ("rgb(255, 255, 255)", opt.Get("Array/Color")->GetListColor().front().GetRgbFormatted().c_str());
EXPECT_EQ(true, opt.Get("Array/Boolean")->GetListBool().front());
}
}
@ -215,7 +215,7 @@ TEST_F(lagi_option, empty_array_decays_to_first_used_type) {
empty_arr_options opt;
EXPECT_NO_THROW(opt.Get("arr")->GetListBool());
EXPECT_THROW(opt.Get("arr")->GetListColour(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidListType);
@ -223,7 +223,7 @@ TEST_F(lagi_option, empty_array_decays_to_first_used_type) {
{
empty_arr_options opt;
EXPECT_NO_THROW(opt.Get("arr")->GetListColour());
EXPECT_NO_THROW(opt.Get("arr")->GetListColor());
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidListType);
@ -236,7 +236,7 @@ TEST_F(lagi_option, empty_array_decays_to_first_used_type) {
EXPECT_NO_THROW(opt.Get("arr")->GetListDouble());
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListColour(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidListType);
}
@ -246,7 +246,7 @@ TEST_F(lagi_option, empty_array_decays_to_first_used_type) {
EXPECT_NO_THROW(opt.Get("arr")->GetListInt());
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListColour(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidListType);
}
@ -256,7 +256,7 @@ TEST_F(lagi_option, empty_array_decays_to_first_used_type) {
EXPECT_NO_THROW(opt.Get("arr")->GetListString());
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListColour(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidListType);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidListType);
}

View File

@ -2,13 +2,13 @@
"Integer" : 0,
"Double" : 0.1,
"String" : "",
"Colour" : "rgb(0, 0, 0)",
"Color" : "rgb(0, 0, 0)",
"Boolean" : false,
"Array" : {
"Integer" : [ { "int" : 0 }, {"int" : 0 } ],
"Double" : [ { "double" : 0.1 }, {"double" : 0.1 } ],
"String" : [ { "string" : "" }, {"string" : "" } ],
"Colour" : [ { "colour" : "rgb(0,0,0)" }, {"colour" : "rgb(0,0,0)" } ],
"Double" : [ { "double" : 0.1 }, {"double" : 0.1 } ],
"String" : [ { "string" : "" }, {"string" : "" } ],
"Color" : [ { "color" : "rgb(0,0,0)" }, {"color" : "rgb(0,0,0)" } ],
"Boolean" : [ { "bool" : false }, {"bool" : false } ]
}
}