protected override BitmapSource RenderFrame(DataRect dataRect, Rect output)
        {
            Grid grid = new Grid();
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
            TextBlock lt = new TextBlock
            {
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                Text = String.Format("({0},{1})", dataRect.XMin, dataRect.YMax)
            };
            grid.Children.Add(lt);
            Grid.SetRow(lt, 0);
            TextBlock rb = new TextBlock
            {
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Right,
                Text = String.Format("({0},{1})", dataRect.XMax, dataRect.YMin)
            };
            grid.Children.Add(rb);
            Grid.SetRow(rb, 1);
            Border border = new Border();
            border.BorderThickness = new Thickness(3);
            border.BorderBrush = Brushes.Blue;
            border.Child = grid;

            RenderTargetBitmap rtb = new RenderTargetBitmap((int)output.Width, (int)output.Height, 96, 96, PixelFormats.Default);
            border.Measure(new Size(output.Width, output.Height));
            border.Arrange(output);
            rtb.Render(border);

            Thread.Sleep(1000);

            return rtb;
        }
Exemple #2
0
        public void BorderHitTestTest()
        {
            Border border = new Border
            {
                Width = 200,
                Height = 100,
                BorderThickness = new Thickness(10, 20, 30, 40),
                IsRootElement = true,
            };

            border.Measure(Size.Infinity);
            border.Arrange(new Rect(border.DesiredSize));

            BackgroundHitTestTest(border, null);
            BorderHitTestTest(border, null);

            border.Background = Brushes.Transparent;
            border.BorderBrush = null;

            BackgroundHitTestTest(border, border);
            BorderHitTestTest(border, border);

            border.Background = null;
            border.BorderBrush = Brushes.Transparent;

            BackgroundHitTestTest(border, null);
            BorderHitTestTest(border, border);

            border.Background = Brushes.Transparent;
            border.BorderBrush = Brushes.Transparent;

            BackgroundHitTestTest(border, border);
            BorderHitTestTest(border, border);
        }
        public override DocumentPage GetPage(int pageNumber)
        {
            var page = _pages[pageNumber];

            var container = new Border();
            container.Padding = _margin;
            container.Child = page;
            container.Measure(PageSize);
            container.Arrange(new Rect(PageSize));

            return new DocumentPage(container);
        }
        public static BitmapSource GetThumbnailImage(this BitmapSource source, double percent, double dpiX, double dpiY)
        {
            double width = source.PixelWidth, height = source.PixelHeight;

            Algorithm.Math.ToPercentSize(percent, ref width, ref height);

            RenderTargetBitmap bmp = new RenderTargetBitmap((int)width, (int)height,
                dpiX, dpiY, PixelFormats.Pbgra32);
            Border image = new Border();
            image.RenderSize = new Size(width, height);
            image.Background = new ImageBrush(source);
            image.Measure(new Size(width, height));
            image.Arrange(new Rect(new Size(width, height)));
            bmp.Render(image);

            return BitmapFrame.Create(bmp);
        }
Exemple #5
0
        public void MouseDeviceButtonTest()
        {
            Border element = new Border { Background = Brushes.Transparent, Width = 100, Height = 100, IsRootElement = true };
            element.Measure(Size.Infinity);
            element.Arrange(new Rect(element.DesiredSize));

            int eventIndex = 0;
            int previewMouseDownIndex = 0;
            int previewMouseUpIndex = 0;
            int mouseDownIndex = 0;
            int mouseUpIndex = 0;

            element.PreviewMouseDown += (sender, e) => previewMouseDownIndex = ++eventIndex;
            element.PreviewMouseUp += (sender, e) => previewMouseUpIndex = ++eventIndex;
            element.MouseDown += (sender, e) => mouseDownIndex = ++eventIndex;
            element.MouseUp += (sender, e) => mouseUpIndex = ++eventIndex;

            TestPresentationSource presentationSource = new TestPresentationSource();
            presentationSource.RootElement = element;

            MouseDevice mouseDevice = new MouseDevice(presentationSource);

            mouseDevice.Activate();

            mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Pressed, new Point(10, 10), 0));
            Assert.AreEqual(MouseButtonState.Pressed, mouseDevice.GetButtonState(MouseButton.Left));
            Assert.AreEqual(1, previewMouseDownIndex);
            Assert.AreEqual(2, mouseDownIndex);

            mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Released, new Point(10, 10), 0));
            Assert.AreEqual(MouseButtonState.Released, mouseDevice.GetButtonState(MouseButton.Left));
            Assert.AreEqual(3, previewMouseUpIndex);
            Assert.AreEqual(4, mouseUpIndex);

            mouseDevice.ProcessRawEvent(new RawMouseButtonEventArgs(MouseButton.Left, MouseButtonState.Pressed, new Point(10, 10), 0));
            Assert.AreEqual(MouseButtonState.Pressed, mouseDevice.GetButtonState(MouseButton.Left));
            Assert.AreEqual(5, previewMouseDownIndex);
            Assert.AreEqual(6, mouseDownIndex);

            mouseDevice.Deactivate();
            Assert.AreEqual(MouseButtonState.Released, mouseDevice.GetButtonState(MouseButton.Left));
            Assert.AreEqual(7, previewMouseUpIndex);
            Assert.AreEqual(8, mouseUpIndex);
        }
Exemple #6
0
		public void MeasureRectangleBorderTest1_1 ()
		{
			// This is the same as the above test but has
			Border b = new Border ();
			Path p = new Path ();
			b.Child = p;
			p.Fill = new SolidColorBrush (Colors.Black);
			RectangleGeometry r = new RectangleGeometry ();
			r.Rect = new Rect (10, 10, 20, 20);
			p.Data = r;

			b.Measure (new Size (50, 50));
			b.Arrange (new Rect (0, 0, 50, 50));

			Assert.AreEqual (new Size (30,30), b.DesiredSize, "b desired");
			Assert.AreEqual (new Size (30,30), p.DesiredSize, "p desired");
			Assert.AreEqual (new Size (50,50), b.RenderSize, "b RenderSize");
			Assert.AreEqual (new Size (50,50), p.RenderSize, "p RenderSize");
		}
