Several improvements to style editor, but still not 100% done

Originally committed to SVN as r1082.
This commit is contained in:
Rodrigo Braz Monteiro 2007-04-16 23:41:06 +00:00
parent 85cafc22bc
commit 94260f649d
6 changed files with 231 additions and 103 deletions

View File

@ -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 ///////////////////////// ///////////////////////// 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 // Get a list of valid ASS encodings
void AssStyle::GetEncodings(wxArrayString &encodingStrings) { void AssStyle::GetEncodings(wxArrayString &encodingStrings) {

View File

@ -53,6 +53,9 @@ public:
AssColor(); AssColor();
AssColor(wxColour &color); AssColor(wxColour &color);
bool operator==(AssColor &col) const;
bool operator!=(AssColor &col) const;
wxColor GetWXColor(); // Return as a wxColor wxColor GetWXColor(); // Return as a wxColor
void SetWXColor(const wxColor &color); // Sets from a wxColor void SetWXColor(const wxColor &color); // Sets from a wxColor
void Parse(const wxString value); // Parse SSA or ASS-style color 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 bool Parse(wxString data,int version=1); // Parses raw ASS/SSA data into everything else
void UpdateData(); // Updates raw data void UpdateData(); // Updates raw data
wxString GetSSAText(); // Retrieves SSA-formatted style 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) 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) 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); static void GetEncodings(wxArrayString &encodingStrings);
AssEntry *Clone(); AssEntry *Clone();
bool IsEqualTo(AssStyle *style);
AssStyle(); AssStyle();
AssStyle(wxString data,int version=1); AssStyle(wxString data,int version=1);

View File

@ -49,6 +49,39 @@
#include "dialog_colorpicker.h" #include "dialog_colorpicker.h"
#include "colour_button.h" #include "colour_button.h"
#include "subs_preview.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 // Create controls
StyleName = new wxTextCtrl(this,-1,style->name); StyleName = new wxTextCtrl(this,-1,style->name);
FontName = new wxTextCtrl(this,-1,style->font,wxDefaultPosition,wxSize(150,20)); FontName = new wxTextCtrl(this,TEXT_FONT_NAME,style->font,wxDefaultPosition,wxSize(150,20));
FontSize = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(30,20),0,wxTextValidator(wxFILTER_NUMERIC,&FontSizeValue)); 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")); wxButton *FontButton = new wxButton(this,BUTTON_STYLE_FONT,_("Choose"));
BoxBold = new wxCheckBox(this,CHECKBOX_STYLE_BOLD,_("Bold")); BoxBold = new wxCheckBox(this,CHECKBOX_STYLE_BOLD,_("Bold"));
BoxItalic = new wxCheckBox(this,CHECKBOX_STYLE_ITALIC,_("Italic")); 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[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[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()); 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)); ColorAlpha1 = new wxTextCtrl(this,TEXT_ALPHA_1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha1Value));
ColorAlpha2 = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha2Value)); ColorAlpha2 = new wxTextCtrl(this,TEXT_ALPHA_2,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha2Value));
ColorAlpha3 = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha3Value)); ColorAlpha3 = new wxTextCtrl(this,TEXT_ALPHA_3,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha3Value));
ColorAlpha4 = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha4Value)); ColorAlpha4 = new wxTextCtrl(this,TEXT_ALPHA_4,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&ColorAlpha4Value));
MarginL = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginLValue)); MarginL = new wxTextCtrl(this,TEXT_MARGIN_L,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginLValue));
MarginR = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginRValue)); MarginR = new wxTextCtrl(this,TEXT_MARGIN_R,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginRValue));
MarginV = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(40,20),0,NumValidator(&MarginVValue)); 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); 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)); Outline = new wxTextCtrl(this,TEXT_OUTLINE,_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)); Shadow = new wxTextCtrl(this,TEXT_SHADOW,_T(""),wxDefaultPosition,wxSize(40,20),0,wxTextValidator(wxFILTER_NUMERIC,&ShadowValue));
OutlineType = new wxCheckBox(this,-1,_("Opaque box")); OutlineType = new wxCheckBox(this,-1,_("Opaque box"));
ScaleX = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition, wxSize(70,20),0,wxTextValidator(wxFILTER_NUMERIC,&ScaleXValue)); ScaleX = new wxTextCtrl(this,TEXT_SCALE_X,_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)); ScaleY = new wxTextCtrl(this,TEXT_SCALE_Y,_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)); Angle = new wxTextCtrl(this,TEXT_ANGLE,_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)); 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); Encoding = new wxComboBox(this,-1,_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);
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 // Set control tooltips
FontName->SetToolTip(_("Font face")); FontName->SetToolTip(_("Font face"));
@ -148,6 +182,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit
OutlineType->SetValue(style->borderstyle == 3); OutlineType->SetValue(style->borderstyle == 3);
SubsPreview->SetStyle(style); SubsPreview->SetStyle(style);
Alignment->SetSelection(AlignToControl(style->alignment)); Alignment->SetSelection(AlignToControl(style->alignment));
SubsPreview->SetText(PreviewText->GetValue());
// Set encoding value // Set encoding value
int encLen = EncodingValue.Length(); int encLen = EncodingValue.Length();
@ -331,6 +366,8 @@ BEGIN_EVENT_TABLE(DialogStyleEditor, wxDialog)
EVT_BUTTON(BUTTON_COLOR_2, DialogStyleEditor::OnSetColor2) EVT_BUTTON(BUTTON_COLOR_2, DialogStyleEditor::OnSetColor2)
EVT_BUTTON(BUTTON_COLOR_3, DialogStyleEditor::OnSetColor3) EVT_BUTTON(BUTTON_COLOR_3, DialogStyleEditor::OnSetColor3)
EVT_BUTTON(BUTTON_COLOR_4, DialogStyleEditor::OnSetColor4) EVT_BUTTON(BUTTON_COLOR_4, DialogStyleEditor::OnSetColor4)
EVT_CHILD_FOCUS(DialogStyleEditor::OnChildFocus)
EVT_TEXT(TEXT_PREVIEW, DialogStyleEditor::OnPreviewTextChange)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -410,6 +447,44 @@ void DialogStyleEditor::Apply (bool apply,bool close) {
work->name = newStyleName; work->name = newStyleName;
} }
// Update work style
UpdateWorkStyle();
// Copy
*style = *work;
style->UpdateData();
AssFile::top->FlagAsModified(_("style change"));
grid->CommitChanges();
// Exit
if (close) {
EndModal(1);
Options.SetText(_T("Style editor preview text"),PreviewText->GetValue());
Options.Save();
}
// Update preview
else SubsPreview->SetStyle(style);
}
// Close
else {
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 // Update scale
ScaleX->GetValue().ToDouble(&(work->scalex)); ScaleX->GetValue().ToDouble(&(work->scalex));
ScaleY->GetValue().ToDouble(&(work->scaley)); ScaleY->GetValue().ToDouble(&(work->scaley));
@ -456,28 +531,6 @@ void DialogStyleEditor::Apply (bool apply,bool close) {
work->italic = BoxItalic->IsChecked(); work->italic = BoxItalic->IsChecked();
work->underline = BoxUnderline->IsChecked(); work->underline = BoxUnderline->IsChecked();
work->strikeout = BoxStrikeout->IsChecked(); work->strikeout = BoxStrikeout->IsChecked();
// Font and its size
work->font = FontName->GetValue();
FontSize->GetValue().ToDouble(&(work->fontsize));
// Copy
*style = *work;
style->UpdateData();
AssFile::top->FlagAsModified(_("style change"));
grid->CommitChanges();
// Exit
if (close) EndModal(1);
// Update preview
SubsPreview->SetStyle(style);
}
// Close
else {
if (close) EndModal(0);
}
} }
@ -518,6 +571,26 @@ void DialogStyleEditor::OnSetColor (int n) {
default: throw _T("Never gets here"); default: throw _T("Never gets here");
} }
modify->SetWXColor(colorButton[n-1]->GetColour()); 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();
}
} }

