Fixing binaries output paths.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
22 using System.ComponentModel;
27 using System.Threading.Tasks;
28 using System.Windows.Forms;
29 using System.ServiceModel;
30 using System.ServiceModel.Channels;
31 using System.Diagnostics;
35 namespace SharpDisplayClient
37 public partial class MainForm : Form
39 public StartParams Params { get; set; }
42 DisplayClient iClient;
44 ContentAlignment Alignment;
45 DataField iTextFieldTop;
53 InitializeComponent();
54 Alignment = ContentAlignment.MiddleLeft;
55 iTextFieldTop = new DataField(0);
61 /// <param name="sender"></param>
62 /// <param name="e"></param>
63 private void MainForm_Load(object sender, EventArgs e)
65 iClient = new DisplayClient(this);
68 //Connect using unique name
69 //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
70 string name = "Client-" + (iClient.ClientCount() - 1);
71 iClient.SetName(name);
72 //Text = Text + ": " + name;
73 Text = "[[" + name + "]] " + iClient.SessionId;
76 textBoxTop.Text = iClient.Name;
77 textBoxBottom.Text = iClient.SessionId;
81 //Parameters where specified use them
82 if (Params.TopText != "")
84 textBoxTop.Text = Params.TopText;
87 if (Params.BottomText != "")
89 textBoxBottom.Text = Params.BottomText;
92 Location = Params.Location;
94 SetBasicLayoutAndText();
101 public delegate void CloseConnectionDelegate();
102 public delegate void CloseDelegate();
107 public void CloseConnectionThreadSafe()
109 if (this.InvokeRequired)
111 //Not in the proper thread, invoke ourselves
112 CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe);
113 this.Invoke(d, new object[] { });
117 //We are in the proper thread
120 string sessionId = iClient.SessionId;
121 Trace.TraceInformation("Closing client: " + sessionId);
123 Trace.TraceInformation("Closed client: " + sessionId);
133 public void CloseThreadSafe()
135 if (this.InvokeRequired)
137 //Not in the proper thread, invoke ourselves
138 CloseDelegate d = new CloseDelegate(CloseThreadSafe);
139 this.Invoke(d, new object[] { });
143 //We are in the proper thread
149 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
151 CloseConnectionThreadSafe();
154 public bool IsClientReady()
156 return (iClient != null && iClient.IsReady());
159 private void buttonAlignLeft_Click(object sender, EventArgs e)
161 Alignment = ContentAlignment.MiddleLeft;
162 textBoxTop.TextAlign = HorizontalAlignment.Left;
163 textBoxBottom.TextAlign = HorizontalAlignment.Left;
166 private void buttonAlignCenter_Click(object sender, EventArgs e)
168 Alignment = ContentAlignment.MiddleCenter;
169 textBoxTop.TextAlign = HorizontalAlignment.Center;
170 textBoxBottom.TextAlign = HorizontalAlignment.Center;
173 private void buttonAlignRight_Click(object sender, EventArgs e)
175 Alignment = ContentAlignment.MiddleRight;
176 textBoxTop.TextAlign = HorizontalAlignment.Right;
177 textBoxBottom.TextAlign = HorizontalAlignment.Right;
180 private void buttonSetTopText_Click(object sender, EventArgs e)
182 //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
183 iTextFieldTop.Text = textBoxTop.Text;
184 iTextFieldTop.Alignment = Alignment;
185 bool res = iClient.SetField(iTextFieldTop);
189 MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);
195 private void buttonSetText_Click(object sender, EventArgs e)
197 SetBasicLayoutAndText();
200 void SetBasicLayoutAndText()
202 //Set one column two lines layout
203 TableLayout layout = new TableLayout(1, 2);
204 iClient.SetLayout(layout);
207 iClient.CreateFields(new DataField[]
209 new DataField(0, textBoxTop.Text, Alignment),
210 new DataField(1, textBoxBottom.Text, Alignment)
215 private void buttonLayoutUpdate_Click(object sender, EventArgs e)
217 //Define a 2 by 2 layout
218 TableLayout layout = new TableLayout(2,2);
219 //Second column only takes up 25%
220 layout.Columns[1].Width = 25F;
221 //Send layout to server
222 iClient.SetLayout(layout);
225 iClient.CreateFields(new DataField[]
227 new DataField(0, textBoxTop.Text, Alignment),
228 new DataField(1, textBoxBottom.Text, Alignment),
229 new DataField(2, "Third text field", Alignment),
230 new DataField(3, "Forth text field", Alignment)
235 private void buttonSetBitmap_Click(object sender, EventArgs e)
242 Bitmap bitmap = new Bitmap(x2,y2);
243 Pen blackPen = new Pen(Color.Black, 3);
245 // Draw line to screen.
246 using (var graphics = Graphics.FromImage(bitmap))
248 graphics.DrawLine(blackPen, x1, y1, x2, y2);
249 graphics.DrawLine(blackPen, x1, y2, x2, y1);
252 DataField field = new DataField(0, bitmap);
253 //field.ColumnSpan = 2;
254 iClient.SetField(field);
257 private void buttonBitmapLayout_Click(object sender, EventArgs e)
259 SetLayoutWithBitmap();
263 /// Define a layout with a bitmap field on the left and two lines of text on the right.
265 private void SetLayoutWithBitmap()
267 //Define a 2 by 2 layout
268 TableLayout layout = new TableLayout(2, 2);
269 //First column only takes 25%
270 layout.Columns[0].Width = 25F;
271 //Second column takes up 75%
272 layout.Columns[1].Width = 75F;
273 //Send layout to server
274 iClient.SetLayout(layout);
276 //Set a bitmap for our first field
282 Bitmap bitmap = new Bitmap(x2, y2);
283 Pen blackPen = new Pen(Color.Black, 3);
285 // Draw line to screen.
286 using (var graphics = Graphics.FromImage(bitmap))
288 graphics.DrawLine(blackPen, x1, y1, x2, y2);
289 graphics.DrawLine(blackPen, x1, y2, x2, y1);
292 //Create a bitmap field from the bitmap we just created
293 DataField field = new DataField(0, bitmap);
294 //We want our bitmap field to span across two rows
298 iClient.CreateFields(new DataField[]
301 new DataField(1, textBoxTop.Text, Alignment),
302 new DataField(2, textBoxBottom.Text, Alignment)
307 private void buttonIndicatorsLayout_Click(object sender, EventArgs e)
309 //Define a 2 by 4 layout
310 TableLayout layout = new TableLayout(2, 4);
312 layout.Columns[0].Width = 87.5F;
314 layout.Columns[1].Width = 12.5F;
315 //Send layout to server
316 iClient.SetLayout(layout);
318 //Create a bitmap for our indicators field
324 Bitmap bitmap = new Bitmap(x2, y2);
325 Pen blackPen = new Pen(Color.Black, 3);
327 // Draw line to screen.
328 using (var graphics = Graphics.FromImage(bitmap))
330 graphics.DrawLine(blackPen, x1, y1, x2, y2);
331 graphics.DrawLine(blackPen, x1, y2, x2, y1);
334 //Create a bitmap field from the bitmap we just created
335 DataField indicator1 = new DataField(2, bitmap);
336 //Create a bitmap field from the bitmap we just created
337 DataField indicator2 = new DataField(3, bitmap);
338 //Create a bitmap field from the bitmap we just created
339 DataField indicator3 = new DataField(4, bitmap);
340 //Create a bitmap field from the bitmap we just created
341 DataField indicator4 = new DataField(5, bitmap);
344 DataField textFieldTop = new DataField(0, textBoxTop.Text, Alignment);
345 textFieldTop.RowSpan = 2;
347 DataField textFieldBottom = new DataField(1, textBoxBottom.Text, Alignment);
348 textFieldBottom.RowSpan = 2;
352 iClient.CreateFields(new DataField[]
364 private void buttonUpdateTexts_Click(object sender, EventArgs e)
367 bool res = iClient.SetFields(new DataField[]
369 new DataField(0, textBoxTop.Text, Alignment),
370 new DataField(1, textBoxBottom.Text, Alignment)
375 MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);
380 private void buttonLayoutOneTextField_Click(object sender, EventArgs e)
382 //Set one column two lines layout
383 TableLayout layout = new TableLayout(1, 1);
384 iClient.SetLayout(layout);
387 iClient.CreateFields(new DataField[]
389 new DataField(0, textBoxTop.Text, Alignment)