Ejemplo n.º 1
0
        private void _patternRender(ICanvasResourceCreator resourceCreator, CanvasDrawingSession drawingSession, CanvasGeometry geometry)
        {
            switch (base.Style.Transparency.Type)
            {
            case BrushType.LinearGradient:
            case BrushType.RadialGradient:
            case BrushType.EllipticalGradient:
            {
                ICanvasBrush canvasBrush = this.Style.Transparency.GetICanvasBrush(resourceCreator);

                using (drawingSession.CreateLayer(canvasBrush, geometry))
                {
                    this._render(resourceCreator, drawingSession, geometry);
                }
            }
            break;

            default:
                using (drawingSession.CreateLayer(1, geometry))
                {
                    this._render(resourceCreator, drawingSession, geometry);
                }
                break;
            }
        }
Ejemplo n.º 2
0
        public override ICanvasImage GetRender(ICanvasResourceCreator resourceCreator, Layerage layerage)
        {
            if (layerage.Children.Count == 0)
            {
                return(null);
            }

            ICanvasImage childImage = LayerBase.Render(resourceCreator, layerage);

            if (childImage is null)
            {
                return(null);
            }

            CanvasCommandList command = new CanvasCommandList(resourceCreator);

            using (CanvasDrawingSession drawingSession = command.CreateDrawingSession())
            {
                if (this.Transform.IsCrop)
                {
                    CanvasGeometry geometryCrop = this.Transform.CropTransformer.ToRectangle(resourceCreator);

                    using (drawingSession.CreateLayer(1, geometryCrop))
                    {
                        drawingSession.DrawImage(childImage);
                    }
                }
                else
                {
                    drawingSession.DrawImage(childImage);
                }
            }
            return(command);
        }
Ejemplo n.º 3
0
        internal CanvasActiveLayer CreateSession(CanvasDevice device, double width, double height, CanvasDrawingSession drawingSession)
        {
            _device         = device;
            _drawingSession = drawingSession;

            UpdateClip(width, height);

            return(_drawingSession.CreateLayer(1f, _currentClip));
        }
Ejemplo n.º 4
0
        private void DrawCoverItem(CanvasDrawingSession graphics, CoverFlowItem item)
        {
            var center = item.CurrentPosition;
            var width  = mItemWidth * item.CurrentScale;
            var height = mItemHeight * item.CurrentScale;

            using (graphics.CreateLayer((float)item.CurrentOpacity))
            {
                graphics.DrawImage(mProducts[item.Index], new Rect(center.X - width / 2, center.Y - height / 2, width, height));
            }
        }
Ejemplo n.º 5
0
        public void StartGroup(string id, float x, float y, float width, float height, bool clipContent)
        {
            if (clipContent)
            {
                _layers.Add(id, _activeLayerRect);

                if (_activeLayer != null)
                {
                    _activeLayer.Dispose();
                    _activeLayer     = null;
                    _activeLayerRect = Rect.Empty;
                }

                if (_session != null)
                {
                    _activeLayerRect = new Rect(x, y, width, height);
                    _activeLayer     = _session.CreateLayer(1.0f, _activeLayerRect);
                }
            }
        }
Ejemplo n.º 6
0
 internal virtual void setClip(ui.geom.Rectangle clip)
 {
     if (clip == null)
     {
         return;
     }
     if (clip.getWidth() <= 0)
     {
         // System.Diagnostics.Debug.WriteLine("aaaaaaaaaaaaaaaaaaaa width");
         clip.setWidth(1);
     }
     if (clip.getHeight() <= 0)
     {
         // System.Diagnostics.Debug.WriteLine("aaaaaaaaaaaaaaaaaaaa height");
         clip.setHeight(1);
     }
     layer = graphics.CreateLayer(1f, new Rect(
                                      clip.getX(),
                                      clip.getY(),
                                      clip.getWidth(),
                                      clip.getHeight()
                                      ));
 }
Ejemplo n.º 7
0
        public override void Draw(CanvasDrawingSession session)
        {
            var brush = brushes["grey"];

            using (session.CreateLayer(0.7f))
            {
                session.Antialiasing = CanvasAntialiasing.Antialiased;

                for (var x = 0.0f; x < size.Width; x += (float)cell.Width)
                {
                    session.DrawLine(new Vector2(x, 0.0f), new Vector2(x, (float)size.Height), brush, 1.0f);
                }

                for (var y = 0.0f; y < size.Height; y += (float)cell.Height)
                {
                    session.DrawLine(new Vector2(0.0f, y), new Vector2((float)size.Width, y), brush, 1.0f);
                }
            }
        }
