Beispiel #1
0
        public void TransformStack_TranlateSaveRestore_Verify()
        {
			using (var context = new Eto.Wpf.Platform().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(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));
			}
        }
Beispiel #2
0
 public void SetClip(IGraphicsPath path)
 {
     TransformStack.PopAll();
     ResetClip();
     clipPath   = path.Clone().ToWpf();           // require a clone so changes to path don't affect current clip
     clipBounds = clipPath.Bounds.ToEtoF();
     ApplyClip();
     TransformStack.PushAll();
 }
Beispiel #3
0
 public void SetClip(RectangleF rectangle)
 {
     TransformStack.PopAll();
     ResetClip();
     clipBounds = rectangle;
     clipPath   = null;
     ApplyClip();
     TransformStack.PushAll();
 }
Beispiel #4
0
 void CreateGroup()
 {
     CloseGroup();
     if (baseContext == null)
     {
         baseContext = Control;
     }
     group   = new swm.DrawingGroup();
     Control = group.Open();
     TransformStack.PushAll();
     ApplyClip();
 }
Beispiel #5
0
 void CloseGroup()
 {
     if (group != null && baseContext != null)
     {
         TransformStack.PopAll();
         ResetClip();
         Control.Close();
         baseContext.DrawDrawing(group);
         Control = baseContext;
         group   = null;
         ApplyClip();
         TransformStack.PushAll();
     }
 }
Beispiel #6
0
        public void Clear(SolidBrush brush)
        {
            var rect = clipBounds ?? initialClip;

            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(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, bounds);
                Control.Pop();

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