Work on assa bg box

This commit is contained in:
niksedk 2021-12-29 10:08:36 +01:00
parent 42d3168a5f
commit a1e4a081f8
5 changed files with 816 additions and 372 deletions

View File

@ -886,29 +886,86 @@ namespace Nikse.SubtitleEdit.Core.Common
return newTop;
}
public int CalcBottomCropping(Color transparentColor)
public int CalcTopCropping(Color color)
{
int y = Height - 1;
int cropping = 0;
while (y > 0)
var y = 0;
for (; y < Height; y++)
{
int x = 0;
while (x < Width)
if (!IsHorizontalLineColor(y, color))
{
var c = GetPixel(x, y);
if (c != transparentColor && c.A != 0)
{
return cropping;
}
x++;
break;
}
y--;
cropping++;
}
return cropping;
return y;
}
public int CalcBottomCropping(Color color)
{
var y = Height - 1;
for (; y > 0; y--)
{
if (!IsHorizontalLineColor(y, color))
{
break;
}
}
return Height - y;
}
public int CalcLeftCropping(Color color)
{
var x = 0;
for (; x < Width; x++)
{
if (!IsVerticalLineColor(x, color))
{
break;
}
}
return x;
}
public int CalcRightCropping(Color color)
{
var x = Width - 1;
for (; x > 0; x--)
{
if (!IsVerticalLineColor(x, color))
{
break;
}
}
return Width - x;
}
public bool IsVerticalLineColor(int x, Color color)
{
for (var y = 0; y < Height; y++)
{
if (!IsColorClose(GetPixel(x, y), color, 9))
{
return false;
}
}
return true;
}
public bool IsHorizontalLineColor(int y, Color color)
{
for (var x = 0; x < Width; x++)
{
if (!IsColorClose(GetPixel(x, y), color, 9))
{
return false;
}
}
return true;
}
public void Fill(Color color)

View File

@ -853,7 +853,7 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
var styles = new List<SsaStyle>();
foreach (var styleName in GetStylesFromHeader(header))
{
styles.Add(AdvancedSubStationAlpha.GetSsaStyle(styleName, header));
styles.Add(GetSsaStyle(styleName, header));
}
return styles;
}
@ -2625,5 +2625,12 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
return new SsaStyle { Name = styleName };
}
public static string UpdateOrAddStyle(string header, SsaStyle style)
{
var styles = GetSsaStylesFromHeader(header).Where(p=>p.Name != style.Name).ToList();
styles.Add(style);
return GetHeaderAndStylesFromAdvancedSubStationAlpha(header, styles);
}
}
}

View File

@ -1035,7 +1035,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
// header
stream.WriteByte(1);
for (int i = 1; i < 23; i++)
for (var i = 1; i < 23; i++)
{
stream.WriteByte(0);
}
@ -1043,23 +1043,32 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
stream.WriteByte(0x60);
// paragraphs
int number = 0;
foreach (var p in subtitle.Paragraphs)
var number = 1;
var firstParagraph = subtitle.Paragraphs.FirstOrDefault();
if (firstParagraph != null &&
Math.Abs(firstParagraph.StartTime.TotalMilliseconds) < 0.001 &&
firstParagraph.EndTime.TotalMilliseconds < 350)
{
WriteParagraph(stream, p, number, number + 1 == subtitle.Paragraphs.Count);
number = 0;
}
for (var index = 0; index < subtitle.Paragraphs.Count; index++)
{
var p = subtitle.Paragraphs[index];
WriteParagraph(stream, p, number, index + 1 == subtitle.Paragraphs.Count);
number++;
}
// footer
stream.WriteByte(0xff);
for (int i = 0; i < 11; i++)
for (var i = 0; i < 11; i++)
{
stream.WriteByte(0);
}
stream.WriteByte(0x11);
stream.WriteByte(0);
byte[] footerBuffer = Encoding.ASCII.GetBytes("dummy end of file");
var footerBuffer = Encoding.ASCII.GetBytes("dummy end of file");
stream.Write(footerBuffer, 0, footerBuffer.Length);
return true;
}
@ -1176,8 +1185,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (!isLast)
{
fs.WriteByte(0);
fs.WriteByte((byte)((number + 1) % 256));
fs.WriteByte((byte)((number + 1) / 256));
fs.WriteByte((byte)(number % 256));
fs.WriteByte((byte)(number / 256));
fs.WriteByte(0x60);
}
}

View File

