public TextInfo(ICanvasResourceCreator rc, String text)
 {
     
     format = RendererSettings.getInstance().getLabelFont();
     textLayout = new CanvasTextLayout(rc, text, format, 0.0f, 0.0f);
     bounds = getTextBounds();
 }
Exemplo n.º 2
1
        public async Task LoadSurfaceAsync(ICanvasResourceCreator resourceCreator)
        {
            if (surfaceLoaded)
                return;
            List<CanvasBitmap> tempSurfaceList = new List<CanvasBitmap>();
            for (int i = 0; i < surfaceCount; i++)
            {
                var surf = await CanvasBitmap.LoadAsync(resourceCreator, surfaceNameHeader + i.ToString("00000") + ".png");
                var center = surf.Size.ToVector2() / 2;
                var bounds = surf.Bounds;
                tempSurfaceList.Add(surf);

            }
            this.center = tempSurfaceList[0].Size.ToVector2() / 2;
            bound = tempSurfaceList[0].Bounds;
            sunSurfaces = tempSurfaceList.ToArray();
            xOffset = bound.Width / 2;
            yOffset = bound.Height / 2;
            surfaceLoaded = true;
        }
Exemplo n.º 3
0
 async Task LoadDrawing(ICanvasResourceCreator resourceCreator)
 {
     var svgDocument = await XmlDocument.LoadFromFileAsync(wantedSvgFile, new XmlLoadSettings() { ProhibitDtd = false });
     svgDrawing = await SvgDrawing.LoadAsync(resourceCreator, svgDocument);
     loadedSvgFile = wantedSvgFile;
     canvas.Invalidate();
 }
Exemplo n.º 4
0
 public async Task LoadSurfaceAsync(ICanvasResourceCreator creator, IRandomAccessStream stream)
 {
     tempSurface = await CanvasBitmap.LoadAsync(creator, stream);
     bound = tempSurface.Bounds;
     center = tempSurface.Size.ToVector2() / 2;
     blur.Source = tempSurface;
 }
 public PathInfo(ICanvasResourceCreator rc, Windows.UI.Color color, System.Single strokeWidth, CanvasStrokeStyle strokeStyle) //Pen pen, bool fill, int shapeType)
 {
     Vector2 offset = new Vector2(0.0f, 0.0f);
     _cpb = new CanvasPathBuilder(rc);
     //_cpb.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin);
     _color = color;
     //_fill = fill;
     //_type = shapeType;
 }
