# HG changeset patch # User sl # Date 1413228113 -7200 # Node ID 1d0cd5e6e0a99279109e2811332899585690a2b0 # Parent 6e50baf5a8110e9ee2ab0b33c8d6e4dbf0a8f032 Bitmap field now mostly working. diff -r 6e50baf5a811 -r 1d0cd5e6e0a9 Client/MainForm.Designer.cs --- a/Client/MainForm.Designer.cs Mon Oct 13 20:05:48 2014 +0200 +++ b/Client/MainForm.Designer.cs Mon Oct 13 21:21:53 2014 +0200 @@ -36,7 +36,7 @@ this.buttonAlignLeft = new System.Windows.Forms.Button(); this.buttonSetTopText = new System.Windows.Forms.Button(); this.buttonLayoutUpdate = new System.Windows.Forms.Button(); - this.button1 = new System.Windows.Forms.Button(); + this.buttonSetBitmap = new System.Windows.Forms.Button(); this.SuspendLayout(); // // buttonSetText @@ -113,22 +113,22 @@ this.buttonLayoutUpdate.UseVisualStyleBackColor = true; this.buttonLayoutUpdate.Click += new System.EventHandler(this.buttonLayoutUpdate_Click); // - // button1 + // buttonSetBitmap // - this.button1.Location = new System.Drawing.Point(12, 190); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 26; - this.button1.Text = "Set Bitmap"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); + this.buttonSetBitmap.Location = new System.Drawing.Point(12, 190); + this.buttonSetBitmap.Name = "buttonSetBitmap"; + this.buttonSetBitmap.Size = new System.Drawing.Size(75, 23); + this.buttonSetBitmap.TabIndex = 26; + this.buttonSetBitmap.Text = "Set Bitmap"; + this.buttonSetBitmap.UseVisualStyleBackColor = true; + this.buttonSetBitmap.Click += new System.EventHandler(this.buttonSetBitmap_Click); // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(443, 252); - this.Controls.Add(this.button1); + this.Controls.Add(this.buttonSetBitmap); this.Controls.Add(this.buttonLayoutUpdate); this.Controls.Add(this.buttonSetTopText); this.Controls.Add(this.buttonAlignRight); @@ -156,7 +156,7 @@ private System.Windows.Forms.Button buttonAlignLeft; private System.Windows.Forms.Button buttonSetTopText; private System.Windows.Forms.Button buttonLayoutUpdate; - private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button buttonSetBitmap; } } diff -r 6e50baf5a811 -r 1d0cd5e6e0a9 Client/MainForm.cs --- a/Client/MainForm.cs Mon Oct 13 20:05:48 2014 +0200 +++ b/Client/MainForm.cs Mon Oct 13 21:21:53 2014 +0200 @@ -160,19 +160,21 @@ iClient.SetLayout(layout); } - private void button1_Click(object sender, EventArgs e) + private void buttonSetBitmap_Click(object sender, EventArgs e) { - Bitmap bitmap = new Bitmap(60,60); + int x1 = 0; + int y1 = 0; + int x2 = 256; + int y2 = 32; + + Bitmap bitmap = new Bitmap(x2,y2); Pen blackPen = new Pen(Color.Black, 3); - int x1 = 0; - int y1 = 0; - int x2 = 60; - int y2 = 60; // Draw line to screen. using (var graphics = Graphics.FromImage(bitmap)) { graphics.DrawLine(blackPen, x1, y1, x2, y2); + graphics.DrawLine(blackPen, x1, y2, x2, y1); } iClient.SetBitmap(new BitmapField(0, bitmap)); diff -r 6e50baf5a811 -r 1d0cd5e6e0a9 Server/MainForm.cs --- a/Server/MainForm.cs Mon Oct 13 20:05:48 2014 +0200 +++ b/Server/MainForm.cs Mon Oct 13 21:21:53 2014 +0200 @@ -160,9 +160,19 @@ labelFontWidth.Text = "Font width: " + charWidth; } + MarqueeLabel label = null; + //Get the first label control we can find + foreach (Control ctrl in tableLayoutPanel.Controls) + { + if (ctrl is MarqueeLabel) + { + label = (MarqueeLabel)ctrl; + break; + } + } + //Now check font height and show a warning if needed. - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[0]; - if (label.Font.Height > label.Height) + if (label != null && label.Font.Height > label.Height) { labelWarning.Text = "WARNING: Selected font is too height by " + (label.Font.Height - label.Height) + " pixels!"; labelWarning.Visible = true; @@ -322,9 +332,12 @@ DateTime NewTickTime = DateTime.Now; //Update animation for all our marquees - foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls) + foreach (Control ctrl in tableLayoutPanel.Controls) { - ctrl.UpdateAnimation(LastTickTime, NewTickTime); + if (ctrl is MarqueeLabel) + { + ((MarqueeLabel)ctrl).UpdateAnimation(LastTickTime, NewTickTime); + } } @@ -813,9 +826,17 @@ client.Fields[aTextField.Index] = aTextField; //We are in the proper thread - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextField.Index]; - label.Text = aTextField.Text; - label.TextAlign = aTextField.Alignment; + if (tableLayoutPanel.Controls[aTextField.Index] is MarqueeLabel) + { + MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextField.Index]; + label.Text = aTextField.Text; + label.TextAlign = aTextField.Alignment; + } + else + { + //Wrong control type, re-create them all + UpdateTableLayoutPanel(iCurrentClientData); + } // UpdateClientTreeViewNode(client); } @@ -856,11 +877,22 @@ j++; } //Put each our text fields in a label control - for (int i = 0; i < aTextFields.Count; i++) + foreach (TextField field in aTextFields) { - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aTextFields[i].Index]; - label.Text = aTextFields[i].Text; - label.TextAlign = aTextFields[i].Alignment; + if (tableLayoutPanel.Controls[field.Index] is MarqueeLabel) + { + //Proper control type just update the text + MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[field.Index]; + label.Text = field.Text; + label.TextAlign = field.Alignment; + } + else + { + //Wrong control for the given field + //Update our layout thus re-creating our controls + UpdateTableLayoutPanel(iCurrentClientData); + break; //No need to keep on looping layout update will take care of everything + } } @@ -898,8 +930,16 @@ client.Fields[aBitmapField.Index] = aBitmapField; //We are in the proper thread - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aBitmapField.Index]; - label.Text = "Bitmap"; + if (tableLayoutPanel.Controls[aBitmapField.Index] is PictureBox) + { + PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aBitmapField.Index]; + pictureBox.Image = aBitmapField.Bitmap; + } + else + { + //Wrong control type re-create them all + UpdateTableLayoutPanel(iCurrentClientData); + } // UpdateClientTreeViewNode(client); } @@ -1156,21 +1196,26 @@ this.tableLayoutPanel.RowStyles.Add(layout.Rows[j]); } - MarqueeLabel control = new SharpDisplayManager.MarqueeLabel(); - control.AutoEllipsis = true; - control.AutoSize = true; - control.BackColor = System.Drawing.Color.Transparent; - control.Dock = System.Windows.Forms.DockStyle.Fill; - control.Location = new System.Drawing.Point(1, 1); - control.Margin = new System.Windows.Forms.Padding(0); - control.Name = "marqueeLabelCol" + layout.Columns.Count + "Row" + layout.Rows.Count; - control.OwnTimer = false; - control.PixelsPerSecond = 64; - control.Separator = "|"; + + MarqueeLabel label = new SharpDisplayManager.MarqueeLabel(); + label.AutoEllipsis = true; + label.AutoSize = true; + label.BackColor = System.Drawing.Color.Transparent; + label.Dock = System.Windows.Forms.DockStyle.Fill; + label.Location = new System.Drawing.Point(1, 1); + label.Margin = new System.Windows.Forms.Padding(0); + label.Name = "marqueeLabelCol" + layout.Columns.Count + "Row" + layout.Rows.Count; + label.OwnTimer = false; + label.PixelsPerSecond = 64; + label.Separator = "|"; //control.Size = new System.Drawing.Size(254, 30); //control.TabIndex = 2; - control.Font = cds.Font; - control.Text = ""; + label.Font = cds.Font; + label.Text = ""; + label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + label.UseCompatibleTextRendering = true; + + Control control = label; //If we already have a text for that field if (aClient.Fields.Count > tableLayoutPanel.Controls.Count) { @@ -1180,10 +1225,24 @@ TextField textField = (TextField)field; control.Text = textField.Text; } + else if (field is BitmapField) + { + //Create picture box + PictureBox pictue = new PictureBox(); + pictue.AutoSize = true; + pictue.BackColor = System.Drawing.Color.Transparent; + pictue.Dock = System.Windows.Forms.DockStyle.Fill; + pictue.Location = new System.Drawing.Point(1, 1); + pictue.Margin = new System.Windows.Forms.Padding(0); + pictue.Name = "pictureBox" + layout.Columns.Count + "Row" + layout.Rows.Count; + //Set our image + BitmapField bitmapField = (BitmapField)field; + pictue.Image = bitmapField.Bitmap; + // + control = pictue; + } } - - control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - control.UseCompatibleTextRendering = true; + // tableLayoutPanel.Controls.Add(control, i, j); } @@ -1192,6 +1251,56 @@ CheckFontHeight(); } + /// + /// Not used yet. + /// + /// + private void CreateControlForDataField(DataField aField) + { + Control control=null; + if (aField is TextField) + { + MarqueeLabel label = new SharpDisplayManager.MarqueeLabel(); + label.AutoEllipsis = true; + label.AutoSize = true; + label.BackColor = System.Drawing.Color.Transparent; + label.Dock = System.Windows.Forms.DockStyle.Fill; + label.Location = new System.Drawing.Point(1, 1); + label.Margin = new System.Windows.Forms.Padding(0); + label.Name = "marqueeLabel" + aField.Index; + label.OwnTimer = false; + label.PixelsPerSecond = 64; + label.Separator = "|"; + //control.Size = new System.Drawing.Size(254, 30); + //control.TabIndex = 2; + label.Font = cds.Font; + + label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + label.UseCompatibleTextRendering = true; + TextField textField = (TextField)aField; + label.Text = textField.Text; + // + control = label; + } + else if (aField is BitmapField) + { + //Create picture box + PictureBox picture = new PictureBox(); + picture.AutoSize = true; + picture.BackColor = System.Drawing.Color.Transparent; + picture.Dock = System.Windows.Forms.DockStyle.Fill; + picture.Location = new System.Drawing.Point(1, 1); + picture.Margin = new System.Windows.Forms.Padding(0); + picture.Name = "pictureBox" + aField; + //Set our image + BitmapField bitmapField = (BitmapField)aField; + picture.Image = bitmapField.Bitmap; + // + control = picture; + } + + } + private void buttonAlignLeft_Click(object sender, EventArgs e) {