/// <summary> /// Set width to the specified one /// </summary> /// <param name="color"></param> private void SetLineCap(ConnectionCap style) { mCurrentHotTrack = -1; mCurrentSelected = -1; // Search the width on the known width list for (int widthIndex = 0; widthIndex < CustomCaps.SelectableLineCaps.Length; widthIndex++) { if (style == CustomCaps.SelectableLineCaps[widthIndex]) { mCurrentSelected = widthIndex; mCurrentHotTrack = -1; } } this.Refresh(); }
/// <summary> /// Paints one color button /// </summary> /// <param name="graphics"></param> /// <param name="color"></param> /// <param name="hotTrack"></param> /// <param name="selected"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private Rectangle PaintLine(Graphics graphics, ConnectionCap style, bool hotTrack, bool selected, int x, int y) { graphics.SmoothingMode = SmoothingMode.AntiAlias; // Button inside rectangle RectangleF mainRec = new RectangleF(x + 3, y + 3, 100, 1.5F); // Button border rectangle Rectangle borderRec = new Rectangle(x - 7, y - 3, 114, 15); // Check if the button is selected and HotTrack ( no the same color) bool selectedAndHotTrack = selected && hotTrack; // Paints the button using the brushes needed using (Brush hotTrackBrush = new SolidBrush(ArtPalette.ButtonHoverLight)) using (Brush selectedBrush = new SolidBrush(ArtPalette.ButtonHoverDark)) using (Brush selectedHotTrackBrush = new SolidBrush(ArtPalette.SelectedAndHover)) using (Pen selectedPen = new Pen(ArtPalette.SelectedBorder)) using (Pen linePen = new Pen(Color.DimGray, 1.7F)) using (Pen anchorPen = new Pen(Color.DimGray, 5F)) using (Pen borderPen = new Pen(ArtPalette.ButtonBorder)) { //linePen.CustomEndCap = // Paints the rectangle with the Track/Selected color // if this color is selected/hottrack if (selectedAndHotTrack) { graphics.FillRectangle(selectedHotTrackBrush, borderRec); graphics.DrawRectangle(selectedPen, borderRec); } else if (hotTrack) { graphics.FillRectangle(hotTrackBrush, borderRec); graphics.DrawRectangle(selectedPen, borderRec); } else if (selected) { graphics.FillRectangle(selectedBrush, borderRec); graphics.DrawRectangle(selectedPen, borderRec); } // Fills the rectangle with the current color, paints // the background. graphics.DrawString(style.ToString(), this.Font, Brushes.DimGray, x + 109, y - 1); switch (style) { case ConnectionCap.ArrowBoth: anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; graphics.DrawLine(anchorPen, x + 104, y + 4, x + 105, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.NoAnchor; graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); graphics.DrawLine(anchorPen, x - 5, y + 4, x - 4, y + 4); break; case ConnectionCap.ArrowRight: anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); graphics.DrawLine(anchorPen, x + 104, y + 4, x + 105, y + 4); break; case ConnectionCap.ArrowLeft: anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); graphics.DrawLine(anchorPen, x - 5, y + 4, x - 4, y + 4); break; case ConnectionCap.DiamondBoth: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; graphics.DrawLine(anchorPen, x, y + 4, x + 1, y + 4); break; case ConnectionCap.DiamondRight: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); break; case ConnectionCap.DiamondLeft: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.RoundBoth: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.RoundRight: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); break; case ConnectionCap.RoundLeft: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.SquareBoth: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.SquareAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.SquareAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.SquareRight: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.SquareAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); break; case ConnectionCap.SquareLeft: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.SquareAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.Generalization: anchorPen.CustomEndCap = generalizationCap; //anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.Custom; anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.NoAnchor; //graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); anchorPen.Width = 2F; graphics.DrawLine(anchorPen, x - 2, y + 4, x + 96, y + 4); break; case ConnectionCap.NoCap: return borderRec; } //graphics.FillRectangle(Brushes.DimGray, mainRec); //graphics.DrawRectangle(borderPen, Rectangle.Round( mainRec)); } return borderRec; }
/// <summary> /// Initialized a new instance of the OfficeLineCapPicker in order to provide /// color picker control that could be used in a model or non-model form. /// </summary> /// <param name="startingColor">Starting color to the OfficeLineCapPicker control</param> public OfficeLineCapPicker(ConnectionCap startStyle) : this() { LineCap = startStyle; }
public SelectableLineCaps(ConnectionCap cap) { mLineCap = cap; }
/// <summary> /// Initializes a new instance of the ToolStripLineCapPicker that holds /// OfficeColorPicker control inside a ToolStripItem to add to ToolStrip containers. /// </summary> /// <param name="startingColor">The color to assign to the color picker control</param> public ToolStripLineCapPicker(ConnectionCap startingStyle) : base() { LineCap = startingStyle; InitControl(); }
/// <summary> /// Paints one color button /// </summary> /// <param name="graphics"></param> /// <param name="color"></param> /// <param name="hotTrack"></param> /// <param name="selected"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private Rectangle PaintLine(Graphics graphics, ConnectionCap style, bool hotTrack, bool selected, int x, int y) { graphics.SmoothingMode = SmoothingMode.AntiAlias; // Button inside rectangle RectangleF mainRec = new RectangleF(x + 3, y + 3, 100, 1.5F); // Button border rectangle Rectangle borderRec = new Rectangle(x - 7, y - 3, 114, 15); // Check if the button is selected and HotTrack ( no the same color) bool selectedAndHotTrack = selected && hotTrack; // Paints the button using the brushes needed using (Brush hotTrackBrush = new SolidBrush(ArtPalette.ButtonHoverLight)) using (Brush selectedBrush = new SolidBrush(ArtPalette.ButtonHoverDark)) using (Brush selectedHotTrackBrush = new SolidBrush(ArtPalette.SelectedAndHover)) using (Pen selectedPen = new Pen(ArtPalette.SelectedBorder)) using (Pen linePen = new Pen(Color.DimGray, 1.7F)) using (Pen anchorPen = new Pen(Color.DimGray, 5F)) using (Pen borderPen = new Pen(ArtPalette.ButtonBorder)) { //linePen.CustomEndCap = // Paints the rectangle with the Track/Selected color // if this color is selected/hottrack if (selectedAndHotTrack) { graphics.FillRectangle(selectedHotTrackBrush, borderRec); graphics.DrawRectangle(selectedPen, borderRec); } else if (hotTrack) { graphics.FillRectangle(hotTrackBrush, borderRec); graphics.DrawRectangle(selectedPen, borderRec); } else if (selected) { graphics.FillRectangle(selectedBrush, borderRec); graphics.DrawRectangle(selectedPen, borderRec); } // Fills the rectangle with the current color, paints // the background. graphics.DrawString(style.ToString(), this.Font, Brushes.DimGray, x + 109, y - 1); switch (style) { case ConnectionCap.ArrowBoth: anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; graphics.DrawLine(anchorPen, x + 104, y + 4, x + 105, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.NoAnchor; graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); graphics.DrawLine(anchorPen, x - 5, y + 4, x - 4, y + 4); break; case ConnectionCap.ArrowRight: anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); graphics.DrawLine(anchorPen, x + 104, y + 4, x + 105, y + 4); break; case ConnectionCap.ArrowLeft: anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); graphics.DrawLine(anchorPen, x - 5, y + 4, x - 4, y + 4); break; case ConnectionCap.DiamondBoth: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; graphics.DrawLine(anchorPen, x, y + 4, x + 1, y + 4); break; case ConnectionCap.DiamondRight: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); break; case ConnectionCap.DiamondLeft: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.RoundBoth: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.RoundRight: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); break; case ConnectionCap.RoundLeft: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.SquareBoth: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.SquareAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.SquareAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.SquareRight: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.SquareAnchor; graphics.DrawLine(anchorPen, x + 99, y + 4, x + 100, y + 4); break; case ConnectionCap.SquareLeft: graphics.DrawLine(linePen, x + 2, y + 4, x + 100, y + 4); anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.SquareAnchor; graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); break; case ConnectionCap.Generalization: anchorPen.CustomEndCap = generalizationCap; //anchorPen.EndCap = System.Drawing.Drawing2D.LineCap.Custom; anchorPen.StartCap = System.Drawing.Drawing2D.LineCap.NoAnchor; //graphics.DrawLine(anchorPen, x - 1, y + 4, x + 1, y + 4); anchorPen.Width = 2F; graphics.DrawLine(anchorPen, x - 2, y + 4, x + 96, y + 4); break; case ConnectionCap.NoCap: return(borderRec); } //graphics.FillRectangle(Brushes.DimGray, mainRec); //graphics.DrawRectangle(borderPen, Rectangle.Round( mainRec)); } return(borderRec); }