Exemplo n.º 6
0
        void EnsureSvgDrawingLoaded(ICanvasResourceCreator resourceCreator)
        {
            if (IsLoadInProgress())
                return;

            if (wantedSvgFile != loadedSvgFile)
            {
                loadDrawingTask = LoadDrawing(resourceCreator);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Loads a spritesheet from an image file and
        /// a JSON description file.
        /// </summary>
        /// <param name="uri">
        /// Path to the spritesheet image file including
        /// file extension. The description file is determined
        /// by appending ".json" to this URI.
        /// </param>
        /// <returns>Sprite sheet</returns>
        public static async Task<SpriteSheet> LoadFromApplicationUriAsync(Uri uri, ICanvasResourceCreator resourceCreator)
        {
            var image = await CanvasBitmap.LoadAsync(resourceCreator, uri);

            var jsonUri = new Uri(uri.ToString() + ".json");
            var jsonFile = await StorageFile.GetFileFromApplicationUriAsync(jsonUri);
            var json = await FileIO.ReadTextAsync(jsonFile);

            var description = JsonConvert.DeserializeAnonymousType(json, new { Width = 0, Height = 0, Padding = 0, Names = new string[0] });
            return new SpriteSheet(image, description.Names, new OB.Point(description.Width, description.Height), description.Padding);
        }
        public PathInfo(ICanvasResourceCreator rc, Windows.UI.Color color, System.Single strokeWidth, bool fill, int shapeType) //Pen pen, bool fill, int shapeType)
        {
            Vector2 offset = new Vector2(0.0f, 0.0f);
            _cpb = new CanvasPathBuilder(rc);

            _color = color;
            _fill = fill;
            _type = shapeType;
            CanvasGeometry path = CanvasGeometry.CreatePath(_cpb);
            //path.ComputeBounds

            //var geometry = CanvasGeometry.CreatePath(pathBuilder);
        }
Exemplo n.º 9
0
        public override async Task CreateResourcesAsync(ICanvasResourceCreator resourceCreator)
        {
            await base.CreateResourcesAsync(resourceCreator);

            // This particle system uses additive blending, which has a side effect of leaving 1.0
            // in the framebuffer alpha channel for black texels (which are visually transparent when
            // using additive blending). This doesn't normally affect anything (it is irrelevant what
            // the framebuffer alpha ends up containing, as long as the color channels look the way we
            // want) but thumbnail generation relies on alpha to blend the icon over its background color.
            // To avoid ugly black borders around the thumbnail, we edit the bitmap to have zero alpha,
            // leaving only additive RGB data.

            if (ThumbnailGenerator.IsDrawingThumbnail)
            {
                var colors = bitmap.GetPixelColors();

                for (int i = 0; i < colors.Length; i++)
                {
                    colors[i].A = 0;
                }

                bitmap.SetPixelColors(colors);
            }
        }
Exemplo n.º 10
0
 /// <summary></summary>
 public void CreateFromSoftwareBitmap(ICanvasResourceCreator resourceCreator, Windows.Graphics.Imaging.SoftwareBitmap sourceBitmap)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 11
0
        private void RecreateGeometry(ICanvasResourceCreator resourceCreator)
        {
            leftGeometry = CreateGeometry(resourceCreator, LeftGeometryType);
            rightGeometry = CreateGeometry(resourceCreator, RightGeometryType);

            if (enableTransform)
            {
                Matrix3x2 placeNearOrigin = Matrix3x2.CreateTranslation(-200, -200);
                Matrix3x2 undoPlaceNearOrigin = Matrix3x2.CreateTranslation(200, 200);

                Matrix3x2 rotate0 = Matrix3x2.CreateRotation((float)Math.PI / 4.0f); // 45 degrees
                Matrix3x2 scale0 = Matrix3x2.CreateScale(1.5f);

                Matrix3x2 rotate1 = Matrix3x2.CreateRotation((float)Math.PI / 6.0f); // 30 degrees
                Matrix3x2 scale1 = Matrix3x2.CreateScale(2.0f);

                leftGeometry = leftGeometry.Transform(placeNearOrigin * rotate0 * scale0 * undoPlaceNearOrigin);
                rightGeometry = rightGeometry.Transform(placeNearOrigin * rotate1 * scale1 * undoPlaceNearOrigin);
            }

            combinedGeometry = leftGeometry.CombineWith(rightGeometry, interGeometryTransform, WhichCombineType);

            if (UseFillOrStroke == FillOrStroke.Stroke)
            {
                CanvasStrokeStyle strokeStyle = new CanvasStrokeStyle();
                strokeStyle.DashStyle = CanvasDashStyle.Dash;
                combinedGeometry = combinedGeometry.Stroke(15.0f, strokeStyle);
            }

            totalDistanceOnContourPath = combinedGeometry.ComputePathLength();

            if (showTessellation)
            {
                tessellation = combinedGeometry.Tessellate();
            }
        }
        private static CanvasCommandList GetMarqueeToolGeometry(CanvasDrawingSession drawingSession, ICanvasResourceCreator resourceCreator, CanvasGeometry canvasGeometry)
        {
            CanvasCommandList canvasCommandList = new CanvasCommandList(resourceCreator);

            using (CanvasDrawingSession ds = canvasCommandList.CreateDrawingSession())
            {
                ds.FillGeometry(canvasGeometry, Windows.UI.Colors.DodgerBlue);
            }
            return(canvasCommandList);
        }
Exemplo n.º 13
0
 public virtual void CreateResources(ICanvasResourceCreator device)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// Turn to geometry.
 /// </summary>
 /// <param name="resourceCreator"> The resource-creator. </param>
 /// <param name="matrix"> The matrix. </param>
 /// <returns> The product geometry. </returns>
 public CanvasGeometry ToRectangle(ICanvasResourceCreator resourceCreator, Matrix3x2 matrix) => TransformerGeometry.CreateRectangle(resourceCreator, this, matrix);
Exemplo n.º 15
0
        private CanvasTextLayout CreateTextLayout(ICanvasResourceCreator resourceCreator, Size size)
        {
            var format = new CanvasTextFormat()
            {
                HorizontalAlignment = GetCanvasHorizontalAlignemnt(),
                VerticalAlignment = GetCanvasVerticalAlignment()
            };

            return new CanvasTextLayout(
                resourceCreator,
                Text,
                format,
                (float)size.Width,
                (float)size.Height);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Turn to geometry.
 /// </summary>
 /// <param name="resourceCreator"> The resource-creator. </param>
 /// <param name="matrix"> The matrix. </param>
 /// <returns></returns>
 public CanvasGeometry ToEllipse(ICanvasResourceCreator resourceCreator, Matrix3x2 matrix) => TransformerGeometry.CreateEllipse(resourceCreator, this, matrix);
        public override CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator)
        {
            Transformer transformer = base.Transform.Transformer;

            return(TransformerGeometry.CreateHeart(resourceCreator, transformer, this.Spread));
        }
Exemplo n.º 18
0
 public static CanvasBitmap ToWin2D(this Bitmap bmp, ICanvasResourceCreator resourceCreator)
 {
     return(CanvasBitmap.CreateFromBytes(resourceCreator, bmp.Bytes, bmp.Width, bmp.Height, DirectXPixelFormat.B8G8R8A8UIntNormalized));
 }
Exemplo n.º 19
0
 public static CanvasSolidColorBrush ToWin2D(this Brush brush, ICanvasResourceCreator resourceCreator)
 {
     return(new CanvasSolidColorBrush(resourceCreator, brush.Color.ToWin2D()));
 }
Exemplo n.º 20
0
 public W2DImage(ICanvasResourceCreator creator, CanvasBitmap bitmap)
 {
     _creator = creator;
     _bitmap  = bitmap;
 }
 /// <summary>
 /// Creates a Squircle geometry with the specified extents.
 /// </summary>
 /// <param name="resourceCreator">Resource creator</param>
 /// <param name="x">X offset of the TopLeft corner of the Squircle</param>
 /// <param name="y">Y offset of the TopLeft corner of the Squircle</param>
 /// <param name="width">Width of the Squircle</param>
 /// <param name="height">Height of the Squircle</param>
 /// <param name="radiusX">Corner Radius on the x-axis</param>
 /// <param name="radiusY">Corner Radius on the y-axis</param>
 /// <returns><see cref="CanvasGeometry"/></returns>
 public static CanvasGeometry CreateSquircle(ICanvasResourceCreator resourceCreator, float x, float y, float width, float height, float radiusX, float radiusY)
 {
     using var pathBuilder = new CanvasPathBuilder(resourceCreator);
     pathBuilder.AddSquircleFigure(x, y, width, height, radiusX, radiusY);
     return(CanvasGeometry.CreatePath(pathBuilder));
 }
        /// <summary>
        /// Parses the Path data in string format and converts it to <see cref="CanvasGeometry"/>.
        /// </summary>
        /// <param name="resourceCreator">ICanvasResourceCreator</param>
        /// <param name="pathData">Path data</param>
        /// <returns><see cref="CanvasGeometry"/></returns>
        internal static CanvasGeometry Parse(ICanvasResourceCreator resourceCreator, string pathData)
        {
            var pathFigures = new List <ICanvasPathElement>();

            var matches = RegexFactory.CanvasGeometryRegex.Matches(pathData);

            // If no match is found or no captures in the match, then it means // that the path data is invalid.
            if (matches.Count == 0)
            {
                ThrowForZeroCount();
            }

            // If the match contains more than one captures, it means that there are multiple FillRuleElements present in the path data.
            // There can be only one FillRuleElement in the path data (at the beginning).
            if (matches.Count > 1)
            {
                ThrowForNotOneCount();
            }

            var figures = new List <ICanvasPathElement>();

            foreach (PathFigureType type in Enum.GetValues(typeof(PathFigureType)))
            {
                foreach (Capture figureCapture in matches[0].Groups[type.ToString()].Captures)
                {
                    var figureRootIndex = figureCapture.Index;
                    var regex           = RegexFactory.GetRegex(type);
                    var figureMatch     = regex.Match(figureCapture.Value);
                    if (!figureMatch.Success)
                    {
                        continue;
                    }

                    // Process the 'Main' Group which contains the Path Command and
                    // corresponding attributes
                    var figure = PathElementFactory.CreatePathFigure(type, figureMatch, figureRootIndex);
                    figures.Add(figure);

                    // Process the 'Additional' Group which contains just the attributes
                    figures.AddRange(from Capture capture in figureMatch.Groups["Additional"].Captures
                                     select PathElementFactory.CreateAdditionalPathFigure(type, capture, figureRootIndex + capture.Index, figure.IsRelative));
                }
            }

            // Sort the figures by their indices
            pathFigures.AddRange(figures.OrderBy(f => f.Index));
            if (pathFigures.Count > 0)
            {
                // Check if the first element in the _figures list is a FillRuleElement
                // which would indicate the fill rule to be followed while creating the
                // path. If it is not present, then insert a default FillRuleElement at
                // the beginning.
                if ((pathFigures.ElementAt(0) as FillRuleElement) == null)
                {
                    pathFigures.Insert(0, PathElementFactory.CreateDefaultPathElement(PathFigureType.FillRule));
                }
            }
            else
            {
                return(null);
            }

            // Perform validation to check if there are any invalid characters in the path data that were not captured
            var preValidationCount  = RegexFactory.ValidationRegex.Replace(pathData, string.Empty).Length;
            var postValidationCount = pathFigures.Sum(x => x.ValidationCount);

            // If there are invalid characters, extract them and add them to the ArgumentException message
            if (preValidationCount != postValidationCount)
            {
Exemplo n.º 23
0
 protected abstract IEnumerable <CanvasGeometry> CreateGeometries(Win2DRenderNode renderNode, ICanvasResourceCreator resourceCreator);
Exemplo n.º 24
0
        void EnsureMesh(ICanvasResourceCreator resourceCreator)
        {
            if (gradientMesh != null) return;

            CanvasGradientMeshPatch[] patchArray = new CanvasGradientMeshPatch[patchPoints.Count];

            for (int i=0; i<patchPoints.Count; ++i)
            {
                CanvasGradientMeshPatch patch;

                var points = patchPoints[i];
                var colors = new Vector4[] { Color00.Color, Color03.Color, Color30.Color, Color33.Color };
                var edges = new CanvasGradientMeshPatchEdge[] { Edge00To03, Edge03To33, Edge33To30, Edge30To00 };

                if (patchPoints[i].Length == 12)
                {
                    patch = CanvasGradientMesh.CreateCoonsPatch(points, colors, edges);
                }
                else
                {
                    Debug.Assert(patchPoints[i].Length == 16);

                    patch = CanvasGradientMesh.CreateTensorPatch(points, colors, edges);
                }

                patchArray[i] = patch;
            }

            // Gradient meshes are allowed to be zero-sized, so there is no need to 
            // account for zero here.
            gradientMesh = new CanvasGradientMesh(resourceCreator, patchArray);
        }
Exemplo n.º 25
0
        void CreateRadialGradient(ICanvasResourceCreator resourceCreator)
        {
            radialGradient = new CanvasCommandList(resourceCreator);

            using (var drawingSession = radialGradient.CreateDrawingSession())
            {
                var sqrt2 = (float)Math.Sqrt(2);

                var brush = new CanvasRadialGradientBrush(resourceCreator, Colors.White, Colors.Black)
                {
                    Center = tigerSize / 2,

                    RadiusX = tigerSize.X / sqrt2,
                    RadiusY = tigerSize.Y / sqrt2,
                };

                drawingSession.FillRectangle(bitmapTiger.Bounds, brush);
            }
        }
        /// <summary>
        /// Parses the Path data in string format and converts it to CanvasGeometry.
        /// </summary>
        /// <param name="resourceCreator">ICanvasResourceCreator</param>
        /// <param name="pathData">Path data</param>
        /// <param name="logger">(Optional) For logging purpose. To log the set of
        /// CanvasPathBuilder commands, used for creating the CanvasGeometry, in
        /// string format.</param>
        /// <returns>CanvasGeometry</returns>
        public static CanvasGeometry Parse(ICanvasResourceCreator resourceCreator, string pathData,
                                           StringBuilder logger = null)
        {
            var pathFigures = new List <ICanvasPathElement>();

            var matches = RegexFactory.CanvasGeometryRegex.Matches(pathData);

            // If no match is found or no captures in the match, then it means
            // that the path data is invalid.
            if ((matches == null) || (matches.Count == 0))
            {
                throw new ArgumentException($"Invalid Path data!\nPath Data: {pathData}", nameof(pathData));
            }

            // If the match contains more than one captures, it means that there
            // are multiple FillRuleElements present in the path data. There can
            // be only one FillRuleElement in the path data (at the beginning).
            if (matches.Count > 1)
            {
                throw new ArgumentException("Multiple FillRule elements present in Path Data! " +
                                            "There should be only one FillRule within the Path Data. " +
                                            "You can either remove additional FillRule elements or split the Path Data " +
                                            "into multiple Path Data and call the CanvasObject.CreateGeometry() method on each of them." +
                                            $"\nPath Data: {pathData}");
            }

            var figures = new List <ICanvasPathElement>();

            foreach (PathFigureType type in Enum.GetValues(typeof(PathFigureType)))
            {
                foreach (Capture figureCapture in matches[0].Groups[type.ToString()].Captures)
                {
                    var figureRootIndex = figureCapture.Index;
                    var regex           = RegexFactory.GetRegex(type);
                    var figureMatch     = regex.Match(figureCapture.Value);
                    if (!figureMatch.Success)
                    {
                        continue;
                    }
                    // Process the 'Main' Group which contains the Path Command and
                    // corresponding attributes
                    var figure = PathElementFactory.CreatePathFigure(type, figureMatch, figureRootIndex);
                    figures.Add(figure);

                    // Process the 'Additional' Group which contains just the attributes
                    figures.AddRange(from Capture capture in figureMatch.Groups["Additional"].Captures
                                     select PathElementFactory.CreateAdditionalPathFigure(type, capture, figureRootIndex + capture.Index, figure.IsRelative));
                }
            }

            // Sort the figures by their indices
            pathFigures.AddRange(figures.OrderBy(f => f.Index));
            if (pathFigures.Count > 0)
            {
                // Check if the first element in the _figures list is a FillRuleElement
                // which would indicate the fill rule to be followed while creating the
                // path. If it is not present, then insert a default FillRuleElement at
                // the beginning.
                if ((pathFigures.ElementAt(0) as FillRuleElement) == null)
                {
                    pathFigures.Insert(0, PathElementFactory.CreateDefaultPathElement(PathFigureType.FillRule));
                }
            }

            // Perform validation to check if there are any invalid characters in the path data that were not captured
            var preValidationCount = RegexFactory.ValidationRegex.Replace(pathData, string.Empty).Length;

            var postValidationCount = pathFigures.Sum(x => x.ValidationCount);

            if (preValidationCount != postValidationCount)
            {
                throw new ArgumentException($"Path data contains invalid characters!\nPath Data: {pathData}", nameof(pathData));
            }

            if (pathFigures.Count == 0)
            {
                return(null);
            }

            ICanvasPathElement lastElement = null;
            var currentPoint = Vector2.Zero;

            using (var pathBuilder = new CanvasPathBuilder(resourceCreator))
            {
                foreach (var pathFigure in pathFigures)
                {
                    currentPoint = pathFigure.CreatePath(pathBuilder, currentPoint, ref lastElement, logger);
                }

                return(CanvasGeometry.CreatePath(pathBuilder));
            }
        }
Exemplo n.º 27
0
        private CanvasTextLayout CreateTextLayout(ICanvasResourceCreator resourceCreator, float canvasWidth, float canvasHeight)
        {
            CanvasTextFormat textFormat = new CanvasTextFormat()
            {
                FontFamily = fontPicker.CurrentFontFamily,
                FontSize = CurrentFontSize,
                WordWrapping = CanvasWordWrapping.NoWrap,
                HorizontalAlignment = CanvasHorizontalAlignment.Center,
                VerticalAlignment = CanvasVerticalAlignment.Center,
                FontWeight = UseBoldFace ? FontWeights.Bold : FontWeights.Normal,
                FontStyle = UseItalicFace ? FontStyle.Italic : FontStyle.Normal
            };

            string testString = "Ajc";

            return new CanvasTextLayout(resourceCreator, testString, textFormat, canvasWidth, canvasHeight);
        }
Exemplo n.º 28
0
 /// <summary></summary>
 public void CreateFromSoftwareBitmap(ICanvasResourceCreator resourceCreator, Windows.Graphics.Imaging.SoftwareBitmap sourceBitmap)
 {
     throw new System.NotImplementedException();
 }
        public override CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, Matrix3x2 matrix)
        {
            Transformer transformer = base.Transform.Transformer;

            return(TransformerGeometry.CreateCapsule(resourceCreator, transformer, matrix));
        }
 public GlyphRunsToGeometryConverter(ICanvasResourceCreator rc)
 {
     resourceCreator = rc;
 }
Exemplo n.º 31
0
 public override void CreateResources(ICanvasResourceCreator device)
 {
     geometry = CanvasGeometry.CreatePolygon(device, Points.ToArray());
 }
Exemplo n.º 32
0
        /// <summary>
        /// InitBitmap
        /// </summary>
        /// <param name="creator">ICanvasResourceCreator</param>
        /// <returns></returns>
        public async Task InitBitmap(ICanvasResourceCreator creator)
        {
            this.Bitmap = await CanvasBitmap.LoadAsync(creator, this.Image); // Set the scaled bitmap

            this.Effect = ImageManipulation.img(this.Bitmap);                // manipulate the image
        }
Exemplo n.º 33
0
 /// <summary>
 /// ctor with default CanvasStrokeStyle
 /// </summary>
 /// <param name="device">ICanvasResourceCreator</param>
 /// <param name="strokeColor">Color of the stroke</param>
 /// <param name="strokeWidth">Width of the stroke</param>
 public CanvasStroke(ICanvasResourceCreator device, Color strokeColor, float strokeWidth = 1f) :
     this(device, strokeColor, strokeWidth, new CanvasStrokeStyle())
 {
 }
Exemplo n.º 34
0
        private void UpdateOutlineChanges(ICanvasResourceCreator canvas,
                                          ITextModel leftControl, ITextModel rightControl, double controlHeight)
        {
            if (leftControl == null || rightControl == null)
            {
                return;
            }

            int lineCountOrg = leftControl.ValidLineCount;
            int lineCountCur = rightControl.ValidLineCount;
            int maxLineCount = Math.Max(lineCountOrg, lineCountCur);

            int singleOrgLineHeight = (int)(controlHeight / lineCountOrg);
            int singleCurLineHeight = (int)(controlHeight / lineCountCur);

            var removedGeo = new List <CanvasGeometry>();
            var addedGeo   = new List <CanvasGeometry>();

            // Draw removals
            int lineNo = 0;

            for (int i = 0; i < leftControl.LineCount; i++)
            {
                var textLine = leftControl.GetLine(i);
                if (textLine is DiffTextLine diffLine)
                {
                    if (diffLine.ChangeType != DiffLineType.Empty)
                    {
                        lineNo++;
                    }

                    if (diffLine.ChangeType == DiffLineType.Remove)
                    {
                        int ypos = (int)((double)lineNo / maxLineCount * controlHeight);

                        removedGeo.Add(CanvasGeometry.CreateRectangle(canvas,
                                                                      new Rect(12.0, ypos + (int)_leftFileTop, 16.0, singleOrgLineHeight + 1)));
                    }
                }
            }

            lineNo = 0;
            for (int i = 0; i < rightControl.LineCount; i++)
            {
                var textLine = rightControl.GetLine(i);

                if (textLine is DiffTextLine diffLine)
                {
                    if (diffLine.ChangeType != DiffLineType.Empty)
                    {
                        lineNo++;
                    }

                    if (diffLine.ChangeType == DiffLineType.Insert)
                    {
                        int ypos = (int)((double)lineNo / maxLineCount * controlHeight);

                        addedGeo.Add(CanvasGeometry.CreateRectangle(canvas,
                                                                    new Rect(40.0, ypos + (int)_rightFileTop, 16.0, singleCurLineHeight + 1)));
                    }
                }
            }

            // Save the results into a cached geo
            var groupedRemovedGeo = CanvasGeometry.CreateGroup(canvas, removedGeo.ToArray());
            var groupedAddedGeo   = CanvasGeometry.CreateGroup(canvas, addedGeo.ToArray());

            _outlineChangesRemoved = CanvasCachedGeometry.CreateFill(groupedRemovedGeo);
            _outlineChangesAdded   = CanvasCachedGeometry.CreateFill(groupedAddedGeo);
        }
Exemplo n.º 35
0
        private CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, GeometryType type)
        {
            switch (type)
            {
                case GeometryType.Rectangle: return CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 300, 350);
                case GeometryType.RoundedRectangle: return CanvasGeometry.CreateRoundedRectangle(resourceCreator, 80, 80, 400, 400, 100, 100);
                case GeometryType.Ellipse: return CanvasGeometry.CreateEllipse(resourceCreator, 275, 275, 225, 275);
                case GeometryType.Star:
                    {
                        return Utils.CreateStarGeometry(resourceCreator, 250, new Vector2(250, 250));
                    }
                case GeometryType.Group:
                    {
                        CanvasGeometry geo0 = CanvasGeometry.CreateRectangle(resourceCreator, 100, 100, 100, 100);
                        CanvasGeometry geo1 = CanvasGeometry.CreateRoundedRectangle(resourceCreator, 300, 100, 100, 100, 50, 50);

                        CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator);
                        pathBuilder.BeginFigure(200, 200);
                        pathBuilder.AddLine(500, 200);
                        pathBuilder.AddLine(200, 350);
                        pathBuilder.EndFigure(CanvasFigureLoop.Closed);
                        CanvasGeometry geo2 = CanvasGeometry.CreatePath(pathBuilder);

                        return CanvasGeometry.CreateGroup(resourceCreator, new CanvasGeometry[] { geo0, geo1, geo2 });
                    }
            }
            System.Diagnostics.Debug.Assert(false);
            return null;
        }
