GUI/SharpDisplayInterface.cs
branchMiniDisplay
changeset 447 af40a92d480d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/GUI/SharpDisplayInterface.cs	Thu Jan 01 23:35:49 2015 +0100
     1.3 @@ -0,0 +1,204 @@
     1.4 +//
     1.5 +// Define a public API for both SharpDisplay client and server to use.
     1.6 +//
     1.7 +
     1.8 +using System;
     1.9 +using System.Collections.Generic;
    1.10 +using System.Linq;
    1.11 +using System.Text;
    1.12 +using System.Threading.Tasks;
    1.13 +using System.ServiceModel;
    1.14 +using System.Collections;
    1.15 +using System.Drawing;
    1.16 +using System.Runtime.Serialization;
    1.17 +using System.Windows.Forms;
    1.18 +
    1.19 +
    1.20 +namespace SharpDisplay
    1.21 +{
    1.22 +	/// <summary>
    1.23 +	/// For client to specify a specific layout.
    1.24 +	/// </summary>
    1.25 +	[DataContract]
    1.26 +	public class TableLayout
    1.27 +	{
    1.28 +		public TableLayout()
    1.29 +		{
    1.30 +			Columns = new List<ColumnStyle>();
    1.31 +			Rows = new List<RowStyle>();
    1.32 +			Cells = new List<DataField>();
    1.33 +		}
    1.34 +
    1.35 +		public TableLayout(int aColumnCount, int aRowCount)
    1.36 +		{
    1.37 +			Columns = new List<ColumnStyle>();
    1.38 +			Rows = new List<RowStyle>();
    1.39 +
    1.40 +			for (int i = 0; i < aColumnCount; i++)
    1.41 +			{
    1.42 +				Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount));
    1.43 +			}
    1.44 +
    1.45 +			for (int i = 0; i < aRowCount; i++)
    1.46 +			{
    1.47 +				Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount));
    1.48 +			}
    1.49 +		}
    1.50 +
    1.51 +		[DataMember]
    1.52 +		public List<DataField> Cells { get; set; }
    1.53 +
    1.54 +		[DataMember]
    1.55 +		public List<ColumnStyle> Columns { get; set; }
    1.56 +
    1.57 +		[DataMember]
    1.58 +		public List<RowStyle> Rows { get; set; }
    1.59 +	}
    1.60 +
    1.61 +	/// <summary>
    1.62 +	///
    1.63 +	/// </summary>
    1.64 +	[DataContract]
    1.65 +	public class DataField
    1.66 +	{
    1.67 +		public DataField()
    1.68 +		{
    1.69 +			Index = 0;
    1.70 +			ColumnSpan = 1;
    1.71 +			RowSpan = 1;
    1.72 +			//Text
    1.73 +			Text = "";
    1.74 +			Alignment = ContentAlignment.MiddleLeft;
    1.75 +			//Bitmap
    1.76 +			Bitmap = null;
    1.77 +		}
    1.78 +
    1.79 +		//Text constructor
    1.80 +		public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft)
    1.81 +		{
    1.82 +			ColumnSpan = 1;
    1.83 +			RowSpan = 1;
    1.84 +			Index = aIndex;
    1.85 +			Text = aText;
    1.86 +			Alignment = aAlignment;
    1.87 +			//
    1.88 +			Bitmap = null;
    1.89 +		}
    1.90 +
    1.91 +		//Bitmap constructor
    1.92 +		public DataField(int aIndex, Bitmap aBitmap)
    1.93 +		{
    1.94 +			ColumnSpan = 1;
    1.95 +			RowSpan = 1;
    1.96 +			Index = aIndex;
    1.97 +			Bitmap = aBitmap;
    1.98 +			//Text
    1.99 +			Text = "";
   1.100 +			Alignment = ContentAlignment.MiddleLeft;
   1.101 +		}
   1.102 +
   1.103 +
   1.104 +		//Generic layout properties
   1.105 +		[DataMember]
   1.106 +		public int Index { get; set; }
   1.107 +
   1.108 +		[DataMember]
   1.109 +		public int Column { get; set; }
   1.110 +
   1.111 +		[DataMember]
   1.112 +		public int Row { get; set; }
   1.113 +
   1.114 +		[DataMember]
   1.115 +		public int ColumnSpan { get; set; }
   1.116 +
   1.117 +		[DataMember]
   1.118 +		public int RowSpan { get; set; }
   1.119 +
   1.120 +		//Text properties
   1.121 +		[DataMember]
   1.122 +		public string Text { get; set; }
   1.123 +
   1.124 +		[DataMember]
   1.125 +		public ContentAlignment Alignment { get; set; }
   1.126 +
   1.127 +		//Bitmap properties
   1.128 +		[DataMember]
   1.129 +		public Bitmap Bitmap { get; set; }
   1.130 +
   1.131 +		//
   1.132 +		public bool IsBitmap { get { return Bitmap != null; } }
   1.133 +		//
   1.134 +		public bool IsText { get { return Bitmap == null; } }
   1.135 +		//
   1.136 +		public bool IsSameLayout(DataField aField)
   1.137 +		{
   1.138 +			return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan);
   1.139 +		}
   1.140 +	}
   1.141 +
   1.142 +	/// <summary>
   1.143 +	/// Define our SharpDisplay service.
   1.144 +	/// Clients and servers must implement it to communicate with one another.
   1.145 +	/// Through this service clients can send requests to a server.
   1.146 +	/// Through this service a server session can receive requests from a client.
   1.147 +	/// </summary>
   1.148 +	[ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
   1.149 +	public interface IService
   1.150 +	{
   1.151 +		/// <summary>
   1.152 +		/// Set the name of this client.
   1.153 +		/// Name is a convenient way to recognize your client.
   1.154 +		/// Naming you client is not mandatory.
   1.155 +		/// In the absence of a name the session ID is often used instead.
   1.156 +		/// </summary>
   1.157 +		/// <param name="aClientName"></param>
   1.158 +		[OperationContract(IsOneWay = true)]
   1.159 +		void SetName(string aClientName);
   1.160 +
   1.161 +		/// <summary>
   1.162 +		/// </summary>
   1.163 +		/// <param name="aLayout"></param>
   1.164 +		[OperationContract(IsOneWay = true)]
   1.165 +		void SetLayout(TableLayout aLayout);
   1.166 +
   1.167 +		/// <summary>
   1.168 +		/// Set the given field on your display.
   1.169 +		/// Fields are often just lines of text or bitmaps.
   1.170 +		/// </summary>
   1.171 +		/// <param name="aTextFieldIndex"></param>
   1.172 +		[OperationContract(IsOneWay = true)]
   1.173 +		void SetField(DataField aField);
   1.174 +
   1.175 +		/// <summary>
   1.176 +		/// Allows a client to set multiple fields at once.
   1.177 +		/// </summary>
   1.178 +		/// <param name="aFields"></param>
   1.179 +		[OperationContract(IsOneWay = true)]
   1.180 +		void SetFields(System.Collections.Generic.IList<DataField> aFields);
   1.181 +
   1.182 +		/// <summary>
   1.183 +		/// Provides the number of clients currently connected
   1.184 +		/// </summary>
   1.185 +		/// <returns></returns>
   1.186 +		[OperationContract()]
   1.187 +		int ClientCount();
   1.188 +
   1.189 +	}
   1.190 +
   1.191 +	/// <summary>
   1.192 +	/// SharDisplay callback provides a means for a server to notify its clients.
   1.193 +	/// </summary>
   1.194 +	public interface ICallback
   1.195 +	{
   1.196 +		[OperationContract(IsOneWay = true)]
   1.197 +		void OnConnected();
   1.198 +
   1.199 +		/// <summary>
   1.200 +		/// Tell our client to close its connection.
   1.201 +		/// Notably sent when the server is shutting down.
   1.202 +		/// </summary>
   1.203 +		[OperationContract(IsOneWay = true)]
   1.204 +		void OnCloseOrder();
   1.205 +	}
   1.206 +
   1.207 +}