Exemple #7
0
		public void MeasureRectangleBorderTest1 ()
		{
			// See 1_1 1_2 for demonstation of this as a measure invalidation bug.
			Border b = new Border ();
			Path p = new Path ();
			p.Fill = new SolidColorBrush (Colors.Black);
			RectangleGeometry r = new RectangleGeometry ();
			r.Rect = new Rect (10, 10, 20, 20);
			p.Data = r;
			b.Child = p;

			b.Measure (new Size (50, 50));
			b.Arrange (new Rect (0, 0, 50, 50));

			Assert.AreEqual (new Size (0,0), b.DesiredSize, "b desired");
			Assert.AreEqual (new Size (50,50), b.RenderSize, "b RenderSize");
			Assert.AreEqual (new Size (0,0), p.DesiredSize, "p DesiredSize");
			Assert.AreEqual (new Size (50,50), p.RenderSize, "p RenderSize");
		}
Exemple #8
0
        public void BorderRenderTest()
        {
            Brush backgroundBrush = new LinearGradientBrush(30, Colors.Blue, Colors.Green);
            Brush borderBrush = new LinearGradientBrush(-30, Colors.Red, Colors.Blue);
            Thickness borderThickness = new Thickness(10, 20, 30, 40);

            Border border = new Border
            {
                Child = new FrameworkElement { Width = 200, Height = 100 },
                Background = backgroundBrush,
                BorderBrush = borderBrush,
                BorderThickness = borderThickness,
            };

            border.Measure(Size.Infinity);
            border.Arrange(new Rect(border.DesiredSize));

            IRenderElementFactory factory = TestRenderElementFactory.Default;

            border.GetRenderElement(factory);

            Assert.AreEqual(new Rect(240, 160), border.GetRenderElement(factory).Bounds);

            Assert.AreEqual(2, border.GetRenderElement(factory).Children.Count());

            IBorderRenderElement borderRenderElement = border.GetRenderElement(factory).Children.ElementAt(0) as IBorderRenderElement;
            Assert.IsNotNull(borderRenderElement);
            Assert.AreEqual(backgroundBrush, borderRenderElement.Background);
            Assert.AreEqual(borderBrush, borderRenderElement.BorderBrush);
            Assert.AreEqual(borderThickness, borderRenderElement.BorderThickness);
            Assert.AreEqual(new Rect(240, 160), borderRenderElement.Bounds);

            IVisualRenderElement visualRenderElement = border.GetRenderElement(factory).Children.ElementAt(1) as IVisualRenderElement;
            Assert.IsNotNull(visualRenderElement);
            Assert.AreEqual(new Rect(10, 20, 200, 100), visualRenderElement.Bounds);

            border.Child = null;
            Assert.AreEqual(1, border.GetRenderElement(factory).Children.Count());
        }
        // Assumes that the bitmapcontext is active
        private void drawHeaderForBox(WriteableBitmap bitmap, int x, int y, int width, String text)
        {
            const int BOX_HEIGHT = 40;
            const int BOX_WIDTH = 120;

            TranslateTransform transform = new TranslateTransform();
            transform.X = x + (width - BOX_WIDTH) / 2;
            transform.Y = y;

            Border border = new Border();
            border.Height = BOX_HEIGHT;
            border.Width = BOX_WIDTH;
            border.Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0));

            TextBlock textBlock = new TextBlock();
            textBlock.FontSize = 36;
            textBlock.TextAlignment = TextAlignment.Center;
            textBlock.Foreground = new SolidColorBrush(Colors.White);
            textBlock.Text = text;

            border.Child = textBlock;
            border.Arrange(new Rect(0.0, 0.0, border.Width, border.Height));
            border.UpdateLayout();

            bitmap.Render(border, transform);
        }
        void UpdateShadow()
        {
            if (substance == null) return;
            if (style == null) return;

            Thread.Sleep(300);

            // Black material
            DiffuseMaterial material = new DiffuseMaterial(Brushes.Black);
            material.Freeze();

            // Create molecules
            ModelVisual3D container = new ModelVisual3D();
            foreach (Data.Molecule molecule in substance.Molecules)
            {
                foreach (Data.Atom atom in molecule.Atoms)
                {
                    if (style.ColorStyle.ColorScheme[atom.Element].Diffuse.A < 5) continue;
                    Sphere sphere = new Sphere();
                    sphere.Material = material;
                    sphere.Radius = Atom.GetAtomRadius(atom, style.GeometryStyle);
                    sphere.Center = atom.Position;
                    container.Children.Add(sphere);
                }
                double bondRadius = Bond.GetBondRadius(style.GeometryStyle);
                foreach (Data.Bond bond in molecule.Bonds)
                {
                    if (style.ColorStyle.UseSingleBondMaterial)
                    {
                        if (style.ColorStyle.BondMaterial.Diffuse.A < 5) continue;
                    }
                    else if (style.ColorStyle.ColorScheme[bond.Begin.Element].Diffuse.A < 5 ||
                             style.ColorStyle.ColorScheme[bond.End.Element].Diffuse.A < 5) continue;
                    Cylinder cylinder = new Cylinder(bond.Begin.Position, bond.End.Position, bondRadius);
                    cylinder.Material = material;
                    container.Children.Add(cylinder);
                }

                #region Build approximation of ribbon

                double radius = 0.45;
                foreach (Data.Chain chain in molecule.Chains)
                {
                    for (int i = 0; i < chain.Residues.Count; i++)
                    {
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Helix)
                           if (style.GeometryStyle.HelixHeight < 0.05 || style.GeometryStyle.HelixWidth < 0.05) continue;
                           else radius = Residue.HelixWidth * ((style.GeometryStyle.HelixHeight + style.GeometryStyle.HelixWidth) / 2.0);
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Sheet)
                           if (style.GeometryStyle.SheetHeight < 0.05 || style.GeometryStyle.SheetWidth < 0.05) continue;
                           else radius = Residue.SheetWidth * ((style.GeometryStyle.SheetHeight + style.GeometryStyle.SheetWidth) / 2.0);
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.NotDefined)
                           if (style.GeometryStyle.TurnHeight < 0.05 || style.GeometryStyle.TurnWidth < 0.05) continue;
                           else radius = Residue.TurnWidth * ((style.GeometryStyle.TurnHeight + style.GeometryStyle.TurnWidth) / 2.0);

                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Helix && style.ColorStyle.HelixMaterial.Diffuse.A < 5) continue;
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Sheet && style.ColorStyle.SheetMaterial.Diffuse.A < 5) continue;
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.NotDefined && style.ColorStyle.TurnMaterial.Diffuse.A < 5) continue;

                        Data.Atom alfaCarbon = chain.Residues[i].AlfaCarbon;
                        if (alfaCarbon != null)
                        {
                            Point3D begin = alfaCarbon.Position;
                            alfaCarbon = null;
                            for (int j = i + 1; j < chain.Residues.Count; j++)
                            {
                                alfaCarbon = chain.Residues[j].AlfaCarbon;
                                if (alfaCarbon != null) break;
                            }
                            if (alfaCarbon != null)
                            {
                                Point3D end = alfaCarbon.Position;
                                Cylinder cylinder = new Cylinder(begin, end, radius);
                                container.Children.Add(cylinder);
                            }
                        }
                    }
                }

                #endregion
            }

            // Get bounding box
            Rect3D boundingBox = VisualTreeHelper.GetDescendantBounds(container);
            if (boundingBox.IsEmpty)
            {
                shadowRefreshStarted = false;
                return;
            }

            #region Render Shadow

            const double blurSize = 25;
            const int renderTargetWidth = 200;
            int renderTargetHeight = (int)(200.0 * (boundingBox.SizeX / boundingBox.SizeY));
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(renderTargetWidth, renderTargetHeight, 96, 96, PixelFormats.Pbgra32);

            Viewport3D shadowViewport3D = new Viewport3D();
            Border border = new Border();
            border.Padding = new Thickness(blurSize);
            border.Child = shadowViewport3D;

            // Change size of the visualizer
            border.Width = renderTargetBitmap.PixelWidth;
            border.Height = renderTargetBitmap.PixelHeight;
            border.Measure(new Size(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight));
            border.Arrange(new Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight));

            shadowViewport3D.Children.Add(container);

            // Create camera
            OrthographicCamera orthographicCamera = new OrthographicCamera();

            #region Accomodate camera to fit content

            orthographicCamera.Position = new Point3D(boundingBox.Location.X + boundingBox.SizeX / 2.0,
                                                      boundingBox.Location.Y,
                                                      boundingBox.Location.Z + boundingBox.SizeZ / 2.0);
            orthographicCamera.LookDirection = new Vector3D(0, 1, 0);
            orthographicCamera.UpDirection = new Vector3D(-1, 0, 0);
            orthographicCamera.Width = boundingBox.SizeZ;

            #endregion

            orthographicCamera.NearPlaneDistance = 0;

            // Set the camera & correct lights
            shadowViewport3D.Camera = orthographicCamera;

            BlurEffect blurEffect = new BlurEffect();
            blurEffect.Radius = blurSize;

            border.Effect = blurEffect;

            renderTargetBitmap.Render(border);
            renderTargetBitmap.Freeze();

            #endregion

            // Invoke in main thread
            Dispatcher.BeginInvoke((Action) delegate
            {
                #region Create Plane

                Vector3D margin = new Vector3D(boundingBox.SizeX * 0.4, 0, boundingBox.SizeZ * 0.4);
                Point3D[] points = new Point3D[]
                {
                    boundingBox.Location + new Vector3D(-margin.X, -margin.Y, -margin.Z),
                    boundingBox.Location +
                    new Vector3D(margin.X + boundingBox.SizeX, -margin.Y, -margin.Z),
                    boundingBox.Location +
                    new Vector3D(margin.X + boundingBox.SizeX, -margin.Y,
                                margin.Z + boundingBox.SizeZ),
                    boundingBox.Location +
                    new Vector3D(-margin.X, -margin.Y, margin.Z + boundingBox.SizeZ)
                };

                Polygon shadowPlane = new Polygon();
                shadowPlane.Positions = points;
                shadowPlane.TextureCoordinates = new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) };

                #endregion
                shadowBrush.ImageSource = renderTargetBitmap;
                shadowBrush.Stretch = Stretch.Fill;
                shadowTargetOpacity = 0.8;

                shadowPlane.Material = new DiffuseMaterial(shadowBrush);
                shadowContainer.Children.Clear();
                shadowContainer.Children.Add(shadowPlane);

                // Update shadow hash
                shadowRefreshStarted = false;

              }, DispatcherPriority.SystemIdle);
        }
