From 3febcd3f1cae299030ebe6061d9cbea0d5f77e44 Mon Sep 17 00:00:00 2001 From: Luv Letter Date: Sun, 8 Dec 2019 01:18:39 +0800 Subject: [PATCH 1/2] build FullScreen with openTK --- Form1.Designer.cs | 283 ++++++------ Form1.cs | 104 ++++- Form1.resx | 1011 +++++++++++++++++++++++++++++++++++++++++++ NDIRender.cs | 2 +- Ndi-SubTitle.csproj | 5 + OpenTK.dll.config | 25 ++ Render_Form.cs | 101 +++++ packages.config | 1 + 8 files changed, 1404 insertions(+), 128 deletions(-) create mode 100644 OpenTK.dll.config create mode 100644 Render_Form.cs diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 8faa9d1..70b02bf 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -28,6 +28,7 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.lb_program_file = new System.Windows.Forms.Label(); this.btn_start = new System.Windows.Forms.Button(); this.btn_stop = new System.Windows.Forms.Button(); @@ -50,163 +51,112 @@ private void InitializeComponent() this.cmb_Fonts = new System.Windows.Forms.ComboBox(); this.btn_Lock_Font = new System.Windows.Forms.Button(); this.btn_Clear_Fade = new System.Windows.Forms.Button(); + this.btn_refresh_monitor = new System.Windows.Forms.Button(); + this.cmb_monitor = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.btn_lock_screen = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.txt_screen_width = new System.Windows.Forms.TextBox(); + this.txt_screen_height = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.btn_ScnStop = new System.Windows.Forms.Button(); + this.btn_scnStart = new System.Windows.Forms.Button(); + this.gp_render_mode = new System.Windows.Forms.GroupBox(); + this.rdo_Render_NDI = new System.Windows.Forms.RadioButton(); + this.rdo_Render_FullScreen = new System.Windows.Forms.RadioButton(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.gp_render_mode.SuspendLayout(); + this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // lb_program_file // - this.lb_program_file.AutoSize = true; - this.lb_program_file.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lb_program_file.Location = new System.Drawing.Point(12, 12); + resources.ApplyResources(this.lb_program_file, "lb_program_file"); this.lb_program_file.Name = "lb_program_file"; - this.lb_program_file.Size = new System.Drawing.Size(143, 17); - this.lb_program_file.TabIndex = 2; - this.lb_program_file.Text = "Loaded File : "; // // btn_start // - this.btn_start.Location = new System.Drawing.Point(1113, 16); - this.btn_start.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_start, "btn_start"); this.btn_start.Name = "btn_start"; - this.btn_start.Size = new System.Drawing.Size(141, 65); - this.btn_start.TabIndex = 3; - this.btn_start.Text = "Start"; this.btn_start.UseVisualStyleBackColor = true; this.btn_start.Click += new System.EventHandler(this.btn_start_Click); // // btn_stop // - this.btn_stop.Location = new System.Drawing.Point(1281, 16); - this.btn_stop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_stop, "btn_stop"); this.btn_stop.Name = "btn_stop"; - this.btn_stop.Size = new System.Drawing.Size(141, 65); - this.btn_stop.TabIndex = 4; - this.btn_stop.Text = "Stop"; this.btn_stop.UseVisualStyleBackColor = true; this.btn_stop.Click += new System.EventHandler(this.btn_stop_Click); // // lable_text // - this.lable_text.AutoSize = true; - this.lable_text.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lable_text.Location = new System.Drawing.Point(269, 98); + resources.ApplyResources(this.lable_text, "lable_text"); this.lable_text.Name = "lable_text"; - this.lable_text.Size = new System.Drawing.Size(106, 24); - this.lable_text.TabIndex = 5; - this.lable_text.Text = "Status: "; // // lb_selected_file // - this.lb_selected_file.AutoSize = true; - this.lb_selected_file.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lb_selected_file.Location = new System.Drawing.Point(12, 39); + resources.ApplyResources(this.lb_selected_file, "lb_selected_file"); this.lb_selected_file.Name = "lb_selected_file"; - this.lb_selected_file.Size = new System.Drawing.Size(134, 17); - this.lb_selected_file.TabIndex = 6; - this.lb_selected_file.Text = "Selected File:"; // // btn_import // - this.btn_import.Location = new System.Drawing.Point(12, 94); - this.btn_import.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_import, "btn_import"); this.btn_import.Name = "btn_import"; - this.btn_import.Size = new System.Drawing.Size(83, 36); - this.btn_import.TabIndex = 7; - this.btn_import.Text = "Import"; this.btn_import.UseVisualStyleBackColor = true; this.btn_import.Click += new System.EventHandler(this.btn_import_Click); // // btn_Load // - this.btn_Load.Location = new System.Drawing.Point(181, 94); - this.btn_Load.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_Load, "btn_Load"); this.btn_Load.Name = "btn_Load"; - this.btn_Load.Size = new System.Drawing.Size(83, 36); - this.btn_Load.TabIndex = 8; - this.btn_Load.Text = "Load"; this.btn_Load.UseVisualStyleBackColor = true; this.btn_Load.Click += new System.EventHandler(this.btn_Load_Click); // // lb_pre_id // - this.lb_pre_id.AutoSize = true; - this.lb_pre_id.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lb_pre_id.Location = new System.Drawing.Point(1119, 268); + resources.ApplyResources(this.lb_pre_id, "lb_pre_id"); this.lb_pre_id.Name = "lb_pre_id"; - this.lb_pre_id.Size = new System.Drawing.Size(103, 25); - this.lb_pre_id.TabIndex = 9; - this.lb_pre_id.Text = "Preview"; // // lb_pgm_id // - this.lb_pgm_id.AutoSize = true; - this.lb_pgm_id.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lb_pgm_id.Location = new System.Drawing.Point(1119, 118); + resources.ApplyResources(this.lb_pgm_id, "lb_pgm_id"); this.lb_pgm_id.Name = "lb_pgm_id"; - this.lb_pgm_id.Size = new System.Drawing.Size(103, 25); - this.lb_pgm_id.TabIndex = 10; - this.lb_pgm_id.Text = "Program"; // // lb_preview // - this.lb_preview.AutoSize = true; - this.lb_preview.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lb_preview.Location = new System.Drawing.Point(1120, 309); + resources.ApplyResources(this.lb_preview, "lb_preview"); this.lb_preview.Name = "lb_preview"; - this.lb_preview.Size = new System.Drawing.Size(179, 20); - this.lb_preview.TabIndex = 11; - this.lb_preview.Text = "Sub Title Preview"; // // lb_program // - this.lb_program.AutoSize = true; - this.lb_program.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lb_program.Location = new System.Drawing.Point(1119, 159); + resources.ApplyResources(this.lb_program, "lb_program"); this.lb_program.Name = "lb_program"; - this.lb_program.Size = new System.Drawing.Size(179, 20); - this.lb_program.TabIndex = 12; - this.lb_program.Text = "Sub Title Program"; // // btn_fade // - this.btn_fade.Location = new System.Drawing.Point(1281, 445); - this.btn_fade.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_fade, "btn_fade"); this.btn_fade.Name = "btn_fade"; - this.btn_fade.Size = new System.Drawing.Size(141, 65); - this.btn_fade.TabIndex = 13; - this.btn_fade.Text = "Fade (Space)"; this.btn_fade.UseVisualStyleBackColor = true; this.btn_fade.Click += new System.EventHandler(this.btn_fade_Click); // // btn_Hard // - this.btn_Hard.Location = new System.Drawing.Point(1113, 445); - this.btn_Hard.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_Hard, "btn_Hard"); this.btn_Hard.Name = "btn_Hard"; - this.btn_Hard.Size = new System.Drawing.Size(141, 65); - this.btn_Hard.TabIndex = 14; - this.btn_Hard.Text = "Cut (Enter)"; this.btn_Hard.UseVisualStyleBackColor = true; this.btn_Hard.Click += new System.EventHandler(this.btn_Hard_Click); // // btn_Clear_Cut // - this.btn_Clear_Cut.Location = new System.Drawing.Point(1113, 521); - this.btn_Clear_Cut.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_Clear_Cut, "btn_Clear_Cut"); this.btn_Clear_Cut.Name = "btn_Clear_Cut"; - this.btn_Clear_Cut.Size = new System.Drawing.Size(141, 70); - this.btn_Clear_Cut.TabIndex = 15; - this.btn_Clear_Cut.Text = "Clear (Ctrl+Enter)"; this.btn_Clear_Cut.UseVisualStyleBackColor = true; this.btn_Clear_Cut.Click += new System.EventHandler(this.btn_Clear_Click); // // btn_DeleteFile // - this.btn_DeleteFile.Location = new System.Drawing.Point(101, 94); - this.btn_DeleteFile.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_DeleteFile, "btn_DeleteFile"); this.btn_DeleteFile.Name = "btn_DeleteFile"; - this.btn_DeleteFile.Size = new System.Drawing.Size(75, 36); - this.btn_DeleteFile.TabIndex = 16; - this.btn_DeleteFile.Text = "Delete"; this.btn_DeleteFile.UseVisualStyleBackColor = true; this.btn_DeleteFile.Click += new System.EventHandler(this.btn_DeleteFile_Click); // @@ -214,89 +164,160 @@ private void InitializeComponent() // this.lst_File.AllowDrop = true; this.lst_File.FormattingEnabled = true; - this.lst_File.ItemHeight = 15; - this.lst_File.Location = new System.Drawing.Point(12, 136); - this.lst_File.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.lst_File, "lst_File"); this.lst_File.Name = "lst_File"; - this.lst_File.Size = new System.Drawing.Size(252, 484); - this.lst_File.TabIndex = 17; this.lst_File.SelectedIndexChanged += new System.EventHandler(this.lst_File_SelectedIndexChanged); this.lst_File.DragDrop += new System.Windows.Forms.DragEventHandler(this.Lst_File_DragDrop); this.lst_File.DragEnter += new System.Windows.Forms.DragEventHandler(this.Lst_File_DragEnter); // // lst_SubTitle // - this.lst_SubTitle.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + resources.ApplyResources(this.lst_SubTitle, "lst_SubTitle"); this.lst_SubTitle.ForeColor = System.Drawing.Color.Black; this.lst_SubTitle.FormattingEnabled = true; - this.lst_SubTitle.ItemHeight = 20; - this.lst_SubTitle.Location = new System.Drawing.Point(269, 136); - this.lst_SubTitle.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.lst_SubTitle.Name = "lst_SubTitle"; - this.lst_SubTitle.ScrollAlwaysVisible = true; - this.lst_SubTitle.Size = new System.Drawing.Size(837, 484); - this.lst_SubTitle.TabIndex = 18; this.lst_SubTitle.SelectedIndexChanged += new System.EventHandler(this.lst_SubTitle_SelectedIndexChanged); // // lb_Status // - this.lb_Status.AutoSize = true; + resources.ApplyResources(this.lb_Status, "lb_Status"); this.lb_Status.ForeColor = System.Drawing.Color.Red; - this.lb_Status.Location = new System.Drawing.Point(367, 105); this.lb_Status.Name = "lb_Status"; - this.lb_Status.Size = new System.Drawing.Size(63, 15); - this.lb_Status.TabIndex = 20; - this.lb_Status.Text = "NDI Off"; // // lb_Font // - this.lb_Font.AutoSize = true; - this.lb_Font.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lb_Font.Location = new System.Drawing.Point(12, 64); + resources.ApplyResources(this.lb_Font, "lb_Font"); this.lb_Font.Name = "lb_Font"; - this.lb_Font.Size = new System.Drawing.Size(134, 17); - this.lb_Font.TabIndex = 22; - this.lb_Font.Text = "Font File :"; // // cmb_Fonts // this.cmb_Fonts.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmb_Fonts.FormattingEnabled = true; - this.cmb_Fonts.Location = new System.Drawing.Point(153, 64); - this.cmb_Fonts.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.cmb_Fonts, "cmb_Fonts"); this.cmb_Fonts.Name = "cmb_Fonts"; - this.cmb_Fonts.Size = new System.Drawing.Size(287, 23); - this.cmb_Fonts.TabIndex = 23; this.cmb_Fonts.SelectedIndexChanged += new System.EventHandler(this.cmb_Fonts_SelectedIndexChanged); // // btn_Lock_Font // this.btn_Lock_Font.ForeColor = System.Drawing.Color.Red; - this.btn_Lock_Font.Location = new System.Drawing.Point(445, 59); - this.btn_Lock_Font.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_Lock_Font, "btn_Lock_Font"); this.btn_Lock_Font.Name = "btn_Lock_Font"; - this.btn_Lock_Font.Size = new System.Drawing.Size(97, 30); - this.btn_Lock_Font.TabIndex = 24; - this.btn_Lock_Font.Text = "UnLock"; this.btn_Lock_Font.UseVisualStyleBackColor = true; this.btn_Lock_Font.Click += new System.EventHandler(this.btn_Lock_Font_Click); // // btn_Clear_Fade // - this.btn_Clear_Fade.Location = new System.Drawing.Point(1281, 521); - this.btn_Clear_Fade.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + resources.ApplyResources(this.btn_Clear_Fade, "btn_Clear_Fade"); this.btn_Clear_Fade.Name = "btn_Clear_Fade"; - this.btn_Clear_Fade.Size = new System.Drawing.Size(141, 70); - this.btn_Clear_Fade.TabIndex = 25; - this.btn_Clear_Fade.Text = "Fade Clear (Ctrl+Space)"; this.btn_Clear_Fade.UseVisualStyleBackColor = true; this.btn_Clear_Fade.Click += new System.EventHandler(this.btn_Clear_Fade_Click); // + // btn_refresh_monitor + // + resources.ApplyResources(this.btn_refresh_monitor, "btn_refresh_monitor"); + this.btn_refresh_monitor.Name = "btn_refresh_monitor"; + this.btn_refresh_monitor.UseVisualStyleBackColor = true; + this.btn_refresh_monitor.Click += new System.EventHandler(this.btn_refresh_monitor_Click); + // + // cmb_monitor + // + this.cmb_monitor.FormattingEnabled = true; + resources.ApplyResources(this.cmb_monitor, "cmb_monitor"); + this.cmb_monitor.Name = "cmb_monitor"; + // + // label1 + // + resources.ApplyResources(this.label1, "label1"); + this.label1.Name = "label1"; + // + // btn_lock_screen + // + this.btn_lock_screen.ForeColor = System.Drawing.Color.Red; + resources.ApplyResources(this.btn_lock_screen, "btn_lock_screen"); + this.btn_lock_screen.Name = "btn_lock_screen"; + this.btn_lock_screen.UseVisualStyleBackColor = true; + this.btn_lock_screen.Click += new System.EventHandler(this.btn_lock_screen_Click); + // + // label3 + // + resources.ApplyResources(this.label3, "label3"); + this.label3.Name = "label3"; + // + // txt_screen_width + // + resources.ApplyResources(this.txt_screen_width, "txt_screen_width"); + this.txt_screen_width.Name = "txt_screen_width"; + // + // txt_screen_height + // + resources.ApplyResources(this.txt_screen_height, "txt_screen_height"); + this.txt_screen_height.Name = "txt_screen_height"; + // + // label4 + // + resources.ApplyResources(this.label4, "label4"); + this.label4.Name = "label4"; + // + // btn_ScnStop + // + resources.ApplyResources(this.btn_ScnStop, "btn_ScnStop"); + this.btn_ScnStop.Name = "btn_ScnStop"; + this.btn_ScnStop.UseVisualStyleBackColor = true; + this.btn_ScnStop.Click += new System.EventHandler(this.btn_ScnStop_Click); + // + // btn_scnStart + // + resources.ApplyResources(this.btn_scnStart, "btn_scnStart"); + this.btn_scnStart.Name = "btn_scnStart"; + this.btn_scnStart.UseVisualStyleBackColor = true; + this.btn_scnStart.Click += new System.EventHandler(this.btn_scnStart_Click); + // + // gp_render_mode + // + this.gp_render_mode.Controls.Add(this.rdo_Render_FullScreen); + this.gp_render_mode.Controls.Add(this.rdo_Render_NDI); + resources.ApplyResources(this.gp_render_mode, "gp_render_mode"); + this.gp_render_mode.Name = "gp_render_mode"; + this.gp_render_mode.TabStop = false; + // + // rdo_Render_NDI + // + resources.ApplyResources(this.rdo_Render_NDI, "rdo_Render_NDI"); + this.rdo_Render_NDI.Name = "rdo_Render_NDI"; + this.rdo_Render_NDI.UseVisualStyleBackColor = true; + this.rdo_Render_NDI.CheckedChanged += new System.EventHandler(this.rdo_Render_NDI_CheckedChanged); + // + // rdo_Render_FullScreen + // + resources.ApplyResources(this.rdo_Render_FullScreen, "rdo_Render_FullScreen"); + this.rdo_Render_FullScreen.Checked = true; + this.rdo_Render_FullScreen.Name = "rdo_Render_FullScreen"; + this.rdo_Render_FullScreen.TabStop = true; + this.rdo_Render_FullScreen.UseVisualStyleBackColor = true; + this.rdo_Render_FullScreen.CheckedChanged += new System.EventHandler(this.rdo_Render_FullScreen_CheckedChanged); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.btn_refresh_monitor); + this.groupBox1.Controls.Add(this.cmb_monitor); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.btn_lock_screen); + this.groupBox1.Controls.Add(this.txt_screen_height); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.label4); + this.groupBox1.Controls.Add(this.txt_screen_width); + resources.ApplyResources(this.groupBox1, "groupBox1"); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.TabStop = false; + // // Form1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1439, 628); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.gp_render_mode); + this.Controls.Add(this.btn_ScnStop); + this.Controls.Add(this.btn_scnStart); this.Controls.Add(this.btn_Clear_Fade); this.Controls.Add(this.btn_Lock_Font); this.Controls.Add(this.cmb_Fonts); @@ -320,11 +341,13 @@ private void InitializeComponent() this.Controls.Add(this.btn_start); this.Controls.Add(this.lb_program_file); this.KeyPreview = true; - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "Form1"; - this.Text = "Form1"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Load += new System.EventHandler(this.Form1_Load); + this.gp_render_mode.ResumeLayout(false); + this.gp_render_mode.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -353,6 +376,20 @@ private void InitializeComponent() private System.Windows.Forms.ComboBox cmb_Fonts; private System.Windows.Forms.Button btn_Lock_Font; private System.Windows.Forms.Button btn_Clear_Fade; + private System.Windows.Forms.Button btn_refresh_monitor; + private System.Windows.Forms.ComboBox cmb_monitor; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btn_lock_screen; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txt_screen_width; + private System.Windows.Forms.TextBox txt_screen_height; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Button btn_ScnStop; + private System.Windows.Forms.Button btn_scnStart; + private System.Windows.Forms.GroupBox gp_render_mode; + private System.Windows.Forms.RadioButton rdo_Render_FullScreen; + private System.Windows.Forms.RadioButton rdo_Render_NDI; + private System.Windows.Forms.GroupBox groupBox1; } } diff --git a/Form1.cs b/Form1.cs index 65b2e54..ddc6f2a 100644 --- a/Form1.cs +++ b/Form1.cs @@ -7,6 +7,7 @@ using System.IO; using System.Drawing.Text; using Newtonsoft.Json.Linq; +using OpenTK; namespace NDI_SubTitle { @@ -17,6 +18,15 @@ public Form1() InitializeComponent(); } + //Render Mode + enum RenderMode + { + NDI = 0, + FullScreen = 1 + } + RenderMode render_mode = RenderMode.FullScreen; //Default + + // SubTitles private Dictionary ST_Files = new Dictionary(); private string Using_FilePath; private string Selected_FilePath; @@ -33,6 +43,12 @@ public Form1() CancellationTokenSource cancelNDI; float Font_Size; + + //Screen Output + DisplayDevice display_screen = null; + int scn_height, scn_width = 0; + Render_Form render_form = null; + #region Form private void Form1_Load(object sender, EventArgs e) { @@ -100,6 +116,7 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) private void Form1_FormClosing(object sender, FormClosingEventArgs e) { btn_stop_Click(); + Close_Screen(); } #endregion @@ -275,10 +292,19 @@ private void btn_Lock_Font_Click(object sender, EventArgs e) #region Change Buttons private void btn_Clear_Fade_Click(object sender = null, EventArgs e = null) { - if (Renderer == null) - return; - Renderer.Fade(SubTitle.Empty); - Program(SubTitle.Empty); + if (render_mode == RenderMode.NDI) + { + if (Renderer == null) + return; + Renderer.Fade(SubTitle.Empty); + Program(SubTitle.Empty); + } + if(render_mode == RenderMode.FullScreen) + { + if (render_form == null) + return; + + } } private void btn_fade_Click(object sender = null, EventArgs e = null) //Fade @@ -354,5 +380,75 @@ private void Lst_File_DragDrop(object sender, DragEventArgs e) } } } + + private void btn_refresh_monitor_Click(object sender, EventArgs e) + { + Refresh_Monitors(); + } + + private void Refresh_Monitors() + { + if (true) //unlocked + { + cmb_monitor.Items.Clear(); + int id = 0; + foreach (var screen in Screen.AllScreens) + { + // For each screen, add the screen properties to a list box. + cmb_monitor.Items.Add($"{id}:{screen.DeviceName}"); + id++; + } + } + } + + // TODO: Add lock + private void btn_scnStart_Click(object sender, EventArgs e) + { + if (true) //has locked + { + render_form = new Render_Form(display_screen, scn_width, scn_height); + render_form.Run(50.0f, 50.0f); + } + } + + void Close_Screen() + { + if (render_form != null) + { + render_form.Close(); + render_form.Dispose(); + render_form = null; + } + } + + private void btn_ScnStop_Click(object sender, EventArgs e) + { + var ds = MessageBox.Show("Close Output Screen?!!!!", "ARE YOU SURE??", MessageBoxButtons.YesNo); + if (ds == DialogResult.Yes) + Close_Screen(); + } + + private void rdo_Render_NDI_CheckedChanged(object sender, EventArgs e) + { + if (rdo_Render_FullScreen.Checked) render_mode = RenderMode.NDI; + } + + private void rdo_Render_FullScreen_CheckedChanged(object sender, EventArgs e) + { + if (rdo_Render_FullScreen.Checked) render_mode = RenderMode.FullScreen; + + } + + // TODO: Add lock + private void btn_lock_screen_Click(object sender, EventArgs e) + { + int id = cmb_monitor.SelectedIndex; + Screen scn = Screen.AllScreens[id]; + //lb_screen_info.Text = $"Name:{scn.DeviceName} Bits:{scn.BitsPerPixel}"; + display_screen = DisplayDevice.GetDisplay((DisplayIndex)id); + scn_height = Convert.ToInt32(txt_screen_height.Text); + scn_width = Convert.ToInt32(txt_screen_width.Text); + } + } } diff --git a/Form1.resx b/Form1.resx index 1af7de1..a9d43c4 100644 --- a/Form1.resx +++ b/Form1.resx @@ -117,4 +117,1015 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + + 宋体, 10pt + + + 12, 12 + + + 143, 17 + + + 2 + + + Loaded File : + + + lb_program_file + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 25 + + + 564, 67 + + + + 3, 2, 3, 2 + + + 100, 26 + + + 3 + + + NDI Start + + + btn_start + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 24 + + + 670, 67 + + + 3, 2, 3, 2 + + + 100, 26 + + + 4 + + + NDI Stop + + + btn_stop + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 23 + + + True + + + 宋体, 14pt + + + 270, 100 + + + 106, 24 + + + 5 + + + Status: + + + lable_text + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 22 + + + True + + + 宋体, 10pt + + + 12, 39 + + + 134, 17 + + + 6 + + + Selected File: + + + lb_selected_file + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 21 + + + 12, 94 + + + 3, 2, 3, 2 + + + 83, 36 + + + 7 + + + Import + + + btn_import + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 20 + + + 181, 94 + + + 3, 2, 3, 2 + + + 83, 36 + + + 8 + + + Load + + + btn_Load + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 19 + + + True + + + 宋体, 15pt + + + 1118, 296 + + + 103, 25 + + + 9 + + + Preview + + + lb_pre_id + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 18 + + + True + + + 宋体, 15pt + + + 1119, 136 + + + 103, 25 + + + 10 + + + Program + + + lb_pgm_id + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 17 + + + True + + + 宋体, 12pt + + + 1119, 337 + + + 179, 20 + + + 11 + + + Sub Title Preview + + + lb_preview + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 16 + + + True + + + 宋体, 12pt + + + 1119, 177 + + + 179, 20 + + + 12 + + + Sub Title Program + + + lb_program + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 15 + + + 1280, 471 + + + 3, 2, 3, 2 + + + 141, 65 + + + 13 + + + Fade (Space) + + + btn_fade + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 14 + + + 1124, 471 + + + 3, 2, 3, 2 + + + 141, 65 + + + 14 + + + Cut (Enter) + + + btn_Hard + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 13 + + + 1124, 547 + + + 3, 2, 3, 2 + + + 141, 70 + + + 15 + + + Clear (Ctrl+Enter) + + + btn_Clear_Cut + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 12 + + + 101, 94 + + + 3, 2, 3, 2 + + + 75, 36 + + + 16 + + + Delete + + + btn_DeleteFile + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 11 + + + 15 + + + 12, 136 + + + 3, 2, 3, 2 + + + 252, 484 + + + 17 + + + lst_File + + + System.Windows.Forms.ListBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 10 + + + 宋体, 12pt + + + 20 + + + 269, 136 + + + 3, 2, 3, 2 + + + True + + + 837, 484 + + + 18 + + + lst_SubTitle + + + System.Windows.Forms.ListBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 9 + + + True + + + 377, 107 + + + 63, 15 + + + 20 + + + NDI Off + + + lb_Status + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 8 + + + True + + + 宋体, 10pt + + + 12, 64 + + + 134, 17 + + + 22 + + + Font : + + + lb_Font + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + + + 153, 64 + + + 3, 2, 3, 2 + + + 287, 23 + + + 23 + + + cmb_Fonts + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 6 + + + 446, 59 + + + 3, 2, 3, 2 + + + 100, 30 + + + 24 + + + UnLock + + + btn_Lock_Font + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 5 + + + 1280, 547 + + + 3, 2, 3, 2 + + + 141, 70 + + + 25 + + + Fade Clear (Ctrl+Space) + + + btn_Clear_Fade + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + + + NoControl + + + 9, 47 + + + 116, 28 + + + 26 + + + Refresh + + + btn_refresh_monitor + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 0 + + + 131, 18 + + + 123, 23 + + + 27 + + + cmb_monitor + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 1 + + + True + + + 6, 22 + + + 119, 15 + + + 28 + + + Output Screen: + + + label1 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 2 + + + NoControl + + + 131, 47 + + + 123, 28 + + + 29 + + + UnLock + + + btn_lock_screen + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 3 + + + True + + + 6, 85 + + + 47, 15 + + + 32 + + + Width + + + label3 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 5 + + + 59, 81 + + + 66, 25 + + + 33 + + + 1680 + + + txt_screen_width + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 7 + + + 182, 81 + + + 72, 25 + + + 35 + + + 1050 + + + txt_screen_height + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 4 + + + True + + + 131, 85 + + + 55, 15 + + + 34 + + + Height + + + label4 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 6 + + + NoControl + + + 670, 97 + + + 3, 2, 3, 2 + + + 100, 27 + + + 37 + + + Scn Stop + + + btn_ScnStop + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + NoControl + + + 564, 100 + + + 3, 2, 3, 2 + + + 100, 24 + + + 36 + + + Scn Start + + + btn_scnStart + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + True + + + 92, 23 + + + 108, 19 + + + 1 + + + FullScreen + + + rdo_Render_FullScreen + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + gp_render_mode + + + 0 + + + True + + + 6, 22 + + + 52, 19 + + + 0 + + + NDI + + + rdo_Render_NDI + + + System.Windows.Forms.RadioButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + gp_render_mode + + + 1 + + + 564, 9 + + + 206, 53 + + + 38 + + + Render Mode + + + gp_render_mode + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + 776, 12 + + + 269, 112 + + + 39 + + + Screen Settings + + + groupBox1 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + True + + + 8, 15 + + + 1439, 628 + + + 3, 2, 3, 2 + + + Form1 + + + Form1 + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/NDIRender.cs b/NDIRender.cs index fd4a7ee..6c4d5bb 100644 --- a/NDIRender.cs +++ b/NDIRender.cs @@ -40,7 +40,7 @@ public NDIRender(CancellationToken cancellationToken, NDIConfig config, Font fon bmp = new Bitmap(videoFrame.Width, videoFrame.Height, videoFrame.Stride, System.Drawing.Imaging.PixelFormat.Format32bppArgb, videoFrame.BufferPtr); graphics = Graphics.FromImage(bmp); - graphics.SmoothingMode = SmoothingMode.AntiAlias; + graphics.SmoothingMode = SmoothingMode.HighQuality; // NDI Renderer program = SubTitle.Empty; fading = SubTitle.Empty; diff --git a/Ndi-SubTitle.csproj b/Ndi-SubTitle.csproj index 7c85bf1..ea12779 100644 --- a/Ndi-SubTitle.csproj +++ b/Ndi-SubTitle.csproj @@ -75,6 +75,9 @@ packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\OpenTK.3.1.0\lib\net20\OpenTK.dll + @@ -99,6 +102,7 @@ + Form1.cs @@ -113,6 +117,7 @@ Resources.resx True + SettingsSingleFileGenerator diff --git a/OpenTK.dll.config b/OpenTK.dll.config new file mode 100644 index 0000000..7098d39 --- /dev/null +++ b/OpenTK.dll.config @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Render_Form.cs b/Render_Form.cs new file mode 100644 index 0000000..2407722 --- /dev/null +++ b/Render_Form.cs @@ -0,0 +1,101 @@ + +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.ES20; +using OpenTK.Input; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Threading; +using System.Threading.Tasks; + + +namespace NDI_SubTitle +{ + class Render_Form : GameWindow + { + public Render_Form(DisplayDevice dd, int width, int height,Font font,NDIConfig config) + : base(width, height, GraphicsMode.Default, + "SubTitle - FullScreen", GameWindowFlags.Fullscreen, + dd, 4, // OpenGL major version + 0, // OpenGL minor version + GraphicsContextFlags.ForwardCompatible) + { + program = SubTitle.Empty; + fading = SubTitle.Empty; + + // Style + defaultBrush = new SolidBrush(config.Default_Color); + this.font = font; + } + + protected override void OnLoad(EventArgs e) + { + CursorVisible = false; + } + + //Render + public const int Alpha_Max = 255; + public const int Alpha_Min = 255; + + private static readonly object syncLock = new object(); + private Bitmap bmp; + private Graphics graphics; + + private Font font; + private SolidBrush defaultBrush; + private static Point Point_Sub1 = new Point(90, 20); + private static Point Point_Sub2 = new Point(90, 90); + + private SubTitle program; + private SubTitle fading; + private bool isFading; + private int Fading_X; + private readonly int delta_X; + + public void Cut(SubTitle sub) + { + lock (syncLock) + { + if (isFading) + return; + program = sub; + } + } + + public void Fade(SubTitle sub) + { + lock (syncLock) + { + if (isFading) + return; + fading = sub.Clone(); + fading.alpha = Alpha_Min; + isFading = true; + Fading_X = 0; //Reset Fading_X + } + } + + public void ChangeFont(Font font) + { + lock (syncLock) + this.font = font; + } + + + protected override void OnUpdateFrame(FrameEventArgs e) + { + base.OnUpdateFrame(e); + } + protected override void OnRenderFrame(FrameEventArgs e) + { + + } + + } +} \ No newline at end of file diff --git a/packages.config b/packages.config index a75532f..0c00f62 100644 --- a/packages.config +++ b/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file From 8821d4fc8164b8f654448807c4d21a426fbf5854 Mon Sep 17 00:00:00 2001 From: Luv Letter Date: Sat, 28 Dec 2019 01:09:00 +0800 Subject: [PATCH 2/2] almost done --- Form1.Designer.cs | 17 ++++--- Form1.cs | 76 ++++++++++++++++++++-------- NDIRender.cs | 7 +-- Render_Form.cs | 126 +++++++++++++++++++++++++++++++++++++++------- 4 files changed, 174 insertions(+), 52 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 70b02bf..bb1c498 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -62,8 +62,8 @@ private void InitializeComponent() this.btn_ScnStop = new System.Windows.Forms.Button(); this.btn_scnStart = new System.Windows.Forms.Button(); this.gp_render_mode = new System.Windows.Forms.GroupBox(); - this.rdo_Render_NDI = new System.Windows.Forms.RadioButton(); 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.gp_render_mode.SuspendLayout(); this.groupBox1.SuspendLayout(); @@ -221,6 +221,7 @@ private void InitializeComponent() // // cmb_monitor // + this.cmb_monitor.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmb_monitor.FormattingEnabled = true; resources.ApplyResources(this.cmb_monitor, "cmb_monitor"); this.cmb_monitor.Name = "cmb_monitor"; @@ -280,13 +281,6 @@ private void InitializeComponent() this.gp_render_mode.Name = "gp_render_mode"; this.gp_render_mode.TabStop = false; // - // rdo_Render_NDI - // - resources.ApplyResources(this.rdo_Render_NDI, "rdo_Render_NDI"); - this.rdo_Render_NDI.Name = "rdo_Render_NDI"; - this.rdo_Render_NDI.UseVisualStyleBackColor = true; - this.rdo_Render_NDI.CheckedChanged += new System.EventHandler(this.rdo_Render_NDI_CheckedChanged); - // // rdo_Render_FullScreen // resources.ApplyResources(this.rdo_Render_FullScreen, "rdo_Render_FullScreen"); @@ -296,6 +290,13 @@ private void InitializeComponent() this.rdo_Render_FullScreen.UseVisualStyleBackColor = true; this.rdo_Render_FullScreen.CheckedChanged += new System.EventHandler(this.rdo_Render_FullScreen_CheckedChanged); // + // rdo_Render_NDI + // + resources.ApplyResources(this.rdo_Render_NDI, "rdo_Render_NDI"); + this.rdo_Render_NDI.Name = "rdo_Render_NDI"; + this.rdo_Render_NDI.UseVisualStyleBackColor = true; + this.rdo_Render_NDI.CheckedChanged += new System.EventHandler(this.rdo_Render_NDI_CheckedChanged); + // // groupBox1 // this.groupBox1.Controls.Add(this.btn_refresh_monitor); diff --git a/Form1.cs b/Form1.cs index ddc6f2a..91998df 100644 --- a/Form1.cs +++ b/Form1.cs @@ -63,6 +63,7 @@ private void Form1_Load(object sender, EventArgs e) } } cmb_Fonts.SelectedIndex = 1; + Refresh_Monitors(); // Read Config var config_path = Path.Combine(Directory.GetCurrentDirectory(), "NDI-SubTitle.config"); try @@ -265,7 +266,12 @@ private void cmb_Fonts_SelectedIndexChanged(object sender, EventArgs e) { Console.WriteLine("Change Font To " + cmb.SelectedItem.ToString()); //Render_Font = new Font(new FontFamily(cmb.SelectedItem.ToString()), 50); - if (Renderer != null) + if (render_mode == RenderMode.FullScreen) + { + if (render_form != null) + render_form.ChangeFont(new Font(new FontFamily(cmb.SelectedItem.ToString()), Font_Size)); + } + else if (Renderer != null) Renderer.ChangeFont(new Font(new FontFamily(cmb.SelectedItem.ToString()), Font_Size)); } } @@ -299,7 +305,7 @@ private void btn_Clear_Fade_Click(object sender = null, EventArgs e = null) Renderer.Fade(SubTitle.Empty); Program(SubTitle.Empty); } - if(render_mode == RenderMode.FullScreen) + if (render_mode == RenderMode.FullScreen) { if (render_form == null) return; @@ -327,14 +333,24 @@ private void btn_fade_Click(object sender = null, EventArgs e = null) //Fade private void btn_Hard_Click(object sender = null, EventArgs e = null)//Send Directly Preview To Program { - if (Renderer == null) - return; + if (subTitles.Count == 0) return; - if (lst_SubTitle.SelectedIndex < 0) + if (lst_SubTitle.SelectedIndex < 0 || subTitles.Count <= lst_SubTitle.SelectedIndex) return; - if (subTitles.Count > lst_SubTitle.SelectedIndex) + if (render_mode == RenderMode.FullScreen) { + if (render_form == null) return; + render_form.Cut(Previewing); + Program(Previewing); + run_printer = Previewing.id + 1; + if (run_printer != subTitles.Count) + lst_SubTitle.SetSelected(run_printer, true); + } + else + { + if (Renderer == null) + return; Renderer.Cut(Previewing); Program(Previewing); run_printer = Previewing.id + 1; @@ -345,10 +361,11 @@ private void btn_Hard_Click(object sender = null, EventArgs e = null)//Send Dire private void btn_Clear_Click(object sender = null, EventArgs e = null) { - if (Renderer == null) - return; Program(SubTitle.Empty); - Renderer.Cut(SubTitle.Empty); + if (Renderer != null) + Renderer.Cut(SubTitle.Empty); + if (render_form != null) + render_form.Cut(SubTitle.Empty); } #endregion @@ -388,7 +405,7 @@ private void btn_refresh_monitor_Click(object sender, EventArgs e) private void Refresh_Monitors() { - if (true) //unlocked + if (cmb_monitor.Enabled == true) //unlocked { cmb_monitor.Items.Clear(); int id = 0; @@ -398,17 +415,22 @@ private void Refresh_Monitors() cmb_monitor.Items.Add($"{id}:{screen.DeviceName}"); id++; } + if (cmb_monitor.Items.Count >= 1) + cmb_monitor.SelectedIndex = cmb_monitor.Items.Count - 1; } } - // TODO: Add lock private void btn_scnStart_Click(object sender, EventArgs e) { - if (true) //has locked + if (cmb_monitor.Enabled == false) //has locked { - render_form = new Render_Form(display_screen, scn_width, scn_height); + 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.Run(50.0f, 50.0f); } + else + { + MessageBox.Show("Lock Output Screen!"); + } } void Close_Screen() @@ -430,7 +452,7 @@ private void btn_ScnStop_Click(object sender, EventArgs e) private void rdo_Render_NDI_CheckedChanged(object sender, EventArgs e) { - if (rdo_Render_FullScreen.Checked) render_mode = RenderMode.NDI; + if (rdo_Render_NDI.Checked) render_mode = RenderMode.NDI; } private void rdo_Render_FullScreen_CheckedChanged(object sender, EventArgs e) @@ -442,12 +464,26 @@ private void rdo_Render_FullScreen_CheckedChanged(object sender, EventArgs e) // TODO: Add lock private void btn_lock_screen_Click(object sender, EventArgs e) { - int id = cmb_monitor.SelectedIndex; - Screen scn = Screen.AllScreens[id]; - //lb_screen_info.Text = $"Name:{scn.DeviceName} Bits:{scn.BitsPerPixel}"; - display_screen = DisplayDevice.GetDisplay((DisplayIndex)id); - scn_height = Convert.ToInt32(txt_screen_height.Text); - scn_width = Convert.ToInt32(txt_screen_width.Text); + if (cmb_monitor.Enabled == true) //not locked + { + int id = cmb_monitor.SelectedIndex; + if (id == -1) + return; + Screen scn = Screen.AllScreens[id]; + //lb_screen_info.Text = $"Name:{scn.DeviceName} Bits:{scn.BitsPerPixel}"; + display_screen = DisplayDevice.GetDisplay((DisplayIndex)id); + scn_height = Convert.ToInt32(txt_screen_height.Text); + scn_width = Convert.ToInt32(txt_screen_width.Text); + cmb_monitor.Enabled = false; + btn_lock_screen.Text = "Locked"; + btn_lock_screen.ForeColor = Color.Green; + } + else + { + cmb_monitor.Enabled = true; + btn_lock_screen.Text = "Unlocked"; + btn_lock_screen.ForeColor = Color.Red; + } } } diff --git a/NDIRender.cs b/NDIRender.cs index 6c4d5bb..4aefc84 100644 --- a/NDIRender.cs +++ b/NDIRender.cs @@ -167,11 +167,8 @@ public async Task Run() else { // We now submit the frame. Note that this call will be clocked so that we end up submitting at exactly 29.97fps. - lock (syncLock) - { - DrawFrame(); - sendInstance.Send(videoFrame); - } + DrawFrame(); + sendInstance.Send(videoFrame); } } // using sendInstance sendInstance.Dispose(); diff --git a/Render_Form.cs b/Render_Form.cs index 2407722..10561c8 100644 --- a/Render_Form.cs +++ b/Render_Form.cs @@ -1,70 +1,95 @@  using OpenTK; using OpenTK.Graphics; -using OpenTK.Graphics.ES20; +using OpenTK.Graphics.OpenGL; using OpenTK.Input; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Threading; -using System.Threading.Tasks; - +using System.Drawing.Imaging; +using NDI_SubTitle.Properties; namespace NDI_SubTitle { class Render_Form : GameWindow { - public Render_Form(DisplayDevice dd, int width, int height,Font font,NDIConfig config) - : base(width, height, GraphicsMode.Default, - "SubTitle - FullScreen", GameWindowFlags.Fullscreen, - dd, 4, // OpenGL major version - 0, // OpenGL minor version - GraphicsContextFlags.ForwardCompatible) + public Render_Form(DisplayDevice dd, int _width, int _height, Font font, NDIConfig config) + : base(_width, _height, new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, 8), + "SubTitle - FullScreen", GameWindowFlags.Fullscreen, dd) { + Title += ": OpenGL Version: " + GL.GetString(StringName.Version); + height = _height; + width = _width; + + NDI_Config = config; + // Render Initial program = SubTitle.Empty; fading = SubTitle.Empty; + Point_Sub1 = new Point(50, height / 2); + Point_Sub2 = new Point(50, height / 2 + 100); // Style defaultBrush = new SolidBrush(config.Default_Color); this.font = font; - } - protected override void OnLoad(EventArgs e) - { - CursorVisible = false; + bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + graphics = Graphics.FromImage(bmp); + graphics.SmoothingMode = SmoothingMode.HighQuality; + graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; + + // Fade Setting + 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; + + // 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; } + private int height; + private int width; + //Render + private NDIConfig NDI_Config; public const int Alpha_Max = 255; public const int Alpha_Min = 255; private static readonly object syncLock = new object(); private Bitmap bmp; private Graphics graphics; + private int textTexture = -1; private Font font; private SolidBrush defaultBrush; - private static Point Point_Sub1 = new Point(90, 20); - private static Point Point_Sub2 = new Point(90, 90); + private Point Point_Sub1; + private Point Point_Sub2; private SubTitle program; private SubTitle fading; private bool isFading; private int Fading_X; private readonly int delta_X; - + + private bool isChange = false; + public void Cut(SubTitle sub) { lock (syncLock) { - if (isFading) + if (isChange) return; program = sub; + isChange = true; } } @@ -72,11 +97,12 @@ public void Fade(SubTitle sub) { lock (syncLock) { - if (isFading) + if (isChange) return; fading = sub.Clone(); fading.alpha = Alpha_Min; isFading = true; + isChange = true; Fading_X = 0; //Reset Fading_X } } @@ -87,14 +113,76 @@ public void ChangeFont(Font font) this.font = font; } + private void GenerateBmp() + { + if (textTexture != -1) + GL.DeleteTextures(1, ref textTexture); + graphics.Clear(Color.Transparent); + graphics.DrawString(program.First_Sub, font, defaultBrush, Point_Sub1); + graphics.DrawString(program.Second_Sub, font, defaultBrush, Point_Sub2); + bmp.Save("D:\\test.png"); + + GL.ClearColor(Color.AntiqueWhite); + GL.Enable(EnableCap.Texture2D); + + GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); + + GL.GenTextures(1, out textTexture); + GL.BindTexture(TextureTarget.Texture2D, textTexture); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); + BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), + ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); + + bmp.UnlockBits(data); + } + + protected override void OnLoad(EventArgs e) + { + CursorVisible = false; + } + protected override void OnUnload(EventArgs e) + { + GL.DeleteTextures(1, ref textTexture); + } protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); } protected override void OnRenderFrame(FrameEventArgs e) { + if (isChange) + { + lock (syncLock) + { + GenerateBmp(); + GL.Clear(ClearBufferMask.ColorBufferBit); + + GL.MatrixMode(MatrixMode.Modelview); + GL.LoadIdentity(); + GL.BindTexture(TextureTarget.Texture2D, textTexture); + + GL.Begin(BeginMode.Quads); + GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-1.0f, -1.0f); + GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(1.0f, -1.0f); + GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(1.0f, 1.0f); + GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-1.0f, 1.0f); + + GL.End(); + + ErrorCode errorCode = GL.GetError(); + if (errorCode != ErrorCode.NoError) + Console.WriteLine($"OpenTK ERROR!!: {errorCode.ToString()}"); + + SwapBuffers(); + } + isChange = false; + } + SwapBuffers(); } }