View File

@ -107,6 +107,7 @@ private:
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);
void UpdateWorkStyle ();
void OnApply (wxCommandEvent &event); void OnApply (wxCommandEvent &event);
void OnCancel (wxCommandEvent &event); void OnCancel (wxCommandEvent &event);
@ -116,6 +117,8 @@ private:
void OnSetColor2 (wxCommandEvent &event); void OnSetColor2 (wxCommandEvent &event);
void OnSetColor3 (wxCommandEvent &event); void OnSetColor3 (wxCommandEvent &event);
void OnSetColor4 (wxCommandEvent &event); void OnSetColor4 (wxCommandEvent &event);
void OnChildFocus (wxChildFocusEvent &event);
void OnPreviewTextChange (wxCommandEvent &event);
public: public:
DialogStyleEditor(wxWindow *parent,AssStyle *style,SubtitlesGrid *grid); 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 #endif

View File

@ -342,6 +342,11 @@ void OptionsManager::LoadDefaults() {
SetText(_T("Last open automation path"),_T("")); SetText(_T("Last open automation path"),_T(""));
SetBool(_T("kanji timer interpolation"),true); SetBool(_T("kanji timer interpolation"),true);
wxString previewText = _T("Aegisub 0123 ");
previewText += 0x6708;
previewText += 0x8a9e;
SetText(_T("Style editor preview text"),previewText);
} }