Exemple #11
0
		public void Arrange_Rounding()
		{
			Border b = new Border ();
			var path = new Path ();
			//var canvas = new Canvas ();
			b.Child = path;
			//canvas.Children.Add (b);
			RectangleGeometry r = new RectangleGeometry ();
			r.Rect = new Rect (10, 10, 80.1, .2);
			path.Data = r;
			
			path.Width = 20;
			path.Height = 20;
			path.Fill = new SolidColorBrush (Colors.Red);

			b.Measure (new Size (120, 120));
			Assert.IsTrue (path.UseLayoutRounding, "path rounds?");
			Assert.AreEqual (new Size (20,20), path.DesiredSize, "desired");
			Assert.AreEqual (new Size (0,0), path.RenderSize, "render");
			Assert.AreEqual (0, path.ActualWidth);
			Assert.AreEqual (0, path.ActualHeight);

			b.Arrange (new Rect (0, 0, 120, 120));

			Assert.AreEqual (new Size (20,20), path.DesiredSize, "desired");
			Assert.AreEqual (new Size (90,20), path.RenderSize, "render");
			Assert.AreEqual (90, path.ActualWidth);
			Assert.AreEqual (20, path.ActualHeight);
		}
Exemple #12
0
		public void ArrangeTest8 ()
		{
			Canvas c = new Canvas ();
			Border b = new Border ();
			var path = new Path ();
			b.Child = c;
			c.Children.Add (path);
			RectangleGeometry r = new RectangleGeometry ();
			r.Rect = new Rect (10, 10, 80, 90);
			path.Data = r;
			b.Width = 20;
			b.Height = 20;
			path.Fill = new SolidColorBrush (Colors.Red);

			b.Measure (new Size (120, 120));
			b.Arrange (new Rect (0, 0, 120, 120));

			Assert.AreEqual (new Size (20,20), b.DesiredSize, "b desired");
			Assert.AreEqual (new Size (20,20), b.RenderSize, "b rendersize");
			Assert.AreEqual (new Size (20,20), new Size (b.ActualHeight,b.ActualHeight), "b actual");
			Assert.AreEqual (new Size (0,0), path.DesiredSize, "path desired");
			Assert.AreEqual (new Size (0,0), path.RenderSize, "path. render");
			Assert.AreEqual (new Size (0,0), new Size (path.ActualWidth, path.ActualHeight), "path actual");
		}
