Rectangle GetObjectRect(ITextObject tobj) { if (tobj == null) { throw new ArgumentNullException(); } Rectangle rect = PaintHelper.Zoom(tobj.Bounds, Zoom); if (HorizontalScroll.Enabled) { rect.X -= HorizontalScroll.Value; } if (VerticalScroll.Enabled) { rect.Y -= VerticalScroll.Value; } //rect.X += Margin.Left; //rect.Y += Margin.Top; rect.X += TranslatePoint.X; rect.Y += TranslatePoint.Y; return(rect); }
public override IBrush CreateBrush(IGraphics graphics, Color backColor, Rectangle rectangle) { return(graphics.LinearGradientBrush(rectangle, PaintHelper.GetLightColor(backColor, 0.1f), PaintHelper.GetDarkColor(backColor, 0.1f), LinearGradientMode.Vertical)); }
Image CreateIcon() { const int width = 16; const int height = 16; Bitmap bmp = new Bitmap(width, height); using (Graphics grf = Graphics.FromImage(bmp)) { PaintHelper.SetHighQualityRender(grf); // background GraphicsPath path = PaintHelper.GetRoundRectangle(new Rectangle(0, 0, width, height), 1); grf.FillPath(new SolidBrush(BackColor), path); //grf.FillEllipse(new SolidBrush(BackColor), 0, 0, width, height); grf.DrawLine(new Pen(LineColor, 0.3f), 5, 5, 13, 13); // root grf.FillEllipse(new SolidBrush(RootBackColor), 0, 0, 9, 9); grf.DrawEllipse(new Pen(RootBorderColor, 0.3f), 0, 0, 8, 8); // node grf.FillEllipse(new SolidBrush(NodeBackColor), 9, 9, 7, 7); grf.DrawEllipse(new Pen(BorderColor, 0.3f), 9, 9, 6, 6); grf.Dispose(); } return(bmp); }
void PrintChart(ChartPage chart, PrintPageEventArgs e) { if (chart == null) { throw new ArgumentNullException(); } if (chart is MindMap) { var state = e.Graphics.Save(); var contentSize = chart.GetContentSize(); var zoom = PaintHelper.GetZoom(contentSize, e.PageBounds.Size); var args = new RenderArgs(RenderMode.Print, e.Graphics, (MindMap)chart, ChartBox.DefaultChartFont); e.Graphics.ScaleTransform(zoom, zoom); var renderer = new GeneralRender(); renderer.Paint(args.Chart, args); e.Graphics.Restore(state); // print document title if (Options.Current.GetBool(Blumind.Configuration.OptionNames.PageSettigs.PrintDocumentTitle)) { var ptTitle = e.MarginBounds.Location; var brush = new SolidBrush(Color.Black); e.Graphics.DrawString(chart.Name, ChartBox.DefaultChartFont, brush, ptTitle.X, ptTitle.Y); } } }
Point[] GetPoints(Rectangle rectFrom, Rectangle rectTo, Vector4 vectorFrom, Vector4 vectorTo) { Point ptF = PaintHelper.CenterPoint(rectFrom); Point ptT = PaintHelper.CenterPoint(rectTo); Point[] pts = new Point[4]; switch (vectorFrom) { case Vector4.Left: pts[0] = new Point(rectFrom.Left, ptF.Y); pts[1] = new Point(rectFrom.Left - (rectFrom.Left - rectTo.Right) / 2, ptF.Y); pts[2] = new Point(rectFrom.Left - (rectFrom.Left - rectTo.Right) / 2, ptT.Y); pts[3] = new Point(rectTo.Right, ptT.Y); break; case Vector4.Top: pts[0] = new Point(ptF.X, rectFrom.Top); pts[1] = new Point(ptF.X, rectFrom.Top - (rectFrom.Top - rectTo.Bottom) / 2); pts[2] = new Point(ptT.X, rectFrom.Top - (rectFrom.Top - rectTo.Bottom) / 2); pts[3] = new Point(ptT.X, rectTo.Bottom); break; case Vector4.Right: pts[0] = new Point(rectFrom.Right, ptF.Y); pts[1] = new Point(rectFrom.Right + (rectTo.Left - rectFrom.Right) / 2, ptF.Y); pts[2] = new Point(rectFrom.Right + (rectTo.Left - rectFrom.Right) / 2, ptT.Y); pts[3] = new Point(rectTo.Left, ptT.Y); break; case Vector4.Bottom: pts[0] = new Point(ptF.X, rectFrom.Bottom); switch (vectorTo) { case Vector4.Left: pts[1] = new Point(ptF.X, ptT.Y); pts[2] = pts[1]; pts[3] = new Point(rectTo.Left, ptT.Y); break; case Vector4.Right: pts[1] = new Point(ptF.X, ptT.Y); pts[2] = pts[1]; pts[3] = new Point(rectTo.Right, ptT.Y); break; default: pts[1] = new Point(ptF.X, rectFrom.Bottom + (rectTo.Top - rectFrom.Bottom) / 2); pts[2] = new Point(ptT.X, rectFrom.Bottom + (rectTo.Top - rectFrom.Bottom) / 2); pts[3] = new Point(ptT.X, rectTo.Top); break; } break; default: break; } return(pts); }
private void boomarkDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (this.bookmarkData == null) { return; } lock (this.paintLock) { try { if (e.RowIndex < 0 || e.ColumnIndex < 0 || this.bookmarkData.Bookmarks.Count <= e.RowIndex) { e.Handled = false; return; } int lineNum = this.bookmarkData.Bookmarks[e.RowIndex].LineNum; //if (e.ColumnIndex == 1) //{ // CommentPainting(this.bookmarkDataGridView, lineNum, e); //} //else { PaintHelper.CellPainting(this.logPaintContext, this.bookmarkDataGridView, lineNum, e); } } catch (Exception ex) { Logger.logError(ex.StackTrace); } } }
public Topic[] GetTopicsInRect(Rectangle rect) { rect.X -= ChartBox.Margin.Left; rect.Y -= ChartBox.Margin.Top; rect.X -= TranslatePoint.X; rect.Y -= TranslatePoint.Y; // if (HorizontalScroll.Enabled) { rect.X += HorizontalScroll.Value; } if (VerticalScroll.Enabled) { rect.Y += VerticalScroll.Value; } rect = PaintHelper.DeZoom(rect, Zoom); // List <Topic> topics = new List <Topic>(); if (Map != null && Map.Root != null) { GetTopicsInRect(Map.Root, rect, topics); } return(topics.ToArray()); }
void PaintNavigationMapLinkLines(IGraphics graphics, Topic topic, float zoom, IFont font) { // links foreach (Link link in topic.Links) { if (!link.Visible) { continue; } var layout = link.LayoutData; Color color = (topic.MindMap != null && link.Color.IsEmpty) ? topic.MindMap.LinkLineColor : link.Color; IPen pen = graphics.Pen(color, link.LineStyle); Point[] pts = new Point[] { layout.StartPoint, layout.ControlPoint1, layout.ControlPoint2, layout.EndPoint }; for (int i = 0; i < pts.Length; i++) { pts[i] = PaintHelper.Zoom(pts[i], zoom); } graphics.DrawBezier(pen, pts[0], pts[1], pts[2], pts[3]); } if (!topic.Children.IsEmpty && !topic.Folded) { foreach (Topic subTopic in topic.Children) { PaintNavigationMapLinkLines(graphics, subTopic, zoom, font); } } }
/*public override void PaintValue(PaintValueEventArgs e) * { * e.Graphics.FillRectangle(Brushes.White, e.Bounds); * if (e.Value is LineAnchor && ((LineCap)e.Value) != LineCap.Flat) * { * Pen pen = new Pen(Color.Black, 5); * Point pt = PaintHelper.CenterPoint(e.Bounds); * if (IsEndCap) * { * pen.EndCap = (LineCap)e.Value; * e.Graphics.DrawLine(pen, e.Bounds.Left + 2, pt.Y, e.Bounds.Right - pen.Width - 2, pt.Y); * } * else * { * pen.StartCap = (LineCap)e.Value; * e.Graphics.DrawLine(pen, e.Bounds.Left + pen.Width + 2, pt.Y, e.Bounds.Right - 2, pt.Y); * } * } * }*/ protected override void DrawListItem(DrawItemEventArgs e, Rectangle rect, ListItem <LineAnchor> listItem) { var value = listItem.Value; //base.DrawItem(e, rect, value); if (value != LineAnchor.None) { Color foreColor = ((e.State & DrawItemState.Selected) == DrawItemState.Selected) ? SystemColors.HighlightText : SystemColors.WindowText; Point pt = PaintHelper.CenterPoint(rect); rect.Inflate(-10, 0); rect.X += 5; rect.Width -= 5; IGraphics grf = new GdiGraphics(e.Graphics); var gs = grf.Save(); grf.SetHighQualityRender(); var pen = grf.Pen(foreColor, 5); if (IsEndCap) { grf.DrawLine(pen, rect.Left, pt.Y, rect.Right, pt.Y, LineAnchor.None, (LineAnchor)value); } else { grf.DrawLine(pen, rect.Left, pt.Y, rect.Right, pt.Y, (LineAnchor)value, LineAnchor.None); } grf.Restore(gs); } }
public void DrawImage(Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight) { if (image == null) { return; } XmlElement element = Dom.CreateElement("image"); element.SetAttribute("x", destRect.X.ToString()); element.SetAttribute("y", destRect.Y.ToString()); element.SetAttribute("width", destRect.Width.ToString()); element.SetAttribute("height", destRect.Height.ToString()); XmlAttribute href = Dom.CreateAttribute("xlink", "href", "http://www.w3.org/1999/xlink"); if (srcX != 0 || srcY != 0 || srcWidth != image.Width || srcHeight != image.Width) { using (var slice = PaintHelper.CutImage(image, srcX, srcY, srcWidth, srcHeight)) { href.Value = "data:image/png;base64," + ST.ImageBase64String(slice); } } else { href.Value = "data:image/png;base64," + ST.ImageBase64String(image); } element.Attributes.Append(href); AppendElement(element); }
Rectangle GetObjectRect(ITextObject tobj) { if (tobj == null) { throw new ArgumentNullException(); } Rectangle rect; if (tobj is Topic) { rect = PaintHelper.Zoom(((Topic)tobj).GlobalTextBounds, Zoom); } else { rect = PaintHelper.Zoom(tobj.Bounds, Zoom); } if (HorizontalScroll.Enabled) { rect.X -= HorizontalScroll.Value; } if (VerticalScroll.Enabled) { rect.Y -= VerticalScroll.Value; } rect.X += TranslatePoint.X; rect.Y += TranslatePoint.Y; return(rect); }
public override void ApplyTheme(UITheme theme) { base.ApplyTheme(theme); this.Font = theme.DefaultFont; this.BackColor = theme.Colors.MediumLight; if (recentFilesView1 != null) { recentFilesView1.BackColor = theme.Colors.MediumLight; recentFilesView1.CellBackColor = Color.Transparent;// metroBox1.BackColor; recentFilesView1.CellForeColor = PaintHelper.FarthestColor(recentFilesView1.BackColor, theme.Colors.Dark, theme.Colors.Light); recentFilesView1.ActiveCellBackColor = Color.FromArgb(128, theme.Colors.Sharp); recentFilesView1.ActiveCellForeColor = theme.Colors.SharpText; } if (buttonListBox1 != null) { buttonListBox1.BackColor = PaintHelper.GetDarkColor(theme.Colors.MediumLight, 0.1f); buttonListBox1.ButtonBackColor = Color.Transparent;// theme.Colors.MediumDark; buttonListBox1.ButtonForeColor = PaintHelper.FarthestColor(buttonListBox1.BackColor, theme.Colors.Dark, theme.Colors.Light); buttonListBox1.ButtonHoverBackColor = theme.Colors.Sharp; buttonListBox1.ButtonHoverForeColor = theme.Colors.SharpText; } }
static Region GetUpdateRegion(PointF[] pts, int width) { if (pts == null || pts.Length == 0) { return(null); } width = Math.Max(1, width); Region region = null; for (int i = 1; i < pts.Length; i++) { var rectblock = PaintHelper.GetRectangle(pts[i - 1], pts[i]); rectblock.Inflate(width, width); if (region == null) { region = new Region(rectblock); } else { region.Union(rectblock); } } return(region); }
protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index < 0 || e.Index >= Items.Count) { base.OnDrawItem(e); return; } e.DrawBackground(); Rectangle rect = GetItemRectangle(e.Index); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { PaintHelper.DrawHoverBackgroundFlat(e.Graphics, rect, SystemColors.Highlight); } else { e.Graphics.DrawLine(SystemPens.ControlLight, rect.Left + 2, rect.Bottom - 1, rect.Right - 2, rect.Bottom - 1); } if (Owner != null) { var item = Items[e.Index]; if (item is ListItem <T> ) { Owner.DrawListItem(e, rect, (ListItem <T>)item); } } }
/*public void GeneralSvg(XmlElement parentNode, Rectangle rectFrom, Rectangle rectTo, Vector4 vectorFrom, Vector4 vectorTo, Color color) * { * Point[] pts = GetPoints(rectFrom, rectTo, vectorFrom, vectorTo); * if (pts == null) * return; * * StringBuilder sb = new StringBuilder(); * sb.AppendFormat("M{0},{1} ", pts[0].X, pts[0].Y); * sb.AppendFormat("C{0},{1} {2},{3} {4},{5}", pts[1].X, pts[1].Y, pts[2].X, pts[2].Y, pts[3].X, pts[3].Y); * * XmlElement path = parentNode.OwnerDocument.CreateElement("path"); * path.SetAttribute("d", sb.ToString()); * path.SetAttribute("fill", "none"); * parentNode.AppendChild(path); * * if (!color.IsEmpty) * path.SetAttribute("stroke", ST.ToString(color)); * }*/ private Point[] GetPoints(Rectangle rectFrom, Rectangle rectTo, Vector4 vector, Vector4 vectorTo) { Point org = PaintHelper.CenterPoint(rectFrom); Point to = PaintHelper.CenterPoint(rectTo); double dis = IsRoot ? ArrowBase : ArrowBase / 3; // Point startPoint = GetOffsetPoint(org, to, dis); Point point4 = GetRandomPoint(org, to, 0.5, this.rand1); Point point5 = GetRandomPoint(to, org, 0.5, this.rand2); Point point6 = GetOffsetPoint(org, to, -dis); Point point7 = GetOffsetPoint(point4, to, -5.0); Point pt = GetOffsetPoint(to, org, -2.0); Point pt2 = GetOffsetPoint(to, org, 1.0); // return(new Point[] { startPoint, point4, point5, pt, pt2, point5, point7, point6, }); }
private void Start() { int width = _imgList[0].BitmapImage.Width; int height = _imgList[0].BitmapImage.Height; Console.WriteLine("--Sprites per Line: "); int spritesPerLine = int.Parse(Console.ReadLine()); Color[][] newImageMatrix = ImageProcessing.CreateBlankColorMatrix((width + 2) * spritesPerLine, (height + 2) * (int)Math.Ceiling(_imgList.Count / (double)spritesPerLine)); int accX = 1; int accY = 1; int index = 0; foreach (ImportedImage img in _imgList) { ImageProcessing.AddImageIntoMatrix(newImageMatrix, img.BitmapImage, accX, accY); accX += width + 2; if (++index % spritesPerLine == 0) { accY += height + 2; accX = 1; } } ImageProcessing.CreateImage(newImageMatrix).Save(Parameters.SpritesheetOutputDirectory + @"output.png"); ExplorerHelper.OpenDirectory(Parameters.SpritesheetOutputDirectory); Thread.Sleep(1500); PaintHelper.OpenPictureFromOutputFolder(Parameters.SpritesheetOutputDirectory + @"output.png"); }
public void CalculateImageCenter() { var size = new Size(100, 50); var center = PaintHelper.CalculateCenterLocation(size); center.ShouldBeEquivalentTo(new Point(50, 25)); }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(Color.White); if (imageDonation != null) { var clientSize = ClientSize; PaintHelper.DrawImageInRange(e.Graphics, imageDonation, new Rectangle(0, 0, clientSize.Width, clientSize.Height)); } }
protected override void OnCreateControl() { base.OnCreateControl(); if (!this.DesignMode) { BackColor = PaintHelper.WithoutAlpha(mindMapView1.ChartBackColor); } }
public void CalculateNewSize() { var oldS = new Size(10, 15); var factor = 3f; var newS = PaintHelper.CalculateNewSize(oldS, factor); newS.ShouldBeEquivalentTo(new Size(30, 45)); }
public void CalculateShrinkFactor() { var actual = new Size(25, 35); var specified = new Size(5, 7); var factor = PaintHelper.CalculateTransformationFactor(actual, specified); factor.Should().BeInRange(0.2f - 0.01f, 0.2f + 0.01f); }
public void CalculateUnproportionalFactor() { var actual = new Size(100, 50); var specified = new Size(20, 25); var factor = PaintHelper.CalculateTransformationFactor(actual, specified); factor.Should().BeInRange(0.2f - 0.01f, 0.2f + 0.01f); }
public void CalculateАugmentativeFactor() { var actual = new Size(50, 100); var specified = new Size(100, 200); var factor = PaintHelper.CalculateTransformationFactor(actual, specified); factor.ShouldBeEquivalentTo(2); }
public void ComplexMoveRectangles() { var rectangles = Generate().ToList(); var imageS = PaintHelper.CalculateImageSize(rectangles); var offset = PaintHelper.CalculateCenterLocation(imageS); var moved = rectangles.Select(x => new Rectangle(new Point(x.X + offset.X, x.Y + offset.Y), x.Size)); moved.All(x => OnPicture(imageS, x)).Should().BeTrue(); }
public override void OnMouseMove(ExMouseEventArgs e) { base.OnMouseMove(e); if (NewLineFrom != null) { Point pt = PaintHelper.CenterPoint(NewLineFrom.Bounds); pt = View.PointToReal(pt); Rectangle rect = PaintHelper.GetRectangle(pt, MousePoint); rect = Rectangle.Union(rect, PaintHelper.GetRectangle(pt, new Point(e.X, e.Y))); MousePoint.X = e.X; MousePoint.Y = e.Y; InvalidateChart(rect, false); } else { // test - is drag control handle if (PressMouseButton == MouseButtons.Left && SelectedObject.ControlHandle != BezierPoint.None) { DragControlHandle(SelectedObject.ControlHandle, new Point(e.X, e.Y)); e.Suppress = true; if (View.Cursor != Cursors.SizeAll) { View.Cursor = Cursors.SizeAll; } } else { HoverObject = HitTest(e.X, e.Y); // test - is open url if (HoverObject.Link != null && Helper.TestModifierKeys(Keys.Shift) && !string.IsNullOrEmpty(HoverObject.Link.Hyperlink)) { e.Suppress = true; if (View.Cursor != Cursors.Hand) { View.Cursor = Cursors.Hand; } } else if (HoverObject.ControlHandle != BezierPoint.None) { if (View.Cursor != Cursors.SizeAll) { View.Cursor = Cursors.SizeAll; } e.Suppress = true; } //else //View.Cursor = Cursors.Default; } } }
public override void PaintValue(PaintValueEventArgs e) { if (e.Value is PictureWidget.PictureDesign) { PictureWidget.PictureDesign pd = (PictureWidget.PictureDesign)e.Value; if (pd.Data != null) { PaintHelper.DrawImageInRange(e.Graphics, pd.Data, e.Bounds); } } }
Point[] GetPointsForRoot(TopicShape shapeFrom, TopicShape shapeTo, Rectangle rectFrom, Rectangle rectTo, Vector4 vector, Vector4 vectorTo) { var fcp = PaintHelper.CenterPoint(rectFrom); int bezierTurn; Point[] pts = new Point[4]; switch (vector) { case Vector4.Left: bezierTurn = Math.Min(MaxBezierTurn, Math.Abs(rectTo.Right - rectFrom.Left)); pts[3] = new Point(rectTo.Right, rectTo.Y + rectTo.Height / 2); pts[2] = new Point(rectTo.Right + bezierTurn, pts[3].Y); break; case Vector4.Right: bezierTurn = Math.Min(MaxBezierTurn, Math.Abs(rectTo.Left - rectFrom.Right)); pts[3] = new Point(rectTo.X, rectTo.Y + rectTo.Height / 2); pts[2] = new Point(rectTo.X - bezierTurn, pts[3].Y); break; case Vector4.Top: bezierTurn = Math.Min(MaxBezierTurn, Math.Abs(rectFrom.Top - rectTo.Bottom)); pts[3] = new Point(rectTo.X + rectTo.Width / 2, rectTo.Bottom); pts[2] = new Point(rectTo.X + rectTo.Width / 2, rectTo.Bottom + bezierTurn); break; case Vector4.Bottom: bezierTurn = Math.Min(MaxBezierTurn, Math.Abs(rectTo.Top - rectFrom.Bottom)); pts[3] = new Point(rectTo.X + rectTo.Width / 2, rectTo.Top); pts[2] = new Point(rectTo.X + rectTo.Width / 2, rectTo.Top - bezierTurn); break; } Point?startPoint; if (shapeFrom == TopicShape.Ellipse) { startPoint = PaintHelper.GetPointForPointIntersectEllipse(rectFrom, pts[3]); } else { startPoint = PaintHelper.GetPointForLineIntersectRectangle(rectFrom, pts[3]); } if (!startPoint.HasValue) { return(null); } pts[0] = startPoint.Value; pts[1] = startPoint.Value; return(pts); }
void CreatePath(Rectangle rect) { if (Path != null) { Path.Dispose(); } Rect = rect; Path = PaintHelper.GetRoundRectangle(rect, Round); }
public override void ApplyTheme(UITheme theme) { base.ApplyTheme(theme); if (TabBar != null) { //TabBar.ItemBackColor = this.BackColor; TabBar.ItemBackColor = PaintHelper.GetDarkColor(this.BackColor, 0.15); TabBar.ItemForeColor = PaintHelper.FarthestColor(TabBar.ItemBackColor, theme.Colors.Dark, theme.Colors.Light); } }
protected override void DrawActiveTab(DrawTabArgs tabArgs) { tabArgs.Appearance.BackColor = Color.Chocolate; tabArgs.Appearance.BackColor2 = Color.Cornsilk; tabArgs.Appearance.GradientMode = LinearGradientMode.Vertical; tabArgs.DrawBackground(); DirectionRectangle rect = new DirectionRectangle(PaintHelper.CalcTabContentBounds(tabArgs, DockingSkins.SkinTabHeader), !tabArgs.IsVertical); rect.CutFromHead(TabPanelPainter.TabHorzTextIndent); rect.CutFromTail(1); tabArgs.DrawString(tabArgs.TabLayout.TabText, rect.Bounds); }
/// <summary> /// Draw all ring constraint types /// </summary> protected override void OnPaintShape(DiagramPaintEventArgs e, ref PaintHelper helper) { base.OnPaintShape(e, ref helper); RingConstraint ringConstraint = this.AssociatedRingConstraint; RectangleF boundsF = RectangleD.ToRectangleF(this.AbsoluteBounds); Graphics g = e.Graphics; RingConstraintType ringType = ringConstraint.RingType; RectangleF innerBounds; Pen pen = helper.Pen; Brush brush = helper.Brush; switch (ringType) { case RingConstraintType.Undefined: break; case RingConstraintType.Reflexive: DrawLeftDot(g, boundsF, brush); break; case RingConstraintType.PurelyReflexive: DrawLeftDot(g, boundsF, brush); { float height = boundsF.Height; float left = boundsF.Left + boundsF.Width / 2; DashStyle originalDashStyle = pen.DashStyle; pen.DashStyle = DashStyle.Solid; g.DrawLine(pen, left, boundsF.Top + height * (.5f - SMALL_LENGTH_FACTOR / 2), left, boundsF.Top + height * (.5f + SMALL_LENGTH_FACTOR / 2)); pen.DashStyle = originalDashStyle; } break; case RingConstraintType.Irreflexive: DrawLeftDot(g, boundsF, brush); DrawRightLine(g, boundsF, pen, 1f); break; case RingConstraintType.Asymmetric: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, true); DrawBottomLine(g, boundsF, pen); break; case RingConstraintType.Antisymmetric: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, false); DrawBottomLine(g, boundsF, pen); break; case RingConstraintType.Transitive: DrawTriangleDots(g, boundsF, brush, false); break; case RingConstraintType.Intransitive: case RingConstraintType.StronglyIntransitive: DrawTriangleDots(g, boundsF, brush, ringType == RingConstraintType.StronglyIntransitive); DrawTriangleBottomLine(g, boundsF, pen); break; case RingConstraintType.Acyclic: DrawTriangleDots(g, boundsF, brush, false); DrawBottomLine(g, boundsF, pen); break; case RingConstraintType.AcyclicTransitive: DrawTriangle(g, boundsF, pen); DrawTriangleDots(g, boundsF, brush, false); DrawBottomLine(g, boundsF, pen, .6f); break; case RingConstraintType.AcyclicIntransitive: case RingConstraintType.AcyclicStronglyIntransitive: DrawTriangle(g, boundsF, pen); DrawTriangleBottomLine(g, boundsF, pen); DrawTriangleDots(g, boundsF, brush, ringType == RingConstraintType.AcyclicStronglyIntransitive); DrawBottomLine(g, boundsF, pen); break; case RingConstraintType.TransitiveAsymmetric: case RingConstraintType.TransitiveAntisymmetric: case RingConstraintType.AsymmetricIntransitive: case RingConstraintType.AsymmetricStronglyIntransitive: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, ringType != RingConstraintType.TransitiveAntisymmetric); DrawBottomLine(g, boundsF, pen); innerBounds = GetInnerBounds(boundsF); DrawTriangle(g, innerBounds, pen); DrawTriangleDots(g, innerBounds, brush, ringType == RingConstraintType.AsymmetricStronglyIntransitive); switch (ringType) { case RingConstraintType.AsymmetricIntransitive: case RingConstraintType.AsymmetricStronglyIntransitive: DrawTriangleBottomLine(g, innerBounds, pen); break; } break; case RingConstraintType.ReflexiveTransitive: case RingConstraintType.TransitiveIrreflexive: DrawLeftDot(g, boundsF, brush); if (ringType == RingConstraintType.TransitiveIrreflexive) { DrawRightLine(g, boundsF, pen, .75f); } innerBounds = GetInnerBounds(boundsF); DrawTriangle(g, innerBounds, pen); DrawTriangleDots(g, innerBounds, brush, false); break; case RingConstraintType.Symmetric: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, true); break; case RingConstraintType.SymmetricTransitive: case RingConstraintType.SymmetricIntransitive: case RingConstraintType.SymmetricStronglyIntransitive: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, true); innerBounds = GetInnerBounds(boundsF); DrawTriangle(g, innerBounds, pen); DrawTriangleDots(g, innerBounds, brush, ringType == RingConstraintType.SymmetricStronglyIntransitive); if (ringType != RingConstraintType.SymmetricTransitive) { DrawTriangleBottomLine(g, innerBounds, pen); } break; case RingConstraintType.SymmetricIrreflexive: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, true); innerBounds = GetReflexiveInSymmetricBounds(boundsF); DrawEllipse(g, innerBounds, pen); DrawRightLine(g, innerBounds, pen, 1f); break; case RingConstraintType.ReflexiveSymmetric: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, true); DrawEllipse(g, GetReflexiveInSymmetricBounds(boundsF), pen); break; case RingConstraintType.ReflexiveAntisymmetric: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, false); DrawEllipse(g, GetReflexiveInSymmetricBounds(boundsF), pen); DrawBottomLine(g, boundsF, pen); break; case RingConstraintType.ReflexiveTransitiveAntisymmetric: DrawLeftDot(g, boundsF, brush); DrawRightDot(g, boundsF, pen, brush, false); DrawBottomLine(g, boundsF, pen); innerBounds = GetInnerBounds(boundsF); DrawTriangle(g, innerBounds, pen); DrawTriangleDots(g, innerBounds, brush, false); g.DrawArc(pen, GetReflexiveInSymmetricBounds(boundsF), 27, 300); // Angles determined empirically to stop on triangle, not worth calculating break; } }
/// <summary> /// Overrideable shape painting for use after the paint helper is initialized /// </summary> /// <param name="e">The event arguments</param> /// <param name="helper">The initialized pain helper.</param> protected virtual void OnPaintShape(DiagramPaintEventArgs e, ref PaintHelper helper) { IConstraint constraint = AssociatedConstraint; RectangleD bounds = AbsoluteBounds; RectangleF boundsF = RectangleD.ToRectangleF(bounds); Graphics g = e.Graphics; const double cos45 = 0.70710678118654752440084436210485; Pen pen = helper.Pen; Brush brush = helper.Brush; switch (constraint.ConstraintType) { #region Frequency case ConstraintType.Frequency: { break; } #endregion #region Ring case ConstraintType.Ring: // Note: goto default here restores the frowny face. However, // with the error feedback, we already have UI indicating there // is a problem. break; #endregion #region Equality case ConstraintType.Equality: { double xOffset = bounds.Width * .3; float xLeft = (float)(bounds.Left + xOffset); float xRight = (float)(bounds.Right - xOffset); double yCenter = bounds.Top + bounds.Height / 2; double yOffset = (double)pen.Width * 1.0; float y = (float)(yCenter - yOffset); g.DrawLine(pen, xLeft, y, xRight, y); y = (float)(yCenter + yOffset); g.DrawLine(pen, xLeft, y, xRight, y); break; } #endregion #region Mandatory case ConstraintType.DisjunctiveMandatory: { // Draw the dot RectangleF shrinkBounds = boundsF; shrinkBounds.Inflate(-boundsF.Width * .22f, -boundsF.Height * .22f); g.FillEllipse(brush, shrinkBounds); if (null != ExclusiveOrConstraintCoupler.GetExclusiveOrExclusionConstraint((MandatoryConstraint)constraint)) { goto case ConstraintType.Exclusion; } break; } #endregion #region Exclusion case ConstraintType.Exclusion: { // Draw the X double offset = (bounds.Width + pen.Width) * (1 - cos45) / 2; float leftX = (float)(bounds.Left + offset); float rightX = (float)(bounds.Right - offset); float topY = (float)(bounds.Top + offset); float bottomY = (float)(bounds.Bottom - offset); g.DrawLine(pen, leftX, topY, rightX, bottomY); g.DrawLine(pen, leftX, bottomY, rightX, topY); break; } #endregion #region Uniqueness case ConstraintType.ExternalUniqueness: { // Draw a single line for a uniqueness constraint and a double // line for preferred uniqueness UniquenessConstraint euc = constraint as UniquenessConstraint; double widthAdjust = (double)pen.Width / 2; float xLeft = (float)(bounds.Left + widthAdjust); float xRight = (float)(bounds.Right - widthAdjust); if (euc.IsPreferred) { double yCenter = bounds.Top + bounds.Height / 2; double yOffset = (double)pen.Width * .7; float y = (float)(yCenter - yOffset); g.DrawLine(pen, xLeft, y, xRight, y); y = (float)(yCenter + yOffset); g.DrawLine(pen, xLeft, y, xRight, y); } else { float y = (float)(bounds.Top + bounds.Height / 2); g.DrawLine(pen, xLeft, y, xRight, y); } break; } #endregion #region Subset case ConstraintType.Subset: { RectangleD arcBounds = bounds; double shrinkBy = -bounds.Height * .35; double yOffset = pen.Width * .7; double xOffset = shrinkBy * .35; arcBounds.Inflate(shrinkBy, shrinkBy); arcBounds.Offset(xOffset, -yOffset); g.DrawArc(pen, RectangleD.ToRectangleF(arcBounds), 90, 180); float xLeft = (float)arcBounds.Center.X; float xRight = (float)(bounds.Right + shrinkBy - xOffset); float y = (float)arcBounds.Top; g.DrawLine(pen, xLeft, y, xRight, y); y = (float)arcBounds.Bottom; g.DrawLine(pen, xLeft, y, xRight, y); y = (float)(arcBounds.Bottom + yOffset + yOffset); g.DrawLine(pen, (float)arcBounds.Left, y, xRight, y); break; } #endregion #region Fallback (default) default: { // Draws a frowny face float eyeY = boundsF.Y + (boundsF.Height / 3); PointF leftEyeStart = new PointF(boundsF.X + (boundsF.Width * 0.3f), eyeY); PointF leftEyeEnd = new PointF(boundsF.X + (boundsF.Width * 0.4f), eyeY); PointF rightEyeStart = new PointF(boundsF.X + (boundsF.Width * 0.6f), eyeY); PointF rightEyeEnd = new PointF(boundsF.X + (boundsF.Width * 0.7f), eyeY); g.DrawLine(pen, leftEyeStart, leftEyeEnd); g.DrawLine(pen, rightEyeStart, rightEyeEnd); float mouthLeft = boundsF.X + (boundsF.Width * 0.25f); float mouthTop = boundsF.Y + (boundsF.Height * 0.55f); RectangleF mouthRectangle = new RectangleF(mouthLeft, mouthTop, boundsF.Width * 0.5f, boundsF.Height * 0.25f); g.DrawArc(pen, mouthRectangle, 180, 180); break; } #endregion } if (constraint.Modality == ConstraintModality.Deontic && constraint.ConstraintType != ConstraintType.Ring) { float startPenWidth = pen.Width; pen.Width = startPenWidth * .70f; float boxSide = (float)((1 - cos45) * bounds.Width); g.FillEllipse(this.StyleSet.GetBrush(DiagramBrushes.DiagramBackground), (float)bounds.Left, (float)bounds.Top, boxSide, boxSide); g.DrawArc(pen, (float)bounds.Left, (float)bounds.Top, boxSide, boxSide, 0, 360); pen.Width = startPenWidth; } }
/// <summary> /// Draw the various constraint types /// </summary> /// <param name="e">DiagramPaintEventArgs</param> public sealed override void OnPaintShape(DiagramPaintEventArgs e) { if (null == Utility.ValidateStore(Store)) { return; } base.OnPaintShape(e); PaintHelper helper = new PaintHelper(e, this); try { OnPaintShape(e, ref helper); } finally { helper.Dispose(); } }
/// <summary> /// Draw the various constraint types /// </summary> protected override void OnPaintShape(DiagramPaintEventArgs e, ref PaintHelper paintHelper) { base.OnPaintShape(e, ref paintHelper); RectangleD bounds = AbsoluteBounds; Graphics g = e.Graphics; StringFormat stringFormat = new StringFormat(); stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Center; Font font = StyleSet.GetFont(FrequencyConstraintTextResource); g.DrawString(GetFrequencyString(), font, paintHelper.Brush, RectangleD.ToRectangleF(bounds), stringFormat); }