Exemplo n.º 36
0
 public void CreateResources(ICanvasResourceCreator resourceCreator)
 {
     _ship.CreateResources(resourceCreator);
 }
Exemplo n.º 37
0
        CanvasGeometry MakeDirectionIcon(ICanvasResourceCreator creator)
        {
            var builder = new CanvasPathBuilder(creator);

            float radius = 3;
            float lineWidth = 20;

            builder.BeginFigure(0, 0);
            builder.AddLine(0, radius * 2);
            builder.EndFigure(CanvasFigureLoop.Open);

            float y = radius;
            builder.BeginFigure(0, y);
            builder.AddArc(new Vector2(lineWidth + radius, y + radius), radius, radius, -(float)Math.PI/2, (float)Math.PI);
            y += radius * 2;
            builder.AddArc(new Vector2(radius, y + radius), radius, radius, -(float)Math.PI/2, -(float)Math.PI);

            y += radius * 2;
            float x = lineWidth * 2 / 3;
            builder.AddLine(x, y);

            builder.EndFigure(CanvasFigureLoop.Open);

            builder.BeginFigure(x - radius, y - radius/3);
            builder.AddLine(x, y);
            builder.AddLine(x - radius, y + radius/3);
            builder.EndFigure(CanvasFigureLoop.Open);

            return CanvasGeometry.CreatePath(builder);
        }