Exemple #13
0
		public void BorderComputeLargerSize_StretchUniformToFill_IntrinsicBorderSized ()
		{
			Border b = new Border ();
			var c = new Path ();
			b.Child = c;
			c.Stretch = Stretch.UniformToFill;
			b.Width = 75;
			b.Height = 66;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired0");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual0");

			var data = new RectangleGeometry ();
			data.Rect = new Rect (0,10,25,23);
			c.Data = data;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired1");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot");

			b.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (75,66), c.DesiredSize, "c desired2");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual2");
			Assert.AreEqual (new Size (0,0), c.RenderSize, "c render2");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot2");

			b.Arrange (new Rect (8,6,b.DesiredSize.Width,b.DesiredSize.Height));

			Assert.AreEqual (new Size (75,66), c.DesiredSize, "c desired3");
			Assert.AreEqual (new Size (75,69), new Size (c.ActualWidth,c.ActualHeight), "c actual3");
			Assert.AreEqual (new Size (75,69), c.RenderSize, "c render3");
			Assert.AreEqual (new Rect (0,0,75,66), LayoutInformation.GetLayoutSlot (c), "c slot3");
		}
Exemple #14
0
		public void LayoutMarginTest ()
		{
			Border b = new Border ();
			var stack = new StackPanel ();
			stack.Children.Add (CreateSlotItem ());
			stack.Children.Add (CreateSlotItem ());
			stack.Children.Add (CreateSlotItem ());
			stack.HorizontalAlignment = HorizontalAlignment.Right;
			b.Width = 50;
			b.Child = stack;
			stack.Margin = new Thickness (10,20,0,0);
			
			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));
			
			Assert.AreEqual (new Rect (0,0,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString ());
			Assert.AreEqual (new Rect (0,33,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString ());
			Assert.AreEqual (new Rect (0,66,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString ());
			Assert.AreEqual (new Rect (0,0,50,119).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString (), "stack");
			Assert.AreEqual (new Rect (0,0,50,119).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString (), "border");
			
			Assert.AreEqual (new Size (50,119),b.DesiredSize);
			Assert.AreEqual (new Size (35,119),stack.DesiredSize);
		}
Exemple #15
0
		public void LayoutSlotTest4InTree ()
		{
			Border b = new Border ();
			var stack = new StackPanel ();

			var panel = new Grid ();
			panel.Children.Add (b);

			panel.Background = new SolidColorBrush (Colors.Green);

			stack.Children.Add (CreateSlotItem ());
			stack.Children.Add (CreateSlotItem ());
  			stack.Children.Add (CreateSlotItem ());
			stack.HorizontalAlignment = HorizontalAlignment.Right;
			b.Width = 50;
			b.Child = stack;

			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual");

			b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));
			
			Assert.AreEqual (new Rect (0,0,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0");
			Assert.AreEqual (new Rect (0,33,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1");
			Assert.AreEqual (new Rect (0,66,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2");
			Assert.AreEqual (new Rect (0,0,50,99).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString ());
			Assert.AreEqual (new Rect (0,0,50,99).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString ());
			
			Assert.AreEqual (new Size (50,99),b.DesiredSize);
			Assert.AreEqual (new Size (25,99),stack.DesiredSize);
			Assert.AreEqual (new Size (25,99), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual");

			TestPanel.Children.Add (panel);
			Assert.AreEqual (new Size (0,0),b.DesiredSize);
			Assert.AreEqual (new Size (0,0),stack.DesiredSize);

			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			Assert.AreEqual (new Size (0,0), new Size (stack.ActualWidth, stack.ActualHeight), "stack actual");
			b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));

			Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0 in tree");
			Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1 in tree");
			Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2 in tree");
			Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString ());
			Assert.AreEqual (new Rect (0,0,0,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString ());
			Assert.AreEqual (new Size (50,99),b.DesiredSize);
			Assert.AreEqual (new Size (25,99),stack.DesiredSize);
			TestPanel.Children.Remove (panel);

			CreateAsyncTest (panel, () => {
					Assert.AreEqual (new Rect (0,0,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "slot0");
					Assert.AreEqual (new Rect (0,33,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "slot1");
					Assert.AreEqual (new Rect (0,66,25,33).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "slot2");
					Assert.AreEqual (new Rect (0,0,50,TestPanel.ActualHeight).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString (), "slot3");
					Assert.AreEqual(new Rect(0, 0, TestPanel.ActualWidth, TestPanel.ActualHeight).ToString(), LayoutInformation.GetLayoutSlot((FrameworkElement)b).ToString(), "slot4");

					Assert.AreEqual (new Size (50,99),b.DesiredSize, "b desired async");
					Assert.AreEqual (new Size (25,99),stack.DesiredSize, "stack desired async");
				});
		}
Exemple #16
0
		public void BorderCallsLayoutTest ()
		{
			var parent = new Border ();
			LayoutPoker c = new LayoutPoker ();
			parent.Child = c;

			c.Width = 50;
			c.Height = 50;
			
			int measure_called = 0;
			int arrange_called = 0;
			c.Measured += (Size real) => { 
				c.MeasureResult = real; 
				measure_called++;
			};
			c.Arranged += (Size real) => {
				c.ArrangeResult = real;
				arrange_called++;
			};

			parent.Measure (new Size (100, 100));
			Assert.AreEqual (0, arrange_called, "arrange called 0");
			Assert.AreEqual (1, measure_called, "measure called 0");

			Assert.AreEqual (new Size (50,50), c.DesiredSize, "c desired");
			Assert.AreEqual (new Size (50,50), parent.DesiredSize, "parent desired");

			parent.Arrange (new Rect (0, 0, 100, 100));

			Assert.AreEqual (1, arrange_called, "arrange called 1");
			Assert.AreEqual (1, measure_called, "measure called 1");

			c.InvalidateMeasure ();
			c.InvalidateArrange ();
			parent.InvalidateArrange ();
			parent.InvalidateMeasure ();
			parent.Arrange (new Rect (0, 0, 100, 100));

			Assert.AreEqual (2, arrange_called, "arrange called 2");
			Assert.AreEqual (2, measure_called, "measure called 2");
		}
Exemple #17
0
		public void Measure_StretchFill_Test3 ()
		{
			Border b = new Border ();
		        Canvas c = (Canvas)XamlReader.Load (@"
<Canvas xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <Border Width=""50"" Height=""50"">
    <Path Width=""25"" Height=""25"" x:Name=""foo"" Stretch=""Fill"" Data=""F1 M 10,10 20,20 10,20"" StrokeLineJoin=""Round"" Stroke=""Red""/>
  </Border>
</Canvas>");
			b.Child = c;
			Path foo = (Path)c.FindName ("foo");

			b.Measure (new Size (300, 300));
			Assert.AreEqual (new Size (0,0), b.DesiredSize, "b desired0");
			Assert.AreEqual (new Size (25,25), foo.DesiredSize, "foo desired0");
			Assert.AreEqual (new Size (0,0), foo.RenderSize, "foo render0");

			b.Arrange (new Rect (10, 10, 300, 300));
			Assert.AreEqual (new Size (0,0), b.DesiredSize, "b desired1");

			Assert.AreEqual (new Size (25,25), foo.DesiredSize, "foo desired1");
			Assert.AreEqual (new Size (25,25), foo.RenderSize, "foo render1");
			Tester.WriteLine (String.Format ("foo.Actual ({0},{1})", foo.ActualWidth, foo.ActualHeight));
			Assert.AreEqual (new Size (25,25), new Size (foo.ActualWidth, foo.ActualHeight), "foo actual0");

			Border foo_parent = (Border)VisualTreeHelper.GetParent (foo);
			Assert.AreEqual (new Size (50,50), foo_parent.DesiredSize, "foo_parent desired1");
			Assert.AreEqual (new Size (50,50), foo_parent.RenderSize, "foo_parent render1");
			Tester.WriteLine (String.Format ("foo_parent.Actual ({0},{1})", foo_parent.ActualWidth, foo_parent.ActualHeight));
			Assert.AreEqual (new Size (50,50), new Size (foo_parent.ActualWidth, foo_parent.ActualHeight), "foo_parent actual1");
			
		}
Exemple #18
0
		public void Measure_StretchFill_Test2 ()
		{
			Border b = new Border ();
		        Canvas c = (Canvas)XamlReader.Load (@"
<Canvas xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
  <Path x:Name=""bar"" Width=""50"" Height=""50"" Stretch=""Fill"" Data=""F1 M 10,10 20,20 10,20"" StrokeLineJoin=""Round"" Stroke=""Blue""/>
</Canvas>");

			b.Child = c;
			Path bar = (Path)c.FindName ("bar");

			b.InvalidateMeasure ();
			b.Measure (new Size (300, 300));
			Assert.AreEqual (new Size (0,0), b.DesiredSize, "b desired0");
			Assert.AreEqual (new Size (0,0), bar.DesiredSize, "bar desired0");
			Assert.AreEqual (new Size (0,0), bar.RenderSize, "bar render0");

			Assert.AreEqual (new Size (50,50), new Size (bar.ActualWidth, bar.ActualHeight), "bar actual1");

			b.Arrange (new Rect (10, 10, 300, 300));
			Assert.AreEqual (new Size (0,0), b.DesiredSize, "b desired1");
			Assert.AreEqual (new Size (0,0), bar.DesiredSize, "bar desired1");
			Assert.AreEqual (new Size (0,0), bar.RenderSize, "bar render1");

			Assert.AreEqual (new Size (50,50), new Size (bar.ActualWidth, bar.ActualHeight), "bar actual1");
		}
Exemple #19
0
		public void MeasureRectangleBorderTest1_2 ()
		{
			// See test 1_1 and 1 for more information
			Border b = new Border ();
			Path p = new Path ();
			p.Fill = new SolidColorBrush (Colors.Black);
			RectangleGeometry r = new RectangleGeometry ();
			r.Rect = new Rect (10, 10, 20, 20);
			p.Data = r;
			b.Child = p;

			p.InvalidateMeasure ();
			b.Measure (new Size (50, 50));
			b.Arrange (new Rect (0, 0, 50, 50));

			Assert.AreEqual (new Size (30,30), b.DesiredSize, "b desired");
			Assert.AreEqual (new Size (30,30), p.DesiredSize, "p DesiredSize");
			Assert.AreEqual (new Size (50,50), b.RenderSize, "b RenderSize");
			Assert.AreEqual (new Size (50,50), p.RenderSize, "p RenderSize");
		}
Exemple #20
0
		public void BorderComputeLargerSize_StretchUniformToFill_AlignCenter_IntrinsicBorderSized ()
		{
			Border b = new Border ();
			var c = new Path ();
			b.Child = c;
			c.Stretch = Stretch.UniformToFill;
			b.Width = 75;
			c.VerticalAlignment = VerticalAlignment.Center;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired0");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual0");

			var data = new RectangleGeometry ();
			data.Rect = new Rect (0,10,25,23);
			c.Data = data;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired1");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot");

			b.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (75,100), c.DesiredSize, "c desired2");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual2");
			Assert.AreEqual (new Size (0,0), c.RenderSize, "c render2");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot2");

			b.Arrange (new Rect (8,6,b.DesiredSize.Width,b.DesiredSize.Height));

			Assert.AreEqual (new Size (75,100), c.DesiredSize, "c desired3");
			Assert.AreEqual (109, c.ActualWidth, "c.ActualWidth");
			Assert.IsTrue (c.RenderSize.Height < 100.3 && c.RenderSize.Height > 100.2, "c.renderSize.Height = "+ c.RenderSize.Height.ToString ());
			Assert.IsTrue (c.ActualHeight < 100.3 && c.ActualHeight > 100.2, "c.ActualHeight = "+ c.ActualHeight.ToString ());

			Assert.AreEqual (109, c.RenderSize.Width, "c.RenderSize.Width");
			Assert.AreEqual (new Rect (0,0,75,100), LayoutInformation.GetLayoutSlot (c), "c slot3");
		}
Exemple #21
0
		public void ArrangeTooLongLineTest ()
		{
			Border b = new Border ();
			TextBlock tb = new TextBlock ();
			tb.Text = "Hello and don't you forget Who I am";
			
			b.Child = tb;
			b.Width = 44;
			
			Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "1. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
			Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "1. line count based on textblock.ActualHeight");
			//Assert.IsTrue (tb.ActualWidth < 202.4 && tb.ActualWidth > 202.3, "1. tb.ActualWidth is " + tb.ActualWidth.ToString ());
			//Assert.AreEqual (16, tb.ActualHeight, "1. tb.ActualHeight");

			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			
			Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "2. textblock.ActualWidth is " + tb.ActualWidth.ToString ());
			Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "2. line count based on textblock.ActualHeight");
			Assert.AreEqual (1, GetLineCount (tb.DesiredSize.Height), "2. line count based on textblock.DesiredSize");
			Assert.AreEqual (1, GetLineCount (b.DesiredSize.Height), "2. line count based on border.DesiredSize");
			//Assert.AreEqual (new Size (44,16), tb.DesiredSize, "2. tb.DesiredSize");
			//Assert.AreEqual (new Size (44,16), b.DesiredSize, "2. b.DesiredSize");
			//Assert.IsTrue (tb.ActualWidth < 202.4 && tb.ActualWidth > 202.3, "2. tb.ActualWidth is " + tb.ActualWidth.ToString ());
			//Assert.AreEqual (16, tb.ActualHeight, "2. tb.ActualHeight");

			b.Arrange (new Rect (0,0, b.DesiredSize.Width, b.DesiredSize.Height));
			
			Assert.IsTrue (tb.ActualWidth > 192.8 && tb.ActualWidth < 202.4, "3. tb.ActualWidth is " + tb.ActualWidth.ToString ());
			Assert.AreEqual (1, GetLineCount (tb.ActualHeight), "3. line count based on textblock.ActualHeight");
			Assert.AreEqual (1, GetLineCount (tb.DesiredSize.Height), "3. line count based on textblock.DesiredSize");
			Assert.AreEqual (1, GetLineCount (b.ActualHeight), "3. line count based on border.ActualHeight");
			Assert.AreEqual (1, GetLineCount (b.DesiredSize.Height), "3. line count based on border.DesiredSize");
			//Assert.AreEqual (new Size (44,16), tb.DesiredSize, "3. tb.DesiredSize");
			//Assert.AreEqual (new Size (44,16), b.DesiredSize, "3. b.DesiredSize");
			//Assert.IsTrue (tb.ActualWidth > 202.3 && tb.ActualWidth < 202.4,"3. tb.ActualWidth is " + tb.ActualWidth.ToString ());
			//Assert.AreEqual (16, tb.ActualHeight, "3. tb.ActualHeight");
			//Assert.AreEqual (new Size (44,16), new Size (b.ActualWidth, b.ActualHeight), "3. b.Actual*");
		}
Exemple #22
0
		public void LayoutSlotTest2 ()
		{
			Border b = new Border ();
			var stack = new StackPanel ();
			stack.Children.Add (CreateSlotItem ());
			stack.Children.Add (CreateSlotItem ());
			stack.Children.Add (CreateSlotItem ());
			b.Width = 50;
			b.Height = 300;
			b.Child = stack;

			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));
			
			Assert.AreEqual (new Rect (0,0,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]));
			Assert.AreEqual (new Rect (0,33,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]));
			Assert.AreEqual (new Rect (0,66,50,33), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]));
			
			Assert.AreEqual (new Size (50,300),b.DesiredSize);
			Assert.AreEqual (new Size (50,300),b.RenderSize);
			
		}
        public static FrameworkElement GetRendreable(IconVm iconVm, ImageSource sourceIcon, Color color)
        {
            var border = new Border()
            {
                Background = new SolidColorBrush(color),
                Width = iconVm.Width,
                Height = iconVm.Height
            };
            var image = new Image()
            {
                Stretch = Stretch.Uniform,
                Source = sourceIcon,
                Width = iconVm.ImageWidth,
                Height = iconVm.ImageHeight,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };


            border.Child = image;

            border.Measure(new Size(border.Width, border.Height));
            border.Arrange(new Rect(new Size(border.Width, border.Height)));
            border.UpdateLayout();
            return border;
        }
