Exemple #1
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(Context 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.ToClippedRectangle(Width - 20, Height));
                    cr.Clip();

                    cr.LineWidth = lineWidth;

                    cr.Rectangle(cellBounds.ToRectangle());
                    if (!CellPainter.PaintCell(columnIndex, rowIndex))
                    {
                        //cr.SetSourceColor(CellPainter.GetForegroundColour(columnIndex, rowIndex));
                        //cr.Stroke();
                    }
                    else
                    {
                        // Draw the filled in cell.
#if NETCOREAPP
                        this.StyleContext.State = CellPainter.GetCellState(columnIndex, rowIndex);
                        this.StyleContext.RenderBackground(cr, cellBounds.Left, cellBounds.Top, cellBounds.Width - 5, cellBounds.Height - 5);
                        var c = this.StyleContext.GetColor(this.StyleContext.State);
                        cr.SetSourceColor(new Cairo.Color(c.Red, c.Green, c.Blue, c.Alpha));
#else
                        cr.SetSourceColor(CellPainter.GetBackgroundColour(columnIndex, rowIndex));
                        cr.Fill();
                        cr.SetSourceColor(CellPainter.GetForegroundColour(columnIndex, rowIndex));
#endif
                        // Draw cell outline.
                        if (ShowLines)
                        {
                            cr.Rectangle(cellBounds.ToRectangle());
                            cr.Stroke();
                        }

                        //Set text font options for cell.
                        var layout = this.CreatePangoLayout(text);
                        layout.FontDescription = new Pango.FontDescription();
                        if (CellPainter.TextItalics(columnIndex, rowIndex))
                        {
                            layout.FontDescription.Style = Pango.Style.Italic;
                        }
                        if (CellPainter.TextBold(columnIndex, rowIndex))
                        {
                            layout.FontDescription.Weight = Pango.Weight.Bold;
                        }
                        layout.GetPixelExtents(out Pango.Rectangle inkRectangle, out Pango.Rectangle logicalRectangle);

                        // Vertically center the text.
                        double y = cellBounds.Top + (cellBounds.Height - logicalRectangle.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 - inkRectangle.Width;
                        }

                        cr.MoveTo(x, y);
                        Pango.CairoHelper.ShowLayout(cr, layout);
                    }
                    cr.ResetClip();
#if NETCOREAPP
                    this.StyleContext.State = StateFlags.Normal;
#endif
                }
            }
            catch (Exception ex)
            {
                MainView.MasterView.ShowError(ex);
            }
        }
Exemple #2
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);
            }
        }