예제 #1
0
        /// <summary>Paint on the graphics context</summary>
        /// <param name="context">The graphics context to draw on</param>
        public override void Paint(IDrawContext context)
        {
            Color outlineColour;

            if (Selected)
            {
                outlineColour = Color.Blue;
            }
            else if (transparent)
            {
                outlineColour = DefaultBackgroundColour;
            }
            else
            {
                outlineColour = DefaultOutlineColour;
            }

            Color backgroundColour = transparent ? DefaultBackgroundColour : Colour;
            Color textColour       = DefaultOutlineColour;

            // Draw circle
            context.SetColour(outlineColour);
            context.SetLineWidth(3);
            context.NewPath();
            context.Arc(Location.X, Location.Y, Width / 2, 0, 2 * Math.PI);
            context.StrokePreserve();
            context.SetColour(backgroundColour);
            context.Fill();

            // Write text
            context.SetLineWidth(1);
            context.SetColour(textColour);
            context.SetFontSize(13);


            DrawCentredText(context, Name, Location);
        }
예제 #2
0
파일: Sheet.cs 프로젝트: lie112/ApsimX
        /// <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);
            }
        }