@ -35,25 +35,65 @@ namespace Nikse.SubtitleEdit.Forms.Assa
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.labelInfo = new System.Windows.Forms.Label();
this.numericUpDownRotateX = new System.Windows.Forms.NumericUpDown();
this.groupBoxDrawing = new System.Windows.Forms.GroupBox();
this.label4 = new System.Windows.Forms.Label();
this.numericUpDown4 = new System.Windows.Forms.NumericUpDown();
this.textBox1 = new System.Windows.Forms.TextBox();
this.labelRotateX = new System.Windows.Forms.Label();
this.numericUpDownRotateY = new System.Windows.Forms.NumericUpDown();
this.labelRotateY = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.numericUpDownRotateX = new System.Windows.Forms.NumericUpDown();
this.numericUpDownMarginBottom = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.comboBoxProgressBarEdge = new System.Windows.Forms.ComboBox();
this.numericUpDownMarginTop = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.labelEdgeStyle = new System.Windows.Forms.Label();
this.labelPreviewPleaseWait = new System.Windows.Forms.Label();
this.buttonPreview = new System.Windows.Forms.Button();
this.comboBoxBoxStyle = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.numericUpDownBoxLayer = new System.Windows.Forms.NumericUpDown();
this.label5 = new System.Windows.Forms.Label();
this.numericUpDownMarginRight = new System.Windows.Forms.NumericUpDown();
this.label6 = new System.Windows.Forms.Label();
this.numericUpDownMarginLeft = new System.Windows.Forms.NumericUpDown();
this.panelPrimaryColor = new System.Windows.Forms.Panel();
this.buttonPrimaryColor = new System.Windows.Forms.Button();
this.panelShadowColor = new System.Windows.Forms.Panel();
this.buttonShadowColor = new System.Windows.Forms.Button();
this.label7 = new System.Windows.Forms.Label();
this.numericUpDownShadowWidth = new System.Windows.Forms.NumericUpDown();
this.label8 = new System.Windows.Forms.Label();
this.numericUpDownOutlineWidth = new System.Windows.Forms.NumericUpDown();
this.panelOutlineColor = new System.Windows.Forms.Panel();
this.buttonOutlineColor = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label10 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.label11 = new System.Windows.Forms.Label();
this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
this.checkBoxFillWidth = new System.Windows.Forms.CheckBox();
this.checkBoxFillHeight = new System.Windows.Forms.CheckBox();
this.label9 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label12 = new System.Windows.Forms.Label();
this.numericUpDown5 = new System.Windows.Forms.NumericUpDown();
this.groupBoxPreview.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPreview)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRotateX)).BeginInit();
this.groupBoxDrawing.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRotateY)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRotateX)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginBottom)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginTop)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownBoxLayer)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginRight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginLeft)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownShadowWidth)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownOutlineWidth)).BeginInit();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).BeginInit();
this.SuspendLayout();
//
// groupBoxPreview
@ -62,9 +102,9 @@ namespace Nikse.SubtitleEdit.Forms.Assa
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxPreview.Controls.Add(this.pictureBoxPreview);
this.groupBoxPreview.Location = new System.Drawing.Point(12, 157);
this.groupBoxPreview.Location = new System.Drawing.Point(12, 232);
this.groupBoxPreview.Name = "groupBoxPreview";
this.groupBoxPreview.Size = new System.Drawing.Size(949, 537);
this.groupBoxPreview.Size = new System.Drawing.Size(949, 462);
this.groupBoxPreview.TabIndex = 2;
this.groupBoxPreview.TabStop = false;
this.groupBoxPreview.Text = "Preview";
@ -74,11 +114,10 @@ namespace Nikse.SubtitleEdit.Forms.Assa
this.pictureBoxPreview.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxPreview.Location = new System.Drawing.Point(3, 16);
this.pictureBoxPreview.Name = "pictureBoxPreview";
this.pictureBoxPreview.Size = new System.Drawing.Size(943, 518);
this.pictureBoxPreview.Size = new System.Drawing.Size(943, 443);
this.pictureBoxPreview.TabIndex = 0;
this.pictureBoxPreview.TabStop = false;
this.pictureBoxPreview.Click += new System.EventHandler(this.pictureBoxPreview_Click);
this.pictureBoxPreview.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBoxPreview_MouseMove);
//
// buttonOK
//
@ -109,46 +148,73 @@ namespace Nikse.SubtitleEdit.Forms.Assa
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// labelInfo
// groupBoxDrawing
//
this.labelInfo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.labelInfo.AutoSize = true;
this.labelInfo.Location = new System.Drawing.Point(12, 704);
this.labelInfo.Name = "labelInfo";
this.labelInfo.Size = new System.Drawing.Size(205, 13);
this.labelInfo.TabIndex = 6;
this.labelInfo.Text = "Click on video to toggle set/move position";
this.groupBoxDrawing.Controls.Add(this.label4);
this.groupBoxDrawing.Controls.Add(this.numericUpDown4);
this.groupBoxDrawing.Controls.Add(this.textBox1);
this.groupBoxDrawing.Controls.Add(this.labelRotateX);
this.groupBoxDrawing.Controls.Add(this.numericUpDownRotateY);
this.groupBoxDrawing.Controls.Add(this.labelRotateY);
this.groupBoxDrawing.Controls.Add(this.numericUpDownRotateX);
this.groupBoxDrawing.Location = new System.Drawing.Point(727, 12);
this.groupBoxDrawing.Name = "groupBoxDrawing";
this.groupBoxDrawing.Size = new System.Drawing.Size(231, 214);
this.groupBoxDrawing.TabIndex = 29;
this.groupBoxDrawing.TabStop = false;
this.groupBoxDrawing.Text = "Drawing";
//
// numericUpDownRotateX
// label4
//
this.numericUpDownRotateX.Location = new System.Drawing.Point(88, 17);
this.numericUpDownRotateX.Maximum = new decimal(new int[] {
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 72);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(33, 13);
this.label4.TabIndex = 32;
this.label4.Text = "Layer";
//
// numericUpDown4
//
this.numericUpDown4.Location = new System.Drawing.Point(82, 70);
this.numericUpDown4.Maximum = new decimal(new int[] {
360,
0,
0,
0});
this.numericUpDownRotateX.Minimum = new decimal(new int[] {
this.numericUpDown4.Minimum = new decimal(new int[] {
360,
0,
0,
-2147483648});
this.numericUpDownRotateX.Name = "numericUpDownRotateX";
this.numericUpDownRotateX.Size = new System.Drawing.Size(52, 20);
this.numericUpDownRotateX.TabIndex = 18;
this.numericUpDownRotateX.ValueChanged += new System.EventHandler(this.numericUpDownRotateX_ValueChanged);
this.numericUpDown4.Name = "numericUpDown4";
this.numericUpDown4.Size = new System.Drawing.Size(52, 20);
this.numericUpDown4.TabIndex = 33;
this.numericUpDown4.Value = new decimal(new int[] {
8,
0,
0,
-2147483648});
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(6, 96);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(219, 112);
this.textBox1.TabIndex = 21;
//
// labelRotateX
//
this.labelRotateX.AutoSize = true;
this.labelRotateX.Location = new System.Drawing.Point(12, 19);
this.labelRotateX.Location = new System.Drawing.Point(6, 17);
this.labelRotateX.Name = "labelRotateX";
this.labelRotateX.Size = new System.Drawing.Size(65, 13);
this.labelRotateX.Size = new System.Drawing.Size(56, 13);
this.labelRotateX.TabIndex = 17;
this.labelRotateX.Text = "X margin left";
this.labelRotateX.Text = "Margin left";
//
// numericUpDownRotateY
//
this.numericUpDownRotateY.Location = new System.Drawing.Point(88, 42);
this.numericUpDownRotateY.Location = new System.Drawing.Point(82, 40);
this.numericUpDownRotateY.Maximum = new decimal(new int[] {
360,
0,
@ -167,50 +233,338 @@ namespace Nikse.SubtitleEdit.Forms.Assa
// labelRotateY
//
this.labelRotateY.AutoSize = true;
this.labelRotateY.Location = new System.Drawing.Point(12, 44);
this.labelRotateY.Location = new System.Drawing.Point(6, 42);
this.labelRotateY.Name = "labelRotateY";
this.labelRotateY.Size = new System.Drawing.Size(71, 13);
this.labelRotateY.Size = new System.Drawing.Size(62, 13);
this.labelRotateY.TabIndex = 19;
this.labelRotateY.Text = "X margin right";
this.labelRotateY.Text = "Margin right";
//
// label1
// numericUpDownRotateX
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 73);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(65, 13);
this.label1.TabIndex = 21;
this.label1.Text = "Y margin left";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(88, 71);
this.numericUpDown1.Maximum = new decimal(new int[] {
this.numericUpDownRotateX.Location = new System.Drawing.Point(82, 15);
this.numericUpDownRotateX.Maximum = new decimal(new int[] {
360,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
this.numericUpDownRotateX.Minimum = new decimal(new int[] {
360,
0,
0,
-2147483648});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(52, 20);
this.numericUpDown1.TabIndex = 22;
this.numericUpDownRotateX.Name = "numericUpDownRotateX";
this.numericUpDownRotateX.Size = new System.Drawing.Size(52, 20);
this.numericUpDownRotateX.TabIndex = 18;
this.numericUpDownRotateX.ValueChanged += new System.EventHandler(this.numericUpDownRotateX_ValueChanged);
//
// numericUpDownMarginBottom
//
this.numericUpDownMarginBottom.Location = new System.Drawing.Point(113, 96);
this.numericUpDownMarginBottom.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.numericUpDownMarginBottom.Minimum = new decimal(new int[] {
1000,
0,
0,
-2147483648});
this.numericUpDownMarginBottom.Name = "numericUpDownMarginBottom";
this.numericUpDownMarginBottom.Size = new System.Drawing.Size(52, 20);
this.numericUpDownMarginBottom.TabIndex = 24;
this.numericUpDownMarginBottom.Value = new decimal(new int[] {
10,
0,
0,
0});
this.numericUpDownMarginBottom.ValueChanged += new System.EventHandler(this.PreviewValueChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 98);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(71, 13);
this.label2.Size = new System.Drawing.Size(81, 13);
this.label2.TabIndex = 23;
this.label2.Text = "Y margin right";
this.label2.Text = "Padding bottom";
//
// numericUpDownMarginTop
//
this.numericUpDownMarginTop.Location = new System.Drawing.Point(113, 71);
this.numericUpDownMarginTop.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.numericUpDownMarginTop.Minimum = new decimal(new int[] {
1000,
0,
0,
-2147483648});
this.numericUpDownMarginTop.Name = "numericUpDownMarginTop";
this.numericUpDownMarginTop.Size = new System.Drawing.Size(52, 20);
this.numericUpDownMarginTop.TabIndex = 22;
this.numericUpDownMarginTop.Value = new decimal(new int[] {
10,
0,
0,
0});
this.numericUpDownMarginTop.ValueChanged += new System.EventHandler(this.PreviewValueChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 73);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 13);
this.label1.TabIndex = 21;
this.label1.Text = "Padding top";
//
// labelEdgeStyle
//
this.labelEdgeStyle.AutoSize = true;
this.labelEdgeStyle.Location = new System.Drawing.Point(13, 164);
this.labelEdgeStyle.Name = "labelEdgeStyle";
this.labelEdgeStyle.Size = new System.Drawing.Size(30, 13);
this.labelEdgeStyle.TabIndex = 25;
this.labelEdgeStyle.Text = "Style";
//
// comboBoxBoxStyle
//
this.comboBoxBoxStyle.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxBoxStyle.FormattingEnabled = true;
this.comboBoxBoxStyle.Items.AddRange(new object[] {
"Square corners",
"Rounded corners"});
this.comboBoxBoxStyle.Location = new System.Drawing.Point(49, 161);
this.comboBoxBoxStyle.Name = "comboBoxBoxStyle";
this.comboBoxBoxStyle.Size = new System.Drawing.Size(116, 21);
this.comboBoxBoxStyle.TabIndex = 26;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(13, 131);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(33, 13);
this.label3.TabIndex = 30;
this.label3.Text = "Layer";
//
// numericUpDownBoxLayer
//
this.numericUpDownBoxLayer.Location = new System.Drawing.Point(113, 129);
this.numericUpDownBoxLayer.Maximum = new decimal(new int[] {
360,
0,
0,
0});
this.numericUpDownBoxLayer.Minimum = new decimal(new int[] {
360,
0,
0,
-2147483648});
this.numericUpDownBoxLayer.Name = "numericUpDownBoxLayer";
this.numericUpDownBoxLayer.Size = new System.Drawing.Size(52, 20);
this.numericUpDownBoxLayer.TabIndex = 31;
this.numericUpDownBoxLayer.Value = new decimal(new int[] {
9,
0,
0,
-2147483648});
this.numericUpDownBoxLayer.ValueChanged += new System.EventHandler(this.PreviewValueChanged);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 19);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(63, 13);
this.label5.TabIndex = 34;
this.label5.Text = "Padding left";
//
// numericUpDownMarginRight
//
this.numericUpDownMarginRight.Location = new System.Drawing.Point(113, 42);
this.numericUpDownMarginRight.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.numericUpDownMarginRight.Minimum = new decimal(new int[] {
1000,
0,
0,
-2147483648});
this.numericUpDownMarginRight.Name = "numericUpDownMarginRight";
this.numericUpDownMarginRight.Size = new System.Drawing.Size(52, 20);
this.numericUpDownMarginRight.TabIndex = 37;
this.numericUpDownMarginRight.Value = new decimal(new int[] {
10,
0,
0,
0});
this.numericUpDownMarginRight.ValueChanged += new System.EventHandler(this.PreviewValueChanged);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(12, 44);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(69, 13);
this.label6.TabIndex = 36;
this.label6.Text = "Padding right";
//
// numericUpDownMarginLeft
//
this.numericUpDownMarginLeft.Location = new System.Drawing.Point(113, 17);
this.numericUpDownMarginLeft.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.numericUpDownMarginLeft.Minimum = new decimal(new int[] {
1000,
0,
0,
-2147483648});
this.numericUpDownMarginLeft.Name = "numericUpDownMarginLeft";
this.numericUpDownMarginLeft.Size = new System.Drawing.Size(52, 20);
this.numericUpDownMarginLeft.TabIndex = 35;
this.numericUpDownMarginLeft.Value = new decimal(new int[] {
10,
0,
0,
0});
this.numericUpDownMarginLeft.ValueChanged += new System.EventHandler(this.PreviewValueChanged);
//
// panelPrimaryColor
//
this.panelPrimaryColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelPrimaryColor.Location = new System.Drawing.Point(291, 20);
this.panelPrimaryColor.Name = "panelPrimaryColor";
this.panelPrimaryColor.Size = new System.Drawing.Size(21, 20);
this.panelPrimaryColor.TabIndex = 39;
this.panelPrimaryColor.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panelPrimaryColor_MouseClick);
//
// buttonPrimaryColor
//
this.buttonPrimaryColor.Location = new System.Drawing.Point(200, 19);
this.buttonPrimaryColor.Name = "buttonPrimaryColor";
this.buttonPrimaryColor.Size = new System.Drawing.Size(85, 23);
this.buttonPrimaryColor.TabIndex = 38;
this.buttonPrimaryColor.Text = "Box color";
this.buttonPrimaryColor.UseVisualStyleBackColor = true;
this.buttonPrimaryColor.Click += new System.EventHandler(this.buttonPrimaryColor_Click);
//
// panelShadowColor
//
this.panelShadowColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelShadowColor.Location = new System.Drawing.Point(291, 140);
this.panelShadowColor.Name = "panelShadowColor";
this.panelShadowColor.Size = new System.Drawing.Size(21, 20);
this.panelShadowColor.TabIndex = 41;
this.panelShadowColor.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panelShadowColor_MouseClick);
//
// buttonShadowColor
//
this.buttonShadowColor.Location = new System.Drawing.Point(200, 139);
this.buttonShadowColor.Name = "buttonShadowColor";
this.buttonShadowColor.Size = new System.Drawing.Size(85, 23);
this.buttonShadowColor.TabIndex = 40;
this.buttonShadowColor.Text = "Shadow color";
this.buttonShadowColor.UseVisualStyleBackColor = true;
this.buttonShadowColor.Click += new System.EventHandler(this.buttonShadowColor_Click);
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(197, 169);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(89, 13);
this.label7.TabIndex = 42;
this.label7.Text = "Shadow distance";
//
// numericUpDownShadowWidth
//
this.numericUpDownShadowWidth.Location = new System.Drawing.Point(200, 185);
this.numericUpDownShadowWidth.Name = "numericUpDownShadowWidth";
this.numericUpDownShadowWidth.Size = new System.Drawing.Size(52, 20);
this.numericUpDownShadowWidth.TabIndex = 43;
this.numericUpDownShadowWidth.ValueChanged += new System.EventHandler(this.PreviewValueChanged);
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(197, 88);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(68, 13);
this.label8.TabIndex = 46;
this.label8.Text = "Outline width";
//
// numericUpDownOutlineWidth
//
this.numericUpDownOutlineWidth.Location = new System.Drawing.Point(200, 104);
this.numericUpDownOutlineWidth.Name = "numericUpDownOutlineWidth";
this.numericUpDownOutlineWidth.Size = new System.Drawing.Size(52, 20);
this.numericUpDownOutlineWidth.TabIndex = 47;
this.numericUpDownOutlineWidth.Value = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDownOutlineWidth.ValueChanged += new System.EventHandler(this.PreviewValueChanged);
//
// panelOutlineColor
//
this.panelOutlineColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelOutlineColor.Location = new System.Drawing.Point(291, 59);
this.panelOutlineColor.Name = "panelOutlineColor";
this.panelOutlineColor.Size = new System.Drawing.Size(21, 20);
this.panelOutlineColor.TabIndex = 45;
this.panelOutlineColor.MouseClick += new System.Windows.Forms.MouseEventHandler(this.panelOutlineColor_MouseClick);
//
// buttonOutlineColor
//
this.buttonOutlineColor.Location = new System.Drawing.Point(200, 58);
this.buttonOutlineColor.Name = "buttonOutlineColor";
this.buttonOutlineColor.Size = new System.Drawing.Size(85, 23);
this.buttonOutlineColor.TabIndex = 44;
this.buttonOutlineColor.Text = "Outline color";
this.buttonOutlineColor.UseVisualStyleBackColor = true;
this.buttonOutlineColor.Click += new System.EventHandler(this.buttonOutlineColor_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBoxFillHeight);
this.groupBox1.Controls.Add(this.label9);
this.groupBox1.Controls.Add(this.numericUpDown1);
this.groupBox1.Controls.Add(this.label12);
this.groupBox1.Controls.Add(this.numericUpDown5);
this.groupBox1.Controls.Add(this.checkBoxFillWidth);
this.groupBox1.Controls.Add(this.label10);
this.groupBox1.Controls.Add(this.numericUpDown2);
this.groupBox1.Controls.Add(this.label11);
this.groupBox1.Controls.Add(this.numericUpDown3);
this.groupBox1.Location = new System.Drawing.Point(340, 20);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(178, 206);
this.groupBox1.TabIndex = 48;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Drawing";
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(17, 50);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(56, 13);
this.label10.TabIndex = 17;
this.label10.Text = "Margin left";
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(88, 96);
this.numericUpDown2.Location = new System.Drawing.Point(93, 73);
this.numericUpDown2.Maximum = new decimal(new int[] {
360,
0,
@ -223,71 +577,138 @@ namespace Nikse.SubtitleEdit.Forms.Assa
-2147483648});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(52, 20);
this.numericUpDown2.TabIndex = 24;
this.numericUpDown2.TabIndex = 20;
//
// comboBoxProgressBarEdge
// label11
//
this.comboBoxProgressBarEdge.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxProgressBarEdge.FormattingEnabled = true;
this.comboBoxProgressBarEdge.Items.AddRange(new object[] {
"Square corners",
"Rounded corners"});
this.comboBoxProgressBarEdge.Location = new System.Drawing.Point(217, 19);
this.comboBoxProgressBarEdge.Name = "comboBoxProgressBarEdge";
this.comboBoxProgressBarEdge.Size = new System.Drawing.Size(188, 21);
this.comboBoxProgressBarEdge.TabIndex = 26;
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(17, 75);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(62, 13);
this.label11.TabIndex = 19;
this.label11.Text = "Margin right";
//
// labelEdgeStyle
// numericUpDown3
//
this.labelEdgeStyle.AutoSize = true;
this.labelEdgeStyle.Location = new System.Drawing.Point(181, 22);
this.labelEdgeStyle.Name = "labelEdgeStyle";
this.labelEdgeStyle.Size = new System.Drawing.Size(30, 13);
this.labelEdgeStyle.TabIndex = 25;
this.labelEdgeStyle.Text = "Style";
this.numericUpDown3.Location = new System.Drawing.Point(93, 48);
this.numericUpDown3.Maximum = new decimal(new int[] {
360,
0,
0,
0});
this.numericUpDown3.Minimum = new decimal(new int[] {
360,
0,
0,
-2147483648});
this.numericUpDown3.Name = "numericUpDown3";
this.numericUpDown3.Size = new System.Drawing.Size(52, 20);
this.numericUpDown3.TabIndex = 18;
//
// labelPreviewPleaseWait
// checkBoxFillWidth
//
this.labelPreviewPleaseWait.AutoSize = true;
this.labelPreviewPleaseWait.Location = new System.Drawing.Point(857, 35);
this.labelPreviewPleaseWait.Name = "labelPreviewPleaseWait";
this.labelPreviewPleaseWait.Size = new System.Drawing.Size(70, 13);
this.labelPreviewPleaseWait.TabIndex = 28;
this.labelPreviewPleaseWait.Text = "Please wait...";
this.checkBoxFillWidth.AutoSize = true;
this.checkBoxFillWidth.Location = new System.Drawing.Point(7, 22);
this.checkBoxFillWidth.Name = "checkBoxFillWidth";
this.checkBoxFillWidth.Size = new System.Drawing.Size(66, 17);
this.checkBoxFillWidth.TabIndex = 34;
this.checkBoxFillWidth.Text = "Fill width";
this.checkBoxFillWidth.UseVisualStyleBackColor = true;
//
// buttonPreview
// checkBoxFillHeight
//
this.buttonPreview.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.buttonPreview.Location = new System.Drawing.Point(860, 9);
this.buttonPreview.Name = "buttonPreview";
this.buttonPreview.Size = new System.Drawing.Size(101, 23);
this.buttonPreview.TabIndex = 27;
this.buttonPreview.Text = "Preview";
this.buttonPreview.UseVisualStyleBackColor = true;
this.buttonPreview.Click += new System.EventHandler(this.buttonPreview_Click);
this.checkBoxFillHeight.AutoSize = true;
this.checkBoxFillHeight.Location = new System.Drawing.Point(6, 116);
this.checkBoxFillHeight.Name = "checkBoxFillHeight";
this.checkBoxFillHeight.Size = new System.Drawing.Size(70, 17);
this.checkBoxFillHeight.TabIndex = 39;
this.checkBoxFillHeight.Text = "Fill height";
this.checkBoxFillHeight.UseVisualStyleBackColor = true;
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(16, 144);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(57, 13);
this.label9.TabIndex = 35;
this.label9.Text = "Margin top";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(92, 167);
this.numericUpDown1.Maximum = new decimal(new int[] {
360,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
360,
0,
0,
-2147483648});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(52, 20);
this.numericUpDown1.TabIndex = 38;
//
// label12
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(16, 169);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(74, 13);
this.label12.TabIndex = 37;
this.label12.Text = "Margin bottom";
//
// numericUpDown5
//
this.numericUpDown5.Location = new System.Drawing.Point(92, 142);
this.numericUpDown5.Maximum = new decimal(new int[] {
360,
0,
0,
0});
this.numericUpDown5.Minimum = new decimal(new int[] {
360,
0,
0,
-2147483648});
this.numericUpDown5.Name = "numericUpDown5";
this.numericUpDown5.Size = new System.Drawing.Size(52, 20);
this.numericUpDown5.TabIndex = 36;
//
// AssSetBackground
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(973, 734);
this.Controls.Add(this.labelPreviewPleaseWait);
this.Controls.Add(this.buttonPreview);
this.Controls.Add(this.comboBoxProgressBarEdge);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label8);
this.Controls.Add(this.numericUpDownOutlineWidth);
this.Controls.Add(this.panelOutlineColor);
this.Controls.Add(this.buttonOutlineColor);
this.Controls.Add(this.label7);
this.Controls.Add(this.numericUpDownShadowWidth);
this.Controls.Add(this.panelShadowColor);
this.Controls.Add(this.buttonShadowColor);
this.Controls.Add(this.panelPrimaryColor);
this.Controls.Add(this.buttonPrimaryColor);
this.Controls.Add(this.label5);
this.Controls.Add(this.numericUpDownMarginRight);
this.Controls.Add(this.label3);
this.Controls.Add(this.label6);
this.Controls.Add(this.numericUpDownBoxLayer);
this.Controls.Add(this.numericUpDownMarginLeft);
this.Controls.Add(this.groupBoxDrawing);
this.Controls.Add(this.comboBoxBoxStyle);
this.Controls.Add(this.labelEdgeStyle);
this.Controls.Add(this.label1);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.numericUpDownMarginTop);
this.Controls.Add(this.label2);
this.Controls.Add(this.numericUpDown2);
this.Controls.Add(this.labelRotateX);
this.Controls.Add(this.labelInfo);
this.Controls.Add(this.numericUpDownRotateX);
this.Controls.Add(this.numericUpDownMarginBottom);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.labelRotateY);
this.Controls.Add(this.groupBoxPreview);
this.Controls.Add(this.numericUpDownRotateY);
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
@ -298,15 +719,30 @@ namespace Nikse.SubtitleEdit.Forms.Assa
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Generate background box";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ApplyCustomStyles_FormClosing);
this.Load += new System.EventHandler(this.AssSetBackground_Load);
this.Shown += new System.EventHandler(this.SetPosition_Shown);
this.ResizeEnd += new System.EventHandler(this.SetPosition_ResizeEnd);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ApplyCustomStyles_KeyDown);
this.groupBoxPreview.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPreview)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRotateX)).EndInit();
this.groupBoxDrawing.ResumeLayout(false);
this.groupBoxDrawing.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRotateY)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRotateX)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginBottom)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginTop)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownBoxLayer)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginRight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginLeft)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownShadowWidth)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownOutlineWidth)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -318,18 +754,46 @@ namespace Nikse.SubtitleEdit.Forms.Assa
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.PictureBox pictureBoxPreview;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label labelInfo;
private System.Windows.Forms.NumericUpDown numericUpDownRotateX;
private System.Windows.Forms.GroupBox groupBoxDrawing;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.NumericUpDown numericUpDown4;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label labelRotateX;
private System.Windows.Forms.NumericUpDown numericUpDownRotateY;
private System.Windows.Forms.Label labelRotateY;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.NumericUpDown numericUpDownRotateX;
private System.Windows.Forms.NumericUpDown numericUpDownMarginBottom;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.ComboBox comboBoxProgressBarEdge;
private System.Windows.Forms.NumericUpDown numericUpDownMarginTop;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label labelEdgeStyle;
private System.Windows.Forms.Label labelPreviewPleaseWait;
private System.Windows.Forms.Button buttonPreview;
private System.Windows.Forms.ComboBox comboBoxBoxStyle;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown numericUpDownBoxLayer;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.NumericUpDown numericUpDownMarginRight;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.NumericUpDown numericUpDownMarginLeft;
private System.Windows.Forms.Panel panelPrimaryColor;
private System.Windows.Forms.Button buttonPrimaryColor;
private System.Windows.Forms.Panel panelShadowColor;
private System.Windows.Forms.Button buttonShadowColor;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.NumericUpDown numericUpDownShadowWidth;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.NumericUpDown numericUpDownOutlineWidth;
private System.Windows.Forms.Panel panelOutlineColor;
private System.Windows.Forms.Button buttonOutlineColor;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.CheckBox checkBoxFillHeight;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.NumericUpDown numericUpDown5;
private System.Windows.Forms.CheckBox checkBoxFillWidth;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.NumericUpDown numericUpDown3;
}
}

