From 94260f649d96ca7a6ebe387924cbfd50cb2be92d Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 16 Apr 2007 23:41:06 +0000 Subject: [PATCH] Several improvements to style editor, but still not 100% done Originally committed to SVN as r1082. --- aegisub/ass_style.cpp | 45 +++++++ aegisub/ass_style.h | 6 +- aegisub/dialog_style_editor.cpp | 211 +++++++++++++++++++++----------- aegisub/dialog_style_editor.h | 19 +-- aegisub/options.cpp | 5 + aegisub/subs_preview.cpp | 48 +++++--- 6 files changed, 231 insertions(+), 103 deletions(-) diff --git a/aegisub/ass_style.cpp b/aegisub/ass_style.cpp index fd78daa69..345ca6259 100644 --- a/aegisub/ass_style.cpp +++ b/aegisub/ass_style.cpp @@ -126,6 +126,16 @@ wxString AssColor::GetSSAFormatted () { } +///////////// +// Operators +bool AssColor::operator==(AssColor &col) const { + return r==col.r && g==col.g && b==col.b && a==col.a; +} +bool AssColor::operator!=(AssColor &col) const { + return r!=col.r || g!=col.g || b!=col.b || a!=col.a; +} + + ///////////////////////// AssStyle ///////////////////////// /////////////////////// @@ -521,6 +531,41 @@ AssEntry *AssStyle::Clone() { } +/////////////////////////// +// Equal to another style? +bool AssStyle::IsEqualTo(AssStyle *style) { + // memcmp won't work because strings won't match + if (style->alignment != alignment || + style->angle != angle || + style->bold != bold || + style->borderstyle != borderstyle || + style->encoding != encoding || + style->font != font || + style->fontsize != fontsize || + style->italic != italic || + style->Margin[0] != Margin[0] || + style->Margin[1] != Margin[1] || + style->Margin[2] != Margin[2] || + style->Margin[3] != Margin[3] || + style->name != name || + style->outline != outline || + style->outline_w != outline_w || + style->primary != primary || + style->scalex != scalex || + style->scaley != scaley || + style->secondary != secondary || + style->shadow != shadow || + style->shadow_w != shadow_w || + style->spacing != spacing || + style->strikeout != strikeout || + style->underline != underline || + style->relativeTo != relativeTo) + return false; + + else return true; +} + + ///////////////////////////////////// // Get a list of valid ASS encodings void AssStyle::GetEncodings(wxArrayString &encodingStrings) { diff --git a/aegisub/ass_style.h b/aegisub/ass_style.h index 7da22a122..dc1ed1ae4 100644 --- a/aegisub/ass_style.h +++ b/aegisub/ass_style.h @@ -53,6 +53,9 @@ public: AssColor(); AssColor(wxColour &color); + bool operator==(AssColor &col) const; + bool operator!=(AssColor &col) const; + wxColor GetWXColor(); // Return as a wxColor void SetWXColor(const wxColor &color); // Sets from a wxColor void Parse(const wxString value); // Parse SSA or ASS-style color @@ -96,12 +99,13 @@ public: bool Parse(wxString data,int version=1); // Parses raw ASS/SSA data into everything else void UpdateData(); // Updates raw data wxString GetSSAText(); // Retrieves SSA-formatted style + wxString GetMarginString(int which); // Returns the margin value as a string (0 = left, 1 = right, 2 = vertical/top, 3 = bottom) void SetMarginString(const wxString value,int which); // Sets margin value from a string (0 = left, 1 = right, 2 = vertical/top, 3 = bottom) - static void GetEncodings(wxArrayString &encodingStrings); AssEntry *Clone(); + bool IsEqualTo(AssStyle *style); AssStyle(); AssStyle(wxString data,int version=1); diff --git a/aegisub/dialog_style_editor.cpp b/aegisub/dialog_style_editor.cpp index c0dd67234..92fbca258 100644 --- a/aegisub/dialog_style_editor.cpp +++ b/aegisub/dialog_style_editor.cpp @@ -49,6 +49,39 @@ #include "dialog_colorpicker.h" #include "colour_button.h" #include "subs_preview.h" +#include "options.h" + + +/////// +// IDs +enum { + BUTTON_STYLE_FONT = 1050, + CHECKBOX_STYLE_BOLD, + CHECKBOX_STYLE_ITALIC, + CHECKBOX_STYLE_UNDERLINE, + CHECKBOX_STYLE_STRIKEOUT, + BUTTON_COLOR_1, + BUTTON_COLOR_2, + BUTTON_COLOR_3, + BUTTON_COLOR_4, + RADIO_ALIGNMENT, + TEXT_FONT_NAME, + TEXT_FONT_SIZE, + TEXT_ALPHA_1, + TEXT_ALPHA_2, + TEXT_ALPHA_3, + TEXT_ALPHA_4, + TEXT_MARGIN_L, + TEXT_MARGIN_R, + TEXT_MARGIN_V, + TEXT_OUTLINE, + TEXT_SHADOW, + TEXT_SCALE_X, + TEXT_SCALE_Y, + TEXT_ANGLE, + TEXT_SPACING, + TEXT_PREVIEW +}; /////////////// @@ -86,8 +119,8 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit // Create controls StyleName = new wxTextCtrl(this,-1,style->name); - FontName = new wxTextCtrl(this,-1,style->font,wxDefaultPosition,wxSize(150,20)); - FontSize = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(30,20),0,wxTextValidator(wxFILTER_NUMERIC,&FontSizeValue)); + FontName = new wxTextCtrl(this,TEXT_FONT_NAME,style->font,wxDefaultPosition,wxSize(150,20)); + 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")); BoxItalic = new wxCheckBox(this,CHECKBOX_STYLE_ITALIC,_("Italic")); @@ -97,24 +130,25 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit colorButton[1] = new ColourButton(this,BUTTON_COLOR_2,wxSize(45,16),style->secondary.GetWXColor()); colorButton[2] = new ColourButton(this,BUTTON_COLOR_3,wxSize(45,16),style->outline.GetWXColor()); colorButton[3] = new ColourButton(this,BUTTON_COLOR_4,wxSize(45,16),style->shadow.GetWXColor()); - ColorAlpha1 = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha1Value)); - ColorAlpha2 = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha2Value)); - ColorAlpha3 = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha3Value)); - ColorAlpha4 = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha4Value)); - MarginL = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginLValue)); - MarginR = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginRValue)); - MarginV = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginVValue)); + ColorAlpha1 = new wxTextCtrl(this,TEXT_ALPHA_1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha1Value)); + ColorAlpha2 = new wxTextCtrl(this,TEXT_ALPHA_2,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha2Value)); + ColorAlpha3 = new wxTextCtrl(this,TEXT_ALPHA_3,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha3Value)); + ColorAlpha4 = new wxTextCtrl(this,TEXT_ALPHA_4,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha4Value)); + MarginL = new wxTextCtrl(this,TEXT_MARGIN_L,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginLValue)); + MarginR = new wxTextCtrl(this,TEXT_MARGIN_R,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginRValue)); + MarginV = new wxTextCtrl(this,TEXT_MARGIN_V,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginVValue)); Alignment = new wxRadioBox(this, RADIO_ALIGNMENT, _("Alignment"), wxDefaultPosition, wxDefaultSize, 9, alignValues, 3, wxRA_SPECIFY_COLS); - Outline = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&OutlineValue)); - Shadow = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&ShadowValue)); + Outline = new wxTextCtrl(this,TEXT_OUTLINE,_T(""),wxDefaultPosition,wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&OutlineValue)); + Shadow = new wxTextCtrl(this,TEXT_SHADOW,_T(""),wxDefaultPosition,wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&ShadowValue)); OutlineType = new wxCheckBox(this,-1,_("Opaque box")); - ScaleX = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition, wxSize(70,20),0,wxTextValidator(wxFILTER_NUMERIC,&ScaleXValue)); - ScaleY = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition, wxSize(70,20),0,wxTextValidator(wxFILTER_NUMERIC,&ScaleYValue)); - Angle = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition, wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&AngleValue)); - Spacing = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&SpacingValue)); + ScaleX = new wxTextCtrl(this,TEXT_SCALE_X,_T(""),wxDefaultPosition, wxSize(70,20),0,wxTextValidator(wxFILTER_NUMERIC,&ScaleXValue)); + ScaleY = new wxTextCtrl(this,TEXT_SCALE_Y,_T(""),wxDefaultPosition, wxSize(70,20),0,wxTextValidator(wxFILTER_NUMERIC,&ScaleYValue)); + 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,-1,_T(""),wxDefaultPosition, wxDefaultSize, encodingStrings,wxCB_READONLY); SubsPreview = new SubtitlesPreview(this,-1,wxDefaultPosition,wxSize(100,60),wxSUNKEN_BORDER); - PreviewText = new wxTextCtrl(this,-1,_T("preview text (TODO)")); + PreviewText = NULL; // Yes, this IS necessary + PreviewText = new wxTextCtrl(this,TEXT_PREVIEW,Options.AsText(_T("Style editor preview text"))); // Set control tooltips FontName->SetToolTip(_("Font face")); @@ -148,6 +182,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit OutlineType->SetValue(style->borderstyle == 3); SubsPreview->SetStyle(style); Alignment->SetSelection(AlignToControl(style->alignment)); + SubsPreview->SetText(PreviewText->GetValue()); // Set encoding value int encLen = EncodingValue.Length(); @@ -331,6 +366,8 @@ 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_CHILD_FOCUS(DialogStyleEditor::OnChildFocus) + EVT_TEXT(TEXT_PREVIEW, DialogStyleEditor::OnPreviewTextChange) END_EVENT_TABLE() @@ -410,56 +447,8 @@ void DialogStyleEditor::Apply (bool apply,bool close) { work->name = newStyleName; } - // Update scale - ScaleX->GetValue().ToDouble(&(work->scalex)); - ScaleY->GetValue().ToDouble(&(work->scaley)); - - // Update encoding - long templ = 0; - wxString enc = Encoding->GetValue(); - enc.Left(enc.Find(_T("-"))-1).ToLong(&templ); - work->encoding = templ; - - // Angle and spacing - Angle->GetValue().ToDouble(&(work->angle)); - Spacing->GetValue().ToDouble(&(work->spacing)); - - // Outline type - if(OutlineType->IsChecked()) work->borderstyle = 3; - else work->borderstyle = 1; - - // Shadow and outline - Shadow->GetValue().ToDouble(&(work->shadow_w)); - Outline->GetValue().ToDouble(&(work->outline_w)); - - // Alignment - work->alignment = ControlToAlign(Alignment->GetSelection()); - - // Margins - work->SetMarginString(MarginL->GetValue(),0); - work->SetMarginString(MarginR->GetValue(),1); - work->SetMarginString(MarginV->GetValue(),2); // make sure both top and bottom margins reflect vertical margin - work->SetMarginString(MarginV->GetValue(),3); - - // Color alphas - ColorAlpha1->GetValue().ToLong(&templ); - work->primary.a = templ; - ColorAlpha2->GetValue().ToLong(&templ); - work->secondary.a = templ; - ColorAlpha3->GetValue().ToLong(&templ); - work->outline.a = templ; - ColorAlpha4->GetValue().ToLong(&templ); - work->shadow.a = templ; - - // Bold/italic/underline/strikeout - work->bold = BoxBold->IsChecked(); - work->italic = BoxItalic->IsChecked(); - work->underline = BoxUnderline->IsChecked(); - work->strikeout = BoxStrikeout->IsChecked(); - - // Font and its size - work->font = FontName->GetValue(); - FontSize->GetValue().ToDouble(&(work->fontsize)); + // Update work style + UpdateWorkStyle(); // Copy *style = *work; @@ -468,19 +457,83 @@ void DialogStyleEditor::Apply (bool apply,bool close) { grid->CommitChanges(); // Exit - if (close) EndModal(1); + if (close) { + EndModal(1); + Options.SetText(_T("Style editor preview text"),PreviewText->GetValue()); + Options.Save(); + } // Update preview - SubsPreview->SetStyle(style); + else SubsPreview->SetStyle(style); } // Close else { - if (close) EndModal(0); + if (close) { + EndModal(0); + Options.SetText(_T("Style editor preview text"),PreviewText->GetValue()); + Options.Save(); + } } } +///////////////////// +// Update work style +void DialogStyleEditor::UpdateWorkStyle() { + // Font and its size + work->font = FontName->GetValue(); + FontSize->GetValue().ToDouble(&(work->fontsize)); + + // Update scale + ScaleX->GetValue().ToDouble(&(work->scalex)); + ScaleY->GetValue().ToDouble(&(work->scaley)); + + // Update encoding + long templ = 0; + wxString enc = Encoding->GetValue(); + enc.Left(enc.Find(_T("-"))-1).ToLong(&templ); + work->encoding = templ; + + // Angle and spacing + Angle->GetValue().ToDouble(&(work->angle)); + Spacing->GetValue().ToDouble(&(work->spacing)); + + // Outline type + if(OutlineType->IsChecked()) work->borderstyle = 3; + else work->borderstyle = 1; + + // Shadow and outline + Shadow->GetValue().ToDouble(&(work->shadow_w)); + Outline->GetValue().ToDouble(&(work->outline_w)); + + // Alignment + work->alignment = ControlToAlign(Alignment->GetSelection()); + + // Margins + work->SetMarginString(MarginL->GetValue(),0); + work->SetMarginString(MarginR->GetValue(),1); + work->SetMarginString(MarginV->GetValue(),2); // make sure both top and bottom margins reflect vertical margin + work->SetMarginString(MarginV->GetValue(),3); + + // Color alphas + ColorAlpha1->GetValue().ToLong(&templ); + work->primary.a = templ; + ColorAlpha2->GetValue().ToLong(&templ); + work->secondary.a = templ; + ColorAlpha3->GetValue().ToLong(&templ); + work->outline.a = templ; + ColorAlpha4->GetValue().ToLong(&templ); + work->shadow.a = templ; + + // Bold/italic/underline/strikeout + work->bold = BoxBold->IsChecked(); + work->italic = BoxItalic->IsChecked(); + work->underline = BoxUnderline->IsChecked(); + work->strikeout = BoxStrikeout->IsChecked(); +} + + /////////////////// // Choose font box void DialogStyleEditor::OnChooseFont (wxCommandEvent &event) { @@ -518,6 +571,26 @@ void DialogStyleEditor::OnSetColor (int n) { default: throw _T("Never gets here"); } modify->SetWXColor(colorButton[n-1]->GetColour()); + SubsPreview->SetStyle(work); +} + + +////////////////////// +// Child focus change +void DialogStyleEditor::OnChildFocus (wxChildFocusEvent &event) { + UpdateWorkStyle(); + SubsPreview->SetStyle(work); + event.Skip(); +} + + +//////////////////////// +// Preview text changed +void DialogStyleEditor::OnPreviewTextChange (wxCommandEvent &event) { + if (PreviewText) { + SubsPreview->SetText(PreviewText->GetValue()); + event.Skip(); + } } diff --git a/aegisub/dialog_style_editor.h b/aegisub/dialog_style_editor.h index cf5414265..3890b8fe9 100644 --- a/aegisub/dialog_style_editor.h +++ b/aegisub/dialog_style_editor.h @@ -107,6 +107,7 @@ private: void SetBitmapColor (int n,wxColour color); int AlignToControl (int n); int ControlToAlign (int n); + void UpdateWorkStyle (); void OnApply (wxCommandEvent &event); void OnCancel (wxCommandEvent &event); @@ -116,6 +117,8 @@ private: void OnSetColor2 (wxCommandEvent &event); void OnSetColor3 (wxCommandEvent &event); void OnSetColor4 (wxCommandEvent &event); + void OnChildFocus (wxChildFocusEvent &event); + void OnPreviewTextChange (wxCommandEvent &event); public: DialogStyleEditor(wxWindow *parent,AssStyle *style,SubtitlesGrid *grid); @@ -128,20 +131,4 @@ public: }; -/////// -// IDs -enum { - BUTTON_STYLE_FONT = 1050, - CHECKBOX_STYLE_BOLD, - CHECKBOX_STYLE_ITALIC, - CHECKBOX_STYLE_UNDERLINE, - CHECKBOX_STYLE_STRIKEOUT, - BUTTON_COLOR_1, - BUTTON_COLOR_2, - BUTTON_COLOR_3, - BUTTON_COLOR_4, - RADIO_ALIGNMENT -}; - - #endif diff --git a/aegisub/options.cpp b/aegisub/options.cpp index 65376e173..919a6ea10 100644 --- a/aegisub/options.cpp +++ b/aegisub/options.cpp @@ -342,6 +342,11 @@ void OptionsManager::LoadDefaults() { SetText(_T("Last open automation path"),_T("")); SetBool(_T("kanji timer interpolation"),true); + + wxString previewText = _T("Aegisub 0123 "); + previewText += 0x6708; + previewText += 0x8a9e; + SetText(_T("Style editor preview text"),previewText); } diff --git a/aegisub/subs_preview.cpp b/aegisub/subs_preview.cpp index 38e117705..34a99fafc 100644 --- a/aegisub/subs_preview.cpp +++ b/aegisub/subs_preview.cpp @@ -39,26 +39,24 @@ //////////// // Includes +#include "ass_style.h" #include "subs_preview.h" #include "video_provider_dummy.h" #include "subtitles_provider.h" #include "ass_file.h" -#include "ass_style.h" /////////////// // Constructor -SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int style) -: wxWindow(parent,id,pos,size,style) +SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int winStyle) +: wxWindow(parent,id,pos,size,winStyle) { - SetSizeHints(size.GetWidth(),size.GetHeight(),-1,-1); - bmp = NULL; AssStyle temp; - wxString text = _T("Aegisub 0123 "); - text += 0x6708; - text += 0x8a9e; - SetText(text); + bmp = NULL; + style = NULL; SetStyle(&temp); + SetText(_T("preview")); + SetSizeHints(size.GetWidth(),size.GetHeight(),-1,-1); } @@ -66,17 +64,31 @@ SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize si // Destructor SubtitlesPreview::~SubtitlesPreview() { delete bmp; + delete style; } ///////////// // Set style void SubtitlesPreview::SetStyle(AssStyle *_style) { - style = AssEntry::GetAsStyle(_style->Clone()); - style->name = _T("Preview"); - style->alignment = 5; - for (int i=0;i<4;i++) style->Margin[i] = 0; - style->UpdateData(); + // Prepare style + AssStyle *tmpStyle = AssEntry::GetAsStyle(_style->Clone()); + tmpStyle->name = _T("Preview"); + tmpStyle->alignment = 5; + for (int i=0;i<4;i++) tmpStyle->Margin[i] = 0; + tmpStyle->UpdateData(); + + // See if it's any different from the current + if (style) { + if (tmpStyle->IsEqualTo(style)) { + delete tmpStyle; + return; + } + } + + // Update + delete style; + style = tmpStyle; UpdateBitmap(); } @@ -84,8 +96,10 @@ void SubtitlesPreview::SetStyle(AssStyle *_style) { //////////// // Set text void SubtitlesPreview::SetText(wxString text) { - showText = text; - UpdateBitmap(); + if (text != showText) { + showText = text; + UpdateBitmap(); + } } @@ -126,7 +140,7 @@ void SubtitlesPreview::UpdateBitmap(int w,int h) { subs->InsertStyle(style); subs->SetScriptInfo(_T("PlayResX"),wxString::Format(_T("%i"),w)); subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),h)); - subs->AddLine(_T("Dialogue: 0,0:00:00.00,0:00:05.00,Preview,,0000,0000,0000,,") + showText,_T("[Events]"),0,ver,&outGroup); + subs->AddLine(_T("Dialogue: 0,0:00:00.00,0:00:05.00,Preview,,0000,0000,0000,,{\\q2}") + showText,_T("[Events]"),0,ver,&outGroup); // Apply subtitles SubtitlesProvider *provider = SubtitlesProviderFactory::GetProvider();