public void DrawGraph(Graphics graphics, GraphAtom[] graphLine, Rectangle bounds, int cellWidth, RevisionGraphItemType type, bool useColors) { Verify.Argument.IsNotNull(graphics, nameof(graphics)); if (graphLine != null) { int x = bounds.X; int y = bounds.Y; int w = cellWidth; int hw = w / 2; int h = bounds.Height; int hh = h / 2; int r = bounds.Right; for (int i = 0; (i < graphLine.Length) && (x < r); ++i, x += w) { var atom = graphLine[i]; var colors = atom.ElementColors; if (!atom.IsEmpty) { var lightBackground = GitterApplication.Style.Type == GitterStyleType.LightBackground; var pens = lightBackground ? GraphColors.PensForLightBackground : GraphColors.PensForDarkBackground; if (atom.HasElement(GraphElement.VerticalTop)) { var pen = pens[useColors ? colors[GraphElementId.VerticalTop] : 0]; graphics.DrawLine(pen, x + hw, y, x + hw, y + hh); } if (atom.HasElement(GraphElement.VerticalBottom)) { var pen = pens[useColors ? colors[GraphElementId.VerticalBottom] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x + hw, y + h); } if (atom.HasElement(GraphElement.HorizontalLeft)) { var pen = pens[useColors ? colors[GraphElementId.HorizontalLeft] : 0]; graphics.DrawLine(pen, x, y + hh, x + hw, y + hh); } if (atom.HasElement(GraphElement.HorizontalRight)) { var pen = pens[useColors ? colors[GraphElementId.HorizontalRight] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x + w, y + hh); } if (atom.HasElement(GraphElement.LeftTopCorner)) { var pen = pens[useColors ? colors[GraphElementId.LeftTopCorner] : 0]; graphics.DrawLine(pen, x, y + hh, x + hw, y); } if (atom.HasElement(GraphElement.LeftTop)) { var pen = pens[useColors ? colors[GraphElementId.LeftTop] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x, y); } if (atom.HasElement(GraphElement.RightTopCorner)) { var pen = pens[useColors ? colors[GraphElementId.RightTopCorner] : 0]; graphics.DrawLine(pen, x + w - 1, y + hh, x + hw, y); } if (atom.HasElement(GraphElement.RightTop)) { var pen = pens[useColors ? colors[GraphElementId.RightTop] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x + w, y); } if (atom.HasElement(GraphElement.RightBottomCorner)) { var pen = pens[useColors ? colors[GraphElementId.RightBottomCorner] : 0]; graphics.DrawLine(pen, x + w - 1, y + hh, x + hw, y + h - 1); } if (atom.HasElement(GraphElement.RightBottom)) { var pen = pens[useColors ? colors[GraphElementId.RightBottom] : 0]; graphics.DrawLine(pen, x + w, y + h, x + hw, y + hh); } if (atom.HasElement(GraphElement.LeftBottomCorner)) { var pen = pens[useColors ? colors[GraphElementId.LeftBottomCorner] : 0]; graphics.DrawLine(pen, x + hw, y + h - 1, x, y + hh); } if (atom.HasElement(GraphElement.LeftBottom)) { var pen = pens[useColors ? colors[GraphElementId.LeftBottom] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x, y + h); } if (atom.HasElement(GraphElement.Dot)) { const int cr = 3; const int cd = cr * 2; int cx = x + hw - cr; int cy = y + hh - cr; var oldSmoothingMode = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.AntiAlias; switch (type) { case RevisionGraphItemType.Generic: { var brush = lightBackground ? GraphColors.DotBrushForLightBackground : GraphColors.DotBrushForDarkBackground; graphics.FillEllipse(brush, cx, cy, cd, cd); } break; case RevisionGraphItemType.Current: { var brush = Brushes.LightGreen; graphics.FillEllipse(brush, cx, cy, cd, cd); var pen = lightBackground ? GraphColors.CirclePenForLightBackground : GraphColors.CirclePenForDarkBackground; graphics.DrawEllipse(pen, cx + .5f, cy + .5f, cd - 1, cd - 1); } break; case RevisionGraphItemType.Uncommitted: { var brush = SystemBrushes.Window; graphics.FillEllipse(brush, cx, cy, cd, cd); var pen = lightBackground ? GraphColors.CirclePenForLightBackground : GraphColors.CirclePenForDarkBackground; graphics.DrawEllipse(pen, cx + .5f, cy + .5f, cd - 1, cd - 1); } break; case RevisionGraphItemType.Unstaged: { var brush = Brushes.Red; graphics.FillEllipse(brush, cx, cy, cd, cd); var pen = lightBackground ? GraphColors.CirclePenForLightBackground : GraphColors.CirclePenForDarkBackground; graphics.DrawEllipse(pen, cx + .5f, cy + .5f, cd - 1, cd - 1); } break; } graphics.SmoothingMode = oldSmoothingMode; } } } } }
public static void OnPaintSubItem(SubItemPaintEventArgs paintEventArgs, GraphAtom[] graph, RevisionGraphItemType itemType) { if (graph != null) { bool showColors; var rgc = paintEventArgs.Column as GraphColumn; if (rgc != null) { showColors = rgc.ShowColors; } else { showColors = GraphColumn.DefaultShowColors; } GlobalBehavior.GraphStyle.DrawGraph( paintEventArgs.Graphics, graph, paintEventArgs.Bounds, GraphCellWidth, itemType, showColors); } }
public void DrawGraph(Graphics graphics, GraphAtom[] graphLine, Rectangle bounds, int cellWidth, RevisionGraphItemType type, bool useColors) { Verify.Argument.IsNotNull(graphics, "graphics"); if(graphLine != null) { int x = bounds.X; int y = bounds.Y; int w = cellWidth; int hw = w / 2; int h = bounds.Height; int hh = h / 2; int r = bounds.Right; for(int i = 0; (i < graphLine.Length) && (x < r); ++i, x += w) { var atom = graphLine[i]; var colors = atom.ElementColors; if(!atom.IsEmpty) { var lightBackground = GitterApplication.Style.Type == GitterStyleType.LightBackground; var pens = lightBackground ? GraphColors.PensForLightBackground : GraphColors.PensForDarkBackground; if(atom.HasElement(GraphElement.VerticalTop)) { var pen = pens[useColors ? colors[GraphElementId.VerticalTop] : 0]; graphics.DrawLine(pen, x + hw, y, x + hw, y + hh); } if(atom.HasElement(GraphElement.VerticalBottom)) { var pen = pens[useColors ? colors[GraphElementId.VerticalBottom] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x + hw, y + h); } if(atom.HasElement(GraphElement.HorizontalLeft)) { var pen = pens[useColors ? colors[GraphElementId.HorizontalLeft] : 0]; graphics.DrawLine(pen, x, y + hh, x + hw, y + hh); } if(atom.HasElement(GraphElement.HorizontalRight)) { var pen = pens[useColors ? colors[GraphElementId.HorizontalRight] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x + w, y + hh); } if(atom.HasElement(GraphElement.LeftTopCorner)) { var pen = pens[useColors ? colors[GraphElementId.LeftTopCorner] : 0]; graphics.DrawLine(pen, x, y + hh, x + hw, y); } if(atom.HasElement(GraphElement.LeftTop)) { var pen = pens[useColors ? colors[GraphElementId.LeftTop] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x, y); } if(atom.HasElement(GraphElement.RightTopCorner)) { var pen = pens[useColors ? colors[GraphElementId.RightTopCorner] : 0]; graphics.DrawLine(pen, x + w - 1, y + hh, x + hw, y); } if(atom.HasElement(GraphElement.RightTop)) { var pen = pens[useColors ? colors[GraphElementId.RightTop] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x + w, y); } if(atom.HasElement(GraphElement.RightBottomCorner)) { var pen = pens[useColors ? colors[GraphElementId.RightBottomCorner] : 0]; graphics.DrawLine(pen, x + w - 1, y + hh, x + hw, y + h - 1); } if(atom.HasElement(GraphElement.RightBottom)) { var pen = pens[useColors ? colors[GraphElementId.RightBottom] : 0]; graphics.DrawLine(pen, x + w, y + h, x + hw, y + hh); } if(atom.HasElement(GraphElement.LeftBottomCorner)) { var pen = pens[useColors ? colors[GraphElementId.LeftBottomCorner] : 0]; graphics.DrawLine(pen, x + hw, y + h - 1, x, y + hh); } if(atom.HasElement( GraphElement.LeftBottom)) { var pen = pens[useColors ? colors[GraphElementId.LeftBottom] : 0]; graphics.DrawLine(pen, x + hw, y + hh, x, y + h); } if(atom.HasElement(GraphElement.Dot)) { const int cr = 3; const int cd = cr * 2; int cx = x + hw - cr; int cy = y + hh - cr; var oldSmoothingMode = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.AntiAlias; switch(type) { case RevisionGraphItemType.Generic: { var brush = lightBackground ? GraphColors.DotBrushForLightBackground : GraphColors.DotBrushForDarkBackground; graphics.FillEllipse(brush, cx, cy, cd, cd); } break; case RevisionGraphItemType.Current: { var brush = Brushes.LightGreen; graphics.FillEllipse(brush, cx, cy, cd, cd); var pen = lightBackground ? GraphColors.CirclePenForLightBackground : GraphColors.CirclePenForDarkBackground; graphics.DrawEllipse(pen, cx + .5f, cy + .5f, cd - 1, cd - 1); } break; case RevisionGraphItemType.Uncommitted: { var brush = SystemBrushes.Window; graphics.FillEllipse(brush, cx, cy, cd, cd); var pen = lightBackground ? GraphColors.CirclePenForLightBackground : GraphColors.CirclePenForDarkBackground; graphics.DrawEllipse(pen, cx + .5f, cy + .5f, cd - 1, cd - 1); } break; case RevisionGraphItemType.Unstaged: { var brush = Brushes.Red; graphics.FillEllipse(brush, cx, cy, cd, cd); var pen = lightBackground ? GraphColors.CirclePenForLightBackground : GraphColors.CirclePenForDarkBackground; graphics.DrawEllipse(pen, cx + .5f, cy + .5f, cd - 1, cd - 1); } break; } graphics.SmoothingMode = oldSmoothingMode; } } } } }
public static void OnPaintSubItem(SubItemPaintEventArgs paintEventArgs, GraphAtom[] graph, RevisionGraphItemType itemType) { if(graph != null) { bool showColors; var rgc = paintEventArgs.Column as GraphColumn; if(rgc != null) { showColors = rgc.ShowColors; } else { showColors = GraphColumn.DefaultShowColors; } GlobalBehavior.GraphStyle.DrawGraph( paintEventArgs.Graphics, graph, paintEventArgs.Bounds, GraphCellWidth, itemType, showColors); } }