Exemplo n.º 1
0
        public PathShape ToFillPathShape(IToolContext context, IBaseShape shape)
        {
            using (var geometry = ToPath(context, shape))
            {
                if (geometry != null)
                {
                    var style = context.DocumentContainer?.StyleLibrary?.Get(shape.StyleId);
                    if (style == null)
                    {
                        style = context.DocumentContainer?.StyleLibrary?.CurrentItem;
                    }

                    var path = SkiaHelper.ToFillPath(context, style, geometry);
                    if (path != null)
                    {
                        var union = SkiaHelper.Op(SKPathOp.Union, new[] { path, path });
                        if (union != null && !union.IsEmpty)
                        {
                            return(SkiaHelper.ToPathShape(context, union, context.DocumentContainer?.StyleLibrary?.CurrentItem, context?.DocumentContainer?.PointTemplate));
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public void Import(IToolContext context, string path, IContainerView containerView)
        {
            try
            {
                var picture = SkiaHelper.ToSKPicture(path);
                if (picture != null)
                {
                    var image = new ImageShape()
                    {
                        Points      = new ObservableCollection <IPointShape>(),
                        StartPoint  = new PointShape(0.0, 0.0, context?.DocumentContainer?.PointTemplate),
                        Point       = new PointShape(picture.CullRect.Width, picture.CullRect.Height, context?.DocumentContainer?.PointTemplate),
                        Path        = path,
                        StretchMode = StretchMode.Center,
                        Text        = new Text(),
                        StyleId     = context.DocumentContainer?.StyleLibrary?.CurrentItem?.Title,
                    };

                    image.StartPoint.Owner = image;
                    image.Point.Owner      = image;

                    picture.Dispose();

                    context.DocumentContainer?.ContainerView?.CurrentContainer.Shapes.Add(image);
                    context.DocumentContainer?.ContainerView?.InputService?.Redraw?.Invoke();
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.Message);
                Log.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 3
0
        private IList <SKPath> ToPaths(IToolContext context, IList <IBaseShape> shapes)
        {
            if (shapes == null || shapes.Count <= 0)
            {
                return(null);
            }

            var paths = new List <SKPath>();

            for (int i = 0; i < shapes.Count; i++)
            {
                var fillType = SKPathFillType.Winding;
                if (shapes[i] is PathShape pathShape)
                {
                    fillType = SkiaHelper.ToSKPathFillType(pathShape.FillType);
                }
                var path = new SKPath()
                {
                    FillType = fillType
                };
                var result = SkiaHelper.AddShape(context, shapes[i], 0.0, 0.0, path);
                if (result == true && path.IsEmpty == false)
                {
                    paths.Add(path);
                }
                else
                {
                    path.Dispose();
                }
            }

            return(paths);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 设置位图矩阵
        /// </summary>
        private void SetMainBitmapMatrix()
        {
            //计算矩形范围
            var rect = SkiaHelper.CalculateRectangle(SkiaHelper.CalculateRectangle(rectInfo, outImageWidht, outImageHeight).rect, mainBitmap.Bitmap.Width, mainBitmap.Bitmap.Height, config.Aspect);

            mainBitmap.Matrix = new SKMatrix(rect.scaleX, 0, rectInfo.MidX - rect.rect.Width / 2, 0, rect.scaleY, rectInfo.MidY - rect.rect.Height / 2, 0, 0, 1);
        }
Exemplo n.º 5
0
        private SKPath ToPath(IToolContext context, IBaseShape shape)
        {
            var fillType = SKPathFillType.Winding;

            if (shape is PathShape pathShape)
            {
                fillType = SkiaHelper.ToSKPathFillType(pathShape.FillType);
            }

            var geometry = new SKPath()
            {
                FillType = fillType
            };

            if (SkiaHelper.AddShape(context, shape, 0.0, 0.0, geometry) == true)
            {
                return(geometry);
            }
            else
            {
                geometry.Dispose();
            }

            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Any initialization steps that can be done in the background.
        /// </summary>
        public override void Initialize()
        {
            // init des location services.
            typeof(LocationService).Assembly.CreatableTypes()
            .EndingWith("Service")
            .AsInterfaces()
            .RegisterAsLazySingleton();

            // static registration => same instance
            Mvx.IoCProvider.RegisterSingleton(Plugin.Settings.CrossSettings.Current);
            Mvx.IoCProvider.RegisterSingleton <ITcxActivityService>(() => new TcxActivityService());
            Mvx.IoCProvider.RegisterSingleton <IDbActivityService>(() => new DbActivityService());
            Mvx.IoCProvider.RegisterSingleton <DatabaseContext>(() => new DatabaseContext());
            var context = Mvx.IoCProvider.Resolve <DatabaseContext>();

            Mvx.IoCProvider.RegisterSingleton <IRideService>(() => new RideService(context));

            // dynamic registration => new service on resolving
            Mvx.IoCProvider.RegisterType <ICountdownService>(() => new CountdownService());

            this.RegisterAppStart <ViewModels.MainPageViewModel>();

            SkiaHelper.Initialize((float)DeviceDisplay.MainDisplayInfo.Density);

            base.Initialize();
        }
Exemplo n.º 7
0
        public PathShape ToFillPathShape(IToolContext context, IBaseShape shape)
        {
            using (var geometry = ToPath(context, shape))
            {
                if (geometry != null)
                {
                    var style = context.DocumentContainer?.StyleLibrary?.Get(shape.StyleId);
                    if (style == null)
                    {
                        style = context.DocumentContainer?.StyleLibrary?.CurrentItem;
                    }

                    using (var disposable = new CompositeDisposable())
                    {
                        var path = SkiaHelper.ToFillPath(context, style.FillPaint, shape.Effects, geometry, disposable.Disposables);
                        if (path != null)
                        {
                            disposable.Disposables.Add(path);
                            var union = SkiaHelper.Op(SKPathOp.Union, new[] { path, path });
                            if (union != null && !union.IsEmpty)
                            {
                                disposable.Disposables.Add(union);
                                return(SkiaHelper.ToPathShape(context, union, context.DocumentContainer?.StyleLibrary?.CurrentItem, context?.DocumentContainer?.PointTemplate));
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 8
0
        public AMButton()
        {
            timer          = new Timer();
            timer.Interval = 10;
            timer.Tick    += (object sender, EventArgs e) =>
            {
                alpha += 10;
                color  = Color.FromArgb(alpha, HighlightColor);

                if (alpha > 100)
                {
                    timer.Stop();
                }

                Invalidate();
            };

            this.FlatStyle = FlatStyle.Flat;
            this.FlatAppearance.BorderSize  = 1;
            this.FlatAppearance.BorderColor = Color.LightGray;

            SKHelper      = new SkiaHelper();
            SKHelper.Size = new RawSize
            {
                Width  = this.Width,
                Height = this.Height
            };
            SKHelper.SwapChain();
        }
Exemplo n.º 9
0
        public PathShape Op(IToolContext context, PathOp op, ICollection <IBaseShape> selected)
        {
            var path   = default(PathShape);
            var shapes = GetShapes(selected);

            if (shapes != null && shapes.Count > 0)
            {
                var paths = ToPaths(context, shapes);
                if (paths != null && paths.Count > 0)
                {
                    var result = SkiaHelper.Op(SkiaHelper.ToSKPathOp(op), paths);
                    if (result != null)
                    {
                        if (!result.IsEmpty)
                        {
                            var style = context.DocumentContainer?.StyleLibrary?.Get(shapes[0].StyleId);
                            if (style == null)
                            {
                                style = context.DocumentContainer?.StyleLibrary?.CurrentItem;
                            }
                            path = SkiaHelper.ToPathShape(context, result, style, context?.DocumentContainer?.PointTemplate);
                        }
                        result.Dispose();
                    }

                    for (int i = 0; i < paths.Count; i++)
                    {
                        paths[i].Dispose();
                    }
                }
            }
            return(path);
        }
        public MainPage()
        {
            InitializeComponent();

            // - - -  - - -

            MediaPlayer.Current.Playlist.RepeatMode  = RepeatMode.Off;;
            MediaPlayer.Current.Playlist.ShuffleMode = ShuffleMode.Off;

            // Hook into events
            MediaPlayer.Current.StateChanged    += Current_StateChanged;
            MediaPlayer.Current.PositionChanged += Current_PositionChanged;

            MediaPlayer.Current.BufferingChanged += Current_BufferingChanged;

            MediaPlayer.Current.MediaItemFinished += Current_MediaItemFinished;
            MediaPlayer.Current.MediaItemChanged  += Current_MediaItemChanged;


            listViewPlaylist.BindingContext = MediaPlayer.Current;
            listViewPlaylist.ItemsSource    = MediaPlayer.Current.Playlist;

            listViewPlaylist.SetBinding(ListView.SelectedItemProperty, new Binding("Current", BindingMode.TwoWay, source: MediaPlayer.Current.Playlist));

            // - - -  - - -

            #region FontIcon stuff

            switch (Device.RuntimePlatform)
            {
            case Device.Android:
            case Device.UWP:
                btnPlayPrevious.Text        = "";
                btnPlayPrevious.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Backward, 64);

                btnStepBackward.Text        = "";
                btnStepBackward.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Previous, 64);

                btnPlayPause.Text        = "";
                btnPlayPause.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Play_01, 64);

                btnStepForward.Text        = "";
                btnStepForward.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Next, 64);

                btnPlayNext.Text        = "";
                btnPlayNext.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Fast_Forward, 64);

                btnStop.Text        = "";
                btnStop.ImageSource = SkiaHelper.SkiaFontIcon(ZPF.Fonts.MPF.Media_Stop, 64);
                break;

            case Device.WPF:
            default:
                break;
            }
            ;

            #endregion
        }
Exemplo n.º 11
0
        private void AddBitmapToCanvas(TouchManipulationBitmap bitmap)
        {
            var   rectImage   = SkiaHelper.CalculateRectangle(rectInfo, outImageWidht, outImageHeight).rect;
            float scale       = 0.25f;
            var   rectSticker = new SKRect(rectImage.Left + rectImage.Width * scale, rectImage.Top + rectImage.Height * scale, rectImage.Right - rectImage.Width * scale, rectImage.Bottom - rectImage.Height * scale);
            var   rect        = SkiaHelper.CalculateRectangle(rectSticker, bitmap.Bitmap.Width, bitmap.Bitmap.Height);

            bitmap.Matrix = new SKMatrix(rect.scaleX, 0, rectInfo.MidX - rect.rect.Width / 2, 0, rect.scaleY, rectInfo.MidY - rect.rect.Height / 2, 0, 0, 1);
            bitmapCollection.Add(bitmap);
        }
Exemplo n.º 12
0
 public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy)
 {
     using (var renderer = new SkiaShapeRenderer(_context, _view.SelectionState))
         using (var background = SkiaHelper.ToSKPaintBrush(_view.PrintBackground, false))
         {
             var canvas = context as SKCanvas;
             canvas.DrawRect(SkiaHelper.ToSKRect(dx, dy, _view.Width + dx, _view.Height + dy), background);
             _view.CurrentContainer.Draw(canvas, renderer, dx, dy, zx, null, null);
         }
 }
Exemplo n.º 13
0
        public void DrawConic(object dc, ConicShape conic, string styleId, double dx, double dy, double scale)
        {
            var geometry = new SKPath()
            {
                FillType = SKPathFillType.Winding
            };

            SkiaHelper.AddConic(null, conic, dx, dy, geometry);
            _rootNodes[_currentRootNode].Children.Add(new ChildNode(conic, styleId, dx, dy, scale, geometry));
        }
Exemplo n.º 14
0
        public void DrawRectangle(object dc, RectangleShape rectangle, string styleId, double dx, double dy, double scale)
        {
            var geometry = new SKPath()
            {
                FillType = SKPathFillType.Winding
            };

            SkiaHelper.AddRect(null, rectangle, dx, dy, geometry);
            _rootNodes[_currentRootNode].Children.Add(new ChildNode(rectangle, styleId, dx, dy, scale, geometry));
        }
Exemplo n.º 15
0
        public void DrawQuadraticBezier(object dc, QuadraticBezierShape quadraticBezier, string styleId, double dx, double dy, double scale)
        {
            var geometry = new SKPath()
            {
                FillType = SKPathFillType.Winding
            };

            SkiaHelper.AddQuad(null, quadraticBezier, dx, dy, geometry);
            _rootNodes[_currentRootNode].Children.Add(new ChildNode(quadraticBezier, styleId, dx, dy, scale, geometry));
        }
Exemplo n.º 16
0
        public void DrawText(object dc, TextShape text, string styleId, double dx, double dy, double scale)
        {
            var geometry = new SKPath()
            {
                FillType = SKPathFillType.Winding
            };

            SkiaHelper.AddText(null, text, dx, dy, geometry);
            _rootNodes[_currentRootNode].Children.Add(new ChildNode(text, styleId, dx, dy, scale, geometry));
        }
Exemplo n.º 17
0
        public void DrawEllipse(object dc, EllipseShape ellipse, string styleId, double dx, double dy, double scale)
        {
            var geometry = new SKPath()
            {
                FillType = SKPathFillType.Winding
            };

            SkiaHelper.AddOval(null, ellipse, dx, dy, geometry);
            _rootNodes[_currentRootNode].Children.Add(new ChildNode(ellipse, styleId, dx, dy, scale, geometry));
        }
Exemplo n.º 18
0
        protected override async void OnInitialized()
        {
            Xamarin.Forms.Internals.Log.Listeners.Add(new DelegateLogListener((arg1, arg2) => Console.WriteLine($"{arg1}: {arg2}")));

            InitializeComponent();

            SkiaHelper.Initialize((float)DeviceDisplay.MainDisplayInfo.Density);

            await NavigationService.NavigateAsync("NavigationPage/ActivityHeaderPage");
        }
Exemplo n.º 19
0
        public void DrawPath(object dc, PathShape path, string styleId, double dx, double dy, double scale)
        {
            var geometry = new SKPath()
            {
                FillType = SkiaHelper.ToSKPathFillType(path.FillType)
            };

            SkiaHelper.AddPath(null, path, dx, dy, geometry);
            _rootNodes[_currentRootNode].Children.Add(new ChildNode(path, styleId, dx, dy, scale, geometry));
        }
Exemplo n.º 20
0
        public string ToSvgPathData(IToolContext context, ICollection <IBaseShape> selected)
        {
            var sb = new StringBuilder();

            foreach (var shape in selected)
            {
                SkiaHelper.ToSvgPathData(context, shape, sb);
            }

            return(sb.ToString());
        }
Exemplo n.º 21
0
 public PathShape ToPathShape(IToolContext context, string svgPathData)
 {
     if (!string.IsNullOrWhiteSpace(svgPathData))
     {
         using (var path = SkiaHelper.ToPath(svgPathData))
         {
             return(SkiaHelper.ToPathShape(context, path, context.DocumentContainer?.StyleLibrary?.CurrentItem, context?.DocumentContainer?.PointTemplate));
         }
     }
     return(null);
 }
Exemplo n.º 22
0
        public override void Draw(SKCanvas canvas, SKPaint paint)
        {
            float vx   = _p2.X - _p1.X;
            float vy   = _p2.Y - _p1.Y;
            float dist = (float)Math.Sqrt(vx * vx + vy * vy);

            vx /= dist;
            vy /= dist;

            DrawArrowhead(canvas, paint, _p2, vx, vy, SkiaHelper.ToPixel(_arrowLength));
        }
Exemplo n.º 23
0
 internal ImageEditorViewModel(SKBitmap bitmap, ImageEditorConfig config)
 {
     Config        = config;
     cropperCanvas = new ImageCropperCanvasView(bitmap, config.CropAspectRatio);
     mainCanvas    = new TouchManipulationCanvasView(config);
     mainCanvas.AddBitmapToCanvas(bitmap.Copy(), BitmapType.Main);
     mainCanvas.TextBitmapClicked += MainCanvas_TextBitmapClicked;
     mainCanvas.TrashEnabled      += MainCanvas_TrashVisebled;
     ColorCollect = SkiaHelper.GetColors();
     CropCollect  = CropItem.GetCropItems(config.CanChangeCropAspectRatio);
     Message      = config?.LoadingText;
 }
 internal ImageEditorViewModel(SKBitmap bitmap, ImageEditorConfig config)
 {
     Config        = config;
     cropperCanvas = new ImageCropperCanvasView(bitmap, config.CropAspectRatio);
     mainCanvas    = new TouchManipulationCanvasView(config);
     mainCanvas.AddBitmapToCanvas(bitmap.Copy(), BitmapType.Main);
     mainCanvas.TextBitmapClicked += MainCanvas_TextBitmapClicked;
     mainCanvas.TrashEnabled      += MainCanvas_TrashVisebled;
     ColorCollect = SkiaHelper.GetColors();
     CropCollect  = CropItem.GetCropItems(config.CanChangeCropAspectRatio);
     Message      = config?.LoadingText;
     MessagingCenter.Subscribe <Xamarin.Forms.Application>(this, "BBDroidBackButton", (sender) => OnBackPressed());
 }
Exemplo n.º 25
0
        public string ToSvgPathData(IToolContext context, ICollection <IBaseShape> selected)
        {
            var sb     = new StringBuilder();
            var shapes = GetShapes(selected);

            if (shapes != null && shapes.Count > 0)
            {
                foreach (var shape in shapes)
                {
                    SkiaHelper.ToSvgPathData(context, shape, sb);
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 26
0
        private void GetSKPaintFill(IPaint fillPaint, IPaintEffects effects, double scale, out SKPaint brush)
        {
            if (fillPaint.IsTreeDirty() || !_paintCache.TryGetValue(fillPaint, out var brushCached))
            {
                fillPaint.Invalidate();
                brushCached            = SkiaHelper.ToSKPaint(fillPaint, effects, scale, _disposable.Disposables);
                _paintCache[fillPaint] = brushCached;
            }
            else
            {
                SkiaHelper.ToSKPaintUpdate(brushCached, fillPaint, effects, scale, _disposable.Disposables);
            }

            brush = brushCached;
        }
Exemplo n.º 27
0
        private void GetSKPaintFill(ArgbColor color, bool isAntialias, out SKPaint brush)
        {
            if (color.IsDirty == true || !_paintCache.TryGetValue(color, out var brushCached))
            {
                color.Invalidate();
                brushCached        = SkiaHelper.ToSKPaintBrush(color, isAntialias);
                _paintCache[color] = brushCached;
            }
            else
            {
                SkiaHelper.ToSKPaintBrushUpdate(brushCached, color);
            }

            brush = brushCached;
        }
Exemplo n.º 28
0
 public PathShape ToPathShape(IToolContext context, IBaseShape shape)
 {
     using (var geometry = ToPath(context, shape))
     {
         if (geometry != null)
         {
             var style = context.DocumentContainer?.StyleLibrary?.Get(shape.StyleId);
             if (style == null)
             {
                 style = context.DocumentContainer?.StyleLibrary?.CurrentItem;
             }
             return(SkiaHelper.ToPathShape(context, geometry, style, context?.DocumentContainer?.PointTemplate));
         }
     }
     return(null);
 }
Exemplo n.º 29
0
        public IActionResult GetAppendMark(string bucket, string name, string query)
        {
            string visitUrl = $"/{bucket}/{name}";
            var    item     = _bucketImageService.GetByVisitUrl(visitUrl);

            if (item == null)
            {
                return(NotFile());
            }

            string abPath = Path.Combine(_hostingEnvironment.ContentRootPath, item.IOPath);

            if (!System.IO.File.Exists(abPath))
            {
                return(NotFile());
            }

            string cut = null, resize = null;
            Stream stream = null;

            if (!String.IsNullOrEmpty(query))
            {
                var arr = query.Split(',');
                foreach (var q in arr)
                {
                    string temp = q.ToLower();
                    if (temp.StartsWith("m_"))
                    {
                        cut = temp;
                    }
                    if (temp.StartsWith("w_") || temp.StartsWith("h_"))
                    {
                        resize = temp;
                    }
                    if (temp.Equals("l_logo"))
                    {
                        stream = _markLogoService.GetStream();
                    }
                }
            }

            using (var img = SkiaHelper.MakeThumb(abPath, cut, resize, item.ExtName, stream))
            {
                return(File(img.ToArray(), $"image/{item.ExtName?.Substring(1)}"));
            }
        }
Exemplo n.º 30
0
        public MainForm()
        {
/*
 *          using (var g = this.CreateGraphics())
 *          {
 *              SizeF sngScaleFactor = new SizeF();
 *              if (g.DpiX > 96)
 *              {
 *                  sngScaleFactor.Width = g.DpiX / 96;
 *                  sngScaleFactor.Height = g.DpiY / 96;
 *              }
 *
 *              if (this.AutoScaleDimensions == this.CurrentAutoScaleDimensions)
 *              {
 *                  this.Scale(sngScaleFactor);
 *              }
 *          }
 */
            SKHelper = new SkiaHelper()
            {
                Size = new RawSize
                {
                    Width  = this.Width,
                    Height = this.Height
                },
                PostChain = new SkiaHelper.CanvasDelegate((SKCanvas Canvas) =>
                {
                    using (var paint = new SKPaint())
                        using (var shader = SKShader.CreateLinearGradient(
                                   new SKPoint(SKHelper.Size.Width - 200, 200),
                                   new SKPoint(SKHelper.Size.Width, 0),
                                   new SKColor[] { SKColors.Orange, SKColors.Orange, SKColors.Gold },
                                   null,
                                   SKShaderTileMode.Clamp))
                        {
                            paint.IsAntialias = true;
                            paint.Shader      = shader;
                            SKHelper.Skia_Canvas.DrawPaint(paint);
                        }
                })
            };
            InitializeComponent();
            DoubleBuffered = true;
            SKHelper.SwapChain();
        }