Example #1
0
        /// <summary>
        /// Sets the window size but ensures that the window is always fully visible (within screen bounds)
        /// If prefferedSize is bigger than the screen bounds, prefferedSize is scaled to fit the screen keeping the aspect ratio
        /// </summary>
        /// <param name="prefferedSize"></param>
        private void SetPrefferedPreviewSize(Size prefferedSize)
        {
            var screen    = Screen.FromMainWindow();
            var maxBounds = Rect.Inflate(screen.WorkingArea, -100, -100);

            Size wndSize = prefferedSize;

            // scale the prefferedSize while keeping the aspect ratio
            double ratio = Math.Min(maxBounds.Width / prefferedSize.Width,
                                    maxBounds.Height / prefferedSize.Height);

            // but only scale if prefferedSize is bigger than the screen bounds
            if (ratio < 1.0)
            {
                int w = (int)Math.Floor(prefferedSize.Width * ratio);
                int h = (int)Math.Floor(prefferedSize.Height * ratio);

                wndSize = new Size(w, h);
            }

            // ensure visible
            Rect wndBounds = Application.Current.MainWindow.GetBounds();

            double xOffset = Math.Min(0.0, maxBounds.Right - (wndBounds.X + wndSize.Width));
            double yOffset = Math.Min(0.0, maxBounds.Bottom - (wndBounds.Y + wndSize.Height));

            // We break MVVM on purpose because binding these values doesn't work well
            Application.Current.MainWindow.Left = wndBounds.X + xOffset;
            Application.Current.MainWindow.Top  = wndBounds.Y + yOffset;
            Application.Current.MainWindow.SetClientSize(wndSize);
        }
Example #2
0
        WGeometry DoubleCircle()
        {
            var    box          = Node.BoundingBox;
            double w            = box.Width;
            double h            = box.Height;
            var    pathGeometry = new WPathGeometry();
            var    r            = new WRect(box.Left, box.Bottom, w, h);

            pathGeometry.AddGeometry(new WEllipseGeometry(r));
            var inflation = Math.Min(5.0, Math.Min(w / 3, h / 3));

            r.Inflate(-inflation, -inflation);
            pathGeometry.AddGeometry(new WEllipseGeometry(r));
            return(pathGeometry);
        }
Example #3
0
        private void Calculate()
        {
            // check if already calculated
            if (m_blocks.Count != 0)
            {
                return;
            }

            // calculate first block that is displayed
            int blockIndex = 0;

            for (; blockIndex < m_blame.Blocks.Count; blockIndex++)
            {
                Block block = m_blame.Blocks[blockIndex];
                if (block.StartLine <= m_topLineNumber && block.StartLine + block.LineCount > m_topLineNumber)
                {
                    break;
                }
            }

            // determine the position of each block that is displayed
            int lineCount = 0;

            while (lineCount < m_lineCount && blockIndex < m_blame.Blocks.Count)
            {
                Block  block              = m_blame.Blocks[blockIndex];
                int    hiddenLines        = m_topLineNumber - block.StartLine;
                int    remainingLines     = m_lineCount - lineCount;
                int    linesFromThisBlock = Math.Min(block.LineCount - Math.Max(0, hiddenLines), remainingLines);
                double alpha              = 0.75 - (block.Commit.CommitDate - m_oldestCommit).TotalDays * m_dateScale;

                const double authorWidth    = 10;
                Rect         authorPosition = new Rect(0, lineCount * m_lineHeight, authorWidth, linesFromThisBlock * m_lineHeight);
                Rect         commitPosition = new Rect(authorWidth, authorPosition.Top, m_columnWidths[0] - authorWidth, authorPosition.Height);

                // add the commit summary if there is space
                Rect summaryPosition = Rect.Empty;

                if (linesFromThisBlock > 1)
                {
                    summaryPosition = commitPosition;
                    summaryPosition.Inflate(-1, -1);
                    summaryPosition.Offset(0, m_lineHeight);
                    summaryPosition.Height = Math.Min(summaryPosition.Height - m_lineHeight, m_renderSize.Height);
                }

                m_blocks.Add(new DisplayBlock(authorPosition, commitPosition, summaryPosition, alpha, m_authorIndex.ContainsKey(block.Commit.Author) ? m_authorIndex[block.Commit.Author] : 0, block));

                blockIndex++;
                lineCount += linesFromThisBlock;
            }

            // determine the source code lines that are visible
            m_lines.Capacity = m_lineCount;
            m_lines.AddRange(m_blame.Lines
                             .Skip(m_topLineNumber - 1)
                             .Take(m_lineCount)
                             .Select((l, n) => new DisplayLine(l, n + m_topLineNumber)));

            // determine which of those lines are new in their respective commits
            lineCount = 0;
            double newLineX = CodeMarginColumn.Right - 5;

            foreach (var lineGroup in m_lines.GroupConsecutiveBy(l => l.IsNew))
            {
                if (lineGroup.Key)
                {
                    m_newLines.Add(new Rect(newLineX, lineCount * m_lineHeight, 5, lineGroup.Count() * m_lineHeight));
                }

                lineCount += lineGroup.Count();
            }
        }
