Use ColorValidator in DialogStyleEditor

This commit is contained in:
Thomas Goyne 2013-06-11 16:40:00 -07:00
parent 77dd026555
commit f5ee5ca740
2 changed files with 21 additions and 31 deletions

View file

@ -188,10 +188,12 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
BoxItalic = new wxCheckBox(this, -1, _("&Italic")); BoxItalic = new wxCheckBox(this, -1, _("&Italic"));
BoxUnderline = new wxCheckBox(this, -1, _("&Underline")); BoxUnderline = new wxCheckBox(this, -1, _("&Underline"));
BoxStrikeout = new wxCheckBox(this, -1, _("&Strikeout")); BoxStrikeout = new wxCheckBox(this, -1, _("&Strikeout"));
colorButton[0] = new ColourButton(this, wxSize(55, 16), true, style->primary); ColourButton *colorButton[] = {
colorButton[1] = new ColourButton(this, wxSize(55, 16), true, style->secondary); new ColourButton(this, wxSize(55, 16), true, style->primary, ColorValidator(&work->primary)),
colorButton[2] = new ColourButton(this, wxSize(55, 16), true, style->outline); new ColourButton(this, wxSize(55, 16), true, style->secondary, ColorValidator(&work->secondary)),
colorButton[3] = new ColourButton(this, wxSize(55, 16), true, style->shadow); new ColourButton(this, wxSize(55, 16), true, style->outline, ColorValidator(&work->outline)),
new ColourButton(this, wxSize(55, 16), true, style->shadow, ColorValidator(&work->shadow))
};
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
margin[i] = spin_ctrl(this, style->Margin[i], 9999); margin[i] = spin_ctrl(this, style->Margin[i], 9999);
Alignment = new wxRadioBox(this, -1, _("Alignment"), wxDefaultPosition, wxDefaultSize, 9, alignValues, 3, wxRA_SPECIFY_COLS); Alignment = new wxRadioBox(this, -1, _("Alignment"), wxDefaultPosition, wxDefaultSize, 9, alignValues, 3, wxRA_SPECIFY_COLS);
@ -267,28 +269,26 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
FontSizer->Add(FontSizerBottom, 1, wxTOP | wxEXPAND, 5); FontSizer->Add(FontSizerBottom, 1, wxTOP | wxEXPAND, 5);
// Colors sizer // Colors sizer
wxSizer *ColorSizer[4];
wxString colorLabels[] = { _("Primary"), _("Secondary"), _("Outline"), _("Shadow") }; wxString colorLabels[] = { _("Primary"), _("Secondary"), _("Outline"), _("Shadow") };
ColorsSizer->AddStretchSpacer(1); ColorsSizer->AddStretchSpacer(1);
for (int i=0;i<4;i++) { for (int i = 0; i < 4; ++i) {
ColorSizer[i] = new wxBoxSizer(wxVERTICAL); auto sizer = new wxBoxSizer(wxVERTICAL);
ColorSizer[i]->Add(new wxStaticText(this, -1, colorLabels[i]), 0, wxBOTTOM | wxALIGN_CENTER, 5); sizer->Add(new wxStaticText(this, -1, colorLabels[i]), 0, wxBOTTOM | wxALIGN_CENTER, 5);
ColorSizer[i]->Add(colorButton[i], 0, wxBOTTOM | wxALIGN_CENTER, 5); sizer->Add(colorButton[i], 0, wxBOTTOM | wxALIGN_CENTER, 5);
ColorsSizer->Add(ColorSizer[i], 0, wxLEFT, i?5:0); ColorsSizer->Add(sizer, 0, wxLEFT, i?5:0);
} }
ColorsSizer->AddStretchSpacer(1); ColorsSizer->AddStretchSpacer(1);
// Margins // Margins
wxString marginLabels[] = { _("Left"), _("Right"), _("Vert") }; wxString marginLabels[] = { _("Left"), _("Right"), _("Vert") };
MarginSizer->AddStretchSpacer(1); MarginSizer->AddStretchSpacer(1);
wxSizer *marginSubSizer[3];
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
marginSubSizer[i] = new wxBoxSizer(wxVERTICAL); auto sizer = new wxBoxSizer(wxVERTICAL);
marginSubSizer[i]->AddStretchSpacer(1); sizer->AddStretchSpacer(1);
marginSubSizer[i]->Add(new wxStaticText(this, -1, marginLabels[i]), 0, wxCENTER, 0); sizer->Add(new wxStaticText(this, -1, marginLabels[i]), 0, wxCENTER, 0);
marginSubSizer[i]->Add(margin[i], 0, wxTOP | wxCENTER, 5); sizer->Add(margin[i], 0, wxTOP | wxCENTER, 5);
marginSubSizer[i]->AddStretchSpacer(1); sizer->AddStretchSpacer(1);
MarginSizer->Add(marginSubSizer[i], 0, wxEXPAND | wxLEFT, i?5:0); MarginSizer->Add(sizer, 0, wxEXPAND | wxLEFT, i?5:0);
} }
MarginSizer->AddStretchSpacer(1); MarginSizer->AddStretchSpacer(1);
@ -396,7 +396,7 @@ DialogStyleEditor::DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Con
Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::bind(&HelpButton::OpenPage, "Style Editor"), wxID_HELP); Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::bind(&HelpButton::OpenPage, "Style Editor"), wxID_HELP);
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
colorButton[i]->Bind(EVT_COLOR, std::bind(&DialogStyleEditor::OnSetColor, this, i + 1, std::placeholders::_1)); colorButton[i]->Bind(EVT_COLOR, &DialogStyleEditor::OnSetColor, this);
} }
DialogStyleEditor::~DialogStyleEditor() { DialogStyleEditor::~DialogStyleEditor() {
@ -471,7 +471,6 @@ void DialogStyleEditor::Apply(bool apply, bool close) {
} }
} }
/// @brief Update work style
void DialogStyleEditor::UpdateWorkStyle() { void DialogStyleEditor::UpdateWorkStyle() {
work->font = from_wx(FontName->GetValue()); work->font = from_wx(FontName->GetValue());
FontSize->GetValue().ToDouble(&(work->fontsize)); FontSize->GetValue().ToDouble(&(work->fontsize));
@ -502,14 +501,8 @@ void DialogStyleEditor::UpdateWorkStyle() {
work->strikeout = BoxStrikeout->IsChecked(); work->strikeout = BoxStrikeout->IsChecked();
} }
void DialogStyleEditor::OnSetColor(int n, wxThreadEvent& evt) { void DialogStyleEditor::OnSetColor(wxThreadEvent&) {
switch (n) { TransferDataFromWindow();
case 1: work->primary = evt.GetPayload<agi::Color>(); break;
case 2: work->secondary = evt.GetPayload<agi::Color>(); break;
case 3: work->outline = evt.GetPayload<agi::Color>(); break;
case 4: work->shadow = evt.GetPayload<agi::Color>(); break;
default: throw agi::InternalError("attempted setting colour id outside range", 0);
}
if (SubsPreview) if (SubsPreview)
SubsPreview->SetStyle(*work); SubsPreview->SetStyle(*work);
} }

View file

@ -43,7 +43,6 @@
namespace agi { struct Context; } namespace agi { struct Context; }
class AssStyle; class AssStyle;
class AssStyleStorage; class AssStyleStorage;
class ColourButton;
class PersistLocation; class PersistLocation;
class SubtitlesPreview; class SubtitlesPreview;
@ -73,7 +72,6 @@ class DialogStyleEditor : public wxDialog {
wxCheckBox *BoxItalic; wxCheckBox *BoxItalic;
wxCheckBox *BoxUnderline; wxCheckBox *BoxUnderline;
wxCheckBox *BoxStrikeout; wxCheckBox *BoxStrikeout;
ColourButton *colorButton[4];
wxSpinCtrl *margin[3]; wxSpinCtrl *margin[3];
wxRadioBox *Alignment; wxRadioBox *Alignment;
wxTextCtrl *Outline; wxTextCtrl *Outline;
@ -103,8 +101,7 @@ class DialogStyleEditor : public wxDialog {
/// @param close Should the dialog be closed? /// @param close Should the dialog be closed?
void Apply(bool apply,bool close); void Apply(bool apply,bool close);
/// @brief Sets color for one of the four color buttons /// @brief Sets color for one of the four color buttons
/// @param n Colour to set void OnSetColor(wxThreadEvent& evt);
void OnSetColor(int n, wxThreadEvent& evt);
public: public:
DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store = 0, std::string const& new_name = ""); DialogStyleEditor(wxWindow *parent, AssStyle *style, agi::Context *c, AssStyleStorage *store = 0, std::string const& new_name = "");