Exemplo n.º 38
0
 /// <summary>
 /// Creates the ICanvasStroke from the parsed data
 /// </summary>
 /// <returns>ICanvasStroke</returns>
 public override ICanvasStroke CreateStroke(ICanvasResourceCreator resourceCreator)
 {
     return(new CanvasStroke(_brush.CreateBrush(resourceCreator), _width, _style.Style));
 }
        void CreateClockFace(ICanvasResourceCreator sender)
        {
            const float begin = center - radius - lineLength / 2;
            const float end = center + radius + lineLength / 2;

            using (var builder = new CanvasPathBuilder(sender))
            {

                // Since we have concentric circles that we want to remain filled we want to use Winding to determine the filled region.
                builder.SetFilledRegionDetermination(CanvasFilledRegionDetermination.Winding);

                builder.AddCircleFigure(new Vector2(center), radius);
                builder.AddCircleFigure(new Vector2(center), radius * 0.6f);

                builder.AddOneLineFigure(center, begin, center, begin + lineLength);
                builder.AddOneLineFigure(center, end - lineLength, center, end);
                builder.AddOneLineFigure(begin, center, begin + lineLength, center);
                builder.AddOneLineFigure(end - lineLength, center, end, center);

                using (CanvasGeometry clockFaceGeometry = CanvasGeometry.CreatePath(builder))
                {
                    clockFaceCachedFill = CanvasCachedGeometry.CreateFill(clockFaceGeometry);
                    clockFaceCachedStroke18 = CanvasCachedGeometry.CreateStroke(clockFaceGeometry, 18, timeCircleStrokeStyle);
                    clockFaceCachedStroke16 = CanvasCachedGeometry.CreateStroke(clockFaceGeometry, 16, timeCircleStrokeStyle);
                }
            }
        }
