mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Fix assa background box issue - thx Érico :)
Showing multiple different boxes at the same time should now work
This commit is contained in:
parent
6fe7502fe7
commit
efb5d225fc
@ -46,6 +46,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
private bool _loading = true;
|
||||
private string _assaBox;
|
||||
private readonly Random _random = new Random();
|
||||
private string _boxStyleName;
|
||||
private int _top;
|
||||
private int _bottom;
|
||||
private int _left;
|
||||
@ -55,6 +56,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
private Color _boxOutlineColor;
|
||||
private long _totalFrames;
|
||||
private FileSystemWatcher _drawingFileWatcher;
|
||||
private readonly Subtitle _wholeSubtitle;
|
||||
|
||||
public AssSetBackground(Subtitle subtitle, int[] selectedIndices, string videoFileName, VideoInfo videoInfo, double videoPositionSeconds)
|
||||
{
|
||||
@ -65,6 +67,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
_videoFileName = videoFileName;
|
||||
_videoInfo = videoInfo;
|
||||
_videoPositionSeconds = videoPositionSeconds;
|
||||
_wholeSubtitle = subtitle;
|
||||
|
||||
_subtitleWithNewHeader = new Subtitle(subtitle, false);
|
||||
if (string.IsNullOrWhiteSpace(_subtitleWithNewHeader.Header))
|
||||
@ -213,6 +216,15 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
buttonAssaDraw.Visible = File.Exists(Path.Combine(Configuration.PluginsDirectory, "AssaDraw.dll"));
|
||||
progressBar1.Visible = false;
|
||||
labelProgress.Text = string.Empty;
|
||||
|
||||
var tryCount = 0;
|
||||
_boxStyleName = "SE-box-bg";
|
||||
var styleNames = AdvancedSubStationAlpha.GetStylesFromHeader(subtitle.Header);
|
||||
while (styleNames.Any(p => p == _boxStyleName) && tryCount < 100)
|
||||
{
|
||||
_boxStyleName = $"SE-box-bg{_random.Next(1234)}";
|
||||
tryCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SafeNumericUpDownAssign(NumericUpDown numericUpDown, int value)
|
||||
@ -292,8 +304,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
|
||||
var p2 = new Paragraph(_assaBox ?? string.Empty, p.StartTime.TotalMilliseconds, p.EndTime.TotalMilliseconds)
|
||||
{
|
||||
Layer = Configuration.Settings.Tools.AssaBgBoxLayer,
|
||||
Extra = "SE-box-bg"
|
||||
Layer = GetLayer(),
|
||||
Extra = _boxStyleName,
|
||||
};
|
||||
|
||||
if (!checkBoxOnlyDrawing.Checked)
|
||||
@ -308,6 +320,19 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private int GetLayer()
|
||||
{
|
||||
var layer = Configuration.Settings.Tools.AssaBgBoxLayer;
|
||||
var tryCount = 0;
|
||||
while (_wholeSubtitle.Paragraphs.Any(p => p.Layer == layer) && tryCount < 100)
|
||||
{
|
||||
layer = Configuration.Settings.Tools.AssaBgBoxLayer - _random.Next(8421);
|
||||
tryCount++;
|
||||
}
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
private void AddBgBoxStyles(Subtitle subtitle)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(subtitle.Header))
|
||||
@ -338,7 +363,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
var styleBoxBg = new SsaStyle
|
||||
{
|
||||
Alignment = "7",
|
||||
Name = "SE-box-bg",
|
||||
Name = _boxStyleName,
|
||||
MarginLeft = 0,
|
||||
MarginRight = 0,
|
||||
MarginVertical = 0,
|
||||
@ -482,8 +507,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
{
|
||||
StartTime = { TotalMilliseconds = p.StartTime.TotalMilliseconds },
|
||||
EndTime = { TotalMilliseconds = p.EndTime.TotalMilliseconds },
|
||||
Layer = Configuration.Settings.Tools.AssaBgBoxLayer,
|
||||
Extra = "SE-box-bg"
|
||||
Layer = GetLayer(),
|
||||
Extra = _boxStyleName,
|
||||
};
|
||||
|
||||
if (!checkBoxOnlyDrawing.Checked)
|
||||
@ -1388,7 +1413,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
|
||||
{
|
||||
ColorChooser.SetLastColor(buttonPickColor.BackColor);
|
||||
pictureBoxPreview_MouseLeave(null, null);
|
||||
labelProgress.Text = string.Format(LanguageSettings.Current.AssaSetBackgroundBox.ColorPickerSetLastColor , Utilities.ColorToHexWithTransparency(buttonPickColor.BackColor));
|
||||
labelProgress.Text = string.Format(LanguageSettings.Current.AssaSetBackgroundBox.ColorPickerSetLastColor, Utilities.ColorToHexWithTransparency(buttonPickColor.BackColor));
|
||||
System.Threading.SynchronizationContext.Current.Post(TimeSpan.FromMilliseconds(3500), () =>
|
||||
{
|
||||
labelProgress.Text = _videoText;
|
||||
|
Loading…
Reference in New Issue
Block a user