protected override void DrawBackground( IDrawContext drawContext, Rectangle bounds) { Rectangle textBounds = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height); if (this.IsEnabled) { base.DrawBackground(drawContext, bounds); var foregroundColor = this.ForegroundColor; if (foregroundColor.HasValue) { drawContext.DrawText(this.Text, textBounds, foregroundColor.Value, this._textFormat); } } else { drawContext.Clear(Colors.Transparent); var foregroundColor = this.DisabledColor; if (foregroundColor.HasValue) { drawContext.DrawText(this.Text, textBounds, foregroundColor.Value, this._textFormat); } } }
protected override void DrawBackground( IDrawContext drawContext, Rectangle bounds) { const float Padding = 10.0f; base.DrawBackground(drawContext, bounds); bounds = bounds.Deflate(Padding, 0); float origin = (this._swipeDirection == ListViewSwipeDirection.Primary ? 1.0f : 0.0f); Rectangle imageBounds = new Rectangle( bounds.X + (origin * (bounds.Width - this._iconSize.Width)), bounds.Center.Y - (this._iconSize.Height / 2.0f), this._iconSize.Width, this._iconSize.Height); Rectangle textBounds = bounds.Deflate(imageBounds.Width + Padding, 0); if (null != this.Icon) { drawContext.DrawImage(this.Icon, imageBounds, this.ForegroundColor); } if (null != this.Text) { drawContext.DrawText(this.Text, textBounds, this.ForegroundColor, this._textFormat); } }
protected override void DrawBackground( IDrawContext drawContext, Rectangle bounds) { base.DrawBackground(drawContext, bounds); // Calculate text bounds float textHeight = bounds.Height / 4; Rectangle textBounds = new Rectangle(bounds.X, bounds.Bottom - textHeight, bounds.Width, textHeight); // Calculate button bounds float buttonDimension = Math.Min(bounds.Width, bounds.Height - textHeight); float buttonRadius = buttonDimension / 2; Rectangle buttonBounds = new Rectangle( bounds.Center.X - buttonRadius, bounds.Center.Y - (textHeight / 2) - buttonRadius, buttonDimension, buttonDimension); // Calculate image bounds float imageDimension = buttonDimension / 2; Rectangle imageBounds = new Rectangle( buttonBounds.Center.X - (imageDimension / 2), buttonBounds.Center.Y - (imageDimension / 2), imageDimension, imageDimension); Bitmap icon = this.RadioButtonItem.Icon; if (this._isTouchDown) { drawContext.FillEllipse(buttonBounds, this.Theme.SubtleForegroundColor); if (null != icon) { drawContext.DrawImage(icon, imageBounds, Colors.White); } } else if (this.IsChecked) { drawContext.FillEllipse(buttonBounds, this.Theme.AccentColor); if (null != icon) { drawContext.DrawImage(icon, imageBounds, Colors.White); } } else { drawContext.DrawEllipse(buttonBounds.Center, buttonRadius - 1.0f, buttonRadius - 1.0f, this.Theme.SubtleForegroundColor, strokeWidth: 1.0f); if (null != icon) { drawContext.DrawImage(icon, imageBounds, this.Theme.SubtleForegroundColor); } } drawContext.DrawText(this.RadioButtonItem.Text, textBounds, this.Theme.SubtleForegroundColor, this._textFormat); }
/// <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); }
protected override void DrawBackground( IDrawContext drawContext, Rectangle bounds) { base.DrawBackground(drawContext, bounds); // Calculate text bounds float textHeight = bounds.Height; Rectangle textBounds = new Rectangle(bounds.X, bounds.Bottom - textHeight, bounds.Width, textHeight); // Calculate button bounds float buttonDimension = Math.Min(bounds.Width, bounds.Height); float buttonRadius = buttonDimension / 2; Rectangle buttonBounds = new Rectangle( bounds.Center.X - buttonRadius, bounds.Center.Y - buttonRadius, buttonDimension, buttonDimension); if (this._isTouchDown) { drawContext.FillEllipse(buttonBounds, this.Theme.SubtleForegroundColor); drawContext.DrawText(this._text, textBounds, Colors.White, this._textFormat); } else if (this.IsChecked) { drawContext.FillEllipse(buttonBounds, this.Theme.AccentColor); drawContext.DrawText(this._text, textBounds, Colors.White, this._textFormat); } else { drawContext.DrawEllipse(buttonBounds.Center, buttonRadius - 1.0f, buttonRadius - 1.0f, this.Theme.SubtleForegroundColor, strokeWidth: 1.0f); drawContext.DrawText(this._text, textBounds, this.Theme.SubtleForegroundColor, this._textFormat); } }
protected override void DrawBackground( IDrawContext drawContext, Rectangle bounds) { base.DrawBackground(drawContext, bounds); //drawContext.DrawRectangle(bounds, Color.FromArgb(0x40, 255, 0, 0)); float margin = Math.Min(bounds.Width, bounds.Height) * 0.1f; bounds = bounds.Inflate(-margin, -margin); float imageDimension = Math.Min(bounds.Width, bounds.Height) * 0.65f; float textHeight = bounds.Height * 0.35f; Rectangle imageBounds = new Rectangle( bounds.Center.X - (imageDimension / 2f), bounds.Center.Y - ((imageDimension + textHeight) / 2f), imageDimension, imageDimension); Rectangle textBounds = new Rectangle(bounds.X, imageBounds.Bottom, bounds.Width, bounds.Bottom - imageBounds.Bottom); //drawContext.DrawRectangle(bounds, Color.FromArgb(0x40, 255, 0, 0)); //drawContext.DrawRectangle(imageBounds, Color.FromArgb(0x40, 255, 0, 0)); //drawContext.DrawRectangle(textBounds, Color.FromArgb(0x40, 255, 0, 0)); Color foregroundColor; if (this.Theme == AppTheme.Dark) { if (this.IsChecked) { foregroundColor = this.Application.Theme.AccentColor; } else { foregroundColor = this.Application.Theme.SubtleForegroundColor; } } else { foregroundColor = Colors.White; } drawContext.DrawImage(this._icon, imageBounds, foregroundColor); drawContext.DrawText(this.Text, textBounds, foregroundColor, this._textFormat); }
protected override void DrawBackground( IDrawContext drawContext, Rectangle bounds) { base.DrawBackground(drawContext, bounds); float imageDimension = Math.Min(bounds.Width, bounds.Height) * 0.65f; float textHeight = bounds.Height * 0.35f; Rectangle imageBounds = new Rectangle( bounds.Center.X - (imageDimension / 2f), bounds.Center.Y - ((imageDimension + textHeight) / 2f), imageDimension, imageDimension); drawContext.DrawImage(this._icon, imageBounds, this.AccentColor); Rectangle textBounds = new Rectangle(bounds.X, imageBounds.Bottom, bounds.Width, bounds.Bottom - imageBounds.Bottom); drawContext.DrawText(this.Text, textBounds, this.AccentColor, this._textFormat); }
protected override void DrawBackground( IDrawContext drawContext, Rectangle bounds) { base.DrawBackground(drawContext, bounds); float margin = Math.Min(bounds.Width, bounds.Height) * 0.1f; bounds = bounds.Inflate(-margin, -margin); float imageDimension = Math.Min(bounds.Width, bounds.Height) * 0.75f; float textHeight = bounds.Height * 0.25f; Rectangle imageBounds = new Rectangle( bounds.Center.X - (imageDimension / 2f), bounds.Center.Y - ((imageDimension + textHeight) / 2f), imageDimension, imageDimension); Rectangle textBounds = new Rectangle(bounds.X, imageBounds.Bottom, bounds.Width, textHeight); drawContext.DrawImage(this.MenuItem.Icon, imageBounds, this.ForegroundColor); drawContext.DrawText(this.MenuItem.Text, textBounds, this.ForegroundColor, this._textFormat); }
/// <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); } }