From 59ea9a9c1105716e096f1d66037f26df97f11031 Mon Sep 17 00:00:00 2001 From: luvletter2333 Date: Sun, 16 May 2021 03:50:13 +0800 Subject: [PATCH] add scrollbar --- Form1.Designer.cs | 144 +++++++++++++++ Form1.cs | 59 +++++- Form1.resx | 448 +++++++++++++++++++++++++++++++++++++++++++--- RenderConfig.cs | 2 + Render_Form.cs | 30 ++-- 5 files changed, 637 insertions(+), 46 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index bb1c498..7431c92 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -65,8 +65,25 @@ private void InitializeComponent() this.rdo_Render_FullScreen = new System.Windows.Forms.RadioButton(); this.rdo_Render_NDI = new System.Windows.Forms.RadioButton(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.scroll_sub1X = new System.Windows.Forms.HScrollBar(); + this.label2 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.scroll_sub1Y = new System.Windows.Forms.HScrollBar(); + this.label6 = new System.Windows.Forms.Label(); + this.scroll_sub2X = new System.Windows.Forms.HScrollBar(); + this.label7 = new System.Windows.Forms.Label(); + this.scroll_sub2Y = new System.Windows.Forms.HScrollBar(); + this.group_Config = new System.Windows.Forms.GroupBox(); + this.txt_fontSize = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.scroll_fontSize = new System.Windows.Forms.HScrollBar(); + this.txt_sub2Y = new System.Windows.Forms.TextBox(); + 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.gp_render_mode.SuspendLayout(); this.groupBox1.SuspendLayout(); + this.group_Config.SuspendLayout(); this.SuspendLayout(); // // lb_program_file @@ -311,10 +328,119 @@ private void InitializeComponent() this.groupBox1.Name = "groupBox1"; this.groupBox1.TabStop = false; // + // scroll_sub1X + // + resources.ApplyResources(this.scroll_sub1X, "scroll_sub1X"); + this.scroll_sub1X.Maximum = 1920; + this.scroll_sub1X.Name = "scroll_sub1X"; + this.scroll_sub1X.Scroll += new System.Windows.Forms.ScrollEventHandler(this.scroll_sub1X_Scroll); + // + // label2 + // + resources.ApplyResources(this.label2, "label2"); + this.label2.Name = "label2"; + // + // label5 + // + resources.ApplyResources(this.label5, "label5"); + this.label5.Name = "label5"; + // + // scroll_sub1Y + // + resources.ApplyResources(this.scroll_sub1Y, "scroll_sub1Y"); + this.scroll_sub1Y.Maximum = 1080; + this.scroll_sub1Y.Name = "scroll_sub1Y"; + this.scroll_sub1Y.Scroll += new System.Windows.Forms.ScrollEventHandler(this.scroll_sub1Y_Scroll); + // + // label6 + // + resources.ApplyResources(this.label6, "label6"); + this.label6.Name = "label6"; + // + // scroll_sub2X + // + resources.ApplyResources(this.scroll_sub2X, "scroll_sub2X"); + this.scroll_sub2X.Maximum = 1920; + this.scroll_sub2X.Name = "scroll_sub2X"; + this.scroll_sub2X.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hScrollBar3_Scroll); + // + // label7 + // + resources.ApplyResources(this.label7, "label7"); + this.label7.Name = "label7"; + // + // scroll_sub2Y + // + resources.ApplyResources(this.scroll_sub2Y, "scroll_sub2Y"); + this.scroll_sub2Y.Maximum = 1080; + this.scroll_sub2Y.Name = "scroll_sub2Y"; + this.scroll_sub2Y.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hScrollBar4_Scroll); + // + // group_Config + // + this.group_Config.Controls.Add(this.txt_fontSize); + this.group_Config.Controls.Add(this.label8); + this.group_Config.Controls.Add(this.scroll_fontSize); + this.group_Config.Controls.Add(this.txt_sub2Y); + this.group_Config.Controls.Add(this.txt_sub2X); + this.group_Config.Controls.Add(this.txt_sub1Y); + this.group_Config.Controls.Add(this.txt_sub1X); + this.group_Config.Controls.Add(this.label7); + this.group_Config.Controls.Add(this.scroll_sub2Y); + this.group_Config.Controls.Add(this.scroll_sub1X); + this.group_Config.Controls.Add(this.label6); + this.group_Config.Controls.Add(this.label2); + this.group_Config.Controls.Add(this.scroll_sub2X); + this.group_Config.Controls.Add(this.scroll_sub1Y); + this.group_Config.Controls.Add(this.label5); + resources.ApplyResources(this.group_Config, "group_Config"); + this.group_Config.Name = "group_Config"; + this.group_Config.TabStop = false; + // + // txt_fontSize + // + resources.ApplyResources(this.txt_fontSize, "txt_fontSize"); + this.txt_fontSize.Name = "txt_fontSize"; + // + // label8 + // + resources.ApplyResources(this.label8, "label8"); + this.label8.Name = "label8"; + // + // scroll_fontSize + // + resources.ApplyResources(this.scroll_fontSize, "scroll_fontSize"); + this.scroll_fontSize.Maximum = 500; + this.scroll_fontSize.Minimum = 10; + this.scroll_fontSize.Name = "scroll_fontSize"; + this.scroll_fontSize.Value = 10; + this.scroll_fontSize.Scroll += new System.Windows.Forms.ScrollEventHandler(this.scroll_fontSize_Scroll); + // + // txt_sub2Y + // + resources.ApplyResources(this.txt_sub2Y, "txt_sub2Y"); + this.txt_sub2Y.Name = "txt_sub2Y"; + // + // txt_sub2X + // + resources.ApplyResources(this.txt_sub2X, "txt_sub2X"); + this.txt_sub2X.Name = "txt_sub2X"; + // + // txt_sub1Y + // + resources.ApplyResources(this.txt_sub1Y, "txt_sub1Y"); + this.txt_sub1Y.Name = "txt_sub1Y"; + // + // txt_sub1X + // + resources.ApplyResources(this.txt_sub1X, "txt_sub1X"); + this.txt_sub1X.Name = "txt_sub1X"; + // // Form1 // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.group_Config); this.Controls.Add(this.groupBox1); this.Controls.Add(this.gp_render_mode); this.Controls.Add(this.btn_ScnStop); @@ -349,6 +475,8 @@ private void InitializeComponent() this.gp_render_mode.PerformLayout(); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); + this.group_Config.ResumeLayout(false); + this.group_Config.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -391,6 +519,22 @@ private void InitializeComponent() private System.Windows.Forms.RadioButton rdo_Render_FullScreen; private System.Windows.Forms.RadioButton rdo_Render_NDI; private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.HScrollBar scroll_sub1X; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.HScrollBar scroll_sub2Y; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.HScrollBar scroll_sub2X; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.HScrollBar scroll_sub1Y; + private System.Windows.Forms.GroupBox group_Config; + private System.Windows.Forms.TextBox txt_sub2Y; + private System.Windows.Forms.TextBox txt_sub2X; + private System.Windows.Forms.TextBox txt_sub1Y; + private System.Windows.Forms.TextBox txt_sub1X; + private System.Windows.Forms.TextBox txt_fontSize; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.HScrollBar scroll_fontSize; } } diff --git a/Form1.cs b/Form1.cs index cb3f199..0f1bdb5 100644 --- a/Form1.cs +++ b/Form1.cs @@ -41,7 +41,6 @@ enum RenderMode RenderConfig NDI_Config; NDIRender Renderer; CancellationTokenSource cancelNDI; - float Font_Size; //Screen Output @@ -74,17 +73,19 @@ private void Form1_Load(object sender, EventArgs e) else NDI_Config = new RenderConfig(true); if (Config.ContainsKey("Font-Size")) - Font_Size = Convert.ToSingle(Config["Font-Size"].ToString()); + NDI_Config.fontSize = Convert.ToSingle(Config["Font-Size"].ToString()); else - Font_Size = 50; + NDI_Config.fontSize = 50; } catch (Exception ex) { Console.WriteLine("Reading Config File Failed"); Console.WriteLine(ex.ToString()); NDI_Config = new RenderConfig(true); - Font_Size = 50; + NDI_Config.fontSize = 50; } + scroll_fontSize.Value = (int)NDI_Config.fontSize; + } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { @@ -159,7 +160,7 @@ private void btn_start_Click(object sender, EventArgs e) if (Renderer != null) return; cancelNDI = new CancellationTokenSource(); - Renderer = new NDIRender(cancelNDI.Token, NDI_Config, new Font(new FontFamily(cmb_Fonts.SelectedItem.ToString()), Font_Size)); + Renderer = new NDIRender(cancelNDI.Token, NDI_Config, new Font(new FontFamily(cmb_Fonts.SelectedItem.ToString()), NDI_Config.fontSize)); Task.Run(async () => await Renderer.Run()); lb_Status.ForeColor = Color.Green; lb_Status.Text = "NDI On"; @@ -269,10 +270,10 @@ private void cmb_Fonts_SelectedIndexChanged(object sender, EventArgs e) if (render_mode == RenderMode.FullScreen) { if (render_form != null) - render_form.ChangeFont(new Font(new FontFamily(cmb.SelectedItem.ToString()), Font_Size)); + render_form.ChangeFont(new FontFamily(cmb.SelectedItem.ToString())); } else if (Renderer != null) - Renderer.ChangeFont(new Font(new FontFamily(cmb.SelectedItem.ToString()), Font_Size)); + Renderer.ChangeFont(new Font(new FontFamily(cmb.SelectedItem.ToString()), NDI_Config.fontSize)); } } @@ -430,7 +431,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()), Font_Size), NDI_Config); + render_form = new Render_Form(display_screen, scn_width, scn_height, new Font(new FontFamily(cmb_Fonts.SelectedItem.ToString()), NDI_Config.fontSize), NDI_Config); render_form.Run(50.0f, 50.0f); } else @@ -467,6 +468,45 @@ private void rdo_Render_FullScreen_CheckedChanged(object sender, EventArgs e) } + private void scroll_sub1X_Scroll(object sender, ScrollEventArgs e) + { + NDI_Config.Point_Sub1.X = e.NewValue; + txt_sub1X.Text = e.NewValue + ""; NotifyChanges(); + } + + private void scroll_sub1Y_Scroll(object sender, ScrollEventArgs e) + { + NDI_Config.Point_Sub1.Y = e.NewValue; + txt_sub1Y.Text = e.NewValue + ""; NotifyChanges(); + } + private void hScrollBar3_Scroll(object sender, ScrollEventArgs e) + { + NDI_Config.Point_Sub2.X = e.NewValue; + txt_sub2X.Text = e.NewValue + ""; NotifyChanges(); + } + + private void hScrollBar4_Scroll(object sender, ScrollEventArgs e) + { + NDI_Config.Point_Sub2.Y = e.NewValue; + txt_sub2Y.Text = e.NewValue + ""; NotifyChanges(); + } + + private void NotifyChanges() + { + if (render_mode == RenderMode.FullScreen) + { + if (render_form != null) + render_form.onChanged(NDI_Config); + } + } + + private void scroll_fontSize_Scroll(object sender, ScrollEventArgs e) + { + NDI_Config.fontSize = e.NewValue / 10.0f; + txt_fontSize.Text = e.NewValue / 10.0f + ""; + NotifyChanges(); + } + // TODO: Add lock private void btn_lock_screen_Click(object sender, EventArgs e) { @@ -480,6 +520,9 @@ private void btn_lock_screen_Click(object sender, EventArgs e) display_screen = DisplayDevice.GetDisplay((DisplayIndex)id); scn_height = Convert.ToInt32(txt_screen_height.Text); scn_width = Convert.ToInt32(txt_screen_width.Text); + scroll_sub1X.Maximum = scroll_sub2X.Maximum = scn_height; + scroll_sub1Y.Maximum = scroll_sub2Y.Maximum = scn_width; + cmb_monitor.Enabled = false; btn_lock_screen.Text = "Locked"; btn_lock_screen.ForeColor = Color.Green; diff --git a/Form1.resx b/Form1.resx index b22f95b..504ba69 100644 --- a/Form1.resx +++ b/Form1.resx @@ -151,7 +151,7 @@ $this - 25 + 26 776, 94 @@ -178,7 +178,7 @@ $this - 24 + 25 921, 94 @@ -205,7 +205,7 @@ $this - 23 + 24 True @@ -238,7 +238,7 @@ $this - 22 + 23 True @@ -271,7 +271,7 @@ $this - 21 + 22 16, 132 @@ -298,7 +298,7 @@ $this - 20 + 21 249, 132 @@ -325,7 +325,7 @@ $this - 19 + 20 True @@ -358,7 +358,7 @@ $this - 18 + 19 True @@ -391,7 +391,7 @@ $this - 17 + 18 True @@ -424,7 +424,7 @@ $this - 16 + 17 True @@ -457,7 +457,7 @@ $this - 15 + 16 1760, 659 @@ -484,7 +484,7 @@ $this - 14 + 15 1546, 659 @@ -511,7 +511,7 @@ $this - 13 + 14 1546, 766 @@ -538,7 +538,7 @@ $this - 12 + 13 139, 132 @@ -565,7 +565,7 @@ $this - 11 + 12 21 @@ -592,7 +592,7 @@ $this - 10 + 11 宋体, 12pt @@ -625,7 +625,7 @@ $this - 9 + 10 True @@ -655,7 +655,7 @@ $this - 8 + 9 True @@ -688,7 +688,7 @@ $this - 7 + 8 210, 90 @@ -712,7 +712,7 @@ $this - 6 + 7 613, 83 @@ -739,7 +739,7 @@ $this - 5 + 6 1760, 766 @@ -766,7 +766,7 @@ $this - 4 + 5 NoControl @@ -1024,7 +1024,7 @@ $this - 2 + 3 NoControl @@ -1054,7 +1054,7 @@ $this - 3 + 4 True @@ -1144,7 +1144,7 @@ $this - 1 + 2 1067, 17 @@ -1174,6 +1174,402 @@ $this + 1 + + + NoControl + + + 123, 81 + + + 661, 24 + + + 0 + + + scroll_sub1X + + + System.Windows.Forms.HScrollBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 9 + + + True + + + 44, 81 + + + 76, 21 + + + 1 + + + Sub1 X + + + label2 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 11 + + + True + + + NoControl + + + 44, 138 + + + 76, 21 + + + 3 + + + Sub1 Y + + + label5 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 14 + + + NoControl + + + 123, 138 + + + 661, 24 + + + 2 + + + scroll_sub1Y + + + System.Windows.Forms.HScrollBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 13 + + + True + + + NoControl + + + 44, 195 + + + 76, 21 + + + 5 + + + Sub2 X + + + label6 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 10 + + + NoControl + + + 129, 195 + + + 661, 24 + + + 4 + + + scroll_sub2X + + + System.Windows.Forms.HScrollBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 12 + + + True + + + NoControl + + + 44, 251 + + + 76, 21 + + + 7 + + + Sub2 Y + + + label7 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 7 + + + NoControl + + + 129, 251 + + + 661, 24 + + + 6 + + + scroll_sub2Y + + + System.Windows.Forms.HScrollBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 8 + + + 809, 298 + + + 100, 31 + + + 14 + + + txt_fontSize + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 0 + + + True + + + NoControl + + + 11, 301 + + + 109, 21 + + + 13 + + + Font Size + + + label8 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 1 + + + NoControl + + + 129, 301 + + + 661, 24 + + + 12 + + + scroll_fontSize + + + System.Windows.Forms.HScrollBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 2 + + + 809, 248 + + + 100, 31 + + + 11 + + + txt_sub2Y + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 3 + + + 809, 192 + + + 100, 31 + + + 10 + + + txt_sub2X + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 4 + + + 809, 135 + + + 100, 31 + + + 9 + + + txt_sub1Y + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 5 + + + 809, 78 + + + 100, 31 + + + 8 + + + txt_sub1X + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + group_Config + + + 6 + + + 16, 881 + + + 1059, 424 + + + 41 + + + Render Config + + + group_Config + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 @@ -1183,7 +1579,7 @@ 11, 21 - 1979, 879 + 1979, 1317 4, 3, 4, 3 diff --git a/RenderConfig.cs b/RenderConfig.cs index 1001293..c4c82fe 100644 --- a/RenderConfig.cs +++ b/RenderConfig.cs @@ -21,6 +21,7 @@ public class RenderConfig public Point Point_Sub1; public Point Point_Sub2; public Color Default_Color; + public float fontSize; public int Fade_Time; //ms public RenderConfig(bool is_default = false) @@ -35,6 +36,7 @@ public RenderConfig(bool is_default = false) Point_Sub1 = new Point(90, 20); Point_Sub2 = new Point(90, 90); + fontSize = 25.0f; Default_Color = Color.White; Fade_Time = 500; } diff --git a/Render_Form.cs b/Render_Form.cs index e3d91d0..7ad8ffe 100644 --- a/Render_Form.cs +++ b/Render_Form.cs @@ -30,8 +30,6 @@ public Render_Form(DisplayDevice dd, int _width, int _height, Font font, RenderC // Render Initial program = SubTitle.Empty; fading = SubTitle.Empty; - Point_Sub1 = config.Point_Sub1; - Point_Sub2 = config.Point_Sub2; // Style defaultBrush = new SolidBrush(config.Default_Color); @@ -83,8 +81,6 @@ public Render_Form(DisplayDevice dd, int _width, int _height, Font font, RenderC private Font font; private SolidBrush defaultBrush; - private Point Point_Sub1; - private Point Point_Sub2; private SubTitle program; private SubTitle fading; @@ -121,10 +117,20 @@ public void Fade(SubTitle sub) } } - public void ChangeFont(Font font) + public void ChangeFont(FontFamily font) { lock (syncLock) - this.font = font; + this.font = new Font(font, Config.fontSize); + isChange = true; + } + + public void onChanged(RenderConfig config) + { + lock (syncLock) + { + font = new Font(font.FontFamily, config.fontSize); + isChange = true; + } } private void GenerateBmp() @@ -135,8 +141,8 @@ private void GenerateBmp() if (!isFading) { - graphics.DrawString(program.First_Sub, font, defaultBrush, Point_Sub1); - graphics.DrawString(program.Second_Sub, font, defaultBrush, Point_Sub2); + graphics.DrawString(program.First_Sub, font, defaultBrush, Config.Point_Sub1); + graphics.DrawString(program.Second_Sub, font, defaultBrush, Config.Point_Sub2); } else { @@ -176,8 +182,8 @@ private void GenerateBmp() if (alpha < 0) alpha = 0; var brush = new SolidBrush(Color.FromArgb(alpha, Color.White)); - graphics.DrawString(program.First_Sub, font, brush, Point_Sub1); - graphics.DrawString(program.Second_Sub, font, brush, Point_Sub2); + graphics.DrawString(program.First_Sub, font, brush, Config.Point_Sub1); + graphics.DrawString(program.Second_Sub, font, brush, Config.Point_Sub2); } else if (Fading_X >= Alpha_Max / 2) { @@ -188,8 +194,8 @@ private void GenerateBmp() if (alpha > 255) alpha = 255; var brush = new SolidBrush(Color.FromArgb(alpha, Color.White)); - graphics.DrawString(fading.First_Sub, font, brush, Point_Sub1); - graphics.DrawString(fading.Second_Sub, font, brush, Point_Sub2); + graphics.DrawString(fading.First_Sub, font, brush, Config.Point_Sub1); + graphics.DrawString(fading.Second_Sub, font, brush, Config.Point_Sub2); } Fading_X += delta_X; }