public void DrawSlicedImagePrimitive(Mesh imageMesh,
                                      ImageGeometry imageGeometry, Rect rect, StyleRuleSet style, Vector offset)
 {
     this.SetImageMesh(imageMesh);
     this.DrawSlicedImage(imageGeometry, Rect.Offset(rect, offset), style);
     this.SetImageMesh(null);
 }
Пример #2
0
 public void DeleteImage()
 {
     if (_image == null)
     {
         return;
     }
     _image.Dispose();
     _image = null;
 }
Пример #3
0
        /// <summary>
        /// 添加一个图片元素
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ImageBtn_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == true)
            {
                string        filename = ofd.FileName;
                ImageGeometry ig       = new ImageGeometry(new Vector2D(100, 100), filename);
                this.drawingKernel.AddShape(ig);
            }
        }
        public void DrawBoxModel(ImageGeometry imageGeometry, Rect rect, StyleRuleSet style)
        {
            GetBoxes(rect, style, out var borderBoxRect, out var paddingBoxRect, out var contentBoxRect);

            this.DrawBackground(style, paddingBoxRect);

            //Content
            //Content-box
            if (contentBoxRect.TopLeft.X < contentBoxRect.TopRight.X)//content should not be visible when contentBoxRect.TopLeft.X > contentBoxRect.TopRight.X
            {
                if (imageGeometry != null)
                {
                    this.DrawImage(imageGeometry, contentBoxRect, style);
                }
            }

            this.DrawBorder(style, borderBoxRect, paddingBoxRect);
            this.DrawOutline(style, borderBoxRect);

            this.DrawDebug(paddingBoxRect, contentBoxRect);
        }
Пример #5
0
        private void AddImage(ImageGeometry geometry, Point a, Point b, Point uv0, Point uv1, Color col)
        {
            if (MathEx.AmostZero(col.A))
            {
                return;
            }

            if (geometry.Texture == null)
            {
                geometry.SendToGPU();
            }

            //add a new draw command
            DrawCommand cmd = new DrawCommand();

            cmd.ClipRect    = Rect.Big;
            cmd.TextureData = geometry.Texture;
            this.ImageMesh.CommandBuffer.Add(cmd);

            this.ImageMesh.PrimReserve(6, 4);
            this.AddImageRect(a, b, uv0, uv1, col);
        }
Пример #6
0
        /// <summary>
        /// Draw an image Geometry and merge the result to the image mesh.
        /// </summary>
        public void DrawImage(ImageGeometry geometry, Rect rect, StyleRuleSet style)
        {
            Color tintColor = Color.White;//TODO define tint color, possibly as a style rule

            if (geometry.Texture == null)
            {
                geometry.SendToGPU();
            }

            //TODO check if we need to add a new draw command
            //add a new draw command
            DrawCommand cmd = new DrawCommand();

            cmd.ClipRect    = Rect.Big;
            cmd.TextureData = geometry.Texture;
            this.ImageMesh.CommandBuffer.Add(cmd);

            //construct and merge the mesh of this Path into ShapeMesh
            var uvMin = new Point(0, 0);
            var uvMax = new Point(1, 1);

            this.ImageMesh.PrimReserve(6, 4);
            this.AddImageRect(rect, uvMin, uvMax, tintColor);
        }
Пример #7
0
 public void CreateImage(PpmFile file)
 {
     _image = new ImageGeometry(file);
 }
Пример #8
0
 public void CreateImage(StorageFile file)
 {
     _image = new ImageGeometry(file);
 }
Пример #9
0
        /// <summary>
        /// Draw an image content
        /// </summary>
        public void DrawSlicedImage(ImageGeometry geometry, Rect rect, StyleRuleSet style)
        {
            var(top, right, bottom, left) = style.BorderImageSlice;
            Point uv0 = new Point(left / geometry.Image.Width, top / geometry.Image.Height);
            Point uv1 = new Point(1 - right / geometry.Image.Width, 1 - bottom / geometry.Image.Height);

            //     | L |   | R |
            // ----a---b---c---+
            //   T | 1 | 2 | 3 |
            // ----d---e---f---g
            //     | 4 | 5 | 6 |
            // ----h---i---j---k
            //   B | 7 | 8 | 9 |
            // ----+---l---m---n

            var a = rect.TopLeft;
            var b = a + new Vector(left, 0);
            var c = rect.TopRight + new Vector(-right, 0);

            var d = a + new Vector(0, top);
            var e = b + new Vector(0, top);
            var f = c + new Vector(0, top);
            var g = f + new Vector(right, 0);

            var h = rect.BottomLeft + new Vector(0, -bottom);
            var i = h + new Vector(left, 0);
            var j = rect.BottomRight + new Vector(-right, -bottom);
            var k = j + new Vector(right, 0);

            var l = i + new Vector(0, bottom);
            var m = rect.BottomRight + new Vector(-right, 0);
            var n = rect.BottomRight;

            var uv_a = new Point(0, 0);
            var uv_b = new Point(uv0.X, 0);
            var uv_c = new Point(uv1.X, 0);

            var uv_d = new Point(0, uv0.Y);
            var uv_e = new Point(uv0.X, uv0.Y);
            var uv_f = new Point(uv1.X, uv0.Y);
            var uv_g = new Point(1, uv0.Y);

            var uv_h = new Point(0, uv1.Y);
            var uv_i = new Point(uv0.X, uv1.Y);
            var uv_j = new Point(uv1.X, uv1.Y);
            var uv_k = new Point(1, uv1.Y);

            var uv_l = new Point(uv0.X, 1);
            var uv_m = new Point(uv1.X, 1);
            var uv_n = new Point(1, 1);

            this.AddImage(geometry, a, e, uv_a, uv_e, Color.White); //1
            this.AddImage(geometry, b, f, uv_b, uv_f, Color.White); //2
            this.AddImage(geometry, c, g, uv_c, uv_g, Color.White); //3
            this.AddImage(geometry, d, i, uv_d, uv_i, Color.White); //4
            this.AddImage(geometry, e, j, uv_e, uv_j, Color.White); //5
            this.AddImage(geometry, f, k, uv_f, uv_k, Color.White); //6
            this.AddImage(geometry, h, l, uv_h, uv_l, Color.White); //7
            this.AddImage(geometry, i, m, uv_i, uv_m, Color.White); //8
            this.AddImage(geometry, j, n, uv_j, uv_n, Color.White); //9
        }