Exemplo n.º 40
0
        // Loads the bitmap that will be used to draw this particle system.
        public virtual async Task CreateResourcesAsync(ICanvasResourceCreator resourceCreator)
        {
            bitmap = await CanvasBitmap.LoadAsync(resourceCreator, bitmapFilename);

            bitmapCenter = bitmap.Size.ToVector2() / 2;
            bitmapBounds = bitmap.Bounds;
        }
Exemplo n.º 41
0
        void CreateLinearGradient(ICanvasResourceCreator resourceCreator)
        {
            var commandList = new CanvasCommandList(resourceCreator);

            using (var drawingSession = commandList.CreateDrawingSession())
            {
                var brush = new CanvasLinearGradientBrush(resourceCreator, Colors.White, Colors.Black)
                {
                    StartPoint = new Vector2(-tigerSize.X / 4, 0),
                    EndPoint = new Vector2(tigerSize.X * 5 / 4, 0),
                };

                drawingSession.FillRectangle(bitmapTiger.Bounds, brush);
            }

            // Wrap the gradient with a border effect to avoid edge artifacts as we rotate it.
            linearGradient = new Transform2DEffect
            {
                Source = new BorderEffect
                {
                    Source = commandList
                }
            };
        }
 public async Task LoadSurfaceAsync(ICanvasResourceCreator resourceCreator, byte v)
 {
     if (surfaceLoaded && v == flag)
         return;
     flag = v;
     List<CanvasBitmap> tempSurfaceList = new List<CanvasBitmap>();
     List<Vector2> tempCenterList = new List<Vector2>();
     List<Rect> tempBoundsList = new List<Rect>();
     foreach (var surfacename in smokeSurfaceName[flag])
     {
         var surf = await CanvasBitmap.LoadAsync(resourceCreator, surfacename);
         var center = surf.Size.ToVector2() / 2;
         var bounds = surf.Bounds;
         tempSurfaceList.Add(surf);
         tempCenterList.Add(center);
         tempBoundsList.Add(bounds);
     }
     smokeSurfaces = tempSurfaceList.ToArray();
     surfacesCenter = tempCenterList.ToArray();
     surfacesBounds = tempBoundsList.ToArray();
     surfaceLoaded = true;
     ChangeCondition();
 }
