Fix a few colourbutton issues in DialogStyleEditor

Originally committed to SVN as r5723.
This commit is contained in:
Thomas Goyne 2011-10-10 17:29:17 +00:00
parent bd18ad11cb
commit e91834d667
2 changed files with 24 additions and 18 deletions

View file

@ -254,6 +254,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *style, agi::Co
// Preview // Preview
SubsPreview = NULL; SubsPreview = NULL;
PreviewText = NULL; PreviewText = NULL;
ColourButton *previewButton = 0;
if (!SubtitlesProviderFactory::GetClasses().empty()) { if (!SubtitlesProviderFactory::GetClasses().empty()) {
PreviewText = new wxTextCtrl(this, -1, lagi_wxString(OPT_GET("Tool/Style Editor/Preview Text")->GetString())); 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())); previewButton = new ColourButton(this, -1, wxSize(45, 16), lagi_wxColour(OPT_GET("Colour/Style Editor/Background/Preview")->GetColour()));
@ -300,7 +301,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *style, agi::Co
ControlSizer->Add(RightSizer, 1, wxLEFT | wxEXPAND, 5); ControlSizer->Add(RightSizer, 1, wxLEFT | wxEXPAND, 5);
// General Layout // General Layout
MainSizer = new wxBoxSizer(wxVERTICAL); wxSizer *MainSizer = new wxBoxSizer(wxVERTICAL);
MainSizer->Add(ControlSizer, 1, wxALL | wxALIGN_CENTER | wxEXPAND, 5); MainSizer->Add(ControlSizer, 1, wxALL | wxALIGN_CENTER | wxEXPAND, 5);
MainSizer->Add(ButtonSizer, 0, wxBOTTOM | wxEXPAND, 5); MainSizer->Add(ButtonSizer, 0, wxBOTTOM | wxEXPAND, 5);
@ -326,7 +327,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *style, agi::Co
Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(&HelpButton::OpenPage, "Style Editor"), wxID_HELP); Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(&HelpButton::OpenPage, "Style Editor"), wxID_HELP);
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
colorButton[i]->Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(&DialogStyleEditor::OnSetColor, this, i + 1)); colorButton[i]->Bind(wxEVT_COMMAND_BUTTON_CLICKED, bind(&DialogStyleEditor::OnSetColor, this, i + 1, std::tr1::placeholders::_1));
} }
DialogStyleEditor::~DialogStyleEditor () { DialogStyleEditor::~DialogStyleEditor () {
@ -472,7 +473,13 @@ void DialogStyleEditor::OnChooseFont (wxCommandEvent &event) {
/// @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 /// @param n Colour to set
void DialogStyleEditor::OnSetColor (int n) { void DialogStyleEditor::OnSetColor (int n, wxCommandEvent& evt) {
ColourButton *btn = static_cast<ColourButton*>(evt.GetClientData());
if (!btn) {
evt.Skip();
return;
}
AssColor *modify; AssColor *modify;
switch (n) { switch (n) {
case 1: modify = &work->primary; break; case 1: modify = &work->primary; break;
@ -481,8 +488,9 @@ void DialogStyleEditor::OnSetColor (int n) {
case 4: modify = &work->shadow; break; case 4: modify = &work->shadow; break;
default: throw agi::InternalError("attempted setting colour id outside range", 0); default: throw agi::InternalError("attempted setting colour id outside range", 0);
} }
modify->SetWXColor(colorButton[n-1]->GetColour()); modify->SetWXColor(btn->GetColour());
if (SubsPreview) SubsPreview->SetStyle(*work); if (SubsPreview)
SubsPreview->SetStyle(*work);
} }
void DialogStyleEditor::OnChildFocus (wxChildFocusEvent &event) { void DialogStyleEditor::OnChildFocus (wxChildFocusEvent &event) {
@ -498,9 +506,14 @@ void DialogStyleEditor::OnPreviewTextChange (wxCommandEvent &event) {
} }
/// @brief Change colour of preview's background /// @brief Change colour of preview's background
void DialogStyleEditor::OnPreviewColourChange (wxCommandEvent &event) { void DialogStyleEditor::OnPreviewColourChange (wxCommandEvent &evt) {
SubsPreview->SetColour(previewButton->GetColour()); ColourButton *btn = static_cast<ColourButton*>(evt.GetClientData());
OPT_SET("Colour/Style Editor/Background/Preview")->SetColour(STD_STR(previewButton->GetColour().GetAsString(wxC2S_CSS_SYNTAX))); 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)));
}
} }
/// @brief Command event to update preview /// @brief Command event to update preview

View file

@ -140,12 +140,6 @@ class DialogStyleEditor : public wxDialog {
/// DOCME /// DOCME
SubtitlesPreview *SubsPreview; SubtitlesPreview *SubsPreview;
/// DOCME
ColourButton *previewButton;
/// DOCME
wxSizer *MainSizer;
void SetBitmapColor (int n,wxColour color); void SetBitmapColor (int n,wxColour color);
int AlignToControl (int n); int AlignToControl (int n);
int ControlToAlign (int n); int ControlToAlign (int n);
@ -158,11 +152,10 @@ class DialogStyleEditor : public wxDialog {
void OnPreviewTextChange (wxCommandEvent &event); void OnPreviewTextChange (wxCommandEvent &event);
void OnPreviewColourChange (wxCommandEvent &event); void OnPreviewColourChange (wxCommandEvent &event);
void Apply (bool apply,bool close);
void OnSetColor (int n, wxCommandEvent& evt);
public: public:
DialogStyleEditor(wxWindow *parent,AssStyle *style, agi::Context *c,bool local,AssStyleStorage *store,bool newStyle=false); DialogStyleEditor(wxWindow *parent,AssStyle *style, agi::Context *c,bool local,AssStyleStorage *store,bool newStyle=false);
~DialogStyleEditor(); ~DialogStyleEditor();
void Apply (bool apply,bool close);
void OnSetColor (int n);
}; };