Ejemplo n.º 1
0
        private static void RenderFades(SKCanvas canvas, ColorLinesNG skiaView, bool right)
        {
            float width = skiaView.Width * wc;
            float xoffset, pxs, pxe;

            if (!right)
            {
                xoffset = skiaView.X - width;
                pxs     = xoffset;
                pxe     = skiaView.X;
            }
            else
            {
                xoffset = skiaView.X + skiaView.Width;
                pxs     = xoffset + width;
                pxe     = xoffset;
            }
            var fadeRect = SKRect.Create(xoffset, skiaView.Y, width, skiaView.Height);

            using (var shader = SKShader.CreateLinearGradient(
                       new SKPoint(pxs, fadeRect.MidY),
                       new SKPoint(pxe, fadeRect.MidY),
                       fadingGradient3,
                       fadingPos3,
                       SKShaderTileMode.Clamp
                       )) {
                fadePaint.Shader = shader;
                canvas.DrawRect(fadeRect, fadePaint);
            }
        }
Ejemplo n.º 2
0
 private static SKRect VirtualToSkiaCoords(float [] verticies, ColorLinesNG skiaView, float [] textureCoords = null)
 {
     float [] ret = new float[8];
     for (int i = 0; i < 8; i += 6)
     {
         float appVirtualWidth  = skiaView.Right - skiaView.Left,
               appVirtualHeight = skiaView.Top - skiaView.Bottom;
         int appSkiaWidth       = skiaView.Width,
             appSkiaHeight      = skiaView.Height;
         float xAbsVirtual      = (verticies[i] - skiaView.Left) / appVirtualWidth,
               yAbsVirtual      = (skiaView.Top - verticies[i + 1]) / appVirtualHeight;
         float xAbsSkia         = xAbsVirtual * appSkiaWidth,
               yAbsSkia         = yAbsVirtual * appSkiaHeight;
         ret[i]     = skiaView.X + xAbsSkia;
         ret[i + 1] = skiaView.Y + yAbsSkia;
     }
     //TODO: make proper clipping bounds
     if (textureCoords != null)
     {
         float cx = ret[0], cy = ret[1], w = ret[6] - cx, h = cy - ret[7];
         for (int i = 0; i < 8; i += 6)
         {
             ret[i]     = cx + (0.0f + textureCoords[i]) * w;
             ret[i + 1] = cy - (1.0f - textureCoords[i + 1]) * h;
         }
     }
     return(new SKRect(ret[0], ret[7], ret[6], ret[1]));
 }
Ejemplo n.º 3
0
        public void Render(SKImage [] images, ColorLinesNG skiaView, SKCanvas canvas)
        {
            var    destRect = CLReEntity.VirtualToSkiaCoords(this.Verticies, skiaView);
            SKRect?srcRect  = null;

//			if (this.textureCoords != null)
//				srcRect = CLReEntity.VirtualToSkiaCoords(this.Verticies, skiaView, this.textureCoords);

            if (this.Angle != 0.0f)
            {
                canvas.Save();
                canvas.RotateDegrees(this.Angle, destRect.MidX, destRect.MidY);
            }
            if (this.TextureId >= 0)
            {
                if (images[this.TextureId] == null)
                {
                    if (!loadingTextures.Contains(this.TextureId))
                    {
                        loadingTextures.Add(this.TextureId);
                        Task.Run(async() => {
                            images[this.TextureId] = await skiaView.LoadTexture(this.TextureId);
//							loadingTextures.Remove(this.TextureId);
                        });
                    }
                    if (this.Angle != 0.0f)
                    {
                        canvas.Restore();
                    }
                    return;
                }
                if (this.Grayscale)
                {
                    CLReEntity.CanvasDrawImage(canvas, images[this.TextureId], destRect, srcRect, paintGrayscale);
                }
                else if (this.Fill != null)
                {
                    using (texturePaint.ColorFilter = SKColorFilter.CreateBlendMode(CLReEntity.ColorToSKColor((Color)this.Fill), SKBlendMode.Modulate)) {
                        CLReEntity.CanvasDrawImage(canvas, images[this.TextureId], destRect, srcRect, texturePaint);
                    }
                }
                else
                {
                    CLReEntity.CanvasDrawImage(canvas, images[this.TextureId], destRect);
                }
            }
            else
            {
                rectPaint.Color = CLReEntity.ColorToSKColor((Color)this.Fill);
                canvas.DrawRect(destRect, rectPaint);
            }
            if (this.Angle != 0.0f)
            {
                canvas.Restore();
            }
        }