Exemplo n.º 43
0
 /// <summary>
 /// Create a specific geometry.
 /// </summary>
 /// <param name="resourceCreator"> The resource-creator. </param>
 /// <param name="matrix"> The matrix. </param>
 /// <returns> The product geometry. </returns>
 public override CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, Matrix3x2 matrix)
 {
     return(this.CreateGeometry(resourceCreator).Transform(matrix));
 }
Exemplo n.º 44
0
 /// <summary>
 /// Turn to geometry.
 /// </summary>
 /// <param name="resourceCreator"> The resource-creator. </param>
 /// <returns></returns>
 public CanvasGeometry ToEllipse(ICanvasResourceCreator resourceCreator) => TransformerGeometry.CreateEllipse(resourceCreator, this);
Exemplo n.º 45
0
 /// <summary>
 /// Creates the ICanvasBrush from the parsed data
 /// </summary>
 /// <param name="resourceCreator">ICanvasResourceCreator object</param>
 /// <returns>ICanvasBrush</returns>
 public abstract ICanvasBrush CreateBrush(ICanvasResourceCreator resourceCreator);
Exemplo n.º 46
0
 // 载入纹理
 public virtual async Task LoadSurfaceAsync(ICanvasResourceCreator resourceCreator)
 {
     if (surfaceLoaded)
         return;
     bitmap = await CanvasBitmap.LoadAsync(resourceCreator, bitmapFilename);
     surfaceLoaded = true;
 }
        /// <summary>
        /// Renders text into a command list and sets this as the input to the flame
        /// effect graph. The effect graph must already be created before calling this method.
        /// </summary>
        private void SetupText(ICanvasResourceCreator resourceCreator)
        {
            textCommandList = new CanvasCommandList(resourceCreator);

            using (var ds = textCommandList.CreateDrawingSession())
            {
                ds.Clear(Colors.Transparent);

                ds.DrawText(
                    "Windows.UI.Composition",
                    0,
                    0,
                    Colors.White,
                    new Microsoft.Graphics.Canvas.Text.CanvasTextFormat
                    {
                        FontFamily = "Segoe UI",
                        FontSize = 20,
                        HorizontalAlignment = CanvasHorizontalAlignment.Center,
                        VerticalAlignment = CanvasVerticalAlignment.Top
                    });
            }

            // Hook up the command list to the inputs of the flame effect graph.
            morphology.Source = textCommandList;
            composite.Sources[1] = textCommandList;
        }
        private static CanvasGeometry CreateTriangleGeometry(ICanvasResourceCreator resourceCreator, float scale, Vector2 center)
        {
            Vector2[] points =
            {
                new Vector2(-1,1),
                new Vector2(0,-1),
                new Vector2(1,1)
            };

            var transformedPoints = from point in points
                                    select point * scale + center;

            var convertedPoints = transformedPoints;

            return CanvasGeometry.CreatePolygon(resourceCreator, convertedPoints.ToArray());
        }
Exemplo n.º 49
0
        /// <summary>
        /// Renders text into a command list and sets this as the input to the flame
        /// effect graph. The effect graph must already be created before calling this method.
        /// </summary>
        private void SetupText(ICanvasResourceCreator resourceCreator)
        {
            textCommandList = new CanvasCommandList(resourceCreator);

            using (var ds = textCommandList.CreateDrawingSession())
            {
                ds.Clear(Color.FromArgb(0, 0, 0, 0));

                ds.DrawText(
                    text,
                    0,
                    0,
                    Colors.White,
                    new CanvasTextFormat
                    {
                        FontFamily = "Segoe UI",
                        FontSize = fontSize,
                        HorizontalAlignment = CanvasHorizontalAlignment.Center,
                        VerticalAlignment = CanvasVerticalAlignment.Top
                    });
            }

            // Hook up the command list to the inputs of the flame effect graph.
            morphology.Source = textCommandList;
            composite.Sources[1] = textCommandList;
        }
Exemplo n.º 50
0
        private CanvasTextLayout CreateTextLayout(ICanvasResourceCreator resourceCreator, float canvasWidth, float canvasHeight)
        {
            string testString;

            if (CurrentTextLengthOption == TextLengthOption.Short)
            {
                testString = "one two";
            }
            else
            {
                testString = "This is some text which demonstrates Win2D's text-to-geometry option; there are sub-options of this test which apply lining options such as underline or strike-through. Additionally,  this example applies different text directions to ensure glyphs are transformed correctly.";
            }

            if(ThumbnailGenerator.IsDrawingThumbnail)
            {
                testString = "a";
            }

            for (int i = 0; i < testString.Length; ++i)
            {
                if (testString[i] == ' ')
                {
                    int nextSpace = testString.IndexOf(' ', i + 1);
                    int limit = nextSpace == -1 ? testString.Length : nextSpace;

                    WordBoundary wb = new WordBoundary();
                    wb.Start = i + 1;
                    wb.Length = limit - i - 1;
                    everyOtherWordBoundary.Add(wb);
                    i = limit;
                }
            }

            float sizeDim = Math.Min(canvasWidth, canvasHeight);

            CanvasTextFormat textFormat = new CanvasTextFormat()
            {
                FontSize = CurrentTextLengthOption == TextLengthOption.Paragraph? sizeDim * 0.09f : sizeDim * 0.3f,
                Direction = CurrentTextDirection,
            };

            if (ThumbnailGenerator.IsDrawingThumbnail)
            {
                textFormat.FontSize = sizeDim * 0.75f;
            }

            CanvasTextLayout textLayout = new CanvasTextLayout(resourceCreator, testString, textFormat, canvasWidth, canvasHeight);

            if(CurrentTextEffectOption == TextEffectOption.UnderlineEveryOtherWord)
            {
                foreach(WordBoundary wb in everyOtherWordBoundary)
                {
                    textLayout.SetUnderline(wb.Start, wb.Length, true);
                }
            }
            else if (CurrentTextEffectOption == TextEffectOption.StrikeEveryOtherWord)
            {
                foreach (WordBoundary wb in everyOtherWordBoundary)
                {
                    textLayout.SetStrikethrough(wb.Start, wb.Length, true);
                }
            }

            textLayout.VerticalGlyphOrientation = CurrentVerticalGlyphOrientation;

            return textLayout;
        }