Ejemplo n.º 8
0
        internal virtual void setClipShape(ui.geom.Shape clip)
        {
            removeClip();
            if (clip == null)
            {
                return;
            }
            com.codename1.ui.geom.Rectangle bounds = clip.getBounds();
            if (bounds.getWidth() <= 0 || bounds.getHeight() <= 0)
            {
                setClip(bounds);
                return;
            }

            CanvasPathBuilder nativeShape = SilverlightImplementation.instance.cn1ShapeToAndroidPath(clip);

            layer = graphics.CreateLayer(1f, CanvasGeometry.CreatePath(nativeShape));
        }
Ejemplo n.º 9
0
        public override void Draw(CanvasDrawingSession session)
        {
            /*var bitmap = bitmaps["terrain"];
             *
             * using (session.CreateLayer(1.0f))
             * {
             *  var rect = new Rect(new Point(), new Size(50.0d, 50.0d));
             *  session.DrawImage(bitmap, rect);
             * }*/

            //var brush = brushes["grey"];
            var rows    = map.GetLength(0);
            var columns = map.GetLength(1);

            using (session.CreateLayer(0.7f))
            {
                session.Antialiasing = CanvasAntialiasing.Antialiased;

                for (var column = 0; column < columns; column++)
                {
                    var x = column * 25.0f;

                    for (var row = 0; row < rows; row++)
                    {
                        if (0 <= map[row, column])
                        {
                            continue;
                        }

                        var y = row * 25.0f;

                        session.FillRectangle(new Rect(x, y, 25.0d, 25.0d), Colors.Aqua);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private void _render(ICanvasResourceCreator resourceCreator, CanvasDrawingSession drawingSession, CanvasGeometry geometry)
        {
            //Fill
            // Fill a geometry with style.
            if (this.Style.Fill.Type != BrushType.None)
            {
                ICanvasBrush canvasBrush = this.Style.Fill.GetICanvasBrush(resourceCreator);
                drawingSession.FillGeometry(geometry, canvasBrush);
            }

            //CanvasActiveLayer
            using (drawingSession.CreateLayer(1, geometry))
            {
                //Stroke
                // Draw a geometry with style
                if (this.Style.Stroke.Type != BrushType.None)
                {
                    if (this.Style.StrokeWidth != 0)
                    {
                        this.GetPatternRender(resourceCreator, drawingSession, geometry);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void DrawText(FormattedText formattedText, Point point, Rect?clipRect)
        {
            var text = formattedText.Text;

            var vector           = new System.Numerics.Vector2((float)point.X, (float)point.Y);
            var brush            = formattedText.Brush.ToWin2D(drawingSession);
            var canvasTextFormat = new CanvasTextFormat
            {
                FontSize   = formattedText.FontSize,
                FontWeight = formattedText.FontWeight.ToWin2D(),
                FontFamily = formattedText.FontName,
            };

            CanvasActiveLayer layer = null;

            if (clipRect != null)
            {
                layer = drawingSession.CreateLayer(new CanvasSolidColorBrush(drawingSession, Colors.Black.ToWin2D()), clipRect.Value.ToWin2D());
            }

            drawingSession.DrawText(text, vector, brush, canvasTextFormat);

            layer?.Dispose();
        }
Ejemplo n.º 12
0
        public override void Draw(CanvasDrawingSession session)
        {
            var size       = new Size(50.0d, 50.0d);
            var sourceRect = new Rect(0.0d, 0.0d, 25.0d, 25.0d);

            using (session.CreateLayer(1.0f))
            {
                using (var batch = session.CreateSpriteBatch(CanvasSpriteSortMode.Bitmap))
                {
                    for (var row = 0; row < 10; row++)
                    {
                        for (var column = 0; column < 10; column++)
                        {
                            var x = size.Width * column;
                            var y = size.Height * row;

                            batch.DrawFromSpriteSheet(bitmapBrush, new Rect(new Point(x, y), size), sourceRect);
                        }
                    }
                }
            }

            base.Draw(session);
        }
Ejemplo n.º 13
0
        private void SaveClip(byte alpha)
        {
            var currentLayer = _drawingSession.CreateLayer(alpha / 255f, _currentClip);

            _clipSaves.Push(new ClipSave(_currentClip, currentLayer));
        }
Ejemplo n.º 14
0
        private void GetGeometryRender(ICanvasResourceCreator resourceCreator, CanvasDrawingSession drawingSession, Layerage layerage)
        {
            CanvasGeometry geometry = this.CreateGeometry(resourceCreator);

            this.Geometry2 = geometry;

            if (this.Style.IsStrokeBehindFill == false)
            {
                // Fill
                // Fill a geometry with style.
                if (this.Style.Fill.Type != BrushType.None)
                {
                    ICanvasBrush canvasBrush = this.Style.Fill.GetICanvasBrush(resourceCreator);
                    drawingSession.FillGeometry(geometry, canvasBrush);
                }

                // CanvasActiveLayer
                if (layerage.Children.Count != 0)
                {
                    using (drawingSession.CreateLayer(1, geometry))
                    {
                        ICanvasImage childImage = LayerBase.Render(resourceCreator, layerage);

                        if ((childImage is null) == false)
                        {
                            drawingSession.DrawImage(childImage);
                        }
                    }
                }

                // Stroke
                // Draw a geometry with style.
                if (this.Style.Stroke.Type != BrushType.None)
                {
                    if (this.Style.StrokeWidth != 0)
                    {
                        ICanvasBrush      canvasBrush = this.Style.Stroke.GetICanvasBrush(resourceCreator);
                        float             strokeWidth = this.Style.StrokeWidth;
                        CanvasStrokeStyle strokeStyle = this.Style.StrokeStyle;
                        drawingSession.DrawGeometry(geometry, canvasBrush, strokeWidth, strokeStyle);
                    }
                }
            }
            else
            {
                // Stroke
                // Draw a geometry with style.
                if (this.Style.Stroke.Type != BrushType.None)
                {
                    if (this.Style.StrokeWidth != 0)
                    {
                        ICanvasBrush      canvasBrush = this.Style.Stroke.GetICanvasBrush(resourceCreator);
                        float             strokeWidth = this.Style.StrokeWidth;
                        CanvasStrokeStyle strokeStyle = this.Style.StrokeStyle;
                        drawingSession.DrawGeometry(geometry, canvasBrush, strokeWidth, strokeStyle);
                    }
                }

                // CanvasActiveLayer
                if (layerage.Children.Count != 0)
                {
                    using (drawingSession.CreateLayer(1, geometry))
                    {
                        ICanvasImage childImage = LayerBase.Render(resourceCreator, layerage);

                        if ((childImage is null) == false)
                        {
                            drawingSession.DrawImage(childImage);
                        }
                    }
                }

                // Fill
                // Fill a geometry with style.
                if (this.Style.Fill.Type != BrushType.None)
                {
                    ICanvasBrush canvasBrush = this.Style.Fill.GetICanvasBrush(resourceCreator);
                    drawingSession.FillGeometry(geometry, canvasBrush);
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets a specific rended-layer.
        /// </summary>
        /// <param name="resourceCreator"> The resource-creator. </param>
        /// <param name="layerage"> The layerage. </param>
        /// <returns> The rendered layer. </returns>
        public override ICanvasImage GetRender(ICanvasResourceCreator resourceCreator, Layerage layerage)
        {
            CanvasCommandList command = new CanvasCommandList(resourceCreator);

            using (CanvasDrawingSession drawingSession = command.CreateDrawingSession())
            {
                if (this.Transform.IsCrop == false)
                {
                    switch (base.Style.Transparency.Type)
                    {
                    case BrushType.LinearGradient:
                    case BrushType.RadialGradient:
                    case BrushType.EllipticalGradient:
                    {
                        Transformer    transformer  = base.Transform.Transformer;
                        CanvasGeometry geometryCrop = transformer.ToRectangle(resourceCreator);
                        ICanvasBrush   canvasBrush  = this.Style.Transparency.GetICanvasBrush(resourceCreator);

                        using (drawingSession.CreateLayer(canvasBrush, geometryCrop))
                        {
                            this.GetGeometryRender(resourceCreator, drawingSession, layerage);
                        }
                    }
                    break;

                    default:
                        this.GetGeometryRender(resourceCreator, drawingSession, layerage);
                        break;
                    }
                }
                else
                {
                    Transformer    cropTransformer = base.Transform.CropTransformer;
                    CanvasGeometry geometryCrop    = cropTransformer.ToRectangle(resourceCreator);

                    switch (base.Style.Transparency.Type)
                    {
                    case BrushType.LinearGradient:
                    case BrushType.RadialGradient:
                    case BrushType.EllipticalGradient:
                    {
                        ICanvasBrush canvasBrush = this.Style.Transparency.GetICanvasBrush(resourceCreator);

                        using (drawingSession.CreateLayer(canvasBrush, geometryCrop))
                        {
                            this.GetGeometryRender(resourceCreator, drawingSession, layerage);
                        }
                    }
                    break;

                    default:
                        using (drawingSession.CreateLayer(1, geometryCrop))
                        {
                            this.GetGeometryRender(resourceCreator, drawingSession, layerage);
                        }
                        break;
                    }
                }
            }
            return(command);
        }
Ejemplo n.º 16
0
        public void draw(float x, float y, float width, float height, CanvasDrawingSession canvas, CanvasControl view, float f5)
        {
            bool          z;
            int           i;
            float         f6;
            CanvasControl view2 = view;

            checkColors();
            if (view2 == null)
            {
                z = false;
            }
            else
            {
                z = parents.Count > 0 && view2 == parents[0];
            }
            //if (f2 <= f4)
            {
                long j = 0;
                if (z)
                {
                    long elapsedRealtime = Environment.TickCount;
                    long j2 = elapsedRealtime - lastUpdateTime;
                    lastUpdateTime = elapsedRealtime;
                    j = j2 > 20 ? 17 : j2;
                    float f7 = animateToAmplitude;
                    float f8 = amplitude;
                    if (f7 != f8)
                    {
                        float f9  = animateAmplitudeDiff;
                        float f10 = f8 + j * f9;
                        amplitude = f10;
                        if (f9 > 0.0f)
                        {
                            if (f10 > f7)
                            {
                                amplitude = f7;
                            }
                        }
                        else if (f10 < f7)
                        {
                            amplitude = f7;
                        }
                        //view.Invalidate();
                    }
                    float f11 = animateToAmplitude;
                    float f12 = amplitude2;
                    if (f11 != f12)
                    {
                        float f13 = animateAmplitudeDiff2;
                        float f14 = f12 + j * f13;
                        amplitude2 = f14;
                        if (f13 > 0.0f)
                        {
                            if (f14 > f11)
                            {
                                amplitude2 = f11;
                            }
                        }
                        else if (f14 < f11)
                        {
                            amplitude2 = f11;
                        }
                        //view.Invalidate();
                    }
                    if (previousState != null)
                    {
                        float f15 = progressToState + j / 250.0f;
                        progressToState = f15;
                        if (f15 > 1.0f)
                        {
                            progressToState = 1.0f;
                            previousState   = null;
                        }
                        //view.Invalidate();
                    }
                }
                long j3 = j;
                int  i2 = 0;
                while (i2 < 2)
                {
                    if (i2 == 0 && previousState == null)
                    {
                        i = i2;
                    }
                    else
                    {
                        if (i2 == 0)
                        {
                            f6 = 1.0f - progressToState;
                            if (z)
                            {
                                previousState.update((int)(height - y), (int)(width - x), j3, amplitude);
                            }
                            //this.paint.setShader(this.previousState.shader);
                            shader = previousState.shader;
                        }
                        else
                        {
                            WeavingState weavingState = currentState;
                            if (weavingState != null)
                            {
                                f6 = previousState != null ? progressToState : 1.0f;
                                if (z)
                                {
                                    weavingState.update((int)(height - y), (int)(width - x), j3, amplitude);
                                }
                                //this.paint.setShader(this.currentState.shader);
                                shader = currentState.shader;
                            }
                            else
                            {
                                return;
                            }
                        }
                        float f16 = f6;
                        lineBlobDrawable.minRadius  = 0.0f;
                        lineBlobDrawable.maxRadius  = 2.0f + 2.0f * amplitude;
                        lineBlobDrawable1.minRadius = 0.0f;
                        lineBlobDrawable1.maxRadius = 3.0f + 9.0f * amplitude;
                        lineBlobDrawable2.minRadius = 0.0f;
                        lineBlobDrawable2.maxRadius = 3.0f + 9.0f * amplitude;
                        lineBlobDrawable.update(amplitude, 0.3f);
                        lineBlobDrawable1.update(amplitude, 0.7f);
                        lineBlobDrawable2.update(amplitude, 0.7f);
                        if (i2 == 1)
                        {
                            paint.A = (byte)(255.0f * f16);
                        }
                        else
                        {
                            paint.A = 255;
                        }
                        i = i2;

                        if (target == null || target.Size.Width != width)
                        {
                            target = new CanvasRenderTarget(canvas, width, height);
                        }

                        using (var session = target.CreateDrawingSession())
                        {
                            session.Clear(Colors.Transparent);

                            lineBlobDrawable.Draw(x, y, width, height, session, paint, y, f5);
                            paint.A = (byte)(f16 * 76.0f);
                            float dp  = (float)6.0f * amplitude2;
                            float dp2 = (float)6.0f * amplitude2;
                            float f22 = x;
                            lineBlobDrawable1.Draw(f22, y - dp, width, height, session, paint, y, f5);
                            lineBlobDrawable2.Draw(f22, y - dp2, width, height, session, paint, y, f5);
                        }

                        using (var layer = canvas.CreateLayer(new CanvasImageBrush(canvas, target)))
                        {
                            canvas.FillRectangle(0, 0, width, height, shader);
                        }
                    }
                    i2 = i + 1;
                }
            }
        }
Ejemplo n.º 17
0
        private async void Map_MapTapped(int tileX, int tileY, int zoomLevel)
        {
            float canvasScale = 1f;
            float canvasSize  = 768;
            float lineScale   = 1f;

            //int zoomLevel = Math.Min(14, Math.Max(1, (int)sender.ZoomLevel));
            //var tileAddr = MapUtil.WorldToTilePos(args.Location.Position.Longitude, args.Location.Position.Latitude, zoomLevel);
            System.Diagnostics.Debug.WriteLine($"{tileX} x {tileY}");
            System.Diagnostics.Debug.WriteLine($"zoom: {zoomLevel}");
            {
                var reader = await db.GetTile((int)tileX, (int)tileY, zoomLevel);

                if (!reader.HasRows)
                {
                    textOutput.Text = DateTime.Now + ": No data";
                }
                var tile = VectorTile.Parse(reader);
                if (tile.tile_data_raw != null)
                {
                    PBF pbf = new PBF(tile.tile_data_raw);
                    currentTile = ProtoBuf.Serializer.Deserialize <Tile>(new MemoryStream(tile.tile_data_raw));

                    if (GeometryDecoder.CanvasTileId != tile.id)
                    {
                        GeometryDecoder.CanvasTileId = tile.id;

                        if (GeometryDecoder.offscreen == null)
                        {
                            CanvasDevice device = CanvasDevice.GetSharedDevice();
                            GeometryDecoder.offscreen = new CanvasRenderTarget(device, canvasSize, canvasSize, Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi *canvasScale);
                            //GeometryDecoder.offscreenText = new CanvasRenderTarget(device, canvasSize, canvasSize, Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi * canvasScale);
                        }


                        //Performance benchmark
                        Tile.Layer layer_buildings           = null;
                        Tile.Layer layer_landcover           = null;
                        Tile.Layer layer_transportation      = null;
                        Tile.Layer layer_transportation_name = null;
                        Tile.Layer layer_housenumber         = null;
                        Tile.Layer layer_poi = null;

                        if (currentTile.Layers.Any(l => l.Name == "building"))
                        {
                            layer_buildings = currentTile.Layers.Where(l => l.Name == "building").ToList()?.First();
                        }
                        if (currentTile.Layers.Any(l => l.Name == "landcover"))
                        {
                            layer_landcover = currentTile.Layers.Where(l => l.Name == "landcover").ToList()?.First();
                        }
                        if (currentTile.Layers.Any(l => l.Name == "transportation"))
                        {
                            layer_transportation = currentTile.Layers.Where(l => l.Name == "transportation").ToList()?.First();
                        }
                        if (currentTile.Layers.Any(l => l.Name == "transportation_name"))
                        {
                            layer_transportation_name = currentTile.Layers.Where(l => l.Name == "transportation_name").ToList()?.First();
                        }
                        if (currentTile.Layers.Any(l => l.Name == "housenumber"))
                        {
                            layer_housenumber = currentTile.Layers.Where(l => l.Name == "housenumber").ToList()?.First();
                        }
                        if (currentTile.Layers.Any(l => l.Name == "poi"))
                        {
                            layer_poi = currentTile.Layers.Where(l => l.Name == "poi").ToList()?.First();
                        }

                        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
                        stopwatch.Start();

                        Dictionary <string, Windows.UI.Color> landColors = new Dictionary <string, Windows.UI.Color>();
                        landColors.Add("grass", Windows.UI.Colors.LawnGreen);
                        landColors.Add("meadow", Windows.UI.Colors.Green);
                        landColors.Add("wood", Windows.UI.Colors.ForestGreen);
                        landColors.Add("forest", Windows.UI.Colors.DarkGreen);
                        landColors.Add("park", Windows.UI.Colors.LightGreen);
                        landColors.Add("village_green", Windows.UI.Colors.GreenYellow);
                        landColors.Add("wetland", Windows.UI.Colors.CornflowerBlue);
                        landColors.Add("recreation_ground", Windows.UI.Colors.LightYellow);
                        landColors.Add("allotments", Windows.UI.Colors.Red);

                        Dictionary <string, Tuple <Color, float, Color, float> > roadProperties = new Dictionary <string, Tuple <Color, float, Color, float> >();
                        roadProperties.Add("transit", new Tuple <Color, float, Color, float>(Colors.Black, 0.5f, Colors.Black, 0.5f));
                        roadProperties.Add("primary", new Tuple <Color, float, Color, float>(Colors.LightYellow, 3, Colors.SandyBrown, 4.5f));
                        roadProperties.Add("secondary", new Tuple <Color, float, Color, float>(Colors.LightYellow, 2, Colors.SandyBrown, 3f));
                        roadProperties.Add("tertiary", new Tuple <Color, float, Color, float>(Colors.LightYellow, 2, Colors.SandyBrown, 3f));
                        roadProperties.Add("minor", new Tuple <Color, float, Color, float>(Colors.WhiteSmoke, 1.8f, Colors.Gray, 2.5f));
                        roadProperties.Add("service", new Tuple <Color, float, Color, float>(Colors.WhiteSmoke, 1.8f, Colors.Gray, 2.5f));
                        roadProperties.Add("track", new Tuple <Color, float, Color, float>(Colors.LightGray, 1, Colors.Gray, 2));
                        roadProperties.Add("path", new Tuple <Color, float, Color, float>(Colors.LightGray, 1, Colors.Gray, 2));
                        roadProperties.Add("rail", new Tuple <Color, float, Color, float>(Colors.Gainsboro, 0.75f, Colors.DimGray, 1.4f));
                        roadProperties.Add("motorway", new Tuple <Color, float, Color, float>(Colors.Orange, 3, Colors.Red, 4.5f));
                        roadProperties.Add("trunk", new Tuple <Color, float, Color, float>(Colors.Orange, 3, Colors.Red, 4.5f));


                        GeometryDecoder.renderList = new CanvasCommandList(GeometryDecoder.offscreen);
                        GeometryDecoder.renderText = new CanvasCommandList(GeometryDecoder.offscreen);

                        //using (CanvasDrawingSession ds = GeometryDecoder.offscreen.CreateDrawingSession())
                        using (CanvasDrawingSession textDs = GeometryDecoder.renderText.CreateDrawingSession())
                            using (CanvasDrawingSession ds = GeometryDecoder.renderList.CreateDrawingSession())
                                using (CanvasActiveLayer activeLayer = ds.CreateLayer(1, new Rect(0, 0, canvasSize, canvasSize)))
                                    using (CanvasActiveLayer activeTextLayer = textDs.CreateLayer(1, new Rect(0, 0, canvasSize, canvasSize)))
                                    {
                                        ds.Antialiasing = CanvasAntialiasing.Antialiased;
                                        ds.Clear(Windows.UI.Colors.Snow);
                                        for (int it = 0; it < 1; it++)
                                        {
                                            layer_landcover?.Features.ForEach(f =>
                                            {
                                                var tags  = GeometryDecoder.GetTags(f, layer_landcover);
                                                var color = Colors.LightGreen;
                                                if (tags.ContainsKey("subclass"))
                                                {
                                                    color = landColors.ContainsKey(tags["subclass"].StringValue) ? landColors[tags["subclass"].StringValue] : Windows.UI.Colors.LightGreen;
                                                }
                                                GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, color, color);
                                            });

                                            layer_buildings?.Features.ForEach(f =>
                                            {
                                                var tags = GeometryDecoder.GetTags(f, layer_buildings);
                                                GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, Windows.UI.Colors.SandyBrown, Windows.UI.Colors.Brown);
                                            });


                                            List <string> tagsNames = new List <string>();
                                            var           names     = layer_transportation?.Features.ConvertAll <Tuple <string, string> >(f =>
                                            {
                                                var tags = GeometryDecoder.GetTags(f, layer_transportation);

                                                foreach (var t in tags)
                                                {
                                                    tagsNames.Add(t.Key);
                                                }
                                                return(new Tuple <string, string>(tags.ContainsKey("class") ? tags["class"].StringValue : "", tags.ContainsKey("subclass") ? tags["subclass"].StringValue : ""));
                                            }).ToList().Distinct().ToList();

                                            var distinctTagsNames = tagsNames.Distinct().ToList();

                                            Tuple <Color, float, Color, float> rc = new Tuple <Color, float, Color, float>(Colors.Pink, 2, Colors.DeepPink, 2);


                                            Dictionary <int, List <Tile.Feature> > transportationFeatures = new Dictionary <int, List <Tile.Feature> >();
                                            foreach (var f in layer_transportation.Features)
                                            {
                                                var tags  = GeometryDecoder.GetTags(f, layer_transportation);
                                                int layer = tags.ContainsKey("layer") ? (int)tags["layer"].IntValue : 0;
                                                if (!transportationFeatures.ContainsKey(layer))
                                                {
                                                    transportationFeatures.Add(layer, new List <Tile.Feature>());
                                                }
                                                transportationFeatures[layer].Add(f);
                                            }

                                            foreach (int layerNo in transportationFeatures.Keys.OrderBy(k => k))
                                            {
                                                //background / stroke pass
                                                foreach (var f in transportationFeatures[layerNo])
                                                {
                                                    var tags = GeometryDecoder.GetTags(f, layer_transportation);

                                                    if (tags.ContainsKey("class"))
                                                    {
                                                        if (roadProperties.ContainsKey(tags["class"].StringValue))
                                                        {
                                                            var p = roadProperties[tags["class"].StringValue];
                                                            GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, p.Item1, p.Item3, 0, p.Item4 * lineScale, layerNo > 0 ? GeometryDecoder.openStrokeStyle : GeometryDecoder.normalStrokeStyle);
                                                        }
                                                        else
                                                        {
                                                            GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, rc.Item1, rc.Item3, 0, rc.Item4 * lineScale, GeometryDecoder.normalStrokeStyle);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, rc.Item1, rc.Item3, 0, rc.Item4 * lineScale, GeometryDecoder.normalStrokeStyle);
                                                    }
                                                }

                                                //foreground / fill pass
                                                foreach (var f in transportationFeatures[layerNo])
                                                {
                                                    var tags = GeometryDecoder.GetTags(f, layer_transportation);
                                                    if (tags.ContainsKey("class"))
                                                    {
                                                        if (roadProperties.ContainsKey(tags["class"].StringValue))
                                                        {
                                                            var p = roadProperties[tags["class"].StringValue];
                                                            if (tags["class"].StringValue == "rail" || tags["class"].StringValue == "transit")
                                                            {
                                                                GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, p.Item1, p.Item3, p.Item2 * lineScale, 0, GeometryDecoder.railStrokeStyle);
                                                                //												System.Diagnostics.Debug.WriteLine(t)
                                                            }
                                                            else
                                                            {
                                                                GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, p.Item1, p.Item3, p.Item2 * lineScale, 0, GeometryDecoder.normalStrokeStyle);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            System.Diagnostics.Debug.WriteLine($"Unsupported class: {tags["class"]}");
                                                            GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, rc.Item1, rc.Item3, rc.Item2 * lineScale, 0, GeometryDecoder.normalStrokeStyle);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, rc.Item1, rc.Item3, rc.Item2 * lineScale, 0, GeometryDecoder.normalStrokeStyle);
                                                    }
                                                }
                                            }



                                            //								layer_transportation?.Features.ForEach(f =>
                                            //								{
                                            //									var tags = GeometryDecoder.GetTags(f, layer_transportation);

                                            //									if (tags.ContainsKey("class"))
                                            //									{
                                            //										if (roadProperties.ContainsKey(tags["class"].StringValue))
                                            //										{
                                            //											var p = roadProperties[tags["class"].StringValue];
                                            //											GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, p.Item1, p.Item3, 0, p.Item4 * lineScale);
                                            //										}
                                            //										else
                                            //										{
                                            //											GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, rc.Item1, rc.Item3, 0, rc.Item4 * lineScale);
                                            //										}
                                            //									}
                                            //									else
                                            //										GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, rc.Item1, rc.Item3, 0, rc.Item4 * lineScale);
                                            //								});

                                            //								layer_transportation?.Features.ForEach(f =>
                                            //								{
                                            //									var tags = GeometryDecoder.GetTags(f, layer_transportation);
                                            //									if (tags.ContainsKey("class"))
                                            //									{
                                            //										if (roadProperties.ContainsKey(tags["class"].StringValue))
                                            //										{
                                            //											var p = roadProperties[tags["class"].StringValue];
                                            //											if (tags["class"].StringValue == "rail")
                                            //											{
                                            //												GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, p.Item1, p.Item3, p.Item2 * lineScale, 0, GeometryDecoder.railStrokeStyle);
                                            ////												System.Diagnostics.Debug.WriteLine(t)
                                            //											}
                                            //											else
                                            //												GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, p.Item1, p.Item3, p.Item2 * lineScale, 0);
                                            //										}
                                            //										else
                                            //										{
                                            //											System.Diagnostics.Debug.WriteLine($"Unsupported class: {tags["class"]}");
                                            //											GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, rc.Item1, rc.Item3, rc.Item2 * lineScale, 0);
                                            //										}
                                            //									}
                                            //									else
                                            //										GeometryDecoder.DrawGeometry(f, canvasSize / 4096f, ds, rc.Item1, rc.Item3, rc.Item2 * lineScale, 0);
                                            //								});



                                            layer_housenumber?.Features.ForEach(f =>
                                            {
                                                var tags    = GeometryDecoder.GetTags(f, layer_housenumber);
                                                string text = tags["housenumber"].StringValue;
                                                //GeometryDecoder.DrawHousenumber(f, canvasSize / 4096f, textDs, Colors.Black, Colors.White, 1, 1.2f, text);
                                                GeometryDecoder.DrawText(f, canvasSize / 4096f, textDs, Colors.Black, Colors.White, 1, 1.2f, text, 2f);
                                            });

                                            layer_poi?.Features.ForEach(f => {
                                                var tags = GeometryDecoder.GetTags(f, layer_poi);
                                                if (tags.ContainsKey("subclass"))
                                                {
                                                    string subclass = tags["subclass"].StringValue;
                                                    if (icons.ContainsKey(subclass + "_11"))
                                                    {
                                                        GeometryDecoder.DrawIcon(f, canvasSize / 4096f, ds, icons[subclass + "_11"], Colors.Black, Colors.DarkGray);
                                                    }
                                                }
                                            });


                                            layer_transportation_name?.Features.ForEach(f =>
                                            {
                                                var tags = GeometryDecoder.GetTags(f, layer_transportation_name);
                                                if (tags.ContainsKey("name"))
                                                {
                                                    string text = tags["name"].StringValue;
                                                    GeometryDecoder.DrawText(f, canvasSize / 4096f, textDs, Colors.Black, Colors.White, 1, 1.2f, text, 3f);
                                                }
                                            });
                                        }
                                    }
                        //StorageFolder storageFolder = KnownFolders.PicturesLibrary;
                        //StorageFile file = await storageFolder.CreateFileAsync("map.bmp", CreationCollisionOption.ReplaceExisting);
                        //var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
                        //await GeometryDecoder.offscreen.SaveAsync(stream, CanvasBitmapFileFormat.Bmp);
                        //stream.Dispose();



                        stopwatch.Stop();


                        System.Diagnostics.Debug.WriteLine($"TIME: {stopwatch.ElapsedMilliseconds} ms");
                        textOutput.Text = $"TIME: {stopwatch.ElapsedMilliseconds} ms";
                    }
                }
                else
                {
                    currentTile = null;
                }
            }

            win2dCanvas.Invalidate();
        }
Ejemplo n.º 18
0
        protected override void drawChart(CanvasDrawingSession canvas)
        {
            if (chartData != null)
            {
                float fullWidth = (chartWidth / (pickerDelegate.pickerEnd - pickerDelegate.pickerStart));
                float offset    = fullWidth * (pickerDelegate.pickerStart) - HORIZONTAL_PADDING;

                int start = startXIndex - 1;
                if (start < 0)
                {
                    start = 0;
                }
                int end = endXIndex + 1;
                if (end > chartData.lines[0].y.Length - 1)
                {
                    end = chartData.lines[0].y.Length - 1;
                }

                //canvas.save();
                //canvas.clipRect(chartStart, 0, chartEnd, getMeasuredHeight() - chartBottom);
                var transform = canvas.Transform;
                var clip      = canvas.CreateLayer(1, createRect(chartStart, 0, chartEnd, getMeasuredHeight() - chartBottom));

                float transitionAlpha = 1f;
                //canvas.save();
                if (transitionMode == TRANSITION_MODE_PARENT)
                {
                    postTransition  = true;
                    selectionA      = 0f;
                    transitionAlpha = 1f - transitionParams.progress;

                    canvas.Transform = Matrix3x2.CreateScale(
                        new Vector2(1 + 2 * transitionParams.progress, 1f),
                        new Vector2(transitionParams.pX, transitionParams.pY)
                        );
                }
                else if (transitionMode == TRANSITION_MODE_CHILD)
                {
                    transitionAlpha = transitionParams.progress;

                    canvas.Transform = Matrix3x2.CreateScale(
                        new Vector2(transitionParams.progress, 1f),
                        new Vector2(transitionParams.pX, transitionParams.pY)
                        );
                }


                for (int k = 0; k < lines.Count; k++)
                {
                    BarViewData line = lines[k];
                    if (!line.enabled && line.alpha == 0)
                    {
                        continue;
                    }

                    float p;
                    if (chartData.xPercentage.Length < 2)
                    {
                        p = 1f;
                    }
                    else
                    {
                        p = chartData.xPercentage[1] * fullWidth;
                    }
                    int[] y = line.line.y;
                    int   j = 0;

                    float selectedX = 0f;
                    float selectedY = 0f;
                    bool  selected  = false;
                    float a         = line.alpha;
                    for (int i = start; i <= end; i++)
                    {
                        float xPoint      = p / 2 + chartData.xPercentage[i] * fullWidth - offset;
                        float yPercentage = y[i] / currentMaxHeight * a;

                        float yPoint = getMeasuredHeight() - chartBottom - (yPercentage) * (getMeasuredHeight() - chartBottom - SIGNATURE_TEXT_HEIGHT);

                        if (i == selectedIndex && legendShowing)
                        {
                            selected  = true;
                            selectedX = xPoint;
                            selectedY = yPoint;
                            continue;
                        }

                        line.linesPath[j++] = xPoint;
                        line.linesPath[j++] = yPoint;

                        line.linesPath[j++] = xPoint;
                        line.linesPath[j++] = getMeasuredHeight() - chartBottom;
                    }

                    Paint paint = selected || postTransition ? line.unselectedPaint : line.paint;
                    paint.StrokeWidth = p;
                    //paint.setStrokeWidth(p);


                    if (selected)
                    {
                        line.unselectedPaint.Color = Extensions.blendARGB(
                            line.line.color, line.blendColor, 1f - selectionA);
                    }

                    if (postTransition)
                    {
                        line.unselectedPaint.Color = Extensions.blendARGB(
                            line.line.color, line.blendColor, 0);
                    }

                    paint.A = (byte)(transitionAlpha * 255);
                    //canvas.drawLines(line.linesPath, 0, j, paint);
                    canvas.DrawLines(line.linesPath, 0, j, paint);

                    if (selected)
                    {
                        //line.paint.setStrokeWidth(p);
                        line.paint.StrokeWidth = p;
                        line.paint.A           = (byte)(transitionAlpha * 255);
                        //canvas.drawLine(selectedX, selectedY,
                        //        selectedX, getMeasuredHeight() - chartBottom,
                        //        line.paint
                        //);
                        canvas.DrawLine(selectedX, selectedY, selectedX, getMeasuredHeight() - chartBottom, line.paint);
                        line.paint.A = 255;
                    }
                }

                //canvas.restore();
                //canvas.restore();
                clip.Dispose();
                canvas.Transform = transform;
            }
        }