View File

@ -39,26 +39,24 @@
//////////// ////////////
// Includes // Includes
#include "ass_style.h"
#include "subs_preview.h" #include "subs_preview.h"
#include "video_provider_dummy.h" #include "video_provider_dummy.h"
#include "subtitles_provider.h" #include "subtitles_provider.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_style.h"
/////////////// ///////////////
// Constructor // Constructor
SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int style) SubtitlesPreview::SubtitlesPreview(wxWindow *parent,int id,wxPoint pos,wxSize size,int winStyle)
: wxWindow(parent,id,pos,size,style) : wxWindow(parent,id,pos,size,winStyle)
{ {
SetSizeHints(size.GetWidth(),size.GetHeight(),-1,-1);
bmp = NULL;
AssStyle temp; AssStyle temp;
wxString text = _T("Aegisub 0123 "); bmp = NULL;
text += 0x6708; style = NULL;
text += 0x8a9e;
SetText(text);
SetStyle(&temp); 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 // Destructor
SubtitlesPreview::~SubtitlesPreview() { SubtitlesPreview::~SubtitlesPreview() {
delete bmp; delete bmp;
delete style;
} }
///////////// /////////////
// Set style // Set style
void SubtitlesPreview::SetStyle(AssStyle *_style) { void SubtitlesPreview::SetStyle(AssStyle *_style) {
style = AssEntry::GetAsStyle(_style->Clone()); // Prepare style
style->name = _T("Preview"); AssStyle *tmpStyle = AssEntry::GetAsStyle(_style->Clone());
style->alignment = 5; tmpStyle->name = _T("Preview");
for (int i=0;i<4;i++) style->Margin[i] = 0; tmpStyle->alignment = 5;
style->UpdateData(); 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(); UpdateBitmap();
} }
@ -84,8 +96,10 @@ void SubtitlesPreview::SetStyle(AssStyle *_style) {
//////////// ////////////
// Set text // Set text
void SubtitlesPreview::SetText(wxString text) { void SubtitlesPreview::SetText(wxString text) {
if (text != showText) {
showText = text; showText = text;
UpdateBitmap(); UpdateBitmap();
}
} }
@ -126,7 +140,7 @@ void SubtitlesPreview::UpdateBitmap(int w,int h) {
subs->InsertStyle(style); subs->InsertStyle(style);
subs->SetScriptInfo(_T("PlayResX"),wxString::Format(_T("%i"),w)); subs->SetScriptInfo(_T("PlayResX"),wxString::Format(_T("%i"),w));
subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),h)); 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 // Apply subtitles
SubtitlesProvider *provider = SubtitlesProviderFactory::GetProvider(); SubtitlesProvider *provider = SubtitlesProviderFactory::GetProvider();