sl@0: using System; sl@0: using System.Collections.Generic; sl@0: using System.ComponentModel; sl@0: using System.Data; sl@0: using System.Drawing; sl@0: using System.Linq; sl@0: using System.Text; sl@0: using System.Threading.Tasks; sl@0: using System.Windows.Forms; sl@0: using CodeProject.Dialog; sl@0: sl@0: namespace SharpDisplayManager sl@0: { sl@0: public partial class MainForm : Form sl@0: { sl@2: DateTime LastTickTime; sl@3: Display iDisplay; sl@2: sl@0: public MainForm() sl@0: { sl@2: LastTickTime = DateTime.Now; sl@3: iDisplay = new Display(); sl@2: sl@0: InitializeComponent(); sl@7: UpdateStatus(); sl@8: //Load settings sl@8: marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont; sl@8: marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont; sl@9: checkBoxShowBorders.Checked = Properties.Settings.Default.DisplayShowBorders; sl@0: } sl@0: sl@0: private void buttonFont_Click(object sender, EventArgs e) sl@0: { sl@0: //fontDialog.ShowColor = true; sl@0: //fontDialog.ShowApply = true; sl@0: fontDialog.ShowEffects = true; sl@11: fontDialog.Font = marqueeLabelTop.Font; sl@0: //fontDialog.ShowHelp = true; sl@0: sl@0: //fontDlg.MaxSize = 40; sl@0: //fontDlg.MinSize = 22; sl@0: sl@0: //fontDialog.Parent = this; sl@0: //fontDialog.StartPosition = FormStartPosition.CenterParent; sl@0: sl@0: //DlgBox.ShowDialog(fontDialog); sl@0: sl@0: //if (fontDialog.ShowDialog(this) != DialogResult.Cancel) sl@0: if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel) sl@0: { sl@0: sl@4: //MsgBox.Show("MessageBox MsgBox", "MsgBox caption"); sl@0: sl@0: //MessageBox.Show("Ok"); sl@4: marqueeLabelTop.Font = fontDialog.Font; sl@4: marqueeLabelBottom.Font = fontDialog.Font; sl@8: Properties.Settings.Default.DisplayFont = fontDialog.Font; sl@8: Properties.Settings.Default.Save(); sl@0: //label1.Font = fontDlg.Font; sl@0: //textBox1.BackColor = fontDlg.Color; sl@0: //label1.ForeColor = fontDlg.Color; sl@0: } sl@0: } sl@0: sl@0: private void buttonCapture_Click(object sender, EventArgs e) sl@0: { sl@0: System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height); sl@0: tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle); sl@0: bmp.Save("c:\\capture.png"); sl@0: } sl@2: sl@12: private void CheckForRequestResults() sl@12: { sl@12: if (iDisplay.IsRequestPending()) sl@12: { sl@12: switch (iDisplay.AttemptRequestCompletion()) sl@12: { sl@12: case Display.TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus: sl@12: if (iDisplay.PowerSupplyStatus()) sl@12: { sl@12: toolStripStatusLabelPower.Text = "ON"; sl@12: } sl@12: else sl@12: { sl@12: toolStripStatusLabelPower.Text = "OFF"; sl@12: } sl@12: //Issue next request then sl@12: iDisplay.RequestDeviceId(); sl@12: break; sl@12: sl@12: case Display.TMiniDisplayRequest.EMiniDisplayRequestDeviceId: sl@12: toolStripStatusLabelConnect.Text += " - " + iDisplay.DeviceId(); sl@12: //Issue next request then sl@12: iDisplay.RequestFirmwareRevision(); sl@12: break; sl@12: sl@12: case Display.TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision: sl@12: toolStripStatusLabelConnect.Text += " v" + iDisplay.FirmwareRevision(); sl@12: //No more request to issue sl@12: break; sl@12: } sl@12: } sl@12: } sl@12: sl@2: private void timer_Tick(object sender, EventArgs e) sl@12: { sl@2: //Update our animations sl@2: DateTime NewTickTime = DateTime.Now; sl@2: sl@2: marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime); sl@2: marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime); sl@2: sl@4: //Update our display sl@4: if (iDisplay.IsOpen()) sl@4: { sl@12: CheckForRequestResults(); sl@12: sl@4: //Draw to bitmap sl@4: System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height); sl@4: tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle); sl@7: //Send it to our display sl@4: for (int i = 0; i < bmp.Width; i++) sl@4: { sl@4: for (int j = 0; j < bmp.Height; j++) sl@4: { sl@4: unchecked sl@4: { sl@4: uint color=(uint)bmp.GetPixel(i, j).ToArgb(); sl@9: iDisplay.SetPixel(i, j, Convert.ToInt32((checkBoxShowBorders.Checked?color!=0xFFFFFFFF:color == 0xFF000000))); sl@4: } sl@4: } sl@4: } sl@4: sl@4: iDisplay.SwapBuffers(); sl@4: sl@4: } sl@8: sl@8: //Compute instant FPS sl@8: toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " FPS"; sl@8: sl@8: LastTickTime = NewTickTime; sl@8: sl@2: } sl@3: sl@3: private void buttonOpen_Click(object sender, EventArgs e) sl@3: { sl@3: if (iDisplay.Open()) sl@3: { sl@7: UpdateStatus(); sl@12: iDisplay.RequestPowerSupplyStatus(); sl@3: } sl@7: else sl@7: { sl@7: UpdateStatus(); sl@7: toolStripStatusLabelConnect.Text = "Connection error"; sl@7: } sl@7: sl@3: } sl@3: sl@3: private void buttonClose_Click(object sender, EventArgs e) sl@3: { sl@3: iDisplay.Close(); sl@9: UpdateStatus(); sl@3: } sl@3: sl@3: private void buttonClear_Click(object sender, EventArgs e) sl@3: { sl@3: iDisplay.Clear(); sl@3: iDisplay.SwapBuffers(); sl@3: } sl@3: sl@3: private void buttonFill_Click(object sender, EventArgs e) sl@3: { sl@3: iDisplay.Fill(); sl@3: iDisplay.SwapBuffers(); sl@3: } sl@3: sl@3: private void trackBarBrightness_Scroll(object sender, EventArgs e) sl@3: { sl@9: Properties.Settings.Default.DisplayBrightness = trackBarBrightness.Value; sl@9: Properties.Settings.Default.Save(); sl@3: iDisplay.SetBrightness(trackBarBrightness.Value); sl@9: sl@3: } sl@7: sl@7: private void UpdateStatus() sl@7: { sl@7: if (iDisplay.IsOpen()) sl@7: { sl@7: buttonFill.Enabled = true; sl@7: buttonClear.Enabled = true; sl@7: buttonOpen.Enabled = false; sl@7: buttonClose.Enabled = true; sl@7: trackBarBrightness.Enabled = true; sl@7: trackBarBrightness.Minimum = iDisplay.MinBrightness(); sl@11: trackBarBrightness.Maximum = iDisplay.MaxBrightness(); sl@9: trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness; sl@9: trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5); sl@9: trackBarBrightness.SmallChange = 1; sl@9: iDisplay.SetBrightness(Properties.Settings.Default.DisplayBrightness); sl@9: sl@10: toolStripStatusLabelConnect.Text = "Connected - " + iDisplay.Vendor() + " - " + iDisplay.Product(); sl@10: //+ " - " + iDisplay.SerialNumber(); sl@7: } sl@7: else sl@7: { sl@7: buttonFill.Enabled = false; sl@7: buttonClear.Enabled = false; sl@7: buttonOpen.Enabled = true; sl@7: buttonClose.Enabled = false; sl@7: trackBarBrightness.Enabled = false; sl@9: toolStripStatusLabelConnect.Text = "Disconnected"; sl@7: } sl@7: } sl@9: sl@9: private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e) sl@9: { sl@9: Properties.Settings.Default.DisplayShowBorders = checkBoxShowBorders.Checked; sl@9: Properties.Settings.Default.Save(); sl@9: } sl@0: } sl@0: }