Exemple #24
0
		public void AlignmentTest3 ()
		{
			Border b = new Border ();
			var stack = new StackPanel ();
			stack.Children.Add (new Border ());
			stack.Children.Add (new Border ());
			stack.Children.Add (new Border ());
			stack.HorizontalAlignment = HorizontalAlignment.Right;
			b.Width = 50;
			stack.Width = 50;
			b.Child = stack;

			b.Measure (new Size (Double.PositiveInfinity, Double.PositiveInfinity));
			b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));
			
			Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[0]).ToString (), "child 0");
			Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[1]).ToString (), "child 1");
			Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack.Children[2]).ToString (), "child 2");
			Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)stack).ToString (), "stack slot");
			Assert.AreEqual (new Rect (0,0,50,0).ToString (), LayoutInformation.GetLayoutSlot ((FrameworkElement)b).ToString (), "b slot");
			
			Assert.AreEqual (new Size (0,0), stack.Children[0].DesiredSize, "child 0 desired");
			Assert.AreEqual (new Size (50,0),b.DesiredSize, "b desired");
			Assert.AreEqual (new Size (50,0),stack.DesiredSize, "stack desired");
		}
        private void PrintWeekButtonPressed(object sender, RoutedEventArgs e)
        {

            var tDlg = new PrintDialog { PrintQueue = LocalPrintServer.GetDefaultPrintQueue() };
            tDlg.PrintTicket = tDlg.PrintQueue.DefaultPrintTicket;
            tDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;
            tDlg.PrintTicket.PageResolution = new PageResolution(2400, 2400);
            tDlg.PageRangeSelection = PageRangeSelection.AllPages;
            tDlg.UserPageRangeEnabled = true;

            if ((bool)tDlg.ShowDialog())
            {

                var tBut = sender as DependencyObject;
                var tPrintVis = tBut.GetParent<Grid>().GetChildren<RasteredGroup>().FirstOrDefault();

                var tCaps = tDlg.PrintQueue.GetPrintCapabilities(tDlg.PrintTicket);
                Debug.Assert(tCaps.PageImageableArea != null, "tCaps.PageImageableArea != null");
                if (tPrintVis != null)
                {
                    var scale = Math.Min(tCaps.PageImageableArea.ExtentWidth / tPrintVis.ActualWidth,
                                         tCaps.PageImageableArea.ExtentHeight / tPrintVis.ActualHeight);

                    var tBrush = new VisualBrush(tPrintVis);

                    var tGrid = new Border
                                    {
                                        Width = tPrintVis.ActualWidth,
                                        Height = tPrintVis.ActualHeight,
                                        HorizontalAlignment = HorizontalAlignment.Stretch,
                                        VerticalAlignment = VerticalAlignment.Stretch
                                    };

                    var tRect = new Rectangle
                                    {
                                        Margin = new Thickness(30.0D),
                                        //Width = tPrintVis.ActualWidth,
                                        //Height = tPrintVis.ActualHeight,
                                        HorizontalAlignment = HorizontalAlignment.Stretch,
                                        VerticalAlignment = VerticalAlignment.Stretch,
                                        Fill = tBrush
                                    };

                    tGrid.Child = tRect;
                    tGrid.LayoutTransform = new ScaleTransform(scale, scale);


                    var sz = new Size(tCaps.PageImageableArea.ExtentWidth, tCaps.PageImageableArea.ExtentHeight);
                    tGrid.Measure(sz);
                    tGrid.Arrange(new Rect(new Point(tCaps.PageImageableArea.OriginWidth, tCaps.PageImageableArea.OriginHeight), sz));

                    try
                    {
                        tDlg.PrintVisual(tGrid, "HAW Stundenplan Tool Wochenausdruck");
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(String.Format("Beim Drucken trat ein Fehler auf: {0}", exp.Message), "Drucken", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Exemple #26
0
		public void ChildlessArrangeTest5 ()
		{
			Border b = new Border ();
			LayoutPoker c = new LayoutPoker ();
			Size s = new Size (10,10);
			
			b.Padding = new Thickness (1,1,0,0);
			b.Child = c;
			b.Measure (s);

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c DesiredSize");
			Assert.AreEqual (new Size (9,9), c.MeasureArg, "c measure args");
			Assert.AreEqual (new Size (1,1), b.DesiredSize, "b DesiredSize");
			Assert.AreEqual (0,b.ActualWidth);
			Assert.AreEqual (0,b.ActualHeight);
			Assert.AreEqual (0,c.ActualWidth);
			Assert.AreEqual (0,c.ActualHeight);
			
			c.ArrangeResult = new Size (9,9);
			b.Arrange (new Rect (0,0,10,10));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c DesiredSize");
			Assert.AreEqual (new Size (9,9), c.RenderSize, "c render size");
			Assert.AreEqual (new Size (9,9), c.ArrangeArg, "c measure args");
			Assert.AreEqual (new Size (1,1), b.DesiredSize, "b DesiredSize");
			Assert.AreEqual (new Size (10,10), b.RenderSize, "b render size");
			Assert.AreEqual (10,b.ActualWidth);
			Assert.AreEqual (10,b.ActualHeight);
			Assert.AreEqual (9,c.ActualWidth);
			Assert.AreEqual (9,c.ActualHeight);
		}
Exemple #27
0
		public void BorderComputeLargerSize_StretchUniform_SizedIntrinsicBorder ()
		{
			Border b = new Border ();
			var c = new Path ();
			b.Child = c;
			c.Stretch = Stretch.Uniform;
			b.Width = 75;
			b.Height = 50;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired0");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual0");
			
			var data = new RectangleGeometry ();
			data.Rect = new Rect (0,10,25,23);
			c.Data = data;

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c desired1");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual1");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot");

			b.Measure (new Size (100, 100));

			Assert.AreEqual (new Size (54,50), c.DesiredSize, "c desired2");
			Assert.AreEqual (new Size (0,0), new Size (c.ActualWidth,c.ActualHeight), "c actual2");
			Assert.AreEqual (new Size (0,0), c.RenderSize, "c render2");
			Assert.AreEqual (new Rect (0,0,0,0), LayoutInformation.GetLayoutSlot (c), "c slot2");

			b.Arrange (new Rect (8,6,b.DesiredSize.Width,b.DesiredSize.Height));

			Assert.AreEqual (new Size (54,50), c.DesiredSize, "c desired3");
			Assert.IsTrue (c.ActualWidth < 54.4 && c.ActualWidth > 54.3, "c.ActualWidth == " + c.ActualWidth.ToString ());
			Assert.AreEqual (50, c.ActualHeight, "c actual.height");
			Assert.IsTrue (c.RenderSize.Width < 54.4 && c.RenderSize.Width > 54.3, "c.RenderSize.Width = " + c.RenderSize.Width.ToString ());
			Assert.AreEqual (50, c.RenderSize.Height, "c render.height");
			Assert.AreEqual (new Rect (0,0,75,50), LayoutInformation.GetLayoutSlot (c), "c slot2");
		}
Exemple #28
0
		public void ExpandInArrange_OutsideTree_BorderParent_FixedSize ()
		{
			// We always expand star rows if we're not in the live tree
			var parent = new Border ();

			// Measure with infinity and check results.
			MyGrid grid = new MyGrid { Width = 200, Height = 200 };
			grid.AddRows (Star);
			grid.AddColumns (Star);
			grid.AddChild (ContentControlWithChild (), 0, 0, 1, 1);

			parent.Child = grid;
			parent.InvalidateSubtree ();

			parent.Measure (Infinity);
			grid.CheckMeasureArgs ("#1", new Size (200, 200));
			grid.CheckMeasureResult ("#2", new Size (50, 50));
			Assert.AreEqual (new Size (200, 200), grid.DesiredSize, "#3");

			// When we pass in the desired size as the arrange arg,
			// the rows/cols use that as their height/width
			parent.Arrange (new Rect (0, 0, 1000, 10000));
			grid.CheckArrangeArgs ("#4", grid.DesiredSize);
			grid.CheckArrangeResult ("#5", grid.DesiredSize);
			grid.CheckRowHeights ("#6", grid.DesiredSize.Height);
			grid.CheckColWidths ("#7", grid.DesiredSize.Width);

			// If we pass in twice the desired size, the rows/cols consume that too
			grid.Reset ();
			parent.Arrange (new Rect (0, 0, 5, 5));
			grid.CheckMeasureArgs ("#8"); // No re-measuring
			grid.CheckArrangeArgs ("#9"); // No re-arranging
			grid.CheckArrangeResult ("#10");
			grid.CheckRowHeights ("#11", 200);
			grid.CheckColWidths ("#12", 200);

			// If we measure with a finite size, the rows/cols still expand
			// to consume the available space
			grid.Reset ();
			parent.InvalidateSubtree ();
			parent.Measure (new Size (1000, 1000));
			grid.CheckMeasureArgs ("#13", new Size (200, 200));
			grid.CheckMeasureResult ("#14", new Size (50, 50));
			Assert.AreEqual (new Size (200, 200), grid.DesiredSize, "#15");

			// When we pass in the desired size as the arrange arg,
			// the rows/cols use that as their height/width
			parent.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height));
			grid.CheckArrangeArgs ("#16", grid.DesiredSize);
			grid.CheckArrangeResult ("#17", grid.DesiredSize);
			grid.CheckRowHeights ("#18", grid.DesiredSize.Height);
			grid.CheckColWidths ("#19", grid.DesiredSize.Width);
		}
Exemple #29
0
		public void InvalidateArrangeTest ()
		{
			Border b = new Border ();
			LayoutPoker c = new LayoutPoker ();
			Size s = new Size (10,10);
			
			b.Padding = new Thickness (1,1,0,0);
			b.Child = c;
			b.Measure (s);

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c DesiredSize");
			Assert.AreEqual (new Size (9,9), c.MeasureArg, "c measure args");
			Assert.AreEqual (new Size (1,1), b.DesiredSize, "b DesiredSize");
			Assert.AreEqual (0,b.ActualWidth);
			Assert.AreEqual (0,b.ActualHeight);
			Assert.AreEqual (0,c.ActualWidth);
			Assert.AreEqual (0,c.ActualHeight);
			
			c.ArrangeResult = new Size (20,20);
			b.Arrange (new Rect (0,0,10,10));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c DesiredSize");
			Assert.AreEqual (new Size (20,20), c.RenderSize, "c render size");
			Assert.AreEqual (new Size (9,9), c.ArrangeArg, "c measure args");
			Assert.AreEqual (new Size (1,1), b.DesiredSize, "b DesiredSize");
			Assert.AreEqual (new Size (10,10), b.RenderSize, "b render size");
			Assert.AreEqual (new Size (10,10), new Size (b.ActualWidth, b.ActualHeight),"b actual");
			Assert.AreEqual (new Size (20,20), new Size (c.ActualWidth, c.ActualHeight), "c actual");

			c.ArrangeResult = new Size (9,9);
			b.Arrange (new Rect (0,0,10,10));

			// Does not invalidate child
			b.InvalidateArrange ();

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c DesiredSize");
			Assert.AreEqual (new Size (20,20), c.RenderSize, "c render size");
			Assert.AreEqual (new Size (9,9), c.ArrangeArg, "c measure args");
			Assert.AreEqual (new Size (1,1), b.DesiredSize, "b DesiredSize");
			Assert.AreEqual (new Size (10,10), b.RenderSize, "b render size");
			Assert.AreEqual (new Size (10,10), new Size (b.ActualWidth, b.ActualHeight),"b actual1");
			Assert.AreEqual (new Size (20,20), new Size (c.ActualWidth, c.ActualHeight), "c actual1");

			c.InvalidateArrange ();
			b.Arrange (new Rect (0,0,10,10));

			Assert.AreEqual (new Size (0,0), c.DesiredSize, "c DesiredSize");
			Assert.AreEqual (new Size (9,9), c.RenderSize, "c render size");
			Assert.AreEqual (new Size (9,9), c.ArrangeArg, "c measure args");
			Assert.AreEqual (new Size (1,1), b.DesiredSize, "b DesiredSize");
			Assert.AreEqual (new Size (10,10), b.RenderSize, "b render size");
			Assert.AreEqual (new Size (10,10), new Size (b.ActualWidth, b.ActualHeight),"b actual2");
			Assert.AreEqual (new Size (9,9), new Size (c.ActualWidth, c.ActualHeight), "c actual2");
		}
Exemple #30
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     border.Arrange(new Rect(finalSize));
     return(finalSize);
 }