View File

@ -24,17 +24,22 @@ namespace Nikse.SubtitleEdit.Forms.Assa
private string _mpvTextFileName;
private bool _closing;
private bool _videoLoaded;
private int _x = -1;
private int _y = -1;
private int _tempX;
private int _tempY;
private bool _updatePos = true;
private bool _updatePreview = true;
private readonly string _videoFileName;
private readonly VideoInfo _videoInfo;
private bool _positionChanged;
private bool _loading = true;
private static readonly Regex FrameFinderRegex = new Regex(@"[Ff]rame=\s*\d+", RegexOptions.Compiled);
private long _processedFrames;
private string _assaBox;
private int _top;
private int _bottom;
private int _left;
private int _right;
private Color _boxColor;
private Color _boxShadowColor;
private Color _boxOutlineColor;
public AssSetBackground(Subtitle subtitle, int[] selectedIndices, string videoFileName, VideoInfo videoInfo)
{
@ -56,13 +61,21 @@ namespace Nikse.SubtitleEdit.Forms.Assa
// Text = LanguageSettings.Current.AssaSetPosition.SetPosition;
groupBoxPreview.Text = LanguageSettings.Current.General.Preview;
comboBoxProgressBarEdge.Items.Clear();
comboBoxProgressBarEdge.Items.Add(LanguageSettings.Current.AssaProgressBarGenerator.SquareCorners);
comboBoxProgressBarEdge.Items.Add(LanguageSettings.Current.AssaProgressBarGenerator.RoundedCorners);
comboBoxBoxStyle.Items.Clear();
comboBoxBoxStyle.Items.Add(LanguageSettings.Current.AssaProgressBarGenerator.SquareCorners);
comboBoxBoxStyle.Items.Add(LanguageSettings.Current.AssaProgressBarGenerator.RoundedCorners);
buttonOK.Text = LanguageSettings.Current.General.Ok;
buttonCancel.Text = LanguageSettings.Current.General.Cancel;
comboBoxBoxStyle.SelectedIndex = 0;
panelPrimaryColor.BackColor = Color.Black;
_boxColor = panelPrimaryColor.BackColor;
panelOutlineColor.BackColor = Color.Gray;
_boxOutlineColor = panelOutlineColor.BackColor;
panelShadowColor.BackColor = Color.Black;
_boxShadowColor = panelShadowColor.BackColor;
UiUtil.FixLargeFonts(this, buttonOK);
@ -93,51 +106,9 @@ namespace Nikse.SubtitleEdit.Forms.Assa
private void buttonOK_Click(object sender, EventArgs e)
{
_subtitle.Header = _subtitleWithNewHeader.Header;
if (_positionChanged)
{
ApplyOverrideTags(_subtitle);
}
DialogResult = DialogResult.OK;
}
private void ApplyOverrideTags(Subtitle subtitle)
{
var styleToApply = $"{{\\pos({_x},{_y})}}";
UpdatedSubtitle = new Subtitle(subtitle, false);
var indices = GetIndices();
for (int i = 0; i < UpdatedSubtitle.Paragraphs.Count; i++)
{
if (!indices.Contains(i))
{
continue;
}
var p = UpdatedSubtitle.Paragraphs[i];
RemoveOldPosTags(p);
if (p.Text.StartsWith("{\\", StringComparison.Ordinal) && styleToApply.EndsWith('}'))
{
p.Text = styleToApply.TrimEnd('}') + p.Text.Remove(0, 1);
}
else
{
p.Text = styleToApply + p.Text;
}
}
}
private static void RemoveOldPosTags(Paragraph p)
{
p.Text = Regex.Replace(p.Text, @"{\\pos\([\d,\.-]*\)}", string.Empty);
p.Text = Regex.Replace(p.Text, @"\\pos\([\d,\.-]*\)", string.Empty);
}
private int[] GetIndices()
{
return _selectedIndices;
@ -223,14 +194,12 @@ namespace Nikse.SubtitleEdit.Forms.Assa
var format = new AdvancedSubStationAlpha();
var subtitle = new Subtitle();
var indices = GetIndices();
var styleToApply = $"{{\\pos({_x},{_y})}}";
var styleToApply = string.Empty; // $"{{\\pos({_x},{_y})}}";
var p = indices.Length > 0 ?
new Paragraph(_subtitleWithNewHeader.Paragraphs[indices[0]]) :
new Paragraph(Configuration.Settings.General.PreviewAssaText, 0, 1000);
RemoveOldPosTags(p);
// remove fade tags
p.Text = Regex.Replace(p.Text, @"{\\fad\([\d\.,]*\)}", string.Empty);
p.Text = Regex.Replace(p.Text, @"\\fad\([\d\.,]*\)", string.Empty);
@ -240,7 +209,40 @@ namespace Nikse.SubtitleEdit.Forms.Assa
p.Text = styleToApply + p.Text;
subtitle.Paragraphs.Add(p);
// box
//Build box + gen preview via mpv
_assaBox = GenerateBackgroundBox(
_left - (int)numericUpDownMarginLeft.Value,
_top - (int)numericUpDownMarginTop.Value,
_right + (int)numericUpDownMarginRight.Value,
_bottom + (int)numericUpDownMarginBottom.Value);
var p2 = new Paragraph(_assaBox?? string.Empty, 0, 1000);
p2.StartTime.TotalMilliseconds = p.StartTime.TotalMilliseconds;
p2.EndTime.TotalMilliseconds = p.EndTime.TotalMilliseconds;
p2.Layer = (int)numericUpDownBoxLayer.Value;
p2.Style = "SE-progress-bar-bg";
p2.Extra = "SE-progress-bar-bg";
subtitle.Paragraphs.Add(p2);
subtitle.Header = _subtitleWithNewHeader.Header ?? AdvancedSubStationAlpha.DefaultHeader;
var style = new SsaStyle
{
Alignment = "7",
Name = "SE-progress-bar-bg",
MarginLeft = 0,
MarginRight = 0,
MarginVertical = 0,
Primary = _boxColor,
Secondary = _boxShadowColor,
Tertiary = _boxShadowColor,
Background = _boxShadowColor,
Outline = _boxOutlineColor,
ShadowWidth = numericUpDownShadowWidth.Value,
OutlineWidth = numericUpDownOutlineWidth.Value,
};
subtitle.Header = AdvancedSubStationAlpha.UpdateOrAddStyle(subtitle.Header, style);
var text = subtitle.ToText(format);
_mpvTextFileName = FileUtil.GetTempFileName(format.Extension);
File.WriteAllText(_mpvTextFileName, text);
@ -257,8 +259,6 @@ namespace Nikse.SubtitleEdit.Forms.Assa
}
}
private void ApplyCustomStyles_FormClosing(object sender, FormClosingEventArgs e)
{
_closing = true;
@ -272,19 +272,15 @@ namespace Nikse.SubtitleEdit.Forms.Assa
return;
}
if (_updatePos && (_x != _tempX || _y != _tempY))
if (_updatePreview)
{
_x = _tempX;
_y = _tempY;
VideoLoaded(null, null);
_updatePreview = false;
}
}
private void SetPosition_Shown(object sender, EventArgs e)
{
ShowStyleAlignment();
ShowCurrentPosition();
var playResX = AdvancedSubStationAlpha.GetTagFromHeader("PlayResX", "[Script Info]", _subtitleWithNewHeader.Header);
var playResY = AdvancedSubStationAlpha.GetTagFromHeader("PlayResY", "[Script Info]", _subtitleWithNewHeader.Header);
if (string.IsNullOrEmpty(playResX) || string.IsNullOrEmpty(playResY))
@ -302,170 +298,14 @@ namespace Nikse.SubtitleEdit.Forms.Assa
}
}
buttonPreview_Click(null, null);
GeneratePreviewViaMpv();
_loading = false;
}
private void ShowCurrentPosition()
{
var indices = GetIndices();
if (indices.Length == 0)
{
return;
}
var p = _subtitleWithNewHeader.Paragraphs[indices[0]];
var match = Regex.Match(p.Text, @"\\pos\([\d\.,-]*");
if (match.Success)
{
var arr = match.Value.Split('(', ')', ',');
if (arr.Length > 2)
{
if (int.TryParse(arr[1], out var x) && int.TryParse(arr[2], out var y))
{
_x = x;
_y = y;
_updatePos = false;
// labelCurrentTextPosition.Text = string.Format(LanguageSettings.Current.AssaSetPosition.CurrentTextPositionX, $"{_x},{_y}");
}
}
}
match = Regex.Match(p.Text, @"\\frx[\d\.-]*");
if (match.Success)
{
var arr = match.Value.Split('x', '\\', '}');
if (arr.Length > 2)
{
if (decimal.TryParse(arr[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var x))
{
try
{
numericUpDownRotateX.Value = x;
}
catch
{
// ignore
}
}
}
}
match = Regex.Match(p.Text, @"\\fry[\d\.-]*");
if (match.Success)
{
var arr = match.Value.Split('y', '\\', '}');
if (arr.Length > 2)
{
if (decimal.TryParse(arr[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var x))
{
try
{
numericUpDownRotateY.Value = x;
}
catch
{
// ignore
}
}
}
}
match = Regex.Match(p.Text, @"\\frz[\d\.-]*");
if (match.Success)
{
var arr = match.Value.Split('z', '\\', '}');
if (arr.Length > 2)
{
if (decimal.TryParse(arr[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var x))
{
try
{
// numericUpDownRotateZ.Value = x;
}
catch
{
// ignore
}
}
}
}
match = Regex.Match(p.Text, @"\\fax[\d\.-]*");
if (match.Success)
{
var arr = match.Value.Split('x', '\\', '}');
if (arr.Length > 2)
{
if (decimal.TryParse(arr[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var x))
{
try
{
// numericUpDownDistortX.Value = x;
}
catch
{
// ignore
}
}
}
}
match = Regex.Match(p.Text, @"\\fay[\d\.-]*");
if (match.Success)
{
var arr = match.Value.Split('y', '\\', '}');
if (arr.Length > 2)
{
if (decimal.TryParse(arr[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var x))
{
try
{
// numericUpDownDistortY.Value = x;
}
catch
{
// ignore
}
}
}
}
}
private void ShowStyleAlignment()
{
var indices = GetIndices();
if (indices.Length == 0)
{
// labelStyleAlignment.Text = string.Format(LanguageSettings.Current.AssaSetPosition.StyleAlignmentX, "{\\an2}");
return;
}
var p = _subtitleWithNewHeader.Paragraphs[indices[0]];
var style = AdvancedSubStationAlpha.GetSsaStyle(p.Extra, _subtitleWithNewHeader.Header);
//.Text = string.Format(LanguageSettings.Current.AssaSetPosition.StyleAlignmentX, "{\\an" + style.Alignment + "} (" + p.Extra + ")");
}
private void pictureBoxPreview_Click(object sender, EventArgs e)
{
_x = _tempX;
_y = _tempY;
// labelCurrentTextPosition.Text = string.Format(LanguageSettings.Current.AssaSetPosition.CurrentTextPositionX, $"{_x},{_y}");
_updatePos = !_updatePos;
VideoLoaded(null, null);
_positionChanged = true;
}
private void pictureBoxPreview_MouseMove(object sender, MouseEventArgs e)
{
var xAspectRatio = (double)_videoInfo.Width / pictureBoxPreview.Width;
_tempX = (int)Math.Round(e.Location.X * xAspectRatio);
var yAspectRatio = (double)_videoInfo.Height / pictureBoxPreview.Height;
_tempY = (int)Math.Round(e.Location.Y * yAspectRatio);
// labelCurrentPosition.Text = string.Format(LanguageSettings.Current.AssaSetPosition.CurrentMousePositionX, $"{_tempX},{_tempY}");
}
private void SetPosition_ResizeEnd(object sender, EventArgs e)
@ -482,7 +322,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
return;
}
_positionChanged = true;
_updatePreview = true;
VideoLoaded(null, null);
}
@ -490,8 +330,6 @@ namespace Nikse.SubtitleEdit.Forms.Assa
{
try
{
buttonPreview.Enabled = false;
labelPreviewPleaseWait.Visible = true;
Cursor = Cursors.WaitCursor;
// generate blank video
@ -519,8 +357,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
sub.Paragraphs.Add(new Paragraph(GetPreviewParagraph()));
File.WriteAllText(assaTempFileName, new AdvancedSubStationAlpha().ToText(sub, string.Empty));
// hardcode subtitle
var outputVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".mp4");
// hard code subtitle
var outputVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".mp4");
process = GetFfmpegProcess(tempVideoFileName, outputVideoFileName, assaTempFileName);
process.Start();
process.BeginOutputReadLine();
@ -535,13 +373,13 @@ namespace Nikse.SubtitleEdit.Forms.Assa
var bmpFileName = VideoPreviewGenerator.GetScreenShot(outputVideoFileName, "00:00:01");
using (var bmp = new Bitmap(bmpFileName))
{
using (var form = new ExportPngXmlPreview(bmp))
{
form.AllowNext = false;
form.AllowPrevious = false;
labelPreviewPleaseWait.Visible = false;
form.ShowDialog(this);
}
var nBmp = new NikseBitmap(bmp);
_top = nBmp.CalcTopCropping(Color.Cyan);
_bottom = nBmp.Height - nBmp.CalcBottomCropping(Color.Cyan);
_left = nBmp.CalcLeftCropping(Color.Cyan);
_right = nBmp.Width - nBmp.CalcRightCropping(Color.Cyan);
_updatePreview = true;
}
try
@ -559,11 +397,21 @@ namespace Nikse.SubtitleEdit.Forms.Assa
finally
{
Cursor = Cursors.Default;
buttonPreview.Enabled = true;
labelPreviewPleaseWait.Visible = false;
}
}
private string GenerateBackgroundBox(int x, int y, int right, int bottom)
{
if (comboBoxBoxStyle.SelectedIndex == 1) // rounded corners
{
//var barEnd = x + width;
//return $@"{{m {x} {y} b {x} {y} {x} {height} {height} {height} l {barEnd} {height} b {width} {height} {width} {y} {barEnd} {y} l {barEnd} {y} {height} {y}{{\p0}}";
//m top-left - x top - right - x LINE top-right - y maxX height x left height
}
return $"{{\\p1}}m {x} {y} l {right} {y} {right} {bottom} {x} {bottom}{{\\p0}}";
}
private Paragraph GetPreviewParagraph()
{
var idx = _selectedIndices.Min();
@ -610,8 +458,6 @@ namespace Nikse.SubtitleEdit.Forms.Assa
return;
}
// _log?.AppendLine(outLine.Data);
var match = FrameFinderRegex.Match(outLine.Data);
if (!match.Success)
{
@ -629,5 +475,66 @@ namespace Nikse.SubtitleEdit.Forms.Assa
_processedFrames = f;
}
}
private void PreviewValueChanged(object sender, EventArgs e)
{
_updatePreview = true;
}
private void AssSetBackground_Load(object sender, EventArgs e)
{
}
private void buttonPrimaryColor_Click(object sender, EventArgs e)
{
var colorDialog = new ColorChooser();
colorDialog.Color = panelPrimaryColor.BackColor;
if (colorDialog.ShowDialog() == DialogResult.OK)
{
_boxColor = colorDialog.Color;
_updatePreview = true;
panelPrimaryColor.BackColor = colorDialog.Color;
}
}
private void panelPrimaryColor_MouseClick(object sender, MouseEventArgs e)
{
buttonPrimaryColor_Click(null, null);
}
private void buttonShadowColor_Click(object sender, EventArgs e)
{
var colorDialog = new ColorChooser();
colorDialog.Color = panelShadowColor.BackColor;
if (colorDialog.ShowDialog() == DialogResult.OK)
{
_boxShadowColor = colorDialog.Color;
_updatePreview = true;
panelShadowColor.BackColor = colorDialog.Color;
}
}
private void panelShadowColor_MouseClick(object sender, MouseEventArgs e)
{
buttonShadowColor_Click(null, null);
}
private void buttonOutlineColor_Click(object sender, EventArgs e)
{
var colorDialog = new ColorChooser();
colorDialog.Color = panelOutlineColor.BackColor;
if (colorDialog.ShowDialog() == DialogResult.OK)
{
_boxOutlineColor = colorDialog.Color;
_updatePreview = true;
panelOutlineColor.BackColor = colorDialog.Color;
}
}
private void panelOutlineColor_MouseClick(object sender, MouseEventArgs e)
{
buttonOutlineColor_Click(null, null);
}
}
}