Пример #1
0
        public void TransformStack_TranlateSaveRestore_Verify()
        {
			using (var context = new Eto.Platform.Wpf.Generator().Context)
			{
				var current = Matrix.Create();
				var stack = new Stack<IMatrix>();
				Action<IMatrix> push = m => {
					stack.Push(current);
					m.Append(current);
					current = m;
				};
				Action pop = () => current = stack.Pop();

				var target = new TransformStack(Generator.Current, push, pop);

				Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 0f, 0f));

				target.SaveTransform(); // Save

				target.TranslateTransform(5f, 5f);
				Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 5f, 5f));

				target.SaveTransform();

				target.TranslateTransform(10f, 10f);
				Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 15f, 15f));

				target.RestoreTransform();
				Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 5f, 5f));

				target.RestoreTransform();
				Assert.IsTrue(MatrixTests.Equals(current, 1f, 0f, 0f, 1f, 0f, 0f));
			}
        }
Пример #2
0
        public void Clear(SolidBrush brush)
        {
            var rect = this.ClipBounds;

            if (drawingVisual != null)
            {
                // bitmap
                Control.Close();
                var newbmp = new swmi.RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96, 96, swm.PixelFormats.Pbgra32);
                newbmp.Render(visual);

                swm.Geometry maskgeometry;
                if (clipPath != null)
                {
                    maskgeometry = clipPath.ToWpf();
                }
                else
                {
                    maskgeometry = new swm.RectangleGeometry(rect.ToWpf());
                }
                var boundsgeometry = new swm.RectangleGeometry(this.bounds);
                maskgeometry = swm.Geometry.Combine(boundsgeometry, maskgeometry, swm.GeometryCombineMode.Exclude, null);
                var dr = new swm.GeometryDrawing(swm.Brushes.Black, null, maskgeometry);
                var db = new swm.DrawingBrush(dr);
                //db.Transform = new swm.TranslateTransform (0.5, 0.5);

                Control = drawingVisual.RenderOpen();
                PushGuideLines(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                Control.PushOpacityMask(db);
                Control.DrawImage(newbmp, this.bounds);
                Control.Pop();

                TransformStack.PushAll();
                ApplyClip();
            }
            else
            {
                // drawable
                if (brush == null || brush.Color.A < 1.0f)
                {
                    Widget.FillRectangle(Brushes.Black(Generator), rect);
                }
            }
            if (brush != null)
            {
                Widget.FillRectangle(brush, rect);
            }
        }