private Point GetSpriteDrawingCoordinates(RevisionSprite sprite, Point originOffset)
 {
     return(new Point(
                sprite.X.Value - originOffset.X,
                sprite.Y.Value - originOffset.Y
                ));
 }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (e.Button == MouseButtons.Right)
            {
                if (hoveredOverSprite != null)
                {
                    spriteContextMenuAppliesTo = hoveredOverSprite;
                    revisionContextMenu.Show(this, e.Location);
                }
            }
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            var sprite = GetSpriteAtDrawingCoordinates(e.Location);

            if (hoveredOverSprite != sprite)
            {
                hoveredOverSprite = sprite;
                if (sprite != null && sprite.Revision.Diff != null)
                {
                    string text = "arbitrary text replaced by OwnerDraw event";
                    toolTip.SetToolTip(this, text);
                }
                else
                {
                    toolTip.SetToolTip(this, null);
                }
                Invalidate();
            }
        }
        private void DrawCommitCircle(Graphics graphics, RevisionSprite commitSprite, Rectangle circleBounds)
        {
            var circlePath = new GraphicsPath();

            circlePath.AddEllipse(circleBounds);
            var oldClip = graphics.ClipBounds;

            graphics.SetClip(circlePath);

            using (Bitmap bitmap = spritesByCommitHash[commitSprite.Revision.Hash].GetIdenticon(circleSize))
            {
                Point drawPoint = circleBounds.Location;
                // It looks uncentered unless we shift it down and right a little
                drawPoint.Offset(1, 1);

                float bitmapAlpha = commitSprite.Opacity.Value;
                TransparentImage.DrawImageWithAlpha(graphics, bitmap, drawPoint, bitmapAlpha);
            }

            graphics.SetClip(oldClip);

            if (hoveredOverSprite != null && hoveredOverSprite.Revision.Hash == commitSprite.Revision.Hash)
            {
                Color color = Color.FromArgb(255, 128, 0, 0);
                using (Pen pen = new Pen(color, 4))
                {
                    graphics.DrawEllipse(pen, circleBounds);
                }
            }
            else
            {
                Color color = Color.FromArgb((int)(commitSprite.Opacity.Value * 255), 128, 0, 0);
                using (Pen pen = new Pen(color, 1))
                {
                    graphics.DrawEllipse(pen, circleBounds);
                }
            }
        }
 private Point GetSpriteDrawingCoordinates(RevisionSprite sprite)
 {
     return(GetSpriteDrawingCoordinates(sprite, OriginOffset));
 }