Ejemplo n.º 1
0
        public static void OnPaintSubItem(SubItemPaintEventArgs paintEventArgs, Revision data, GraphAtom[] graph, IList<PointerBounds> drawnPointers, int hoveredPointer)
        {
            #region get painting options

            bool showLocalBranches;
            bool showRemoteBranches;
            bool showTags;
            bool showStash;
            bool alignToGraph;
            var rsc = paintEventArgs.Column as SubjectColumn;
            if(drawnPointers != null)
            {
                drawnPointers.Clear();
                if(rsc != null)
                {
                    alignToGraph		= rsc.AlignToGraph;
                    showLocalBranches	= rsc.ShowLocalBranches;
                    showRemoteBranches	= rsc.ShowRemoteBranches;
                    showTags			= rsc.ShowTags;
                    showStash			= rsc.ShowStash;
                }
                else
                {
                    alignToGraph		= SubjectColumn.DefaultAlignToGraph;
                    showLocalBranches	= SubjectColumn.DefaultShowLocalBranches;
                    showRemoteBranches	= SubjectColumn.DefaultShowRemoteBranches;
                    showTags			= SubjectColumn.DefaultShowTags;
                    showStash			= SubjectColumn.DefaultShowStash;
                }
            }
            else
            {
                alignToGraph = (rsc != null) ? rsc.AlignToGraph : SubjectColumn.DefaultAlignToGraph;
                showLocalBranches = false;
                showRemoteBranches = false;
                showTags = false;
                showStash = false;
            }
            var graphStyle = GlobalBehavior.GraphStyle;

            #endregion

            #region align to graph column

            var rect = paintEventArgs.Bounds;
            var graphColumn = paintEventArgs.Column.PreviousVisibleColumn;
            int graphColumnX = 0;
            if(graphColumn != null)
            {
                if(graphColumn.Id != (int)ColumnId.Graph)
                {
                    graphColumn = null;
                }
                else
                {
                    graphColumnX = rect.X - graphColumn.Width;
                }
            }
            if(graphColumn != null && alignToGraph)
            {
                int availWidth = graphColumn.Width - GraphCellWidth * graph.Length;
                for(int i = graph.Length - 1; i >= 0; --i)
                {
                    if(graph[i].Elements != GraphElement.Space)
                    {
                        break;
                    }
                    availWidth += GraphCellWidth;
                }
                if(availWidth != 0)
                {
                    rect.X -= availWidth;
                    rect.Width += availWidth;
                }
            }

            #endregion

            #region prepare to draw references

            int drawnRefs = 0;
            int xoffset = 0;
            var font = paintEventArgs.Column.ContentFont;
            SubItemPaintEventArgs.PrepareContentRectangle(ref rect);

            #endregion

            #region paint tag & branch refs

            bool refsPresent;
            lock(data.References.SyncRoot)
            {
                refsPresent = data.References.Count != 0;
                if((showLocalBranches || showRemoteBranches || showTags) && refsPresent)
                {
                    foreach(var reference in data.References)
                    {
                        int w = 0;
                        switch(reference.Type)
                        {
                            case ReferenceType.LocalBranch:
                                if(showLocalBranches)
                                {
                                    w = graphStyle.DrawBranch(
                                        paintEventArgs.Graphics,
                                        font,
                                        GitterApplication.TextRenderer.LeftAlign,
                                        rect.Left + xoffset,
                                        rect.Top,
                                        rect.Right,
                                        rect.Height,
                                        drawnRefs == hoveredPointer,
                                        (Branch)reference);
                                }
                                break;
                            case ReferenceType.RemoteBranch:
                                if(showRemoteBranches)
                                {
                                    w = graphStyle.DrawBranch(
                                        paintEventArgs.Graphics,
                                        font,
                                        GitterApplication.TextRenderer.LeftAlign,
                                        rect.Left + xoffset,
                                        rect.Top,
                                        rect.Right,
                                        rect.Height,
                                        drawnRefs == hoveredPointer,
                                        (RemoteBranch)reference);
                                }
                                break;
                            case ReferenceType.Tag:
                                if(showTags)
                                {
                                    w = graphStyle.DrawTag(
                                        paintEventArgs.Graphics,
                                        font,
                                        GitterApplication.TextRenderer.LeftAlign,
                                        rect.Left + xoffset,
                                        rect.Top,
                                        rect.Right,
                                        rect.Height,
                                        drawnRefs == hoveredPointer,
                                        (Tag)reference);
                                }
                                break;
                        }
                        if(w != 0)
                        {
                            drawnPointers.Add(new PointerBounds(reference, new Rectangle(rect.X + xoffset, rect.Y, w, rect.Height)));
                            xoffset += w + TagSpacing;
                            ++drawnRefs;
                        }
                        if(xoffset >= rect.Width) break;
                    }
                }
            }

            #endregion

            #region paint stash ref

            var stash = data.Repository.Stash.MostRecentState;
            bool stashPresent = (stash != null && data == stash.Revision);
            if(showStash && stashPresent)
            {
                if(xoffset < rect.Width)
                {
                    int w = graphStyle.DrawStash(
                        paintEventArgs.Graphics,
                        font,
                        GitterApplication.TextRenderer.LeftAlign,
                        rect.Left + xoffset,
                        rect.Top,
                        rect.Right,
                        rect.Height,
                        drawnRefs == hoveredPointer,
                        stash);

                    drawnPointers.Add(new PointerBounds(stash, new Rectangle(rect.X + xoffset, rect.Y, w, rect.Height)));
                    xoffset += w + TagSpacing;
                    ++drawnRefs;
                }
            }

            #endregion

            #region paint reference presence indication

            if(drawnRefs != 0)
            {
                if(graph != null && graph.Length != 0)
                {
                    if(graphColumn != null)
                    {
                        graphStyle.DrawReferenceConnector(paintEventArgs.Graphics, graph, graphColumnX, 21, rect.X, rect.Y, rect.Height);
                    }
                }
                xoffset += 2;
            }
            else
            {
                if(refsPresent || stashPresent)
                {
                    if(graph != null && graph.Length != 0 && graphColumn != null)
                    {
                        graphStyle.DrawReferencePresenceIndicator(paintEventArgs.Graphics, graph, graphColumnX, 21, rect.Y, rect.Height);
                    }
                }
            }

            #endregion

            #region paint subject text

            rect.X += xoffset;
            rect.Width -= xoffset;
            if(rect.Width > 1)
            {
                paintEventArgs.PrepareTextRectangle(font, ref rect);
                GitterApplication.TextRenderer.DrawText(
                    paintEventArgs.Graphics, data.Subject, font, paintEventArgs.Brush, rect);
            }

            #endregion
        }
Ejemplo n.º 2
0
 public static void OnPaintSubItem(SubItemPaintEventArgs paintEventArgs, Revision data, GraphAtom[] graph)
 {
     OnPaintSubItem(paintEventArgs, data, graph, null, -1);
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 public static Size OnMeasureSubItem(SubItemMeasureEventArgs measureEventArgs, Revision data, GraphAtom[] graph)
 {
     return measureEventArgs.MeasureText(data.Subject);
 }
Ejemplo n.º 5
0
 public static Size OnMeasureSubItem(SubItemMeasureEventArgs measureEventArgs, GraphAtom[] graph)
 {
     return new Size((graph != null) ? (graph.Length * GraphCellWidth) : (0), GraphCellHeight);
 }