From 4d20821d0e8b4ea08d5560969e8ff5801c11995d Mon Sep 17 00:00:00 2001 From: luvletter2333 Date: Thu, 17 Jun 2021 03:08:51 +0800 Subject: [PATCH] v1.0 --- Form1.Designer.cs | 196 +++++++++++- Form1.cs | 181 +++++++++-- Form1.resx | 719 ++++++++++++++++++++++++++++++++++++-------- NDI-SubTitle.config | 35 ++- NDIRender.cs | 15 +- RenderConfig.cs | 66 +++- Render_Form.cs | 24 +- 7 files changed, 1025 insertions(+), 211 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index b8a7e86..3abca46 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -74,6 +74,9 @@ private void InitializeComponent() this.label7 = new System.Windows.Forms.Label(); this.scroll_sub2Y = new System.Windows.Forms.HScrollBar(); this.panel_renderConfig = new System.Windows.Forms.GroupBox(); + this.txt_profileRemarks = new System.Windows.Forms.TextBox(); + this.label10 = new System.Windows.Forms.Label(); + this.label_currentFont = new System.Windows.Forms.Label(); this.txt_fadeTime = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); this.scroll_fadeTime = new System.Windows.Forms.HScrollBar(); @@ -85,11 +88,25 @@ private void InitializeComponent() this.txt_sub2X = new System.Windows.Forms.TextBox(); this.txt_sub1Y = new System.Windows.Forms.TextBox(); this.txt_sub1X = new System.Windows.Forms.TextBox(); - this.btn_saveConfig = new System.Windows.Forms.Button(); - this.btn_loadConfig = new System.Windows.Forms.Button(); + this.btn_savePreset1 = new System.Windows.Forms.Button(); + this.btn_loadPreset1 = new System.Windows.Forms.Button(); + this.btn_loadPreset2 = new System.Windows.Forms.Button(); + this.btn_savePreset2 = new System.Windows.Forms.Button(); + this.btn_loadPreset3 = new System.Windows.Forms.Button(); + this.btn_savePreset3 = new System.Windows.Forms.Button(); + this.btn_loadPreset4 = new System.Windows.Forms.Button(); + this.btn_savePreset4 = new System.Windows.Forms.Button(); + this.btn_loadPreset5 = new System.Windows.Forms.Button(); + this.btn_savePreset5 = new System.Windows.Forms.Button(); + this.btn_lockSavePreset = new System.Windows.Forms.Button(); + this.btn_lockLoadPreset = new System.Windows.Forms.Button(); + this.panel_presets = new System.Windows.Forms.GroupBox(); + this.label11 = new System.Windows.Forms.Label(); + this.label_presetRemarks = new System.Windows.Forms.Label(); this.gp_render_mode.SuspendLayout(); this.groupBox1.SuspendLayout(); this.panel_renderConfig.SuspendLayout(); + this.panel_presets.SuspendLayout(); this.SuspendLayout(); // // lb_program_file @@ -387,6 +404,9 @@ private void InitializeComponent() // panel_renderConfig // resources.ApplyResources(this.panel_renderConfig, "panel_renderConfig"); + this.panel_renderConfig.Controls.Add(this.txt_profileRemarks); + this.panel_renderConfig.Controls.Add(this.label10); + this.panel_renderConfig.Controls.Add(this.label_currentFont); this.panel_renderConfig.Controls.Add(this.txt_fadeTime); this.panel_renderConfig.Controls.Add(this.label9); this.panel_renderConfig.Controls.Add(this.scroll_fadeTime); @@ -411,6 +431,22 @@ private void InitializeComponent() this.panel_renderConfig.Name = "panel_renderConfig"; this.panel_renderConfig.TabStop = false; // + // txt_profileRemarks + // + resources.ApplyResources(this.txt_profileRemarks, "txt_profileRemarks"); + this.txt_profileRemarks.Name = "txt_profileRemarks"; + this.txt_profileRemarks.TextChanged += new System.EventHandler(this.txt_profileRemarks_TextChanged); + // + // label10 + // + resources.ApplyResources(this.label10, "label10"); + this.label10.Name = "label10"; + // + // label_currentFont + // + resources.ApplyResources(this.label_currentFont, "label_currentFont"); + this.label_currentFont.Name = "label_currentFont"; + // // txt_fadeTime // resources.ApplyResources(this.txt_fadeTime, "txt_fadeTime"); @@ -488,26 +524,137 @@ private void InitializeComponent() this.txt_sub1X.TextChanged += new System.EventHandler(this.txt_sub1X_TextChanged); this.txt_sub1X.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_NumberFilter); // - // btn_saveConfig + // btn_savePreset1 + // + this.btn_savePreset1.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_savePreset1, "btn_savePreset1"); + this.btn_savePreset1.Name = "btn_savePreset1"; + this.btn_savePreset1.UseVisualStyleBackColor = true; + this.btn_savePreset1.Click += new System.EventHandler(this.btn_savePreset_Click); + // + // btn_loadPreset1 + // + this.btn_loadPreset1.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_loadPreset1, "btn_loadPreset1"); + this.btn_loadPreset1.Name = "btn_loadPreset1"; + this.btn_loadPreset1.UseVisualStyleBackColor = true; + this.btn_loadPreset1.Click += new System.EventHandler(this.btn_loadPreset_Click); + // + // btn_loadPreset2 + // + this.btn_loadPreset2.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_loadPreset2, "btn_loadPreset2"); + this.btn_loadPreset2.Name = "btn_loadPreset2"; + this.btn_loadPreset2.UseVisualStyleBackColor = true; + this.btn_loadPreset2.Click += new System.EventHandler(this.btn_loadPreset_Click); + // + // btn_savePreset2 + // + this.btn_savePreset2.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_savePreset2, "btn_savePreset2"); + this.btn_savePreset2.Name = "btn_savePreset2"; + this.btn_savePreset2.UseVisualStyleBackColor = true; + this.btn_savePreset2.Click += new System.EventHandler(this.btn_savePreset_Click); + // + // btn_loadPreset3 + // + this.btn_loadPreset3.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_loadPreset3, "btn_loadPreset3"); + this.btn_loadPreset3.Name = "btn_loadPreset3"; + this.btn_loadPreset3.UseVisualStyleBackColor = true; + this.btn_loadPreset3.Click += new System.EventHandler(this.btn_loadPreset_Click); + // + // btn_savePreset3 + // + this.btn_savePreset3.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_savePreset3, "btn_savePreset3"); + this.btn_savePreset3.Name = "btn_savePreset3"; + this.btn_savePreset3.UseVisualStyleBackColor = true; + this.btn_savePreset3.Click += new System.EventHandler(this.btn_savePreset_Click); + // + // btn_loadPreset4 + // + this.btn_loadPreset4.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_loadPreset4, "btn_loadPreset4"); + this.btn_loadPreset4.Name = "btn_loadPreset4"; + this.btn_loadPreset4.UseVisualStyleBackColor = true; + this.btn_loadPreset4.Click += new System.EventHandler(this.btn_loadPreset_Click); + // + // btn_savePreset4 + // + this.btn_savePreset4.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_savePreset4, "btn_savePreset4"); + this.btn_savePreset4.Name = "btn_savePreset4"; + this.btn_savePreset4.UseVisualStyleBackColor = true; + this.btn_savePreset4.Click += new System.EventHandler(this.btn_savePreset_Click); + // + // btn_loadPreset5 + // + this.btn_loadPreset5.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_loadPreset5, "btn_loadPreset5"); + this.btn_loadPreset5.Name = "btn_loadPreset5"; + this.btn_loadPreset5.UseVisualStyleBackColor = true; + this.btn_loadPreset5.Click += new System.EventHandler(this.btn_loadPreset_Click); + // + // btn_savePreset5 + // + this.btn_savePreset5.ForeColor = System.Drawing.Color.Black; + resources.ApplyResources(this.btn_savePreset5, "btn_savePreset5"); + this.btn_savePreset5.Name = "btn_savePreset5"; + this.btn_savePreset5.UseVisualStyleBackColor = true; + this.btn_savePreset5.Click += new System.EventHandler(this.btn_savePreset_Click); + // + // btn_lockSavePreset + // + resources.ApplyResources(this.btn_lockSavePreset, "btn_lockSavePreset"); + this.btn_lockSavePreset.ForeColor = System.Drawing.Color.Red; + this.btn_lockSavePreset.Name = "btn_lockSavePreset"; + this.btn_lockSavePreset.UseVisualStyleBackColor = true; + this.btn_lockSavePreset.Click += new System.EventHandler(this.btn_lockSavePreset_Click); + // + // btn_lockLoadPreset + // + resources.ApplyResources(this.btn_lockLoadPreset, "btn_lockLoadPreset"); + this.btn_lockLoadPreset.ForeColor = System.Drawing.Color.Red; + this.btn_lockLoadPreset.Name = "btn_lockLoadPreset"; + this.btn_lockLoadPreset.UseVisualStyleBackColor = true; + this.btn_lockLoadPreset.Click += new System.EventHandler(this.btn_lockLoadPreset_Click); + // + // panel_presets + // + resources.ApplyResources(this.panel_presets, "panel_presets"); + this.panel_presets.Controls.Add(this.btn_loadPreset1); + this.panel_presets.Controls.Add(this.btn_savePreset5); + this.panel_presets.Controls.Add(this.btn_loadPreset5); + this.panel_presets.Controls.Add(this.btn_savePreset4); + this.panel_presets.Controls.Add(this.btn_savePreset1); + this.panel_presets.Controls.Add(this.btn_loadPreset3); + this.panel_presets.Controls.Add(this.btn_savePreset2); + this.panel_presets.Controls.Add(this.btn_loadPreset4); + this.panel_presets.Controls.Add(this.btn_savePreset3); + this.panel_presets.Controls.Add(this.btn_loadPreset2); + this.panel_presets.Name = "panel_presets"; + this.panel_presets.TabStop = false; // - resources.ApplyResources(this.btn_saveConfig, "btn_saveConfig"); - this.btn_saveConfig.ForeColor = System.Drawing.Color.Black; - this.btn_saveConfig.Name = "btn_saveConfig"; - this.btn_saveConfig.UseVisualStyleBackColor = true; + // label11 // - // btn_loadConfig + resources.ApplyResources(this.label11, "label11"); + this.label11.Name = "label11"; // - resources.ApplyResources(this.btn_loadConfig, "btn_loadConfig"); - this.btn_loadConfig.ForeColor = System.Drawing.Color.Black; - this.btn_loadConfig.Name = "btn_loadConfig"; - this.btn_loadConfig.UseVisualStyleBackColor = true; + // label_presetRemarks + // + resources.ApplyResources(this.label_presetRemarks, "label_presetRemarks"); + this.label_presetRemarks.Name = "label_presetRemarks"; // // Form1 // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.btn_loadConfig); - this.Controls.Add(this.btn_saveConfig); + this.Controls.Add(this.label_presetRemarks); + this.Controls.Add(this.label11); + this.Controls.Add(this.panel_presets); + this.Controls.Add(this.btn_lockLoadPreset); + this.Controls.Add(this.btn_lockSavePreset); this.Controls.Add(this.panel_renderConfig); this.Controls.Add(this.groupBox1); this.Controls.Add(this.gp_render_mode); @@ -544,6 +691,7 @@ private void InitializeComponent() this.groupBox1.PerformLayout(); this.panel_renderConfig.ResumeLayout(false); this.panel_renderConfig.PerformLayout(); + this.panel_presets.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -606,8 +754,24 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txt_fadeTime; private System.Windows.Forms.Label label9; private System.Windows.Forms.HScrollBar scroll_fadeTime; - private System.Windows.Forms.Button btn_saveConfig; - private System.Windows.Forms.Button btn_loadConfig; + private System.Windows.Forms.Button btn_savePreset1; + private System.Windows.Forms.Button btn_loadPreset1; + private System.Windows.Forms.Label label_currentFont; + private System.Windows.Forms.Button btn_loadPreset5; + private System.Windows.Forms.Button btn_savePreset5; + private System.Windows.Forms.Button btn_loadPreset4; + private System.Windows.Forms.Button btn_savePreset4; + private System.Windows.Forms.Button btn_loadPreset3; + private System.Windows.Forms.Button btn_savePreset3; + private System.Windows.Forms.Button btn_loadPreset2; + private System.Windows.Forms.Button btn_savePreset2; + private System.Windows.Forms.Button btn_lockSavePreset; + private System.Windows.Forms.Button btn_lockLoadPreset; + private System.Windows.Forms.TextBox txt_profileRemarks; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.GroupBox panel_presets; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.Label label_presetRemarks; } } diff --git a/Form1.cs b/Form1.cs index bc59a0c..4dc7f68 100644 --- a/Form1.cs +++ b/Form1.cs @@ -71,16 +71,7 @@ private void Form1_Load(object sender, EventArgs e) var config_path = Path.Combine(Directory.GetCurrentDirectory(), "NDI-SubTitle.config"); try { - JObject config; - config = JObject.Parse(File.ReadAllText(config_path)); - if (config.ContainsKey("NDI")) - renderConfig = RenderConfig.ReadNDIConfig(config["NDI"] as JObject); - else - renderConfig = new RenderConfig(true); - if (config.ContainsKey("Font-Size")) - renderConfig.fontSize = Convert.ToSingle(config["Font-Size"].ToString()); - else - renderConfig.fontSize = 50; + renderConfig = RenderConfig.ReadConfig(config_path); } catch (Exception ex) { @@ -91,11 +82,14 @@ private void Form1_Load(object sender, EventArgs e) } // set Value for UI scroll_fontSize.Value = (int)renderConfig.fontSize * 10; + txt_fontSize.Text = renderConfig.fontSize.ToString(); txt_sub1X.Text = (scroll_sub1X.Value = renderConfig.Point_Sub1.X).ToString(); txt_sub1Y.Text = (scroll_sub1Y.Value = renderConfig.Point_Sub1.Y).ToString(); txt_sub2X.Text = (scroll_sub2X.Value = renderConfig.Point_Sub2.X).ToString(); txt_sub2Y.Text = (scroll_sub2Y.Value = renderConfig.Point_Sub2.Y).ToString(); txt_fadeTime.Text = (scroll_fadeTime.Value = renderConfig.Fade_Time).ToString(); + label_presetRemarks.Text = renderConfig.Remarks; + txt_profileRemarks.Text = renderConfig.Remarks; const string DEBUG_LYRICS_FILENAME = "test-lyrics.txt"; string filePath = Path.Combine(Directory.GetCurrentDirectory(), DEBUG_LYRICS_FILENAME); if (File.Exists(filePath)) @@ -331,19 +325,13 @@ private void cmb_Fonts_SelectedIndexChanged(object sender, EventArgs e) collection.AddFontFile(filePath); fontFamily = new FontFamily(collection.Families[0].Name, collection); Console.WriteLine($"Change font to selected {fontFamily.Name} from path {filePath}"); - if (render_mode == RenderMode.FullScreen) - { - if (render_form != null) - render_form.ChangeFont(fontFamily); - } } } } ofd.Dispose(); - return; } - fontFamily = new FontFamily(cmb.SelectedItem.ToString()); - //Render_Font = new Font(new FontFamily(cmb.SelectedItem.ToString()), 50); + else + fontFamily = new FontFamily(cmb.SelectedItem.ToString()); if (render_mode == RenderMode.FullScreen) { if (render_form != null) @@ -351,6 +339,7 @@ private void cmb_Fonts_SelectedIndexChanged(object sender, EventArgs e) } else if (Renderer != null) Renderer.ChangeFont(fontFamily); + label_currentFont.Text = $"Current Font: {fontFamily.Name}"; } } @@ -361,7 +350,7 @@ private void btn_Lock_Font_Click(object sender, EventArgs e) // lock it panel_renderConfig.Enabled = false; btn_Lock_Font.ForeColor = Color.Green; - btn_Lock_Font.Text = "Locked"; + btn_Lock_Font.Text = "Render Control Panel - Locked"; } else { @@ -372,6 +361,14 @@ private void btn_Lock_Font_Click(object sender, EventArgs e) } } #endregion + private void btn_load_presets(object sender, EventArgs e) + { + + } + private void btn_save_presets(object sender, EventArgs e) + { + + } #region Change Buttons private void btn_Clear_Fade_Click(object sender = null, EventArgs e = null) @@ -508,7 +505,7 @@ private void btn_scnStart_Click(object sender, EventArgs e) { if (cmb_monitor.Enabled == false) //has locked { - render_form = new Render_Form(display_screen, scn_width, scn_height, new Font(new FontFamily(cmb_Fonts.SelectedItem.ToString()), renderConfig.fontSize), renderConfig); + render_form = new Render_Form(display_screen, scn_width, scn_height, new Font(fontFamily, renderConfig.fontSize), renderConfig); render_form.Run(50.0f, 50.0f); } else @@ -551,6 +548,10 @@ private void NotifyChanges() { if (render_form != null) render_form.onChanged(renderConfig); + } else + { + if (Renderer != null) + Renderer.onChanged(renderConfig); } } @@ -608,6 +609,7 @@ private void scroll_fadeTime_ValueChanged(object sender, EventArgs e) { renderConfig.Fade_Time = scroll_fadeTime.Value; txt_fadeTime.Text = scroll_fadeTime.Value.ToString(); + NotifyChanges(); } private void txt_sub1X_TextChanged(object sender, EventArgs e) @@ -636,7 +638,14 @@ private void txt_sub2Y_TextChanged(object sender, EventArgs e) private void txt_fontSize_TextChanged(object sender, EventArgs e) { - renderConfig.fontSize = Convert.ToSingle(txt_fontSize.Text); + try + { + renderConfig.fontSize = Convert.ToSingle(txt_fontSize.Text); + } + catch (Exception ex) + { + renderConfig.fontSize = 5.0f; + } scroll_fontSize.Value = (int) renderConfig.fontSize * 10; NotifyChanges(); } @@ -644,6 +653,55 @@ private void txt_fontSize_TextChanged(object sender, EventArgs e) private void txt_fadeTime_TextChanged(object sender, EventArgs e) { renderConfig.Fade_Time = scroll_fadeTime.Value = Convert.ToInt32(txt_fadeTime.Text); + NotifyChanges(); + } + + private void btn_lockSavePreset_Click(object sender, EventArgs e) + { + if (btn_savePreset1.Enabled) + { + btn_lockSavePreset.Text = "Save Preset - Locked"; + btn_lockSavePreset.ForeColor = Color.Green; + btn_savePreset1.Enabled = false; + btn_savePreset2.Enabled = false; + btn_savePreset3.Enabled = false; + btn_savePreset4.Enabled = false; + btn_savePreset5.Enabled = false; + } + else + { + btn_lockSavePreset.Text = "Lock Save Preset"; + btn_lockSavePreset.ForeColor = Color.Red; + btn_savePreset1.Enabled = true; + btn_savePreset2.Enabled = true; + btn_savePreset3.Enabled = true; + btn_savePreset4.Enabled = true; + btn_savePreset5.Enabled = true; + } + } + + private void btn_lockLoadPreset_Click(object sender, EventArgs e) + { + if (btn_loadPreset1.Enabled) + { + btn_lockLoadPreset.Text = "Load Preset - Locked"; + btn_lockLoadPreset.ForeColor = Color.Green; + btn_loadPreset1.Enabled = false; + btn_loadPreset2.Enabled = false; + btn_loadPreset3.Enabled = false; + btn_loadPreset4.Enabled = false; + btn_loadPreset5.Enabled = false; + } + else + { + btn_lockLoadPreset.Text = "Lock Load Preset"; + btn_lockLoadPreset.ForeColor = Color.Red; + btn_loadPreset1.Enabled = true; + btn_loadPreset2.Enabled = true; + btn_loadPreset3.Enabled = true; + btn_loadPreset4.Enabled = true; + btn_loadPreset5.Enabled = true; + } } // TODO: Add lock @@ -683,5 +741,86 @@ private void btn_lock_screen_Click(object sender, EventArgs e) } } + private void loadPreset(int number) + { + if (number < 1 || number > 5) + return; + var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"NDI-SubTitle{number}.config"); + + RenderConfig config = RenderConfig.ReadConfig(filePath); + + renderConfig.Point_Sub1.X = config.Point_Sub1.X; + renderConfig.Point_Sub1.Y = config.Point_Sub1.Y; + renderConfig.Point_Sub2.X = config.Point_Sub2.X; + renderConfig.Point_Sub2.Y = config.Point_Sub2.Y; + + renderConfig.Default_Color = config.Default_Color; + renderConfig.fontSize = config.fontSize; + renderConfig.Fade_Time = config.Fade_Time; + renderConfig.Remarks = config.Remarks; + + NotifyChanges(); + + scroll_fontSize.Value = (int)renderConfig.fontSize * 10; + txt_fontSize.Text = renderConfig.fontSize.ToString(); + txt_sub1X.Text = (scroll_sub1X.Value = renderConfig.Point_Sub1.X).ToString(); + txt_sub1Y.Text = (scroll_sub1Y.Value = renderConfig.Point_Sub1.Y).ToString(); + txt_sub2X.Text = (scroll_sub2X.Value = renderConfig.Point_Sub2.X).ToString(); + txt_sub2Y.Text = (scroll_sub2Y.Value = renderConfig.Point_Sub2.Y).ToString(); + txt_fadeTime.Text = (scroll_fadeTime.Value = renderConfig.Fade_Time).ToString(); + label_presetRemarks.Text = renderConfig.Remarks; + txt_profileRemarks.Text = renderConfig.Remarks; + + } + + private void savePreset(int number) + { + var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"NDI-SubTitle{number}.config"); + RenderConfig.SaveConfig(renderConfig, filePath); + } + + private void btn_loadPreset_Click(object sender, EventArgs e) + { + if (!(sender is Button)) + return; + var btn = (Button)sender; + if (!btn.Name.StartsWith("btn_loadPreset")) + return; + int number; + try + { + number = Convert.ToInt32(btn.Name.Replace("btn_loadPreset", "")); + } + catch(Exception ex) + { + return; + } + loadPreset(number); + } + + private void txt_profileRemarks_TextChanged(object sender, EventArgs e) + { + renderConfig.Remarks = txt_profileRemarks.Text; + } + + private void btn_savePreset_Click(object sender, EventArgs e) + { + if (!(sender is Button)) + return; + var btn = (Button)sender; + if (!btn.Name.StartsWith("btn_savePreset")) + return; + int number; + try + { + number = Convert.ToInt32(btn.Name.Replace("btn_savePreset", "")); + } + catch (Exception ex) + { + return; + } + savePreset(number); + } + } } diff --git a/Form1.resx b/Form1.resx index 220b7a0..ace940a 100644 --- a/Form1.resx +++ b/Form1.resx @@ -147,7 +147,7 @@ $this - 26 + 29 635, 81 @@ -171,7 +171,7 @@ $this - 25 + 28 754, 81 @@ -195,7 +195,7 @@ $this - 24 + 27 True @@ -225,7 +225,7 @@ $this - 23 + 26 True @@ -255,7 +255,7 @@ $this - 22 + 25 13, 113 @@ -279,7 +279,7 @@ $this - 21 + 24 204, 113 @@ -303,7 +303,7 @@ $this - 20 + 23 True @@ -333,7 +333,7 @@ $this - 19 + 22 @@ -367,7 +367,7 @@ $this - 18 + 21 True @@ -397,7 +397,7 @@ $this - 17 + 20 Top, Bottom, Left @@ -430,13 +430,13 @@ $this - 16 + 19 Bottom, Left - 1440, 565 + 1440, 561 159, 78 @@ -457,13 +457,13 @@ $this - 15 + 18 Bottom, Left - 1265, 565 + 1265, 561 159, 78 @@ -484,13 +484,13 @@ $this - 14 + 17 Bottom, Left - 1265, 657 + 1265, 653 159, 84 @@ -511,7 +511,7 @@ $this - 13 + 16 114, 113 @@ -535,7 +535,7 @@ $this - 12 + 15 Top, Bottom, Left @@ -547,7 +547,7 @@ 13, 163 - 283, 580 + 283, 562 17 @@ -562,7 +562,7 @@ $this - 11 + 14 Top, Bottom, Left @@ -580,7 +580,7 @@ True - 941, 580 + 941, 556 18 @@ -595,7 +595,7 @@ $this - 9 + 12 True @@ -625,7 +625,7 @@ $this - 8 + 11 True @@ -655,13 +655,13 @@ panel_renderConfig - 11 + 14 106, 274 - 545, 26 + 484, 26 23 @@ -676,16 +676,16 @@ panel_renderConfig - 10 + 13 Bottom, Left - 12, 1123 + 1264, 1026 - 247, 36 + 333, 36 24 @@ -703,13 +703,13 @@ $this - 10 + 13 Bottom, Left - 1440, 657 + 1440, 653 159, 84 @@ -730,7 +730,7 @@ $this - 7 + 10 NoControl @@ -961,7 +961,7 @@ $this - 5 + 8 NoControl @@ -988,7 +988,55 @@ $this - 6 + 9 + + + rdo_Render_FullScreen + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + gp_render_mode + + + 0 + + + rdo_Render_NDI + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + gp_render_mode + + + 1 + + + 635, 11 + + + 232, 63 + + + 38 + + + Render Mode + + + gp_render_mode + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 True @@ -1044,30 +1092,6 @@ 1 - - 635, 11 - - - 232, 63 - - - 38 - - - Render Mode - - - gp_render_mode - - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 4 - 873, 15 @@ -1090,7 +1114,7 @@ $this - 3 + 6 NoControl @@ -1099,7 +1123,7 @@ 101, 42 - 1359, 24 + 985, 24 0 @@ -1114,7 +1138,7 @@ panel_renderConfig - 15 + 18 True @@ -1144,7 +1168,7 @@ panel_renderConfig - 17 + 20 True @@ -1177,7 +1201,7 @@ panel_renderConfig - 20 + 23 NoControl @@ -1186,7 +1210,7 @@ 101, 91 - 1359, 24 + 985, 24 2 @@ -1201,7 +1225,7 @@ panel_renderConfig - 19 + 22 True @@ -1234,7 +1258,7 @@ panel_renderConfig - 16 + 19 NoControl @@ -1243,7 +1267,7 @@ 106, 140 - 1354, 24 + 980, 24 4 @@ -1258,7 +1282,7 @@ panel_renderConfig - 18 + 21 True @@ -1291,7 +1315,7 @@ panel_renderConfig - 13 + 16 NoControl @@ -1300,7 +1324,7 @@ 106, 188 - 1354, 24 + 980, 24 6 @@ -1315,13 +1339,97 @@ panel_renderConfig - 14 + 17 Bottom, Left + + 103, 368 + + + 2, 3, 2, 3 + + + 1103, 28 + + + 56 + + + txt_profileRemarks + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_renderConfig + + + 0 + + + True + + + 15, 368 + + + 80, 18 + + + 55 + + + Remarks: + + + label10 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_renderConfig + + + 1 + + + True + + + 宋体, 10pt + + + NoControl + + + 601, 275 + + + 139, 20 + + + 44 + + + Current Font: + + + label_currentFont + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_renderConfig + + + 2 + - 1474, 321 + 1123, 318 2, 3, 2, 3 @@ -1342,7 +1450,7 @@ panel_renderConfig - 0 + 3 True @@ -1375,7 +1483,7 @@ panel_renderConfig - 1 + 4 NoControl @@ -1384,7 +1492,7 @@ 145, 321 - 1315, 24 + 941, 24 24 @@ -1399,10 +1507,13 @@ panel_renderConfig - 2 + 5 + + + NoControl - 1308, 269 + 957, 266 249, 34 @@ -1423,10 +1534,10 @@ panel_renderConfig - 3 + 6 - 1474, 231 + 1123, 228 2, 3, 2, 3 @@ -1447,7 +1558,7 @@ panel_renderConfig - 4 + 7 True @@ -1480,7 +1591,7 @@ panel_renderConfig - 5 + 8 NoControl @@ -1489,7 +1600,7 @@ 106, 232 - 1354, 24 + 980, 24 12 @@ -1504,10 +1615,10 @@ panel_renderConfig - 6 + 9 - 1474, 188 + 1123, 185 2, 3, 2, 3 @@ -1528,10 +1639,10 @@ panel_renderConfig - 7 + 10 - 1474, 140 + 1123, 137 2, 3, 2, 3 @@ -1552,10 +1663,10 @@ panel_renderConfig - 8 + 11 - 1474, 91 + 1123, 88 2, 3, 2, 3 @@ -1576,10 +1687,10 @@ panel_renderConfig - 9 + 12 - 1474, 42 + 1123, 39 2, 3, 2, 3 @@ -1600,10 +1711,10 @@ panel_renderConfig - 12 + 15 - 13, 755 + 11, 745 2, 3, 2, 3 @@ -1612,7 +1723,7 @@ 2, 3, 2, 3 - 1586, 362 + 1233, 416 41 @@ -1630,66 +1741,426 @@ $this + 5 + + + NoControl + + + 174, 29 + + + 142, 36 + + + 42 + + + Save Preset 1 + + + btn_savePreset1 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 4 + + + NoControl + + + 11, 29 + + + 147, 36 + + + 43 + + + Load Preset 1 + + + btn_loadPreset1 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 0 + + + NoControl + + + 11, 77 + + + 147, 36 + + + 46 + + + Load Preset 2 + + + btn_loadPreset2 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 9 + + + NoControl + + + 174, 77 + + + 142, 36 + + + 45 + + + Save Preset 2 + + + btn_savePreset2 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 6 + + + NoControl + + + 11, 127 + + + 147, 36 + + + 48 + + + Load Preset 3 + + + btn_loadPreset3 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 5 + + + NoControl + + + 174, 127 + + + 142, 36 + + + 47 + + + Save Preset 3 + + + btn_savePreset3 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 8 + + + NoControl + + + 11, 174 + + + 147, 36 + + + 50 + + + Load Preset 4 + + + btn_loadPreset4 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 7 + + + NoControl + + + 174, 174 + + + 142, 36 + + + 49 + + + Save Preset 4 + + + btn_savePreset4 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 3 + + + NoControl + + + 11, 219 + + + 147, 36 + + + 52 + + + Load Preset 5 + + + btn_loadPreset5 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + 2 - + + NoControl + + + 174, 219 + + + 142, 36 + + + 51 + + + Save Preset 5 + + + MiddleRight + + + btn_savePreset5 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel_presets + + + 1 + + Bottom, Left - + NoControl - - 265, 1123 + + 1265, 1068 - - 126, 36 + + 332, 36 - - 42 + + 53 - - Save Config + + Lock Save Preset - - btn_saveConfig + + btn_lockSavePreset - + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - - 1 + + 4 - + Bottom, Left - + NoControl - - 397, 1123 + + 1266, 1113 - - 126, 36 + + 331, 36 - - 43 + + 54 - - Load Config + + Lock Load Preset - - btn_loadConfig + + btn_lockLoadPreset - + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + $this + + + 3 + + + Bottom, Left + + + 1265, 756 + + + 332, 264 + + + 55 + + + Presets + + + panel_presets + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + True + + + 宋体, 13pt + + + 1264, 15 + + + 207, 26 + + + 56 + + + Preset Remarks: + + + label11 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + 宋体, 10pt + + + 1269, 55 + + + 149, 20 + + + 57 + + + Default Preset + + + label_presetRemarks + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + $this - + 0 @@ -1699,7 +2170,7 @@ 9, 18 - 1619, 1172 + 1617, 1180 Form1 diff --git a/NDI-SubTitle.config b/NDI-SubTitle.config index a5b3140..44c5502 100644 --- a/NDI-SubTitle.config +++ b/NDI-SubTitle.config @@ -1,21 +1,20 @@ { - "NDI":{ - "NDI_width":1920, - "NDI_height":180, - "frameRateNumerator":50, - "frameRateDenominator":1, - "Point1_X":145, - "Point1_Y":871, - "Point2_X":145, - "Point2_Y":943, - "Color_Name":"White", - "Color":{ - "alpha":255, - "red":255, - "green":255, - "blue":255 - }, - "Fade_Time":500 + + "Width":1920, + "Height":1080, + "frameRateNumerator":50, + "frameRateDenominator":1, + "Point1_X":145, + "Point1_Y":871, + "Point2_X":145, + "Point2_Y":943, + "Color":{ + "alpha":255, + "red":255, + "green":255, + "blue":255 }, - "Font-Size":30 + "Fade_Time":500, + "Font_Size":25, + "Remarks":"debug preset" } \ No newline at end of file diff --git a/NDIRender.cs b/NDIRender.cs index 6afddae..b5a4222 100644 --- a/NDIRender.cs +++ b/NDIRender.cs @@ -29,14 +29,14 @@ public class NDIRender private SubTitle fading; private bool isFading; private int Fading_X; - private readonly int delta_X; + private int delta_X; - private RenderConfig config; + private RenderConfig Config; public NDIRender(CancellationToken cancellationToken, RenderConfig config, FontFamily fontFamily) { this.cancellationToken = cancellationToken; - this.config = config; + this.Config = config; // We are going to create a 1920x180 frame at 50p, progressive (default). this.videoFrame = new VideoFrame(config.Width, config.Height, config.aspectRatio, config.frameRateNumerator, config.frameRateDenominator); @@ -91,7 +91,7 @@ public void Fade(SubTitle sub) public void ChangeFont(FontFamily fontFamily) { lock (syncLock) - font = new Font(fontFamily, config.fontSize); + font = new Font(fontFamily, Config.fontSize); } private void DrawFrame() @@ -178,5 +178,12 @@ public async Task Run() return 0; } // Main } + + internal void onChanged(RenderConfig config) + { + lock (syncLock) + font = new Font(font.FontFamily, config.fontSize); + delta_X = Alpha_Max / ((Config.frameRateNumerator / Config.frameRateDenominator) * config.Fade_Time / 1000); + } } } \ No newline at end of file diff --git a/RenderConfig.cs b/RenderConfig.cs index c4c82fe..d7526ae 100644 --- a/RenderConfig.cs +++ b/RenderConfig.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -24,45 +25,53 @@ public class RenderConfig public float fontSize; public int Fade_Time; //ms + public string Remarks; + public RenderConfig(bool is_default = false) { if (is_default) { Width = 1920; - Height = 180; + Height = 1080; aspectRatio = Convert.ToSingle(Width) / Convert.ToSingle(Height); frameRateNumerator = 50; frameRateDenominator = 1; - Point_Sub1 = new Point(90, 20); - Point_Sub2 = new Point(90, 90); - fontSize = 25.0f; + Point_Sub1 = new Point(145, 871); + Point_Sub2 = new Point(145, 943); + fontSize = 30.0f; Default_Color = Color.White; Fade_Time = 500; + + Remarks = "default preset"; } } - public static RenderConfig ReadNDIConfig(JObject jo) + public static RenderConfig ReadConfig(String path) { try { + var jo = JObject.Parse(File.ReadAllText(path)); + RenderConfig config = new RenderConfig(); - config.Width = Convert.ToInt32(jo["NDI_width"].ToString()); - config.Height = Convert.ToInt32(jo["NDI_height"].ToString()); + config.Width = Convert.ToInt32(jo["Width"].ToString()); + config.Height = Convert.ToInt32(jo["Height"].ToString()); config.aspectRatio = Convert.ToSingle(config.Width) / Convert.ToSingle(config.Height); config.frameRateNumerator = Convert.ToInt32(jo["frameRateNumerator"].ToString()); config.frameRateDenominator = Convert.ToInt32(jo["frameRateDenominator"].ToString()); config.Point_Sub1 = new Point(Convert.ToInt32(jo["Point1_X"].ToString()), Convert.ToInt32(jo["Point1_Y"].ToString())); config.Point_Sub2 = new Point(Convert.ToInt32(jo["Point2_X"].ToString()), Convert.ToInt32(jo["Point2_Y"].ToString())); - if (jo.ContainsKey("Color_Name")) - config.Default_Color = Color.FromName(jo["Color_Name"].ToString()); - else - config.Default_Color = Color.FromArgb(Convert.ToInt32(jo["Color"]["alpha"].ToString()), + config.Default_Color = Color.FromArgb(Convert.ToInt32(jo["Color"]["alpha"].ToString()), Convert.ToInt32(jo["Color"]["red"].ToString()), Convert.ToInt32(jo["Color"]["green"].ToString()), Convert.ToInt32(jo["Color"]["blue"].ToString())); config.Fade_Time = Convert.ToInt32(jo["Fade_Time"].ToString()); + config.Remarks = jo["Remarks"].ToString(); + if (jo.ContainsKey("Font_Size")) + config.fontSize = Convert.ToSingle(jo["Font_Size"]); + else + config.fontSize = 50; return config; } catch (Exception e) @@ -71,5 +80,40 @@ public static RenderConfig ReadNDIConfig(JObject jo) return new RenderConfig(true);//Return Default Setting } } + + public static void SaveConfig(RenderConfig config, string filePath) + { + try + { + var writer = new StreamWriter(filePath); + JObject jo = new JObject(); + jo["Width"] = config.Width; + jo["Height"] = config.Height; + jo["frameRateNumerator"] = config.frameRateNumerator; + jo["frameRateDenominator"] = config.frameRateDenominator; + + jo["Point1_X"] = config.Point_Sub1.X; + jo["Point1_Y"] = config.Point_Sub1.Y; + jo["Point2_X"] = config.Point_Sub2.X; + jo["Point2_Y"] = config.Point_Sub2.Y; + + jo["Color"] = new JObject(); + jo["Color"]["red"] = config.Default_Color.R; + jo["Color"]["green"] = config.Default_Color.G; + jo["Color"]["blue"] = config.Default_Color.B; + jo["Color"]["alpha"] = config.Default_Color.A; + + jo["Fade_Time"] = config.Fade_Time; + jo["Remarks"] = config.Remarks; + jo["Font_Size"] = config.fontSize; + writer.WriteLine(jo.ToString()); + writer.Flush(); + writer.Close(); + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + } } } diff --git a/Render_Form.cs b/Render_Form.cs index 81b9f7a..bdaf32c 100644 --- a/Render_Form.cs +++ b/Render_Form.cs @@ -44,24 +44,14 @@ public Render_Form(DisplayDevice dd, int _width, int _height, Font font, RenderC isFading = false; // For delta_X, We plus delta_X into alpha // Fade Effect will last for 500ms - // So every frame it will change 255/(50frames/2steps) = 10 - delta_X = Alpha_Max / (config.frameRateNumerator / config.frameRateDenominator) * 2; + // So every frame it will change 255/( ) = 10 + delta_X = Alpha_Max / ((config.frameRateNumerator / config.frameRateDenominator) * config.Fade_Time / 1000); // If Fading_X < Alpha_Max / 2 ,it's the former part (from program to empty) // If Fading_X >= Alpha_Max / 2 ,it's the latter part (from empty to fading ) // If Fading_X >= Alpha_Max ,it means fade ends (set program as fading) Fading_X = 0; - - solidBrushes = new List(); - int alpha = Alpha_Min; - for (; alpha < Alpha_Max; alpha += delta_X) - { - solidBrushes.Add(new SolidBrush(Color.FromArgb(alpha, config.Default_Color))); - } - if (alpha > Alpha_Max) - solidBrushes.Add(new SolidBrush(Color.FromArgb(Alpha_Max, config.Default_Color))); - } private int height; @@ -84,9 +74,7 @@ public Render_Form(DisplayDevice dd, int _width, int _height, Font font, RenderC private SubTitle fading; private bool isFading; private int Fading_X; - private readonly int delta_X; - private List solidBrushes; - private int fadeBrushIndex = 0; + private int delta_X; private bool isChange = false; @@ -127,6 +115,8 @@ public void onChanged(RenderConfig config) { lock (syncLock) font = new Font(font.FontFamily, config.fontSize); + delta_X = Alpha_Max / ((Config.frameRateNumerator / Config.frameRateDenominator) * config.Fade_Time / 1000); + isChange = true; } @@ -178,7 +168,7 @@ private void GenerateBmp() int alpha = Alpha_Max - Fading_X * 2; if (alpha < 0) alpha = 0; - var brush = new SolidBrush(Color.FromArgb(alpha, Color.White)); + var brush = new SolidBrush(Color.FromArgb(alpha, Config.Default_Color)); graphics.DrawString(program.First_Sub, font, brush, Config.Point_Sub1); graphics.DrawString(program.Second_Sub, font, brush, Config.Point_Sub2); } @@ -190,7 +180,7 @@ private void GenerateBmp() int alpha = Fading_X * 2 - Alpha_Max; if (alpha > 255) alpha = 255; - var brush = new SolidBrush(Color.FromArgb(alpha, Color.White)); + var brush = new SolidBrush(Color.FromArgb(alpha, Config.Default_Color)); graphics.DrawString(fading.First_Sub, font, brush, Config.Point_Sub1); graphics.DrawString(fading.Second_Sub, font, brush, Config.Point_Sub2); }