public Disposable PushMask(RectangleF rect, float alpha, Path path = null) { if (alpha >= 1 && path == null) { CurrentRenderTarget.PushAxisAlignedClip(rect.ToRaw(), CurrentRenderTarget.AntialiasMode); return(new Disposable(() => { CurrentRenderTarget.PopAxisAlignedClip(); })); } else { var geometery = path?.GetGeometry(CurrentRenderTarget.Factory); var parameters = new LayerParameters { ContentBounds = rect.ToRaw(), Opacity = alpha, MaskTransform = GetCurrentTransform(), GeometricMask = geometery }; var layer = new Layer(CurrentRenderTarget); CurrentRenderTarget.PushLayer(ref parameters, layer); return(new Disposable(() => { this.CurrentRenderTarget.PopLayer(); layer.Dispose(); geometery?.Dispose(); })); } }
public void DrawPath(Path path, Paint paint, bool fromMask = false) { UpdateDrawingSessionWithFlags(paint.Flags); CurrentRenderTarget.Transform = GetCurrentTransform(); var gradient = paint.Shader as Gradient; var brush = gradient != null ? gradient.GetBrush(CurrentRenderTarget, paint.Alpha) : new SolidColorBrush(CurrentRenderTarget, paint.Color.ToRaw()); var finalBrush = paint.ColorFilter?.Apply(this, brush) ?? brush; using (var geometry = path.GetGeometry(CurrentRenderTarget.Factory)) { if (paint.Style == Paint.PaintStyle.Stroke) { CurrentRenderTarget.DrawGeometry(geometry, finalBrush, paint.StrokeWidth, GetStrokeStyle(paint)); } else { CurrentRenderTarget.FillGeometry(geometry, finalBrush); } } if (gradient == null) { brush?.Dispose(); finalBrush?.Dispose(); } }
private void DrawBackgroundWithBitmap() { if (Transforming) { if (!Checked) { CurrentRenderTarget.drawImage(SliderBitmapFalse, SliderRect.X, SliderRect.Y, SliderRect.Width, SliderRect.Height); CurrentRenderTarget.drawImage(SliderBitmapTrue, SliderRect.X, SliderRect.Y, SliderRect.Width, SliderRect.Height, (float)Progress); } else { CurrentRenderTarget.drawImage(SliderBitmapTrue, SliderRect.X, SliderRect.Y, SliderRect.Width, SliderRect.Height); CurrentRenderTarget.drawImage(SliderBitmapFalse, SliderRect.X, SliderRect.Y, SliderRect.Width, SliderRect.Height, (float)Progress); } } else { if (!Checked) { CurrentRenderTarget.drawImage(SliderBitmapTrue, SliderRect.X, SliderRect.Y, SliderRect.Width, SliderRect.Height); } else { CurrentRenderTarget.drawImage(SliderBitmapFalse, SliderRect.X, SliderRect.Y, SliderRect.Width, SliderRect.Height); } } }
private void DrawThumbWithBitmap() { int x = SliderRect.Left; int x2 = SliderRect.Left + SliderRect.Width - ThumbBitmap.Width; int y = SliderRect.Top; if (Transforming) { int offset = 0; if (!Checked) { offset = (int)(Progress * (-SliderRect.Width)); CurrentRenderTarget.drawImage(this.ThumbBitmap, x2 + offset, y, ThumbBitmap.Width, ThumbBitmap.Height); } else { offset = (int)(Progress * SliderRect.Width); CurrentRenderTarget.drawImage(this.ThumbBitmap, x + offset, y, ThumbBitmap.Width, ThumbBitmap.Height); } } else { if (!Checked) { CurrentRenderTarget.drawImage(this.ThumbBitmap, x, y, ThumbBitmap.Width, ThumbBitmap.Height); } else { CurrentRenderTarget.drawImage(this.ThumbBitmap, x2, y, ThumbBitmap.Width, ThumbBitmap.Height); } } }
public void Clear(Color color) { UpdateDrawingSessionWithFlags(0); CurrentRenderTarget.Clear(color); _matrixSaves.Clear(); _flagSaves.Clear(); _clipSaves.Clear(); }
private void DrawText() { if (!DrawTextOnSlider) { return; } int centerX = SliderRect.Left + SliderRect.Width / 2; int centerXLeft = centerX - SliderRect.Width / 4; int centerXRight = centerX + SliderRect.Width / 4; if (Transforming) { int alpha = 0; alpha = (int)(255 * (1 - Progress)); if (!Checked) { SizeF txtSize = CurrentRenderTarget.MeasureString(TextOnSliderFalse, this.Font); CurrentRenderTarget.drawString(TextOnSliderFalse, centerXRight - (int)txtSize.Width / 2, SliderRect.Y + SliderRect.Height / 2 - (int)txtSize.Height / 2, Color.FromArgb(alpha, TextOnSliderFalseColor).ToArgb(), this.Font ); } else { SizeF txtSize = CurrentRenderTarget.MeasureString(TextOnSliderTrue, this.Font); CurrentRenderTarget.drawString(TextOnSliderTrue, centerXLeft - (int)txtSize.Width / 2, SliderRect.Y + SliderRect.Height / 2 - (int)txtSize.Height / 2, Color.FromArgb(alpha, TextOnSliderFalseColor).ToArgb(), this.Font ); } } else { if (!Checked) { SizeF txtSize = CurrentRenderTarget.MeasureString(TextOnSliderFalse, this.Font); CurrentRenderTarget.drawString(TextOnSliderFalse, centerXRight - (int)txtSize.Width / 2, SliderRect.Y + SliderRect.Height / 2 - (int)txtSize.Height / 2, TextOnSliderFalseColor.ToArgb(), this.Font ); } else { SizeF txtSize = CurrentRenderTarget.MeasureString(TextOnSliderTrue, this.Font); CurrentRenderTarget.drawString(TextOnSliderTrue, centerXLeft - (int)txtSize.Width / 2, SliderRect.Y + SliderRect.Height / 2 - (int)txtSize.Height / 2, TextOnSliderTrueColor.ToArgb(), this.Font ); } } }
public void Clear(Color color) { UpdateDrawingSessionWithFlags(0); CurrentRenderTarget.Clear(new RawColor4(color.R, color.G, color.B, color.A)); ; _matrixSaves.Clear(); _flagSaves.Clear(); _clipSaves.Clear(); }
public void DrawBitmap(Bitmap bitmap, RectangleF src, RectangleF dst, Paint paint) { UpdateDrawingSessionWithFlags(paint.Flags); CurrentRenderTarget.Transform = GetCurrentTransform(); //var canvasComposite = CanvasComposite.SourceOver; // TODO paint.ColorFilter //if (paint.ColorFilter is PorterDuffColorFilter porterDuffColorFilter) // canvasComposite = PorterDuff.ToCanvasComposite(porterDuffColorFilter.Mode); CurrentRenderTarget.DrawBitmap(bitmap, dst, paint.Alpha / 255f, BitmapInterpolationMode.NearestNeighbor, src); }
public SliderCheckbox() { InitializeComponent(); CurrentRenderTarget.setUseAlpha(true); CurrentRenderTarget.onMouseClickHandler += (this.UponMouseClick); CurrentRenderTarget.SmoothMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; CurrentRenderTarget.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low; CurrentRenderTarget.onMouseMoveHandler += (this.onMouseMove); sdlmmControl1.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; sdlmmControl1.SmoothMode = SmoothingMode.HighQuality; sdlmmControl1.InterpolationMode = InterpolationMode.Bicubic; RefreshSliderRect(); }
internal void DrawRect(RectangleF rect, Paint paint) { UpdateDrawingSessionWithFlags(paint.Flags); CurrentRenderTarget.Transform = GetCurrentTransform(); using (var brush = new SolidColorBrush(CurrentRenderTarget, paint.Color.ToRaw())) { if (paint.Style == Paint.PaintStyle.Stroke) { CurrentRenderTarget.DrawRectangle(rect.ToRaw(), brush, paint.StrokeWidth, GetStrokeStyle(paint)); } else { CurrentRenderTarget.FillRectangle(rect.ToRaw(), brush); } } }
public RectangleF DrawText(char character, Paint paint) { var gradient = paint.Shader as Gradient; var brush = gradient != null ? gradient.GetBrush(CurrentRenderTarget, paint.Alpha) : new SolidColorBrush(CurrentRenderTarget, paint.Color.ToRaw()); var finalBrush = paint.ColorFilter?.Apply(this, brush) ?? brush; UpdateDrawingSessionWithFlags(paint.Flags); CurrentRenderTarget.Transform = GetCurrentTransform(); var text = new string(character, 1); //TODO: OID: Check for global factory using (var factory = new SharpDX.DirectWrite.Factory()) { var textFormat = new TextFormat(factory, paint.Typeface.FontFamily, paint.Typeface.Weight, paint.Typeface.Style, paint.TextSize) { //FontSize = paint.TextSize, //FontFamily = paint.Typeface.FontFamily, //FontStyle = paint.Typeface.Style, //FontWeight = paint.Typeface.Weight, //VerticalAlignment = CanvasVerticalAlignment.Center, //HorizontalAlignment = CanvasHorizontalAlignment.Left, //LineSpacingBaseline = 0, //LineSpacing = 0 }; var textLayout = new TextLayout(factory, text, textFormat, 0.0f, 0.0f); CurrentRenderTarget.DrawText(text, textFormat, new RawRectangleF(0, 0, 0, 0), finalBrush); if (gradient == null) { brush?.Dispose(); finalBrush?.Dispose(); } //TODO: OID: LayoutBound is not exists in text layout return(new RectangleF(0, 0, textLayout.DetermineMinWidth(), 0)); } }
private void PaintBody() { if (!Visible) { return; } if (externalTarget == null) { if (this.BackColor != Color.Transparent) { CurrentRenderTarget.Clear(this.BackColor.ToArgb()); } } OnDraw(); if (externalTarget == null) { CurrentRenderTarget.flush(); } }
public void DrawRect(double x1, double y1, double x2, double y2, Paint paint) { UpdateDrawingSessionWithFlags(paint.Flags); CurrentRenderTarget.Transform = GetCurrentTransform(); using (var brush = new SolidColorBrush(CurrentRenderTarget, paint.Color)) { if (paint.Style == Paint.PaintStyle.Stroke) { CurrentRenderTarget.DrawRectangle(new RectangleF((float)x1, (float)y1, (float)(x2 - x1), (float)(y2 - y1)), brush, paint.StrokeWidth, GetStrokeStyle(paint)); } else { CurrentRenderTarget.FillRectangle(new RectangleF((float)x1, (float)y1, (float)(x2 - x1), (float)(y2 - y1)), brush); } } if (paint.Xfermode.Mode == PorterDuff.Mode.Clear) { CurrentRenderTarget.Flush(); } }
private void DrawThumbWithoutBitmap() { int r = SliderRect.Height / 2; int x = SliderRect.Left + r; int x2 = SliderRect.Left + SliderRect.Width - r; int y = SliderRect.Top + r; if (Transforming) { int offset = 0; int x3 = 0; if (Checked) { offset = (int)(Progress * (-SliderRect.Width)); x3 = x2 + offset; if (x3 < x) { x3 = x; } if (HasShadow) { CurrentRenderTarget.fillCircle(x3 + ShadowOffset, y + ShadowOffset, r + ShadowAdditionRadius, ShadowColor); } if (UseGradient) { using (LinearGradientBrush brush = ThumbColorLinearGradientTrue(x3, y, r + 1)) { CurrentRenderTarget.fillCircle(x3, y, r, brush); } using (LinearGradientBrush brush = ThumbColorLinearGradient(x3, y, r + 1, (int)(Progress * 255))) { CurrentRenderTarget.fillCircle(x3, y, r, brush); } } else { CurrentRenderTarget.fillCircle(x3, y, r, ThumbColorTrue.ToArgb()); CurrentRenderTarget.fillCircle(x3, y, r, Color.FromArgb((int)(Progress * 255), ThumbColor).ToArgb()); } } else { offset = (int)(Progress * SliderRect.Width); x3 = x + offset; if (x3 > x2) { x3 = x2; } if (HasShadow) { CurrentRenderTarget.fillCircle(x3 + ShadowOffset, y + ShadowOffset, r + ShadowAdditionRadius, ShadowColor); } if (UseGradient) { using (LinearGradientBrush brush = ThumbColorLinearGradient(x3, y, r + 1)) { CurrentRenderTarget.fillCircle(x3, y, r, brush); } using (LinearGradientBrush brush = ThumbColorLinearGradientTrue(x3, y, r + 1, (int)(Progress * 255))) { CurrentRenderTarget.fillCircle(x3, y, r, brush); } } else { CurrentRenderTarget.fillCircle(x3, y, r, ThumbColor.ToArgb()); CurrentRenderTarget.fillCircle(x3, y, r, Color.FromArgb((int)(Progress * 255), ThumbColorTrue).ToArgb()); } } } else { if (!Checked) { if (HasShadow) { CurrentRenderTarget.fillCircle(x + ShadowOffset, y + ShadowOffset, r + ShadowAdditionRadius, ShadowColor); } if (UseGradient) { using (LinearGradientBrush brush = ThumbColorLinearGradient(x, y, r + 1)) { CurrentRenderTarget.fillCircle(x, y, r, brush); } } else { CurrentRenderTarget.fillCircle(x, y, r, ThumbColor.ToArgb()); } } else { if (HasShadow) { CurrentRenderTarget.fillCircle(x2 + ShadowOffset, y + ShadowOffset, r + ShadowAdditionRadius, ShadowColor); } if (UseGradient) { using (LinearGradientBrush brush = ThumbColorLinearGradientTrue(x2, y, r + 1)) { CurrentRenderTarget.fillCircle(x2, y, r, brush); } } else { CurrentRenderTarget.fillCircle(x2, y, r, ThumbColorTrue.ToArgb()); } } } }
public void Restore() { if (_flagSaves.Count < 1) { return; } var flags = _flagSaves.Pop(); //if ((flags & ClipToLayerSaveFlag) == ClipToLayerSaveFlag) //{ // using (var brush = new SolidColorBrush(CurrentRenderTarget, new RawColor4(0, 0, 0, 0.3f))) // CurrentRenderTarget.FillRectangle(new RectangleF(0, 0, 100, 100), brush); //} if ((flags & MatrixSaveFlag) == MatrixSaveFlag) { _matrix = _matrixSaves.Pop(); } if ((flags & ClipSaveFlag) == ClipSaveFlag) { var clipSave = _clipSaves.Pop(); _currentClip = clipSave.RectangleF; clipSave.Layer.Dispose(); } if ((flags & ClipToLayerSaveFlag) == ClipToLayerSaveFlag) { var drawingSession = _canvasDrawingSessions.Pop(); drawingSession.RenderTarget.Flush(); drawingSession.RenderTarget.EndDraw(); var renderTargetSave = _renderTargetSaves.Pop(); var target = renderTargetSave.RenderTarget.Target; UpdateDrawingSessionWithFlags(renderTargetSave.PaintFlags); CurrentRenderTarget.Transform = GetCurrentTransform(); var canvasComposite = CompositeMode.SourceOver; if (renderTargetSave.PaintXfermode != null) { canvasComposite = PorterDuff.ToCanvasComposite(renderTargetSave.PaintXfermode.Mode); } var rect = new RawRectangleF(0, 0, renderTargetSave.RenderTarget.Size.Width, renderTargetSave.RenderTarget.Size.Height); CurrentRenderTarget.DrawImage(drawingSession.Bitmap, new RawVector2(0, 0), new RawRectangleF(0, 0, renderTargetSave.RenderTarget.Size.Width, renderTargetSave.RenderTarget.Size.Height), //renderTargetSave.PaintAlpha / 255f, InterpolationMode.Linear, canvasComposite); //CurrentRenderTarget.DrawBitmap(drawingSession.Bitmap, 255f, InterpolationMode.Linear); //var rect = new RawRectangleF(0, 0, rt.Size.Width, rt.Size.Height); ////using (var brush = new SolidColorBrush(CurrentRenderTarget, Color.Black)) //// CurrentRenderTarget.FillOpacityMask(rt, brush, OpacityMaskContent.Graphics, rect, rect); //CurrentRenderTarget.DrawImage(rt, rect, renderTargetSave.PaintAlpha / 255f, BitmapInterpolationMode.Linear, rect); //rt.Dispose(); //renderTargetSave.RenderTarget.Dispose(); } CurrentRenderTarget.Flush(); }
private void DrawBackgroundOnNoBitmap() { if (Transforming) { if (!Checked) { if (UseGradient) { using (LinearGradientBrush br2 = RefreshTrueColorLinearGradient(Math.Min(255, (uint)(255 * Progress)), false)) { CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, FalseColorLinearGradient); CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, br2); } } else { CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, FalseColor.ToArgb()); CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, Color.FromArgb((int)(255 * Progress) & 0xff, TrueColor).ToArgb()); } } else { if (UseGradient) { using (LinearGradientBrush br2 = RefreshFalseColorLinearGradient(Math.Min(255, (uint)(255 * Progress)), false)) { CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, TrueColorLinearGradient); CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, br2); } } else { CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, TrueColor.ToArgb()); CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, Color.FromArgb((int)(255 * Progress) & 0xff, FalseColor).ToArgb()); } } } else { if (!Checked) { if (UseGradient) { CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, FalseColorLinearGradient); } else { CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, FalseColor.ToArgb()); } } else { if (UseGradient) { CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, TrueColorLinearGradient); } else { CurrentRenderTarget.fillRoundRect(SliderRect.X, SliderRect.Y + (BackgroundHeightOffset / 2), SliderRect.Width, BackgroundHeight, BackgroundHeight / 2, TrueColor.ToArgb()); } } } }
private void DrawBackgroundFlatten() { if (mFlattenBorderThickness <= 0) { return; } int height = Math.Max(1, SliderRect.Height - FlattenBorderThickness + 1); if (Transforming) { if (!Checked) { Color color2 = Color.FromArgb((int)(255 * Progress), FlattenBorderColorTrue); CurrentRenderTarget.drawRoundRect( SliderRect.X, SliderRect.Y, SliderRect.Width, height, height / 2.0f, FlattenBorderColorFalse.ToArgb(), FlattenBorderThickness); CurrentRenderTarget.drawRoundRect( SliderRect.X, SliderRect.Y, SliderRect.Width, height, height / 2.0f, color2.ToArgb(), FlattenBorderThickness); } else { Color color2 = Color.FromArgb((int)(255 * Progress), FlattenBorderColorFalse); CurrentRenderTarget.drawRoundRect( SliderRect.X, SliderRect.Y, SliderRect.Width, height, height / 2.0f, FlattenBorderColorTrue.ToArgb(), FlattenBorderThickness); CurrentRenderTarget.drawRoundRect( SliderRect.X, SliderRect.Y, SliderRect.Width, height, height / 2.0f, color2.ToArgb(), FlattenBorderThickness); } } else { if (!Checked) { CurrentRenderTarget.drawRoundRect( SliderRect.X, SliderRect.Y, SliderRect.Width, height, height / 2.0f, FlattenBorderColorFalse.ToArgb(), FlattenBorderThickness); } else { CurrentRenderTarget.drawRoundRect( SliderRect.X, SliderRect.Y, SliderRect.Width, height, height / 2.0f, FlattenBorderColorTrue.ToArgb(), FlattenBorderThickness); } } }
public static void Clear(SystemColor color) { CurrentRenderTarget.Clear(color.ToSFMLColor()); }