private void SetupForm() { foreach (KeyValuePair <string, AbstractStyleElement> styleElement in m_Chrono.DrawingStyle.Elements) { if (m_firstElement == null) { m_firstElement = styleElement.Value; } else if (m_secondElement == null) { m_secondElement = styleElement.Value; } else { log.DebugFormat("Discarding style element: \"{0}\". (Only 2 style elements supported).", styleElement.Key); } } // Configure editor line for each element. // The style element is responsible for updating the internal value and the editor appearance. // The element internal value might also be bound to a style helper property so that the underlying drawing will get updated. if (m_firstElement != null) { lblFirstElement.Text = m_firstElement.DisplayName; m_firstElement.ValueChanged += element_ValueChanged; int editorsLeft = 150; // works in High DPI ? Control firstEditor = m_firstElement.GetEditor(); firstEditor.Size = new Size(50, 20); firstEditor.Location = new Point(editorsLeft, lblFirstElement.Top - 3); grpConfig.Controls.Add(firstEditor); if (m_secondElement != null) { lblSecondElement.Text = m_secondElement.DisplayName; m_secondElement.ValueChanged += element_ValueChanged; Control secondEditor = m_secondElement.GetEditor(); secondEditor.Size = new Size(50, 20); secondEditor.Location = new Point(editorsLeft, lblSecondElement.Top - 3); grpConfig.Controls.Add(secondEditor); } else { lblSecondElement.Visible = false; } } else { lblFirstElement.Visible = false; } }
public void ReadXml(XmlReader _xmlReader) { m_StyleElements.Clear(); _xmlReader.ReadStartElement(); // <ToolPreset Key="ToolName"> or <DrawingStyle> while (_xmlReader.NodeType == XmlNodeType.Element) { AbstractStyleElement styleElement = null; string key = _xmlReader.GetAttribute("Key"); switch (_xmlReader.Name) { case "Color": styleElement = new StyleElementColor(_xmlReader); break; case "FontSize": styleElement = new StyleElementFontSize(_xmlReader); break; case "PenSize": styleElement = new StyleElementPenSize(_xmlReader); break; case "LineSize": styleElement = new StyleElementLineSize(_xmlReader); break; case "Arrows": styleElement = new StyleElementLineEnding(_xmlReader); break; case "TrackShape": styleElement = new StyleElementTrackShape(_xmlReader); break; default: log.ErrorFormat("Could not import style element \"{0}\"", _xmlReader.Name); log.ErrorFormat("Content was: {0}", _xmlReader.ReadOuterXml()); break; } if (styleElement != null) { m_StyleElements.Add(key, styleElement); } } _xmlReader.ReadEndElement(); }
public void Bind(AbstractStyleElement original) { // This function is used in the context of cloning, to clone the target data. bindTarget = original.bindTarget; bindTargetProperty = original.bindTargetProperty; }
private void LoadPreset(AbstractDrawingTool preset) { // Load a single preset // Tool title and icon btnToolIcon.BackColor = Color.Transparent; btnToolIcon.Image = preset.Icon; lblToolName.Text = preset.DisplayName; // Clean up styleElements.Clear(); grpConfig.Controls.Clear(); Graphics helper = grpConfig.CreateGraphics(); Size editorSize = new Size(60, 20); int minimalWidth = btnApply.Width + btnCancel.Width + 10; editorsLeft = minimalWidth - 20 - editorSize.Width; int mimimalHeight = grpConfig.Height; int lastEditorBottom = 10; foreach (KeyValuePair <string, AbstractStyleElement> pair in preset.StylePreset.Elements) { AbstractStyleElement styleElement = pair.Value; styleElements.Add(styleElement); Button btn = new Button(); btn.Image = styleElement.Icon; btn.Size = new Size(20, 20); btn.Location = new Point(10, lastEditorBottom + 15); btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderSize = 0; btn.BackColor = Color.Transparent; Label lbl = new Label(); lbl.Text = styleElement.DisplayName; lbl.AutoSize = true; lbl.Location = new Point(btn.Right + 10, lastEditorBottom + 20); SizeF labelSize = helper.MeasureString(lbl.Text, lbl.Font); if (lbl.Left + labelSize.Width + 25 > editorsLeft) { editorsLeft = (int)(lbl.Left + labelSize.Width + 25); } Control miniEditor = styleElement.GetEditor(); miniEditor.Size = editorSize; miniEditor.Location = new Point(editorsLeft, btn.Top); lastEditorBottom = miniEditor.Bottom; grpConfig.Controls.Add(btn); grpConfig.Controls.Add(lbl); grpConfig.Controls.Add(miniEditor); } helper.Dispose(); // Recheck all mini editors to realign them on the leftmost. foreach (Control c in grpConfig.Controls) { if (!(c is Label) && !(c is Button)) { if (c.Left < editorsLeft) { c.Left = editorsLeft; } } } }
private void LoadPreset(AbstractDrawingTool _preset) { // Load a single preset // The layout is dynamic. The groupbox and the whole form is resized when needed on a "GrowOnly" basis. // Tool title and icon btnToolIcon.BackColor = Color.Transparent; btnToolIcon.Image = _preset.Icon; lblToolName.Text = _preset.DisplayName; // Clean up m_Elements.Clear(); grpConfig.Controls.Clear(); Graphics helper = grpConfig.CreateGraphics(); Size editorSize = new Size(60, 20); // Initialize the horizontal layout with a minimal value, // it will be fixed later if some of the entries have long text. int minimalWidth = btnApply.Width + btnCancel.Width + 10; //m_iEditorsLeft = Math.Max(minimalWidth - 20 - editorSize.Width, m_iEditorsLeft); m_iEditorsLeft = minimalWidth - 20 - editorSize.Width; int mimimalHeight = grpConfig.Height; int lastEditorBottom = 10; foreach (KeyValuePair <string, AbstractStyleElement> pair in _preset.StylePreset.Elements) { AbstractStyleElement styleElement = pair.Value; m_Elements.Add(styleElement); //styleElement.ValueChanged += element_ValueChanged; Button btn = new Button(); btn.Image = styleElement.Icon; btn.Size = new Size(20, 20); btn.Location = new Point(10, lastEditorBottom + 15); btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderSize = 0; btn.BackColor = Color.Transparent; Label lbl = new Label(); lbl.Text = styleElement.DisplayName; lbl.AutoSize = true; lbl.Location = new Point(btn.Right + 10, lastEditorBottom + 20); SizeF labelSize = helper.MeasureString(lbl.Text, lbl.Font); if (lbl.Left + labelSize.Width + 25 > m_iEditorsLeft) { // dynamic horizontal layout for high dpi and verbose languages. m_iEditorsLeft = (int)(lbl.Left + labelSize.Width + 25); } Control miniEditor = styleElement.GetEditor(); miniEditor.Size = editorSize; miniEditor.Location = new Point(m_iEditorsLeft, btn.Top); lastEditorBottom = miniEditor.Bottom; grpConfig.Controls.Add(btn); grpConfig.Controls.Add(lbl); grpConfig.Controls.Add(miniEditor); } helper.Dispose(); // Recheck all mini editors for the left positionning. foreach (Control c in grpConfig.Controls) { if (!(c is Label) && !(c is Button)) { if (c.Left < m_iEditorsLeft) { c.Left = m_iEditorsLeft; } } } //grpConfig.Height = Math.Max(lastEditorBottom + 20, grpConfig.Height); //grpConfig.Width = Math.Max(m_iEditorsLeft + editorSize.Width + 20, grpConfig.Width); grpConfig.Height = Math.Max(lastEditorBottom + 20, 110); grpConfig.Width = m_iEditorsLeft + editorSize.Width + 20; lstPresets.Height = grpConfig.Bottom - lstPresets.Top; btnApply.Top = grpConfig.Bottom + 10; btnApply.Left = grpConfig.Right - (btnCancel.Width + 10 + btnApply.Width); btnCancel.Top = btnApply.Top; btnCancel.Left = btnApply.Right + 10; int borderLeft = this.Width - this.ClientRectangle.Width; this.Width = borderLeft + btnCancel.Right + 10; int borderTop = this.Height - this.ClientRectangle.Height; this.Height = borderTop + btnApply.Bottom + 10; }
private void SetupForm() { // Dynamic layout: // Any number of mini editor lines. (must scale vertically) // High dpi vs normal dpi (scales vertically and horizontally) // Verbose languages (scales horizontally) // Clean up grpConfig.Controls.Clear(); Graphics helper = grpConfig.CreateGraphics(); Size editorSize = new Size(60, 20); // Initialize the horizontal layout with a minimal value, // it will be fixed later if some of the entries have long text. int minimalWidth = btnOK.Width + btnCancel.Width + 10; int editorsLeft = minimalWidth - 20 - editorSize.Width; int lastEditorBottom = 10; foreach (KeyValuePair <string, AbstractStyleElement> pair in m_Style.Elements) { AbstractStyleElement styleElement = pair.Value; m_Elements.Add(styleElement); styleElement.ValueChanged += element_ValueChanged; Button btn = new Button(); btn.Image = styleElement.Icon; btn.Size = new Size(20, 20); btn.Location = new Point(10, lastEditorBottom + 15); btn.FlatStyle = FlatStyle.Flat; btn.FlatAppearance.BorderSize = 0; btn.BackColor = Color.Transparent; Label lbl = new Label(); lbl.Text = styleElement.DisplayName; lbl.AutoSize = true; lbl.Location = new Point(btn.Right + 10, lastEditorBottom + 20); SizeF labelSize = helper.MeasureString(lbl.Text, lbl.Font); if (lbl.Left + labelSize.Width + 25 > editorsLeft) { // dynamic horizontal layout for high dpi and verbose languages. editorsLeft = (int)(lbl.Left + labelSize.Width + 25); } Control miniEditor = styleElement.GetEditor(); miniEditor.Size = editorSize; miniEditor.Location = new Point(editorsLeft, btn.Top); lastEditorBottom = miniEditor.Bottom; grpConfig.Controls.Add(btn); grpConfig.Controls.Add(lbl); grpConfig.Controls.Add(miniEditor); } helper.Dispose(); // Recheck all mini editors for the left positionning. foreach (Control c in grpConfig.Controls) { if (!(c is Label) && !(c is Button)) { if (c.Left < editorsLeft) { c.Left = editorsLeft; } } } grpConfig.Height = lastEditorBottom + 20; grpConfig.Width = editorsLeft + editorSize.Width + 20; btnOK.Top = grpConfig.Bottom + 10; btnOK.Left = grpConfig.Right - (btnCancel.Width + 10 + btnOK.Width); btnCancel.Top = btnOK.Top; btnCancel.Left = btnOK.Right + 10; int borderLeft = this.Width - this.ClientRectangle.Width; this.Width = borderLeft + btnCancel.Right + 10; int borderTop = this.Height - this.ClientRectangle.Height; this.Height = borderTop + btnOK.Bottom + 10; }