Ejemplo n.º 4
0
        private static void RenderCuts(SKCanvas canvas, ColorLinesNG skiaView)
        {
            float x       = skiaView.X - skiaView.Width * wc;
            float midy    = skiaView.Y + skiaView.Height * 0.5f;
            float y       = midy - skiaView.Width * (0.5f + wc);
            float width   = skiaView.X + skiaView.Width * (1.0f + wc) - x;
            float height  = skiaView.Y - y;
            var   topRect = SKRect.Create(x, y, width, height);

            y = skiaView.Y + skiaView.Height;
            var bottomRect = SKRect.Create(x, y, width, height);

            canvas.DrawRect(topRect, cutPaint);
            canvas.DrawRect(bottomRect, cutPaint);
        }
Ejemplo n.º 5
0
        public void Render(ColorLinesNG skiaView, SKCanvas canvas)
        {
            CLReEntity r = rentities;
            int        renderSpecialBgTexture = 0;

            for (; r != null; r = r.Next)
            {
                r.Render(this.images, skiaView, canvas);
                if (Device.Idiom != TargetIdiom.Desktop ||
                    renderSpecialBgTexture != 0 ||
                    this.specialBgTextureIds == null ||
                    this.specialBgTextureIds.Length < 2)
                {
                    continue;
                }
                if (r.TextureId == this.specialBgTextureIds[0])
                {
                    renderSpecialBgTexture = 1;
                }
                else if (r.TextureId == this.specialBgTextureIds[1])
                {
                    renderSpecialBgTexture = 2;
                }
            }
            if (renderSpecialBgTexture == 1)
            {
                CLReQueue.RenderFadingCircle(canvas, skiaView);
            }
            else if (renderSpecialBgTexture == 2)
            {
                CLReQueue.RenderFades(canvas, skiaView, false);
                CLReQueue.RenderFades(canvas, skiaView, true);
                CLReQueue.RenderFadingCircle(canvas, skiaView);
            }
            CLReViewEntity v = ventities;

            for (; v != null; v = v.Next)
            {
                v.Render(this.mainLayout, skiaView);
            }
            CLReViewEntity vre = ventitiesToRelease;

            for (; vre != null; vre = vre.Next)
            {
                vre.Release(this.mainLayout);
            }
        }
Ejemplo n.º 6
0
 private void RecountCoordinates(RelativeLayout mainLayout, ColorLinesNG skiaView)
 {
     appSkiaWidth    = skiaView.Right - skiaView.Left;
     appSkiaHeight   = skiaView.Top - skiaView.Bottom;
     appNativeWidth  = mainLayout.Width;
     appNativeHeight = mainLayout.Height;
     xAbsSkia        = (this.x - skiaView.Left) / appSkiaWidth;
     yAbsSkia        = (skiaView.Top - this.y) / appSkiaHeight;
     xAbsNative      = xAbsSkia * appNativeWidth;
     yAbsNative      = yAbsSkia * appNativeHeight;
     x2AbsSkia       = ((this.x + this.width) - skiaView.Left) / appSkiaWidth;
     y2AbsSkia       = (skiaView.Top - (this.y - this.height)) / appSkiaHeight;
     x2AbsNative     = x2AbsSkia * appNativeWidth;
     y2AbsNative     = y2AbsSkia * appNativeHeight;
     widthAbsNative  = x2AbsNative - xAbsNative;
     heightAbsNative = y2AbsNative - yAbsNative;
 }
