/// <summary> /// Init. /// </summary> /// <param name="g">the Perspex graphics object to use</param> /// <param name="initialClip">the initial clip of the graphics</param> /// <param name="releaseGraphics">optional: if to release the graphics object on dispose (default - false)</param> public GraphicsAdapter(DrawingContext g, RRect initialClip, bool releaseGraphics = false) : base(PerspexAdapter.Instance, initialClip) { ArgChecker.AssertArgNotNull(g, "g"); _g = g; _releaseGraphics = releaseGraphics; }
/// <summary> /// /// </summary> /// <param name="context"></param> public override void Render(DrawingContext context) { base.Render(context); if (_state == null) { InitializeDrawable(); InitializeLayers(); } Draw(context); }
public override void Render(DrawingContext context) { var selectionStart = SelectionStart; var selectionEnd = SelectionEnd; if (selectionStart != selectionEnd) { var start = Math.Min(selectionStart, selectionEnd); var length = Math.Max(selectionStart, selectionEnd) - start; var rects = FormattedText.HitTestTextRange(start, length); var brush = new SolidColorBrush(0xff086f9e); foreach (var rect in rects) { context.FillRectangle(brush, rect); } } base.Render(context); if (selectionStart == selectionEnd) { var charPos = FormattedText.HitTestTextPosition(CaretIndex); var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush)?.Color; var caretBrush = Brushes.Black; if(backgroundColor.HasValue) { byte red = (byte)~(backgroundColor.Value.R); byte green = (byte)~(backgroundColor.Value.G); byte blue = (byte)~(backgroundColor.Value.B); caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue)); } if (_caretBlink) { var x = Math.Floor(charPos.X) + 0.5; var y = Math.Floor(charPos.Y) + 0.5; var b = Math.Ceiling(charPos.Bottom) - 0.5; context.DrawLine( new Pen(caretBrush, 1), new Point(x, y), new Point(x, b)); } } }
/// <summary> /// Renders the <see cref="AccessText"/> to a drawing context. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { base.Render(context); int underscore = Text?.IndexOf('_') ?? -1; if (underscore != -1 && ShowAccessKey) { var rect = FormattedText.HitTestTextPosition(underscore); var offset = new Vector(0, -0.5); context.DrawLine( new Pen(Foreground, 1), rect.BottomLeft + offset, rect.BottomRight + offset); } }
/// <summary> /// Renders the control. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { var background = Background; var borderBrush = BorderBrush; var borderThickness = BorderThickness; var cornerRadius = CornerRadius; var rect = new Rect(Bounds.Size).Deflate(BorderThickness); if (background != null) { context.FillRectangle(background, rect, cornerRadius); } if (borderBrush != null && borderThickness > 0) { context.DrawRectangle(new Pen(borderBrush, borderThickness), rect, cornerRadius); } }
public override void Render(DrawingContext context) { var y = 0.0; for (var i = (int)_offset.Y; i < itemCount; ++i) { using (var line = new FormattedText( "Item " + (i + 1), TextBlock.GetFontFamily(this), TextBlock.GetFontSize(this), TextBlock.GetFontStyle(this), TextAlignment.Left, TextBlock.GetFontWeight(this))) { context.DrawText(Brushes.Black, new Point(-_offset.X, y), line); y += _lineSize.Height; } } }
/// <summary> /// Renders the control. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { Bitmap source = Source; if (source != null) { Rect viewPort = new Rect(Bounds.Size); Size sourceSize = new Size(source.PixelWidth, source.PixelHeight); Vector scale = Stretch.CalculateScaling(Bounds.Size, sourceSize); Size scaledSize = sourceSize * scale; Rect destRect = viewPort .CenterIn(new Rect(scaledSize)) .Intersect(viewPort); Rect sourceRect = new Rect(sourceSize) .CenterIn(new Rect(destRect.Size / scale)); context.DrawImage(source, 1, sourceRect, destRect); } }
protected override void OnRender(DrawingContext ctx) { ctx.FillRectangle(Brushes.Green, new Rect(0, 0, Width, Height)); var rc = new Rect(0, 0, Width/3, Height/3); using (ctx.PushPostTransform( Perspex.Matrix.CreateTranslation(-Width/6, -Width/6)* Perspex.Matrix.CreateRotation(_radians)* Perspex.Matrix.CreateTranslation(Width/2, Height/2))) { ctx.FillRectangle(new LinearGradientBrush() { GradientStops = { new GradientStop() {Color = Colors.Blue}, new GradientStop(Colors.Red, 1) } }, rc, 5); } }
public PushedState(DrawingContext context, PushedStateType type, Matrix matrix = default(Matrix)) { _context = context; _type = type; _matrix = matrix; _level = context._currentLevel += 1; context._states.Push(this); }
private void DrawRoundRect(DrawingContext ctx) { ctx.FillRectangle(new SolidColorBrush(Colors.White), new Rect(new Size(ClientSize.Width, ClientSize.Height))); var rc = new Rect(0, 0, 60, 60); var transform = GetTransform(); using (ctx.PushPostTransform(transform)) { ctx.FillRectangle(new SolidColorBrush(Colors.Aqua), rc, 20); ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Magenta), 10), rc, 20); } }
/// <summary> /// Init. /// </summary> public GraphicsAdapter() : base(PerspexAdapter.Instance, RRect.Empty) { _g = null; _releaseGraphics = false; }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="brush"></param> /// <param name="pen"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="rect"></param> private static void DrawEllipseInternal( DrawingContext dc, Brush brush, Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isFilled && !isStroked) return; var r = new Rect(rect.X, rect.Y, rect.Width, rect.Height); var g = new EllipseGeometry(r); dc.DrawGeometry( isFilled ? brush : null, isStroked ? pen : null, g); // TODO: g.Dispose(); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="stroke"></param> /// <param name="rect"></param> /// <param name="offsetX"></param> /// <param name="offsetY"></param> /// <param name="cellWidth"></param> /// <param name="cellHeight"></param> /// <param name="isStroked"></param> private void DrawGridInternal( DrawingContext dc, Pen stroke, ref Rect2 rect, double offsetX, double offsetY, double cellWidth, double cellHeight, bool isStroked) { double ox = rect.X; double oy = rect.Y; double sx = ox + offsetX; double sy = oy + offsetY; double ex = ox + rect.Width; double ey = oy + rect.Height; for (double x = sx; x < ex; x += cellWidth) { var p0 = new Point( _scaleToPage(x), _scaleToPage(oy)); var p1 = new Point( _scaleToPage(x), _scaleToPage(ey)); DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1); } for (double y = sy; y < ey; y += cellHeight) { var p0 = new Point( _scaleToPage(ox), _scaleToPage(y)); var p1 = new Point( _scaleToPage(ex), _scaleToPage(y)); DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1); } }
/// <summary> /// Renders the visual to a <see cref="DrawingContext"/>. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { Brush background = Background; if (background != null) { var renderSize = Bounds.Size; context.FillRectangle(background, new Rect(renderSize)); } base.Render(context); }
/// <summary> /// /// </summary> /// <param name="dc"></param> private void Draw(DrawingContext dc) { var context = this.DataContext as EditorContext; if (context == null || context.Editor == null || context.Editor.Project == null) return; // TODO: Disable anti-aliasing. var translate = dc.PushPreTransform(Matrix.CreateTranslation(_state.PanX, _state.PanY)); var scale = dc.PushPreTransform(Matrix.CreateScale(_state.Zoom, _state.Zoom)); var renderer = context.Editor.Renderers[0]; if (context.Editor.Project == null) return; var container = context.Editor.Project.CurrentContainer; if (container == null) return; if (container.Template != null) { DrawBackground( dc, container.Template.Background, container.Width, container.Height); renderer.Draw( dc, container.Template, container.Properties, null); } DrawBackground( dc, container.Background, container.Width, container.Height); renderer.Draw( dc, container, container.Properties, null); if (container.WorkingLayer != null) { renderer.Draw( dc, container.WorkingLayer, container.Properties, null); } if (container.HelperLayer != null) { renderer.Draw( dc, container.HelperLayer, container.Properties, null); } scale.Dispose(); translate.Dispose(); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="brush"></param> /// <param name="pen"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="rect"></param> private static void DrawRectangleInternal( DrawingContext dc, Brush brush, Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isStroked && !isFilled) return; var r = new Rect(rect.X, rect.Y, rect.Width, rect.Height); if (isFilled) { dc.FillRectangle(brush, r); } if (isStroked) { dc.DrawRectangle(pen, r); } }
public override void Render(DrawingContext context) { var geometry = RenderedGeometry; if (geometry != null) { var pen = new Pen(Stroke, StrokeThickness, new DashStyle(StrokeDashArray), StrokeDashCap, StrokeStartLineCap, StrokeEndLineCap); context.DrawGeometry(Fill, pen, geometry); } }
public override void Render(DrawingContext context) { Rendered = true; }
/// <summary> /// Renders the <see cref="TextBlock"/> to a drawing context. /// </summary> /// <param name="context">The drawing context.</param> public override void Render(DrawingContext context) { Brush background = Background; if (background != null) { context.FillRectangle(background, new Rect(Bounds.Size)); } FormattedText.Constraint = Bounds.Size; context.DrawText(Foreground, new Point(), FormattedText); }
/// <summary> /// Render the html using the given device. /// </summary> /// <param name="g">the device to use to render</param> /// <param name="clip">the clip rectangle of the html container</param> public void PerformPaint(DrawingContext g, Rect clip) { ArgChecker.AssertArgNotNull(g, "g"); using (var ig = new GraphicsAdapter(g, Util.Convert(clip))) { _htmlContainerInt.PerformPaint(ig); } }
protected abstract void OnRender(DrawingContext ctx);
/// <summary> /// Renders the visual to a <see cref="DrawingContext"/>. /// </summary> /// <param name="context">The drawing context.</param> public virtual void Render(DrawingContext context) { Contract.Requires<ArgumentNullException>(context != null); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="pen"></param> /// <param name="isStroked"></param> /// <param name="p0"></param> /// <param name="p1"></param> private static void DrawLineInternal( DrawingContext dc, Pen pen, bool isStroked, ref Point p0, ref Point p1) { if (isStroked) { dc.DrawLine(pen, p0, p1); } }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="c"></param> /// <param name="width"></param> /// <param name="height"></param> private void DrawBackground(DrawingContext dc, ArgbColor c, double width, double height) { var color = Color.FromArgb(c.A, c.R, c.G, c.B); var brush = new SolidColorBrush(color); var rect = new Rect(0, 0, width, height); dc.FillRectangle(brush, rect); // TODO: brush.Dispose(); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="container"></param> private void DrawBackgroundInternal(DrawingContext dc, Container container) { Brush brush = ToSolidBrush(container.Background); var rect = new Rect(0, 0, container.Width, container.Height); dc.FillRectangle(brush, rect); // TODO: brush.Dispose(); }