Exemplo n.º 51
0
        private CanvasTextLayout CreateTextLayout(ICanvasResourceCreator resourceCreator, float canvasWidth, float canvasHeight)
        {
            float sizeDim = Math.Min(canvasWidth, canvasHeight);

            CanvasTextFormat textFormat;
            switch (CurrentTextSampleOption)
            {
                case TextSampleOption.QuickBrownFox:
                    testString = "The quick brown fox jumps over the lazy dog.";
                    textFormat = new CanvasTextFormat()
                    {
                        FontSize = sizeDim * 0.1f,
                        HorizontalAlignment = CanvasHorizontalAlignment.Center,
                        VerticalAlignment = CanvasVerticalAlignment.Center
                    };
                    break;

                case TextSampleOption.LatinLoremIpsum:
                    testString = @"                    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacinia odio lectus, eget luctus felis tincidunt sit amet. Maecenas vel ex porttitor, ultrices nunc feugiat, porttitor quam. Cras non interdum urna. In sagittis tempor leo quis laoreet. Sed pretium tellus ut commodo viverra. Ut volutpat in risus at aliquam. Sed faucibus vitae dolor ut commodo.
                    Mauris mollis rhoncus libero ut porttitor. Suspendisse at egestas nunc. Proin non neque nibh. Mauris eu ornare arcu. Etiam non sem eleifend, imperdiet erat at, hendrerit ante. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer porttitor mauris eu pulvinar commodo. Interdum et malesuada fames ac ante ipsum primis in faucibus.
                    Mauris ultricies fermentum sem sed consequat. Vestibulum iaculis dui nulla, nec pharetra dolor gravida in. Pellentesque vel nisi urna. Donec gravida nunc sed pellentesque feugiat. Aliquam iaculis enim non enim ultrices aliquam. In at leo sed lorem interdum bibendum at non enim. Vivamus fermentum nisl eros, sit amet laoreet justo tincidunt et. Maecenas nunc erat, placerat non efficitur quis, convallis et nunc. Integer eget nunc id nunc convallis hendrerit. Mauris ac ornare nibh, vel condimentum dolor. Nullam dictum nibh eget tempus suscipit. Sed in ligula vitae ligula dignissim semper vel pretium nisl. Suspendisse potenti. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
                    Cras sit amet pretium libero. Maecenas non mauris vitae ante auctor hendrerit. Donec ut felis metus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus sodales commodo imperdiet. Vestibulum maximus diam ac dui rhoncus blandit. Curabitur id tincidunt urna. Vivamus vitae blandit sem. Duis non sem nibh. Proin a lacus ac est egestas aliquam in vel dolor. Duis semper mattis elit, vitae bibendum lacus tempus vel. Quisque eget ultrices orci, id sagittis est. Duis fringilla pretium diam, at finibus ex elementum vel. Aenean nibh lectus, consequat nec libero interdum, gravida vestibulum mi.
                    Etiam arcu libero, semper et maximus eget, mollis in dui. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer hendrerit neque non libero rutrum tincidunt. Fusce in odio vel nisl aliquam tempus. Fusce sollicitudin nisi vel eros consequat, ac pulvinar lorem imperdiet. Aliquam pulvinar metus sed varius porta. Curabitur ac leo laoreet, bibendum erat sit amet, pulvinar purus. Sed laoreet ipsum eu tortor congue vulputate. Integer convallis vulputate urna. Nulla quis vestibulum justo. Vestibulum non purus nunc.";

                    textFormat = new CanvasTextFormat()
                    {
                        FontSize = sizeDim * 0.025f,
                        HorizontalAlignment = CanvasHorizontalAlignment.Left,
                        VerticalAlignment = CanvasVerticalAlignment.Top
                    };
                    break;

                case TextSampleOption.乱数假文:
                default:
                    testString = "不結邊的聲不陸還下絕去以得一票來夠年維書:原有馬下,不時不去遊制日經養投外光、調預知拉越位;去進就管一率客於行小眾一關金的相。現的一展己明物程上益驚,步使超友究比質管日。散奇說。有急理裝臺也足報國發,院來自加樂為?應報心境好調怕銀利的器理濟生他,地人知滿提球術不先表……值想不為品華信子會他過知天清與止為的。實時知嚴怕傳著配法類加,點展源又上後吸上戲上上的不當。一種人利取過微家品領不作出得那、確他他如樂德的,活布還理收,高子許臺輪電性跑整想水功用通。大雙小分過排現令簡。公方要排題公排見教去。終後少!口許一此表自無人……種活構自動一些林、切、師是放不注!氣以那中以新統雖這水?名標天。每利出、帶未心時我斷有看系是士,道此我地技一平水大非我意然,現了。它好作下物失不感一,適事資清有足收不推行……館臺卻告下、動論然中率麼說裡了本大解事成先文如。可再冷自們。一為何。史地著,證政科、展言用往。";

                    textFormat = new CanvasTextFormat()
                    {
                        FontSize = sizeDim * 0.04f,
                        HorizontalAlignment = CanvasHorizontalAlignment.Center,
                        VerticalAlignment = CanvasVerticalAlignment.Center,
                        Direction = CanvasTextDirection.TopToBottomThenRightToLeft
                    };
                    break;
            }

            textFormat.FontFamily = fontPicker.CurrentFontFamily;

            textFormat.TrimmingGranularity = CanvasTextTrimmingGranularity.Word;
            textFormat.TrimmingSign = UseEllipsisTrimming ? CanvasTrimmingSign.Ellipsis : CanvasTrimmingSign.None;

            var textLayout = new CanvasTextLayout(resourceCreator, testString, textFormat, canvasWidth, canvasHeight);

            return textLayout;
        }
 /// <summary>
 /// Creates a CanvasRenderLayer with the geometry, fill brush and stroke specified in
 /// string formats.
 /// </summary>
 /// <param name="creator">ICanvasResourceCreator.</param>
 /// <param name="geometryData">CanvasGeometry string definition.</param>
 /// <param name="brushData">ICanvasBrush string definition.</param>
 /// <param name="strokeData">ICanvasStroke string definition.</param>
 public CanvasRenderLayer(ICanvasResourceCreator creator, string geometryData, string brushData, string strokeData)
 {
     Geometry = String.IsNullOrWhiteSpace(geometryData) ? null : CanvasObject.CreateGeometry(creator, geometryData);
     Brush    = String.IsNullOrWhiteSpace(brushData) ? null : CanvasObject.CreateBrush(creator, brushData);
     Stroke   = String.IsNullOrWhiteSpace(strokeData) ? null : CanvasObject.CreateStroke(creator, strokeData);
 }