Ejemplo n.º 7
0
        private static void RenderFadingCircle(SKCanvas canvas, ColorLinesNG skiaView)
        {
            float midx     = skiaView.X + skiaView.Width * 0.5f;
            float midy     = skiaView.Y + skiaView.Height * 0.5f;
            float x        = skiaView.X - skiaView.Width * wc;
            float y        = midy - skiaView.Width * (0.5f + wc);
            float width    = skiaView.X + skiaView.Width * (1.0f + wc) - x;
            float height   = midy + skiaView.Width * (1.0f + wc) - y;
            var   fadeRect = SKRect.Create(x, y, width, height);

            using (var shader = SKShader.CreateRadialGradient(
                       new SKPoint(midx, midy),
                       width * 0.5f,
                       fadingGradient2,
                       fadingPos2,
                       SKShaderTileMode.Clamp
                       )) {
                fadePaint.Shader = shader;
                canvas.DrawRect(fadeRect, fadePaint);
            }
        }
Ejemplo n.º 8
0
        public void Render(RelativeLayout mainLayout, ColorLinesNG skiaView)
        {
            if (Device.Idiom != TargetIdiom.Desktop)
            {
                this.RecountCoordinates(mainLayout, skiaView);
            }
            Device.BeginInvokeOnMainThread(() => {
                mainLayout.Children.Add(
                    this.view,
                    Constraint.RelativeToParent(parent => {
                    if (Device.Idiom == TargetIdiom.Desktop)
                    {
                        this.RecountCoordinates(mainLayout, skiaView);
                    }
                    double left = 0.0;
                    if (this.view is ICLForms)
                    {
                        left  = (this.view as ICLForms).Padding.Left;
                        left += (this.view as ICLForms).RelativePadding.Left * heightAbsNative;
                    }
                    return(xAbsNative + left);
                }),
                    Constraint.RelativeToParent(parent => {
                    if (Device.Idiom == TargetIdiom.Desktop)
                    {
                        this.RecountCoordinates(mainLayout, skiaView);
                    }
                    double top = 0.0;
                    if (this.view is ICLForms)
                    {
                        top  = (this.view as ICLForms).Padding.Top;
                        top += (this.view as ICLForms).RelativePadding.Top * heightAbsNative;
                    }
                    return(yAbsNative + top);
                }),
                    Constraint.RelativeToParent(parent => {
                    if (Device.Idiom == TargetIdiom.Desktop)
                    {
                        this.RecountCoordinates(mainLayout, skiaView);
                    }
                    double left = 0.0, right = 0.0;
                    if (this.view is ICLForms)
                    {
                        left   = (this.view as ICLForms).Padding.Left;
                        left  += (this.view as ICLForms).RelativePadding.Left * heightAbsNative;
                        right  = (this.view as ICLForms).Padding.Right;
                        right += (this.view as ICLForms).RelativePadding.Right * heightAbsNative;
                    }
                    return(widthAbsNative - (left + right));
                }),
                    Constraint.RelativeToParent(parent => {
                    if (Device.Idiom == TargetIdiom.Desktop)
                    {
                        this.RecountCoordinates(mainLayout, skiaView);
                    }
                    double bottom = 0.0, top = 0.0;
                    if (this.view is ICLForms)
                    {
                        bottom  = (this.view as ICLForms).Padding.Bottom;
                        bottom += (this.view as ICLForms).RelativePadding.Bottom * heightAbsNative;
                        top     = (this.view as ICLForms).Padding.Top;
                        top    += (this.view as ICLForms).RelativePadding.Top * heightAbsNative;
                    }
                    return(heightAbsNative - (bottom + top));
                })
                    );
            });

/*			if (this.view is CLFormsEntry) {
 *                              Task.Run(async () => {
 *                                      await Task.Delay(500);
 *                                      Device.BeginInvokeOnMainThread(() => {
 *                                              if (this.view != null && !this.view.IsFocused) {
 *                                                      (this.view as CLFormsEntry).Focus();
 *                                              }
 *                                      });
 *                              });
 *                      }*/
        }