Example #1
0
        /// <summary>
        /// Draw centred text
        /// </summary>
        /// <param name="context">The graphics context to draw on</param>
        /// <param name="text">The text to draw</param>
        /// <param name="point">The point to centre the text around</param>
        protected void DrawCentredText(IDrawContext context, string text, Point point)
        {
            (int left, int top, int width, int height) = context.GetPixelExtents(text, false, false);
            double x = point.X - (width / 2 + left);
            double y = point.Y - (height / 2 + top);

            context.MoveTo(x, y);
            context.DrawText(text, false, false);
        }
Example #2
0
        /// <summary>
        /// Draw centred text
        /// </summary>
        /// <param name="context">The graphics context to draw on</param>
        /// <param name="text">The text to draw</param>
        /// <param name="point">The point to centre the text around</param>
        protected void DrawCentredText(IDrawContext context, string text, Point point)
        {
            var    extents = context.GetTextExtents(text);
            double x       = point.X - (extents.Width / 2 + extents.X);
            double y       = point.Y - (extents.Height / 2 + extents.Y);

            context.MoveTo(x, y);
            context.ShowText(text);
        }
Example #3
0
        /// <summary>Paint on the graphics context</summary>
        /// <param name="context">The graphics context to draw on</param>
        public override void Paint(IDrawContext context)
        {
            CalcBezPoints();

            if (bezPoints.Count != 0)
            {
                // Create point for upper-left corner of drawing.
                context.NewPath();
                if (Selected)
                {
                    context.SetColour(Color.Blue);
                }
                else
                {
                    context.SetColour(DefaultOutlineColour);
                }

                // Draw text if necessary
                if (Name != null)
                {
                    DrawCentredText(context, Name, Location);
                }

                context.MoveTo(bezPoints[0].X, bezPoints[0].Y);
                Point controlPoint = new Point(Location.X, Location.Y);
                Point bezPoint     = bezPoints[bezPoints.Count - 1];
                context.CurveTo(controlPoint.X, controlPoint.Y, controlPoint.X, controlPoint.Y, bezPoint.X, bezPoint.Y);
                context.Stroke();

                // find closest point in the bezPoints to the intersection point that is outside the target
                // work backwards through BezPoints array and use the first one that is outside the target
                for (int i = bezPoints.Count - 1; i >= 0; i--)
                {
                    Point arrowHead;
                    if (!Target.HitTest(bezPoints[i]))
                    {
                        arrowHead = bezPoints[i];
                        i--;
                        //keep moving along the line until distance = target radius
                        double targetRadius = Target.Width / 2;
                        while (i >= 0)
                        {
                            double dist = GetDistance(bezPoints[i], arrowHead);
                            if (dist >= 20)
                            {
                                DrawArrow(context, bezPoints[i], arrowHead);
                                break;
                            }

                            i--;
                        }
                        break;
                    }
                }
            }
        }
Example #4
0
        /// <summary>Draw an arrow on the specified graphics context</summary>
        /// <param name="context">The graphics context to draw on</param>
        /// <param name="start">The start point of the arrow</param>
        /// <param name="end">The end point of the arrow</param>
        private static void DrawArrow(IDrawContext context, Point start, Point end)
        {
            double angle = Math.Atan2(end.Y - start.Y, end.X - start.X) + Math.PI;

            double arrowLenght  = 10;
            double arrowDegrees = 10;
            double x1           = start.X + arrowLenght * Math.Cos(angle - arrowDegrees);
            double y1           = start.Y + arrowLenght * Math.Sin(angle - arrowDegrees);
            double x2           = start.X + arrowLenght * Math.Cos(angle + arrowDegrees);
            double y2           = start.Y + arrowLenght * Math.Sin(angle + arrowDegrees);

            context.NewPath();
            context.MoveTo(x1, y1);
            context.LineTo(x2, y2);
            context.LineTo(end.X, end.Y);
            context.LineTo(x1, y1);
            context.StrokePreserve();
            context.Fill();
        }
Example #5
0
        /// <summary>Draw a single cell to the context.</summary>
        /// <param name="cr">The context to draw in.</param>
        /// <param name="columnIndex">The column index.</param>
        /// <param name="rowIndex">The row index.</param>
        private void DrawCell(IDrawContext cr, int columnIndex, int rowIndex)
        {
            try
            {
                var text       = DataProvider.GetCellContents(columnIndex, rowIndex);
                var cellBounds = CalculateBounds(columnIndex, rowIndex);
                if (cellBounds != null)
                {
                    if (text == null)
                    {
                        text = string.Empty;
                    }

                    cr.Rectangle(cellBounds.Clip(Width - 20, Height).ToRectangle());
                    cr.Clip();

                    cr.SetLineWidth(lineWidth);

                    cr.Rectangle(cellBounds.ToRectangle());
                    if (CellPainter.PaintCell(columnIndex, rowIndex))
                    {
                        // Draw the filled in cell.

                        cr.State = CellPainter.GetCellState(columnIndex, rowIndex);
                        cr.DrawFilledRectangle(cellBounds.Left, cellBounds.Top, cellBounds.Width - 5, cellBounds.Height - 5);


                        // Draw cell outline.
                        if (ShowLines)
                        {
                            cr.Rectangle(cellBounds.ToRectangle());
                            cr.Stroke();
                        }

                        // Measure text for cell.
                        var r = cr.GetPixelExtents(text,
                                                   CellPainter.TextBold(columnIndex, rowIndex),
                                                   CellPainter.TextItalics(columnIndex, rowIndex));

                        // Vertically center the text.
                        double y = cellBounds.Top + (cellBounds.Height - r.Height) / 2;

                        // Horizontal alignment is determined by the cell painter.
                        double x;
                        if (CellPainter.TextLeftJustify(columnIndex, rowIndex))
                        {
                            x = cellBounds.Left + ColumnPadding;
                        }
                        else
                        {
                            x = cellBounds.Right - ColumnPadding - r.Width;
                        }

                        cr.MoveTo(x, y);
                        cr.DrawText(text, CellPainter.TextBold(columnIndex, rowIndex),
                                    CellPainter.TextItalics(columnIndex, rowIndex));
                    }
                    cr.ResetClip();
                    cr.State = States.Normal;
                }
            }
            catch (Exception ex)
            {
                MainView.MasterView.ShowError(ex);
            }
        }