sl@0
|
1 |
using System;
|
sl@0
|
2 |
using System.Collections.Generic;
|
sl@0
|
3 |
using System.ComponentModel;
|
sl@0
|
4 |
using System.Data;
|
sl@0
|
5 |
using System.Drawing;
|
sl@0
|
6 |
using System.Linq;
|
sl@0
|
7 |
using System.Text;
|
sl@0
|
8 |
using System.Threading.Tasks;
|
sl@0
|
9 |
using System.Windows.Forms;
|
sl@0
|
10 |
using CodeProject.Dialog;
|
sl@0
|
11 |
|
sl@0
|
12 |
namespace SharpDisplayManager
|
sl@0
|
13 |
{
|
sl@0
|
14 |
public partial class MainForm : Form
|
sl@0
|
15 |
{
|
sl@2
|
16 |
DateTime LastTickTime;
|
sl@3
|
17 |
Display iDisplay;
|
sl@2
|
18 |
|
sl@0
|
19 |
public MainForm()
|
sl@0
|
20 |
{
|
sl@2
|
21 |
LastTickTime = DateTime.Now;
|
sl@3
|
22 |
iDisplay = new Display();
|
sl@2
|
23 |
|
sl@0
|
24 |
InitializeComponent();
|
sl@7
|
25 |
UpdateStatus();
|
sl@8
|
26 |
//Load settings
|
sl@8
|
27 |
marqueeLabelTop.Font = Properties.Settings.Default.DisplayFont;
|
sl@8
|
28 |
marqueeLabelBottom.Font = Properties.Settings.Default.DisplayFont;
|
sl@9
|
29 |
checkBoxShowBorders.Checked = Properties.Settings.Default.DisplayShowBorders;
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
private void buttonFont_Click(object sender, EventArgs e)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
//fontDialog.ShowColor = true;
|
sl@0
|
35 |
//fontDialog.ShowApply = true;
|
sl@0
|
36 |
fontDialog.ShowEffects = true;
|
sl@11
|
37 |
fontDialog.Font = marqueeLabelTop.Font;
|
sl@0
|
38 |
//fontDialog.ShowHelp = true;
|
sl@0
|
39 |
|
sl@0
|
40 |
//fontDlg.MaxSize = 40;
|
sl@0
|
41 |
//fontDlg.MinSize = 22;
|
sl@0
|
42 |
|
sl@0
|
43 |
//fontDialog.Parent = this;
|
sl@0
|
44 |
//fontDialog.StartPosition = FormStartPosition.CenterParent;
|
sl@0
|
45 |
|
sl@0
|
46 |
//DlgBox.ShowDialog(fontDialog);
|
sl@0
|
47 |
|
sl@0
|
48 |
//if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
|
sl@0
|
49 |
if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
|
sl@4
|
52 |
//MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
|
sl@0
|
53 |
|
sl@0
|
54 |
//MessageBox.Show("Ok");
|
sl@4
|
55 |
marqueeLabelTop.Font = fontDialog.Font;
|
sl@4
|
56 |
marqueeLabelBottom.Font = fontDialog.Font;
|
sl@8
|
57 |
Properties.Settings.Default.DisplayFont = fontDialog.Font;
|
sl@8
|
58 |
Properties.Settings.Default.Save();
|
sl@0
|
59 |
//label1.Font = fontDlg.Font;
|
sl@0
|
60 |
//textBox1.BackColor = fontDlg.Color;
|
sl@0
|
61 |
//label1.ForeColor = fontDlg.Color;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
private void buttonCapture_Click(object sender, EventArgs e)
|
sl@0
|
66 |
{
|
sl@0
|
67 |
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
|
sl@0
|
68 |
tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
|
sl@0
|
69 |
bmp.Save("c:\\capture.png");
|
sl@0
|
70 |
}
|
sl@2
|
71 |
|
sl@12
|
72 |
private void CheckForRequestResults()
|
sl@12
|
73 |
{
|
sl@12
|
74 |
if (iDisplay.IsRequestPending())
|
sl@12
|
75 |
{
|
sl@12
|
76 |
switch (iDisplay.AttemptRequestCompletion())
|
sl@12
|
77 |
{
|
sl@12
|
78 |
case Display.TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus:
|
sl@12
|
79 |
if (iDisplay.PowerSupplyStatus())
|
sl@12
|
80 |
{
|
sl@12
|
81 |
toolStripStatusLabelPower.Text = "ON";
|
sl@12
|
82 |
}
|
sl@12
|
83 |
else
|
sl@12
|
84 |
{
|
sl@12
|
85 |
toolStripStatusLabelPower.Text = "OFF";
|
sl@12
|
86 |
}
|
sl@12
|
87 |
//Issue next request then
|
sl@12
|
88 |
iDisplay.RequestDeviceId();
|
sl@12
|
89 |
break;
|
sl@12
|
90 |
|
sl@12
|
91 |
case Display.TMiniDisplayRequest.EMiniDisplayRequestDeviceId:
|
sl@12
|
92 |
toolStripStatusLabelConnect.Text += " - " + iDisplay.DeviceId();
|
sl@12
|
93 |
//Issue next request then
|
sl@12
|
94 |
iDisplay.RequestFirmwareRevision();
|
sl@12
|
95 |
break;
|
sl@12
|
96 |
|
sl@12
|
97 |
case Display.TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision:
|
sl@12
|
98 |
toolStripStatusLabelConnect.Text += " v" + iDisplay.FirmwareRevision();
|
sl@12
|
99 |
//No more request to issue
|
sl@12
|
100 |
break;
|
sl@12
|
101 |
}
|
sl@12
|
102 |
}
|
sl@12
|
103 |
}
|
sl@12
|
104 |
|
sl@2
|
105 |
private void timer_Tick(object sender, EventArgs e)
|
sl@12
|
106 |
{
|
sl@2
|
107 |
//Update our animations
|
sl@2
|
108 |
DateTime NewTickTime = DateTime.Now;
|
sl@2
|
109 |
|
sl@2
|
110 |
marqueeLabelTop.UpdateAnimation(LastTickTime, NewTickTime);
|
sl@2
|
111 |
marqueeLabelBottom.UpdateAnimation(LastTickTime, NewTickTime);
|
sl@2
|
112 |
|
sl@4
|
113 |
//Update our display
|
sl@4
|
114 |
if (iDisplay.IsOpen())
|
sl@4
|
115 |
{
|
sl@12
|
116 |
CheckForRequestResults();
|
sl@12
|
117 |
|
sl@4
|
118 |
//Draw to bitmap
|
sl@4
|
119 |
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
|
sl@4
|
120 |
tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
|
sl@7
|
121 |
//Send it to our display
|
sl@4
|
122 |
for (int i = 0; i < bmp.Width; i++)
|
sl@4
|
123 |
{
|
sl@4
|
124 |
for (int j = 0; j < bmp.Height; j++)
|
sl@4
|
125 |
{
|
sl@4
|
126 |
unchecked
|
sl@4
|
127 |
{
|
sl@4
|
128 |
uint color=(uint)bmp.GetPixel(i, j).ToArgb();
|
sl@9
|
129 |
iDisplay.SetPixel(i, j, Convert.ToInt32((checkBoxShowBorders.Checked?color!=0xFFFFFFFF:color == 0xFF000000)));
|
sl@4
|
130 |
}
|
sl@4
|
131 |
}
|
sl@4
|
132 |
}
|
sl@4
|
133 |
|
sl@4
|
134 |
iDisplay.SwapBuffers();
|
sl@4
|
135 |
|
sl@4
|
136 |
}
|
sl@8
|
137 |
|
sl@8
|
138 |
//Compute instant FPS
|
sl@8
|
139 |
toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " FPS";
|
sl@8
|
140 |
|
sl@8
|
141 |
LastTickTime = NewTickTime;
|
sl@8
|
142 |
|
sl@2
|
143 |
}
|
sl@3
|
144 |
|
sl@3
|
145 |
private void buttonOpen_Click(object sender, EventArgs e)
|
sl@3
|
146 |
{
|
sl@3
|
147 |
if (iDisplay.Open())
|
sl@3
|
148 |
{
|
sl@7
|
149 |
UpdateStatus();
|
sl@12
|
150 |
iDisplay.RequestPowerSupplyStatus();
|
sl@3
|
151 |
}
|
sl@7
|
152 |
else
|
sl@7
|
153 |
{
|
sl@7
|
154 |
UpdateStatus();
|
sl@7
|
155 |
toolStripStatusLabelConnect.Text = "Connection error";
|
sl@7
|
156 |
}
|
sl@7
|
157 |
|
sl@3
|
158 |
}
|
sl@3
|
159 |
|
sl@3
|
160 |
private void buttonClose_Click(object sender, EventArgs e)
|
sl@3
|
161 |
{
|
sl@3
|
162 |
iDisplay.Close();
|
sl@9
|
163 |
UpdateStatus();
|
sl@3
|
164 |
}
|
sl@3
|
165 |
|
sl@3
|
166 |
private void buttonClear_Click(object sender, EventArgs e)
|
sl@3
|
167 |
{
|
sl@3
|
168 |
iDisplay.Clear();
|
sl@3
|
169 |
iDisplay.SwapBuffers();
|
sl@3
|
170 |
}
|
sl@3
|
171 |
|
sl@3
|
172 |
private void buttonFill_Click(object sender, EventArgs e)
|
sl@3
|
173 |
{
|
sl@3
|
174 |
iDisplay.Fill();
|
sl@3
|
175 |
iDisplay.SwapBuffers();
|
sl@3
|
176 |
}
|
sl@3
|
177 |
|
sl@3
|
178 |
private void trackBarBrightness_Scroll(object sender, EventArgs e)
|
sl@3
|
179 |
{
|
sl@9
|
180 |
Properties.Settings.Default.DisplayBrightness = trackBarBrightness.Value;
|
sl@9
|
181 |
Properties.Settings.Default.Save();
|
sl@3
|
182 |
iDisplay.SetBrightness(trackBarBrightness.Value);
|
sl@9
|
183 |
|
sl@3
|
184 |
}
|
sl@7
|
185 |
|
sl@7
|
186 |
private void UpdateStatus()
|
sl@7
|
187 |
{
|
sl@7
|
188 |
if (iDisplay.IsOpen())
|
sl@7
|
189 |
{
|
sl@7
|
190 |
buttonFill.Enabled = true;
|
sl@7
|
191 |
buttonClear.Enabled = true;
|
sl@7
|
192 |
buttonOpen.Enabled = false;
|
sl@7
|
193 |
buttonClose.Enabled = true;
|
sl@7
|
194 |
trackBarBrightness.Enabled = true;
|
sl@7
|
195 |
trackBarBrightness.Minimum = iDisplay.MinBrightness();
|
sl@11
|
196 |
trackBarBrightness.Maximum = iDisplay.MaxBrightness();
|
sl@9
|
197 |
trackBarBrightness.Value = Properties.Settings.Default.DisplayBrightness;
|
sl@9
|
198 |
trackBarBrightness.LargeChange = Math.Max(1,(iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5);
|
sl@9
|
199 |
trackBarBrightness.SmallChange = 1;
|
sl@9
|
200 |
iDisplay.SetBrightness(Properties.Settings.Default.DisplayBrightness);
|
sl@9
|
201 |
|
sl@10
|
202 |
toolStripStatusLabelConnect.Text = "Connected - " + iDisplay.Vendor() + " - " + iDisplay.Product();
|
sl@10
|
203 |
//+ " - " + iDisplay.SerialNumber();
|
sl@7
|
204 |
}
|
sl@7
|
205 |
else
|
sl@7
|
206 |
{
|
sl@7
|
207 |
buttonFill.Enabled = false;
|
sl@7
|
208 |
buttonClear.Enabled = false;
|
sl@7
|
209 |
buttonOpen.Enabled = true;
|
sl@7
|
210 |
buttonClose.Enabled = false;
|
sl@7
|
211 |
trackBarBrightness.Enabled = false;
|
sl@9
|
212 |
toolStripStatusLabelConnect.Text = "Disconnected";
|
sl@7
|
213 |
}
|
sl@7
|
214 |
}
|
sl@9
|
215 |
|
sl@9
|
216 |
private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e)
|
sl@9
|
217 |
{
|
sl@9
|
218 |
Properties.Settings.Default.DisplayShowBorders = checkBoxShowBorders.Checked;
|
sl@9
|
219 |
Properties.Settings.Default.Save();
|
sl@9
|
220 |
}
|
sl@0
|
221 |
}
|
sl@0
|
222 |
}
|