Exemplo n.º 1
0
        /// <summary>
        /// Paint svg image
        /// </summary>
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);
            e.Surface.Canvas.Clear();

            if (string.IsNullOrEmpty(ResourceKey) || string.IsNullOrEmpty(AssemblyName))
            {
                return;
            }

            // Get device pixel intencity scale
            DeviceScale = (float)(e.Info.Width / Width);

            if (m_svg == null)
            {
                m_svg = GetSvgImage(AssemblyName, ResourceKey);
            }

            SKPoint position = CalculateTranslation(e.Info);
            float   scale    = CalculateScale(m_svg.Picture.CullRect.Size, WidthRequest, HeightRequest) * DeviceScale;

            SKMatrix matrix = new SKMatrix();

            matrix.SetScaleTranslate(scale, scale, position.X, position.Y);

            using (var paint = new SKPaint())
            {
                // paint.ColorFilter = SKColorFilter.CreateBlendMode(Color.ToSKColor(), SKBlendMode.SrcIn);
                paint.Style         = SKPaintStyle.Fill;
                paint.IsAntialias   = true;
                paint.FilterQuality = SKFilterQuality.None;
                e.Surface.Canvas.DrawPicture(m_svg.Picture, ref matrix, paint);
            }
        }
Exemplo n.º 2
0
        private static SKMatrix TRMatrix(ComponentLoad load, float scaleFactor, IssoPoint2D origin, float ViewHeight, out SKMatrix rmatrix)
        {
            SKPoint  point  = IssoConvert.IssoPoint2DToSkPoint(load.AppNodes[0].Location, scaleFactor, origin, ViewHeight);
            SKMatrix matrix = new SKMatrix();

            matrix.SetScaleTranslate(1, 1, point.X, point.Y);

            rmatrix = SKMatrix.MakeRotationDegrees(load.Direction + 90, point.X, point.Y);

            return(matrix);
        }
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            base.OnPaintSurface(args);

            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear(SKColors.Gray);

            // Calculate rectangle for displaying bitmap
            float  scale      = Math.Min((float)info.Width / bitmap.Width, (float)info.Height / bitmap.Height);
            float  x          = (info.Width - scale * bitmap.Width) / 2;
            float  y          = (info.Height - scale * bitmap.Height) / 2;
            SKRect bitmapRect = new SKRect(x, y, x + scale * bitmap.Width, y + scale * bitmap.Height);

            canvas.DrawBitmap(bitmap, bitmapRect);

            // Calculate a matrix transform for displaying the cropping rectangle
            SKMatrix bitmapScaleMatrix = SKMatrix.MakeIdentity();

            bitmapScaleMatrix.SetScaleTranslate(scale, scale, x, y);

            // Display rectangle
            SKRect scaledCropRect = bitmapScaleMatrix.MapRect(croppingRect.Rect);

            canvas.DrawRect(scaledCropRect, edgeStroke);

            // Display heavier corners
            using (SKPath path = new SKPath())
            {
                path.MoveTo(scaledCropRect.Left, scaledCropRect.Top + CORNER);
                path.LineTo(scaledCropRect.Left, scaledCropRect.Top);
                path.LineTo(scaledCropRect.Left + CORNER, scaledCropRect.Top);

                path.MoveTo(scaledCropRect.Right - CORNER, scaledCropRect.Top);
                path.LineTo(scaledCropRect.Right, scaledCropRect.Top);
                path.LineTo(scaledCropRect.Right, scaledCropRect.Top + CORNER);

                path.MoveTo(scaledCropRect.Right, scaledCropRect.Bottom - CORNER);
                path.LineTo(scaledCropRect.Right, scaledCropRect.Bottom);
                path.LineTo(scaledCropRect.Right - CORNER, scaledCropRect.Bottom);

                path.MoveTo(scaledCropRect.Left + CORNER, scaledCropRect.Bottom);
                path.LineTo(scaledCropRect.Left, scaledCropRect.Bottom);
                path.LineTo(scaledCropRect.Left, scaledCropRect.Bottom - CORNER);

                canvas.DrawPath(path, cornerStroke);
            }

            // Invert the transform for touch tracking
            bitmapScaleMatrix.TryInvert(out inverseBitmapMatrix);
        }
        public static void DrawNode(ComponentNode node, ModelViewSurface surface, SKCanvas canvas)
        {
            SKPath p1 = Rigid();
            SKPath p  = new SKPath();

            /* switch (node.Type)
             * {
             *   case NodeType.Hinge: p = Hinge(); break;
             *   case NodeType.Rigid: p = Rigid(); break;
             *   case NodeType.Pin2d: DrawPinSupport(node, surface, canvas, false); return;
             *   case NodeType.Roller2d: DrawRollerSupport(node, surface, canvas, false); return;
             *   default: p = Point(); break;
             * } */
            if (node.DisallowedDisplacements.Contains(NodeDisplacement.X))
            {
                AddX(p);
            }
            if (node.DisallowedDisplacements.Contains(NodeDisplacement.Y))
            {
                AddY(p);
            }
            if (node.DisallowedDisplacements.Contains(NodeDisplacement.Rotation))
            {
                AddR(p);
            }

            float scale = surface.ViewHeight / 80;

            SKPoint location = IssoConvert.IssoPoint2DToSkPoint(node.Location, surface.ScaleFactor, surface.Origin, surface.ViewHeight);

            SKMatrix matrix = new SKMatrix();

            matrix.SetScaleTranslate(scale, scale, location.X, location.Y);
            p.Transform(matrix);
            p1.Transform(matrix);

            SKPaint paint = new SKPaint
            {
                Style       = SKPaintStyle.StrokeAndFill,
                Color       = Color.Aquamarine.ToSKColor(),
                IsAntialias = true,
                StrokeWidth = 1
            };

            // Если компонент выбран, рисуем его пожирнее
            if (node.CompState == ComponentState.csEdited)
            {
                paint.StrokeWidth += 1;
            }
            canvas.DrawPath(p1, paint);
            paint.Style = SKPaintStyle.Stroke;
            canvas.DrawPath(p, paint);
        }
        private static SKMatrix TRMatrix(ComponentNode c, ModelViewSurface surface, out SKMatrix rmatrix)
        {
            float scale = surface.ViewHeight / 80;

            SKPoint location = IssoConvert.IssoPoint2DToSkPoint(c.Location, surface.ScaleFactor, surface.Origin, surface.ViewHeight);

            SKMatrix matrix = new SKMatrix();

            matrix.SetScaleTranslate(scale, scale, location.X, location.Y);

            //rmatrix = SKMatrix.MakeRotationDegrees(c.Angle - 90, location.X, location.Y);
            rmatrix = SKMatrix.MakeRotationDegrees(0, location.X, location.Y);

            return(matrix);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add submenu icon
        /// </summary>
        protected override void OnPaintForeground(SKPaintSurfaceEventArgs e, Rectangle availableSpace)
        {
            Size actualSubMenuIconSize = new Size();

            if (ItemsSource != null && ItemsSource.Count > 0 && IsSubMenuIconVisible && string.IsNullOrEmpty(SubMenuIconAssemblyName) == false && string.IsNullOrEmpty(SubMenuIconResourceKey) == false)
            {
                if (m_subMenuIconSvg == null)
                {
                    m_subMenuIconSvg = SvgImage.GetSvgImage(SubMenuIconAssemblyName, SubMenuIconResourceKey);
                }

                Rectangle subMenuIconActualLocation = new Rectangle(
                    availableSpace.Width - _subMenuIconSize.Width - SubMenuIconMargin.Right,
                    (availableSpace.Height - _subMenuIconSize.Height) / 2,
                    _subMenuIconSize.Height,
                    _subMenuIconSize.Width);

                float skSubMenuIconX = (float)subMenuIconActualLocation.X * DeviceScale;
                float skSubMenuIconY = (float)subMenuIconActualLocation.Y * DeviceScale;

                SKMatrix subMenuIconMatrix   = new SKMatrix();
                SKPoint  subMenuIconPosition = new SKPoint();

                float scale = SvgImage.CalculateScale(m_subMenuIconSvg.Picture.CullRect.Size, SubMenuIconWidthRequest, SubMenuIconHeightRequest) * DeviceScale;

                subMenuIconPosition.X = (float)skSubMenuIconX + (float)((SubMenuIconWidthRequest - _subMenuIconSize.Width) / 2) * DeviceScale;
                subMenuIconPosition.Y = (float)skSubMenuIconY + (float)((SubMenuIconHeightRequest - _subMenuIconSize.Height) / 2) * DeviceScale;
                subMenuIconMatrix.SetScaleTranslate(scale, scale, subMenuIconPosition.X, subMenuIconPosition.Y);

                using (var paint = new SKPaint())
                {
                    Color color = GetActualSubMenuIconColor();

                    paint.ColorFilter = SKColorFilter.CreateBlendMode(color.ToSKColor(), SKBlendMode.SrcIn);
                    paint.Style       = SKPaintStyle.Fill;
                    paint.IsAntialias = true;
                    e.Surface.Canvas.DrawPicture(m_subMenuIconSvg.Picture, ref subMenuIconMatrix, paint);
                }

                actualSubMenuIconSize = _subMenuIconSize;
            }

            base.OnPaintForeground(e, new Rectangle(availableSpace.X + _checkBoxSize.Width,
                                                    availableSpace.Y,
                                                    availableSpace.Width - actualSubMenuIconSize.Width - _checkBoxSize.Width,
                                                    availableSpace.Height));
        }
Exemplo n.º 7
0
        public override void Preroll(PrerollContext context, SKMatrix matrix)
        {
            SKMatrix child_matrix = matrix;

            child_matrix.SetScaleTranslate(child_matrix.ScaleX, child_matrix.ScaleY, offset_.X, offset_.Y);
            base.Preroll(context, child_matrix);
            if (context.raster_cache != null && layers().Count == 1)
            {
                Layer    child = layers()[0];//.get();
                SKMatrix ctm   = child_matrix;

#if !SUPPORT_FRACTIONAL_TRANSLATION
                ctm = RasterCache.GetIntegralTransCTM(ctm);
#endif
                context.raster_cache.Prepare(context, child, ctm);
            }
        }
Exemplo n.º 8
0
        public override void Preroll(PrerollContext context, SKMatrix matrix)
        {
            SKPicture sk_picture = picture();

            var      cache = context.raster_cache;
            SKMatrix ctm   = matrix;

            ctm.SetScaleTranslate(ctm.ScaleX, ctm.ScaleY, offset_.X, offset_.Y);
#if !SUPPORT_FRACTIONAL_TRANSLATION
            ctm = RasterCache.GetIntegralTransCTM(ctm);
#endif
            cache.Prepare(context.gr_context, sk_picture, ctm, context.dst_color_space, is_complex_, will_change_);


            SKRect bounds = sk_picture.CullRect;
            bounds.Offset(offset_.X, offset_.Y);
            set_paint_bounds(bounds);
        }
Exemplo n.º 9
0
        public override void Preroll(PrerollContext context, SKMatrix matrix)
        {
            SKPicture sk_picture = picture();

            var cache = context.raster_cache;
            //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
            //ORIGINAL LINE: SKMatrix ctm = matrix;
            SKMatrix ctm = matrix;

            ctm.SetScaleTranslate(ctm.ScaleX, ctm.ScaleY, offset_.X, offset_.Y);
#if !SUPPORT_FRACTIONAL_TRANSLATION
            //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
            //ORIGINAL LINE: ctm = RasterCache::GetIntegralTransCTM(ctm);
            ctm = RasterCache.GetIntegralTransCTM(ctm);
#endif
            cache.Prepare(context.gr_context, sk_picture, ctm, context.dst_color_space, is_complex_, will_change_);


            SKRect bounds = sk_picture.CullRect;
            bounds.Offset(offset_.X, offset_.Y);
            set_paint_bounds(bounds);
        }
Exemplo n.º 10
0
        public override void Preroll(PrerollContext context, SKMatrix matrix)
        {
            //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
            //ORIGINAL LINE: SKMatrix child_matrix = matrix;
            SKMatrix child_matrix = matrix;

            child_matrix.SetScaleTranslate(child_matrix.ScaleX, child_matrix.ScaleY, offset_.X, offset_.Y);
            base.Preroll(context, child_matrix);
            if (context.raster_cache != null && layers().Count == 1)
            {
                Layer child = layers()[0];//.get();
                //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                //ORIGINAL LINE: SKMatrix ctm = child_matrix;
                SKMatrix ctm = child_matrix;
#if !SUPPORT_FRACTIONAL_TRANSLATION
                //C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
                //ORIGINAL LINE: ctm = RasterCache::GetIntegralTransCTM(ctm);
                ctm = RasterCache.GetIntegralTransCTM(ctm);
#endif
                context.raster_cache.Prepare(context, child, ctm);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Paint checkbox
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintSelectionElement(SKPaintSurfaceEventArgs e)
        {
            if (_checkMarkSvg == null && string.IsNullOrEmpty(CheckMarkIconAssemblyName) == false && string.IsNullOrEmpty(CheckMarkIconResourceKey) == false)
            {
                _checkMarkSvg = SvgImage.GetSvgImage(CheckMarkIconAssemblyName, CheckMarkIconResourceKey);
            }

            Rectangle checkBoxAvailableLocation = new Rectangle();
            Rectangle availableSpace            = new Rectangle(EllipseDiameter, EllipseDiameter, Width, Height - Padding.VerticalThickness);

            if (CheckBoxLocation == HorizontalLocations.Left)
            {
                checkBoxAvailableLocation = availableSpace;
            }
            else
            {
                checkBoxAvailableLocation = new Rectangle(availableSpace.Width - CheckBoxWidthRequest - CheckBoxMargin.HorizontalThickness + EllipseDiameter, EllipseDiameter, availableSpace.Width, availableSpace.Height);
            }

            Rectangle checkBoxActualLocation = CheckBoxActualLocation(checkBoxAvailableLocation);

            float skCheckBoxBorderThickness = (float)CheckBoxBorderThickness * DeviceScale;
            float skCheckBoxX      = (float)checkBoxActualLocation.X * DeviceScale;
            float skCheckBoxY      = (float)checkBoxActualLocation.Y * DeviceScale;
            float skCheckBoxWidth  = (float)CheckBoxWidthRequest * DeviceScale;
            float skCheckBoxHeight = (float)CheckBoxHeightRequest * DeviceScale;
            float skCornerRadius   = (float)CheckBoxCornerRadius * DeviceScale;

            SKMatrix checkMarkMatrix   = new SKMatrix();
            SKPoint  checkMarkPosition = new SKPoint();

            Size checkMarkIconSize = new Size(CheckBoxWidthRequest - CheckMarkIconMargin.HorizontalThickness, CheckBoxHeightRequest - CheckMarkIconMargin.VerticalThickness);

            float scale = SvgImage.CalculateScale(_checkMarkSvg.Picture.CullRect.Size, checkMarkIconSize.Width, checkMarkIconSize.Height);

            Size actualCheckMarkIconSize = new Size(_checkMarkSvg.Picture.CullRect.Width * scale, _checkMarkSvg.Picture.CullRect.Height * scale);

            scale = scale * DeviceScale;

            checkMarkPosition.X = (float)skCheckBoxX + (float)((CheckBoxWidthRequest - actualCheckMarkIconSize.Width) / 2) * DeviceScale;
            checkMarkPosition.Y = (float)skCheckBoxY + (float)((CheckBoxHeightRequest - actualCheckMarkIconSize.Height) / 2) * DeviceScale;
            checkMarkMatrix.SetScaleTranslate(scale, scale, checkMarkPosition.X, checkMarkPosition.Y);

            SKRect checkBoxPaintRect = new SKRect(skCheckBoxX + skCheckBoxBorderThickness / 2,
                                                  skCheckBoxY + skCheckBoxBorderThickness / 2,
                                                  skCheckBoxX + skCheckBoxWidth - skCheckBoxBorderThickness / 2,
                                                  skCheckBoxY + skCheckBoxHeight - skCheckBoxBorderThickness / 2);

            if (EllipseDiameter > 0 && _toggledAnimationProcess > 0 && _toggledAnimationProcess < 1 && IsEllipseAnimationEnabled)
            {
                SKPaint ellipsePaint = new SKPaint()
                {
                    IsAntialias = true,
                    Style       = SKPaintStyle.Fill,
                };

                if (_toggledAnimationProcess <= 0.5)
                {
                    ellipsePaint.Color = EllipseColor.MultiplyAlpha(_toggledAnimationProcessWithoutEasing * 2).ToSKColor();
                }
                else
                {
                    ellipsePaint.Color = EllipseColor.MultiplyAlpha(1 - (_toggledAnimationProcessWithoutEasing - 0.5) * 2).ToSKColor();
                }

                e.Surface.Canvas.DrawCircle(new SKPoint(checkBoxPaintRect.MidX, checkBoxPaintRect.MidY), (float)(EllipseDiameter / 2) * DeviceScale, ellipsePaint);
            }

            Color backgroundColor = Color.Transparent;

            if (CheckBoxBackgroundColor != null && CheckBoxBackgroundColor != Color.Transparent && ToggledCheckBoxBackgroundColor != null && ToggledCheckBoxBackgroundColor != Color.Transparent)
            {
                backgroundColor = AnimationUtils.ColorTransform(_toggledAnimationProcess, CheckBoxBackgroundColor, ToggledCheckBoxBackgroundColor);
            }
            else if ((CheckBoxBackgroundColor == null || CheckBoxBackgroundColor == Color.Transparent) && ToggledCheckBoxBackgroundColor != null && ToggledCheckBoxBackgroundColor != Color.Transparent)
            {
                backgroundColor = ToggledCheckBoxBackgroundColor;
            }
            else
            {
                backgroundColor = CheckBoxBackgroundColor;
            }

            SKPaint checkBoxBackgroundPaint = new SKPaint
            {
                Style       = SKPaintStyle.Fill,
                IsAntialias = true,
                Color       = backgroundColor.ToSKColor(),
            };

            SKRect rect = new SKRect(
                skCheckBoxX + skCheckBoxBorderThickness,
                skCheckBoxY + skCheckBoxBorderThickness,
                skCheckBoxX + skCheckBoxWidth - skCheckBoxBorderThickness,
                skCheckBoxY + skCheckBoxHeight - skCheckBoxBorderThickness);

            e.Surface.Canvas.Save();

            SKRect r = SKRect.Create(rect.Left, rect.Top, rect.Width, rect.Height);

            if (_toggledAnimationProcess <= 0.75)
            {
                float v = (float)(_toggledAnimationProcess * (1 / 0.75));
                r.Inflate(-rect.Width * v / 2, -rect.Height * v / 2);
                e.Surface.Canvas.ClipRect(r, SKClipOperation.Difference);
            }

            e.Surface.Canvas.DrawRoundRect(checkBoxPaintRect, skCornerRadius, skCornerRadius, checkBoxBackgroundPaint);
            e.Surface.Canvas.Restore();

            SKPaint checkBoxBorderPaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                IsAntialias = true,
                StrokeWidth = skCheckBoxBorderThickness,
                Color       = AnimationUtils.ColorTransform(_toggledAnimationProcess, CheckBoxBorderColor, ToggledCheckBoxBorderColor).ToSKColor(),
            };

            e.Surface.Canvas.DrawRoundRect(checkBoxPaintRect, skCornerRadius, skCornerRadius, checkBoxBorderPaint);

            using (var paint = new SKPaint())
            {
                Color color = Color.Transparent;

                if (_toggledAnimationProcess > 0.75)
                {
                    float v = (float)((_toggledAnimationProcess - 0.75) * (1 / 0.25));
                    color = AnimationUtils.ColorTransform(v, CheckMarkIconColor, ToggledCheckMarkIconColor);
                }

                if (color != Color.Transparent)
                {
                    paint.ColorFilter = SKColorFilter.CreateBlendMode(color.ToSKColor(), SKBlendMode.SrcIn);
                    paint.Style       = SKPaintStyle.Fill;
                    paint.IsAntialias = true;

                    e.Surface.Canvas.DrawPicture(_checkMarkSvg.Picture, ref checkMarkMatrix, paint);
                }
            }
        }
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            base.OnPaintSurface(args);

            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear(SkiaHelper.backgroundColor);

            // Calculate rectangle for displaying bitmap
            var rect = SkiaHelper.CalculateRectangle(new SKRect(0, 0, info.Width, info.Height), bitmap);

            canvas.DrawBitmap(bitmap, rect.rect);

            // Calculate a matrix transform for displaying the cropping rectangle
            SKMatrix bitmapScaleMatrix = SKMatrix.MakeIdentity();

            bitmapScaleMatrix.SetScaleTranslate(rect.scaleX, rect.scaleX, rect.rect.Left, rect.rect.Top);

            // Display rectangle
            SKRect scaledCropRect = bitmapScaleMatrix.MapRect(croppingRect.Rect);


            using (SKPaint edgeStroke = new SKPaint())
            {
                edgeStroke.Style       = SKPaintStyle.Stroke;
                edgeStroke.Color       = SKColors.White;
                edgeStroke.StrokeWidth = 3;
                edgeStroke.IsAntialias = true;
                canvas.DrawRect(scaledCropRect, edgeStroke);
            }

            canvas.DrawSurrounding(rect.rect, scaledCropRect, SKColors.Gray.WithAlpha(190));

            // Display heavier corners
            using (SKPaint cornerStroke = new SKPaint())
                using (SKPath path = new SKPath())
                {
                    cornerStroke.Style       = SKPaintStyle.Stroke;
                    cornerStroke.Color       = SKColors.White;
                    cornerStroke.StrokeWidth = 7;

                    path.MoveTo(scaledCropRect.Left, scaledCropRect.Top + corner);
                    path.LineTo(scaledCropRect.Left, scaledCropRect.Top);
                    path.LineTo(scaledCropRect.Left + corner, scaledCropRect.Top);

                    path.MoveTo(scaledCropRect.Right - corner, scaledCropRect.Top);
                    path.LineTo(scaledCropRect.Right, scaledCropRect.Top);
                    path.LineTo(scaledCropRect.Right, scaledCropRect.Top + corner);

                    path.MoveTo(scaledCropRect.Right, scaledCropRect.Bottom - corner);
                    path.LineTo(scaledCropRect.Right, scaledCropRect.Bottom);
                    path.LineTo(scaledCropRect.Right - corner, scaledCropRect.Bottom);

                    path.MoveTo(scaledCropRect.Left + corner, scaledCropRect.Bottom);
                    path.LineTo(scaledCropRect.Left, scaledCropRect.Bottom);
                    path.LineTo(scaledCropRect.Left, scaledCropRect.Bottom - corner);

                    canvas.DrawPath(path, cornerStroke);
                }

            // Invert the transform for touch tracking
            bitmapScaleMatrix.TryInvert(out inverseBitmapMatrix);
        }