From 77dd02655502e969a6d4c3781369ce4681ab28ca Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 11 Jun 2013 16:32:59 -0700 Subject: [PATCH] Extract ColorValidator from Automation's dialog stuff --- aegisub/src/auto4_lua_dialog.cpp | 26 ++++++-------------------- aegisub/src/colour_button.h | 13 +++++++++++++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/aegisub/src/auto4_lua_dialog.cpp b/aegisub/src/auto4_lua_dialog.cpp index 2a547f522..bf988b95e 100644 --- a/aegisub/src/auto4_lua_dialog.cpp +++ b/aegisub/src/auto4_lua_dialog.cpp @@ -194,43 +194,29 @@ namespace Automation4 { /// A color-picker button class Color : public LuaDialogControl { - std::string text; + agi::Color color; bool alpha; - struct ColorValidator : public wxValidator { - std::string *text; - ColorValidator(std::string *text) : text(text) { } - wxValidator *Clone() const { return new ColorValidator(text); } - bool Validate(wxWindow*) { return true; } - bool TransferToWindow() { return true; } - - bool TransferFromWindow() { - *text = static_cast(GetWindow())->GetColor().GetHexFormatted(); - return true; - } - }; - public: Color(lua_State *L, bool alpha) : LuaDialogControl(L) - , text(get_field(L, "value")) + , color(get_field(L, "value")) , alpha(alpha) { } bool CanSerialiseValue() const { return true; } - std::string SerialiseValue() const { return inline_string_encode(text); } - void UnserialiseValue(const std::string &serialised) { text = inline_string_decode(serialised); } + std::string SerialiseValue() const { return inline_string_encode(color.GetHexFormatted()); } + void UnserialiseValue(const std::string &serialised) { color = inline_string_decode(serialised); } wxControl *Create(wxWindow *parent) { - agi::Color colour(text); - wxControl *cw = new ColourButton(parent, wxSize(50*width,10*height), alpha, colour, ColorValidator(&text)); + wxControl *cw = new ColourButton(parent, wxSize(50*width,10*height), alpha, color, ColorValidator(&color)); cw->SetToolTip(to_wx(hint)); return cw; } void LuaReadBack(lua_State *L) { - lua_pushstring(L, text.c_str()); + lua_pushstring(L, color.GetHexFormatted().c_str()); } }; diff --git a/aegisub/src/colour_button.h b/aegisub/src/colour_button.h index 559281bb5..2a334352d 100644 --- a/aegisub/src/colour_button.h +++ b/aegisub/src/colour_button.h @@ -42,3 +42,16 @@ public: /// Get the currently selected color agi::Color GetColor() { return colour; } }; + +struct ColorValidator : public wxValidator { + agi::Color *color; + ColorValidator(agi::Color *color) : color(color) { } + wxValidator *Clone() const { return new ColorValidator(color); } + bool Validate(wxWindow*) { return true; } + bool TransferToWindow() { return true; } + + bool TransferFromWindow() { + *color = static_cast(GetWindow())->GetColor(); + return true; + } +};