Exemplo n.º 53
0
        /// <summary>
        /// Gets a specific rended-layer.
        /// </summary>
        /// <param name="resourceCreator"> The resource-creator. </param>
        /// <param name="children"> The children layerage. </param>
        /// <returns> The rendered layer. </returns>
        public override ICanvasImage GetRender(ICanvasResourceCreator resourceCreator, IList <Layerage> children)
        {
            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, children);
                        }
                    }
                    break;

                    default:
                        this.GetGeometryRender(resourceCreator, drawingSession, children);
                        break;
                    }
                }
                else
                {
                    Transformer    transformer  = base.Transform.Transformer;
                    CanvasGeometry geometryCrop = transformer.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, children);
                        }
                    }
                    break;

                    default:
                        using (drawingSession.CreateLayer(1, geometryCrop))
                        {
                            this.GetGeometryRender(resourceCreator, drawingSession, children);
                        }
                        break;
                    }
                }
            }
            return(command);
        }
Exemplo n.º 54
0
 /// <summary>
 /// Turn to geometry.
 /// </summary>
 /// <param name="resourceCreator"> The resource-creator. </param>
 /// <returns> The product geometry. </returns>
 public CanvasGeometry ToRectangle(ICanvasResourceCreator resourceCreator) => TransformerGeometry.CreateRectangle(resourceCreator, this);
        private static CanvasGeometry CreateHeart(ICanvasResourceCreator resourceCreator, float scale, Vector2 center)
        {
            center = center - new Vector2(center.X / 2, center.Y / 2);
            CanvasPathBuilder pathBuilder = new CanvasPathBuilder(resourceCreator);
            var begin = new Vector2(0.47f, 0.34f) * scale + center;
            pathBuilder.BeginFigure(begin);
            pathBuilder.AddCubicBezier(new Vector2(0.66f, 0.19f) * scale + center, new Vector2(0.88f, 0.30f) * scale + center, new Vector2(0.88f, 0.48f) * scale + center);
            pathBuilder.AddCubicBezier(new Vector2(0.88f, 0.66f) * scale + center, new Vector2(0.49f, 1) * scale + center, new Vector2(0.49f, 1)* scale + center);
            pathBuilder.AddCubicBezier(new Vector2(0.49f, 1) * scale + center, new Vector2(0, 0.66f) * scale + center, new Vector2(0, 0.48f) * scale + center);
            pathBuilder.AddCubicBezier(new Vector2(0, 0.30f) * scale + center, new Vector2(0.33f, 0.19f) * scale + center, begin);

            pathBuilder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin);
            pathBuilder.EndFigure(CanvasFigureLoop.Closed);
            var geometry = CanvasGeometry.CreatePath(pathBuilder);
            return geometry;
        }
Exemplo n.º 56
0
        /// <summary>
        ///  Convert to curves.
        /// </summary>
        /// <returns> The product curves. </returns>
        public override NodeCollection ConvertToCurves(ICanvasResourceCreator resourceCreator)
        {
            CanvasGeometry geometry = this.CreateGeometry(resourceCreator);

            return(new NodeCollection(geometry));
        }
Exemplo n.º 57
0
        // Helper creates an EffectTransferTable3D by evaluating the specified transfer function for every location within the table.
        private static EffectTransferTable3D CreateTransferTableFromFunction(ICanvasResourceCreator resourceCreator, int sizeB, int sizeG, int sizeR, Func<Vector3, Vector3> transferFunction)
        {
            var tableColors = new List<Color>();

            var maxExtents = new Vector3(sizeR, sizeG, sizeB) - Vector3.One;

            for (int r = 0; r < sizeR; r++)
            {
                for (int g = 0; g < sizeG; g++)
                {
                    for (int b = 0; b < sizeB; b++)
                    {
                        Vector3 sourceColor = new Vector3(r, g, b) / maxExtents;

                        Vector3 outputColor = transferFunction(sourceColor);

                        tableColors.Add(ToColor(outputColor));
                    }
                }
            }

            return EffectTransferTable3D.CreateFromColors(resourceCreator, tableColors.ToArray(), sizeB, sizeG, sizeR);
        }
Exemplo n.º 58
0
        private void GetGeometryRender(ICanvasResourceCreator resourceCreator, CanvasDrawingSession drawingSession, IList <Layerage> children)
        {
            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 (children.Count != 0)
                {
                    using (drawingSession.CreateLayer(1, geometry))
                    {
                        ICanvasImage childImage = LayerBase.Render(resourceCreator, children);

                        if (childImage != null)
                        {
                            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 (children.Count != 0)
                {
                    using (drawingSession.CreateLayer(1, geometry))
                    {
                        ICanvasImage childImage = LayerBase.Render(resourceCreator, children);

                        if (childImage != null)
                        {
                            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);
                }
            }
        }
Exemplo n.º 59
0
        private CanvasCommandList GenerateTextDisplay(ICanvasResourceCreator resourceCreator, float width, float height)
        {
            var cl = new CanvasCommandList(resourceCreator);

            using (var ds = cl.CreateDrawingSession())
            {
                float top = height - offset;

                float center = width / 4.0f;
                float symbolPos = center - 5.0f;
                float labelPos = center + 5.0f;

                for (int i = firstLine; i < lastLine; ++i)
                {
                    float y = top + lineHeight * i;
                    int index = i;

                    if (index < characters.Length)
                    {
                        ds.DrawText(string.Format("{0}", (char)characters[index].Code), symbolPos, y, Colors.White, symbolText);
                        ds.DrawText(string.Format("0x{0:X} - {1}", characters[index].Code, characters[index].Label), labelPos, y, Colors.White, labelText);
                    }
                }
            }

            return cl;
        }
        public override CanvasGeometry CreateGeometry(ICanvasResourceCreator resourceCreator, Matrix3x2 matrix)
        {
            Transformer transformer = base.Transform.Transformer;

            return(TransformerGeometry.CreatePie(resourceCreator, transformer, matrix, this.SweepAngle));
        }