Example #4
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            //base.OnPaint(pe);

            // Draw white background
            Graphics dc = pe.Graphics;

            dc.ResetTransform();
            dc.FillRectangle(Brushes.White, 0, 0, Width, Height);

            // Draw the raster
            Matrix t = TheRasterModel.GetTikzToScreenTransform().ToMatrix();

            //t.Freeze();

            using (Pen pen = new Pen(Brushes.WhiteSmoke, 0.000001f))
            {
                dc.Transform = t;

                TheRasterModel.DrawRaster(
                    (p1, p2) => dc.DrawLine(pen, p1.ToPointF(), p2.ToPointF()),
                    (r1, r2) =>
                {
                    float rr1 = (float)r1, rr2 = (float)r2;
                    dc.DrawEllipse(pen, -rr1, -rr2, 2 * rr1, 2 * rr2);
                });
            }

            dc.ResetTransform();

            // draw unavailable note
            if (TheDisplayModel.IsUnavailable)
            {
                StringFormat f = new StringFormat();
                f.Alignment     = StringAlignment.Center;
                f.LineAlignment = StringAlignment.Center;
                dc.DrawString("<Unavailable>", new Font("Arial", 16), Brushes.Black, ClientRectangle, f);
            }

            // draw the pdf image
            if (TheDisplayModel.IsImageVisible && TheDisplayModel.Bmp != null)
            {
                Point p = new Point((Width - TheDisplayModel.Bmp.Width) / 2, (Height - TheDisplayModel.Bmp.Height) / 2);
                dc.DrawImageUnscaled(TheDisplayModel.Bmp, p);
            }

            // draw the overlay
            if (ShowOverlay)
            {
                // draw shapes from parsetree
                //foreach (var osv in OSViews)
                //osv.Draw(pe.Graphics);
                foreach (var os in TheOverlayModel.DisplayTree.AllItems)
                {
                    os.Draw(dc, Height);
                }

                // draw (visible) auxiliary shapes
                foreach (var ps in PreviewShapes.Where(o => o.Visible))
                {
                    ps.Draw(pe.Graphics);
                }
            }

            // draw adorner(s)
            foreach (var scope in this.TheOverlayModel.DisplayTree.AllItems.OfType <OverlayScope>().Where(v => v.IsCurEditing))
            {
                System.Windows.Rect ShowAt = scope.BB.UpsideDown(Height);
                ShowAt.Inflate(6, 6);

                dc.DrawRectangle(PensAndBrushes.AdornerPen, ShowAt.ToRectangleF());
            }


            // draw the object marker
            if (MarkObject_ShowMarker && MarkObject_Marked != null)
            {
                System.Windows.Rect ShowAt = MarkObject_Marked.BB.UpsideDown(Height);
                ShowAt.Inflate(15, 15);
                using (Pen p = new Pen(Brushes.Red, 6))
                {
                    dc.DrawEllipse(p, ShowAt.ToRectangleF());
                }
            }
        }