Exemple #31
0
		public void AlignmentTest ()
		{
			Border b = new Border ();
			Border b2 = new Border ();
			LayoutPoker poker = new LayoutPoker ();

			b.Child = b2;
			b2.Child = poker;
			b.Width = 50;
			
			b2.HorizontalAlignment = HorizontalAlignment.Right;
			b2.VerticalAlignment = VerticalAlignment.Bottom;

			poker.MeasureResult = new Size (20,20);
			b.Measure (new Size (100,100));

			Assert.AreEqual (new Size (50,100), poker.MeasureArg, "poker m arg");
			Assert.AreEqual (new Size (20,20), poker.DesiredSize, "poker m result");
			Assert.AreEqual (new Size (0,0), poker.BaseMeasureResult, "poker base result");
			
			Assert.AreEqual (new Size (50,20), b.DesiredSize, "b desiredsize");
			Assert.AreEqual (new Size (20,20), b2.DesiredSize, "b2 desiredsize");
			
			poker.ArrangeResult = new Size (20,20);
			b.Arrange (new Rect (0,0,b.DesiredSize.Width,b.DesiredSize.Height));

			Assert.AreEqual (new Size (20,20),poker.ArrangeArg, "poker aa");
			
			Assert.AreEqual (new Rect (0,0,20,20).ToString (), LayoutInformation.GetLayoutSlot (poker).ToString (), "poker slot");
			Assert.AreEqual (new Rect (0,0,50,20).ToString (), LayoutInformation.GetLayoutSlot (b2).ToString (), "b2 slot");
			Assert.AreEqual (new Rect (0,0,50,20).ToString (), LayoutInformation.GetLayoutSlot (b).ToString (), "b slot");
		}