Added a button to change the background colour of the preview box in the style editor.

Originally committed to SVN as r1190.
This commit is contained in:
Rodrigo Braz Monteiro 2007-05-21 04:53:14 +00:00
parent 2be3007cb8
commit 7f1f1c956b
5 changed files with 38 additions and 6 deletions

View File

@ -66,6 +66,7 @@ enum {
BUTTON_COLOR_2,
BUTTON_COLOR_3,
BUTTON_COLOR_4,
BUTTON_PREVIEW_COLOR,
RADIO_ALIGNMENT,
TEXT_FONT_NAME,
TEXT_FONT_SIZE,
@ -124,7 +125,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit
// Create controls
StyleName = new wxTextCtrl(this,-1,style->name);
FontName = new wxComboBox(this,TEXT_FONT_NAME,style->font,wxDefaultPosition,wxSize(150,20),fontList,wxCB_DROPDOWN);
FontName = new wxComboBox(this,TEXT_FONT_NAME,style->font,wxDefaultPosition,wxSize(150,20),fontList,wxCB_DROPDOWN | wxTE_PROCESS_ENTER);
FontSize = new wxTextCtrl(this,TEXT_FONT_SIZE,_T(""),wxDefaultPosition,wxSize(30,20),0,wxTextValidator(wxFILTER_NUMERIC,&FontSizeValue));
//wxButton *FontButton = new wxButton(this,BUTTON_STYLE_FONT,_("Choose"));
BoxBold = new wxCheckBox(this,CHECKBOX_STYLE_BOLD,_("Bold"));
@ -151,9 +152,10 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit
Angle = new wxTextCtrl(this,TEXT_ANGLE,_T(""),wxDefaultPosition, wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&AngleValue));
Spacing = new wxTextCtrl(this,TEXT_SPACING,_T(""),wxDefaultPosition,wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&SpacingValue));
Encoding = new wxComboBox(this,COMBO_ENCODING,_T(""),wxDefaultPosition, wxDefaultSize, encodingStrings,wxCB_READONLY);
SubsPreview = new SubtitlesPreview(this,-1,wxDefaultPosition,wxSize(100,60),wxSUNKEN_BORDER);
SubsPreview = new SubtitlesPreview(this,-1,wxDefaultPosition,wxSize(100,60),wxSUNKEN_BORDER,Options.AsColour(_T("Style editor preview background")));
PreviewText = NULL; // Yes, this IS necessary
PreviewText = new wxTextCtrl(this,TEXT_PREVIEW,Options.AsText(_T("Style editor preview text")));
previewButton = new ColourButton(this,BUTTON_PREVIEW_COLOR,wxSize(45,16),Options.AsColour(_T("Style editor preview background")));
// Set control tooltips
StyleName->SetToolTip(_("Style name"));
@ -308,8 +310,11 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit
// Preview
wxSizer *PreviewBox = new wxStaticBoxSizer(wxVERTICAL,this,_("Preview"));
wxSizer *PreviewBottomSizer = new wxBoxSizer(wxHORIZONTAL);
PreviewBottomSizer->Add(PreviewText,1,wxEXPAND | wxRIGHT,5);
PreviewBottomSizer->Add(previewButton,0,wxEXPAND,0);
PreviewBox->Add(SubsPreview,1,wxEXPAND | wxBOTTOM,5);
PreviewBox->Add(PreviewText,0,wxEXPAND | wxBOTTOM,0);
PreviewBox->Add(PreviewBottomSizer,0,wxEXPAND | wxBOTTOM,0);
// Buttons
wxSizer *ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
@ -374,6 +379,7 @@ BEGIN_EVENT_TABLE(DialogStyleEditor, wxDialog)
EVT_BUTTON(BUTTON_COLOR_2, DialogStyleEditor::OnSetColor2)
EVT_BUTTON(BUTTON_COLOR_3, DialogStyleEditor::OnSetColor3)
EVT_BUTTON(BUTTON_COLOR_4, DialogStyleEditor::OnSetColor4)
EVT_BUTTON(BUTTON_PREVIEW_COLOR, DialogStyleEditor::OnPreviewColourChange)
EVT_CHILD_FOCUS(DialogStyleEditor::OnChildFocus)
EVT_TEXT(TEXT_PREVIEW, DialogStyleEditor::OnPreviewTextChange)
@ -384,6 +390,7 @@ BEGIN_EVENT_TABLE(DialogStyleEditor, wxDialog)
EVT_CHECKBOX(CHECKBOX_OUTLINE, DialogStyleEditor::OnCommandPreviewUpdate)
EVT_COMBOBOX(COMBO_ENCODING, DialogStyleEditor::OnCommandPreviewUpdate)
EVT_COMBOBOX(TEXT_FONT_NAME, DialogStyleEditor::OnCommandPreviewUpdate)
EVT_TEXT_ENTER(TEXT_FONT_NAME, DialogStyleEditor::OnCommandPreviewUpdate)
END_EVENT_TABLE()
@ -612,6 +619,15 @@ void DialogStyleEditor::OnPreviewTextChange (wxCommandEvent &event) {
}
/////////////////////////////////////////
// Change colour of preview's background
void DialogStyleEditor::OnPreviewColourChange (wxCommandEvent &event) {
SubsPreview->SetColour(previewButton->GetColour());
Options.SetColour(_T("Style editor preview background"),previewButton->GetColour());
Options.Save();
}
///////////////////////////////////
// Command event to update preview
void DialogStyleEditor::OnCommandPreviewUpdate (wxCommandEvent &event) {

View File

@ -102,6 +102,7 @@ private:
wxTextCtrl *Spacing;
wxTextCtrl *PreviewText;
SubtitlesPreview *SubsPreview;
ColourButton *previewButton;
wxSizer *MainSizer;
void SetBitmapColor (int n,wxColour color);
@ -120,6 +121,7 @@ private:
void OnChildFocus (wxChildFocusEvent &event);
void OnCommandPreviewUpdate (wxCommandEvent &event);
void OnPreviewTextChange (wxCommandEvent &event);
void OnPreviewColourChange (wxCommandEvent &event);
public:
DialogStyleEditor(wxWindow *parent,AssStyle *style,SubtitlesGrid *grid);

View File

@ -358,6 +358,7 @@ void OptionsManager::LoadDefaults(bool onlyDefaults) {
previewText += 0x6708; // kanji "moon"
previewText += 0x8a9e; // kanji "speak"
SetText(_T("Style editor preview text"),previewText);
SetColour(_T("Style editor preview background"),wxColour(125,153,176));
}

View File

@ -48,7 +48,7 @@
///////////////
// Constructor
SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int winStyle)
SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int winStyle,wxColour col)
: wxWindow(parent,id,pos,size,winStyle)
{
AssStyle temp;
@ -58,6 +58,7 @@ SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize si
SetStyle(&temp);
SetText(_T("preview"));
SetSizeHints(size.GetWidth(),size.GetHeight(),-1,-1);
backColour = col;
}
@ -131,7 +132,7 @@ void SubtitlesPreview::UpdateBitmap(int w,int h) {
}
// Get AegiVideoFrame
if (!vid) vid = new DummyVideoProvider(0.0,10,w,h,wxColour(125,153,176),true);
if (!vid) vid = new DummyVideoProvider(0.0,10,w,h,backColour,true);
AegiVideoFrame frame;
frame.CopyFrom(vid->GetFrame(0));
@ -195,3 +196,13 @@ void SubtitlesPreview::OnSize(wxSizeEvent &event) {
vid = NULL;
UpdateBitmap(event.GetSize().GetWidth(),event.GetSize().GetHeight());
}
//////////////
// Set colour
void SubtitlesPreview::SetColour(wxColour col) {
backColour = col;
delete vid;
vid = NULL;
UpdateBitmap();
}

View File

@ -56,6 +56,7 @@ private:
AssStyle *style;
wxString showText;
VideoProvider *vid;
wxColour backColour;
void UpdateBitmap(int w=-1,int h=-1);
void OnSize(wxSizeEvent &event);
@ -64,8 +65,9 @@ private:
public:
void SetStyle(AssStyle *style);
void SetText(wxString text);
void SetColour(wxColour col);
SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int style);
SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int style,wxColour colour);
~SubtitlesPreview();
DECLARE_EVENT_TABLE()