Example #5
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            //base.OnPaint(pe);
            Cairo.Context dc = Gdk.CairoHelper.Create(args.Window);

            // Draw white background
            //Graphics dc = pe.Graphics;
            dc.IdentityMatrix();

            dc.SetSourceRGB(1.0, 1.0, 1.0);
            dc.Rectangle(0, 0, Allocation.Width, Allocation.Height);
            dc.Fill();

            // Draw the raster
            Cairo.Matrix t = TheRasterModel.GetTikzToScreenTransform().ToCairoMatrix();
            //t.Freeze();

            dc.Save();

            dc.LineWidth = 0.01;            // todo: always 1 pixel
            dc.SetSourceRGB(0.7, 0.7, 0.7); // whitesmoke?
            {
                dc.Transform(t);

                TheRasterModel.DrawRaster(
                    (p1, p2) => { dc.MoveTo(p1.X, p1.Y); dc.LineTo(p2.X, p2.Y); dc.Stroke(); },
                    (r1, r2) =>
                {
                    dc.DrawEllipse(0, 0, 2 * r1, 2 * r2);
                });
            }

            dc.Restore();

            // draw unavailable note
            if (TheDisplayModel.IsUnavailable)
            {
                dc.SetSourceRGB(0, 0, 0);
                dc.SelectFontFace("Arial", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
                //StringFormat f = new StringFormat();
                //f.Alignment = StringAlignment.Center;
                //f.LineAlignment = StringAlignment.Center;
                //dc.DrawString("<Unavailable>", new Font("Arial", 16), Brushes.Black, ClientRectangle, f);
                dc.MoveTo(Allocation.Width / 2, Allocation.Height / 2); //todo
                dc.ShowText("<Unavailable>");
            }

            // draw the pdf image
            if (TheDisplayModel.IsImageVisible && TheDisplayModel.Bmp != null)
            {
                Point p = new Point((Allocation.Width - TheDisplayModel.Bmp.Width) / 2, (Allocation.Height - TheDisplayModel.Bmp.Height) / 2);
                //dc.DrawImageUnscaled(TheDisplayModel.Bmp, p);
                dc.SetSource(TheDisplayModel.Bmp, p.X, p.Y);
                //dc.Rectangle(p.X, p.Y, TheDisplayModel.Bmp.Width, TheDisplayModel.Bmp.Height);
                dc.Paint();
            }

            // draw the overlay
            if (ShowOverlay)
            {
                dc.SetSourceRGB(0, 0, 0);
                // draw shapes from parsetree
                foreach (var osv in OSViews)
                {
                    osv.Draw(dc);
                }

                // draw (visible) auxiliary shapes
                foreach (var ps in PreviewShapes.Where(o => o.Visible))
                {
                    ps.Draw(dc);
                }
            }

            // draw adorner(s)
            foreach (var scope in this.OSViews.OfType <OverlayScopeView>().Where(v => v.IsAdornerVisible))
            {
                dc.SetSourceRGB(0.5, 0.5, 0.5);
                dc.LineWidth = 5;
                System.Windows.Rect ShowAt = scope.GetBB(Allocation.Height);
                ShowAt.Inflate(6, 6);

                dc.Rectangle(ShowAt.ToCairoRectangle());  //(PensAndBrushes.AdornerPen, ShowAt.ToRectangleF());
                dc.Stroke();
            }


            // draw the object marker
            if (MarkObject_ShowMarker && MarkObject_Marked != null)
            {
                System.Windows.Rect ShowAt = MarkObject_Marked.GetBB(Allocation.Height);
                ShowAt.Inflate(15, 15);
                //using (Pen p = new Pen(Brushes.Red, 6))
                {
                    dc.SetSourceRGB(1, 0, 0);
                    dc.LineWidth = 6;
                    dc.DrawEllipse(ShowAt);//p,
                }
            }

            ((IDisposable)dc.Target).Dispose();
            ((IDisposable)dc).Dispose();

            return(true);
        }