예제 #1
0
        private Grid createButton(string uid, System.Windows.VerticalAlignment v, System.Windows.HorizontalAlignment h, Color c)
        {
            var button = new Grid();

            button.Name                = uid;
            button.Uid                 = uid;
            button.Width               = 32;
            button.Height              = 32;
            button.VerticalAlignment   = v;
            button.HorizontalAlignment = h;
            button.Opacity             = 0.75;
            button.Background          = new SolidColorBrush(c);
            return(button);
        }
예제 #2
0
        private Rectangle createRectangle(System.Windows.VerticalAlignment verticalAlignment, Brush color)
        {
            Rectangle r            = new Rectangle();
            Binding   widthBinding = new Binding("Width");

            widthBinding.Source = this;

            r                   = new Rectangle();
            r.DataContext       = this;
            r.VerticalAlignment = verticalAlignment;

            r.Fill = color;
            r.SetBinding(Rectangle.WidthProperty, widthBinding);

            return(r);
        }
예제 #3
0
        public static VerticalAlign ToEto(this sw.VerticalAlignment align)
        {
            switch (align)
            {
            case sw.VerticalAlignment.Top:
                return(VerticalAlign.Top);

            case sw.VerticalAlignment.Bottom:
                return(VerticalAlign.Bottom);

            case sw.VerticalAlignment.Center:
                return(VerticalAlign.Middle);

            default:
                throw new NotSupportedException();
            }
        }
예제 #4
0
        /// <summary>
        /// Create the border geometry.
        /// </summary>
        /// <param name="ha">The horizontal alignment.</param>
        /// <param name="va">The vertical alignment.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="margin">The margin.</param>
        /// <returns>The border geometry.</returns>
        private Geometry CreateBorderGeometry(
            System.Windows.HorizontalAlignment ha, System.Windows.VerticalAlignment va, double width, double height, out Thickness margin)
        {
            double m    = this.Distance;
            var    rect = new Rect(
                ha == System.Windows.HorizontalAlignment.Left ? m : 0, va == System.Windows.VerticalAlignment.Top ? m : 0, width, height);

            margin = new Thickness
            {
                Left   = ha == System.Windows.HorizontalAlignment.Left ? m : 0,
                Top    = va == System.Windows.VerticalAlignment.Top ? m : 0,
                Right  = ha == System.Windows.HorizontalAlignment.Right ? m : 0,
                Bottom = va == System.Windows.VerticalAlignment.Bottom ? m : 0
            };
            return(new RectangleGeometry {
                Rect = rect                            /*, RadiusX = this.CornerRadius, RadiusY = this.CornerRadius*/
            });
        }
예제 #5
0
        /// <summary>
        /// Get the bottom edge of a child element.
        /// </summary>
        /// <param name="element">The child element.</param>
        /// <param name="topEdge">The bottom edge of the column.</param>
        /// <param name="height">The height allowed to the control.</param>
        /// <returns>The position of the bottom edge of the control.</returns>
        private double GetBottom(FrameworkElement element, double topEdge, double height)
        {
            double bottom = topEdge + height;

            System.Windows.VerticalAlignment alignment = element.VerticalAlignment;
            Size size = element.DesiredSize;

            if (alignment == System.Windows.VerticalAlignment.Top)
            {
                bottom -= height - size.Height;
            }
            else if (alignment == System.Windows.VerticalAlignment.Center)
            {
                bottom -= (height - size.Height) / 2;
            }

            return(bottom);
        }
예제 #6
0
        /// <summary>
        /// Get the top edge of a child element.
        /// </summary>
        /// <param name="element">The child element.</param>
        /// <param name="topEdge">The top edge of the column.</param>
        /// <param name="height">The height allowed to the control.</param>
        /// <returns>The position of the top edge of the control.</returns>
        private double GetTop(FrameworkElement element, double topEdge, double height)
        {
            double top = topEdge;

            System.Windows.VerticalAlignment alignment = element.VerticalAlignment;
            Size size = element.DesiredSize;

            if (alignment == System.Windows.VerticalAlignment.Bottom)
            {
                top += height - size.Height;
            }
            else if (alignment == System.Windows.VerticalAlignment.Center)
            {
                top += (height - size.Height) / 2;
            }

            return(top);
        }
예제 #7
0
        public virtual VerticalAlignment Parse(System.Windows.VerticalAlignment verticalAlignment)
        {
            switch (verticalAlignment)
            {
            case System.Windows.VerticalAlignment.Top:
                return(VerticalAlignment.Top);

            case System.Windows.VerticalAlignment.Center:
                return(VerticalAlignment.Center);

            case System.Windows.VerticalAlignment.Bottom:
                return(VerticalAlignment.Bottom);

            case System.Windows.VerticalAlignment.Stretch:
                return(VerticalAlignment.Fill);
            }

            throw new ArgumentOutOfRangeException("horizontalAlignment");
        }
 private static TFrameworkElement VerticalAlignment <TFrameworkElement>(this TFrameworkElement @this, V verticalAlignment)
     where TFrameworkElement : FrameworkElement
 {
     @this.VerticalAlignment = verticalAlignment;
     return(@this);
 }
예제 #9
0
        /// <summary>
        /// Creates a border geometry with a 'pointer'.
        /// </summary>
        /// <param name="ha">The horizontal alignment.</param>
        /// <param name="va">The vertical alignment.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="margin">The margin.</param>
        /// <returns>The border geometry.</returns>
        private Geometry CreatePointerBorderGeometry(
            System.Windows.HorizontalAlignment ha, System.Windows.VerticalAlignment va, double width, double height, out Thickness margin)
        {
            Point[] points = null;
            double  m      = this.Distance;

            margin = new Thickness();

            if (ha == System.Windows.HorizontalAlignment.Center && va == System.Windows.VerticalAlignment.Bottom)
            {
                double x0 = 0;
                double x1 = width;
                double x2 = (x0 + x1) / 2;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness {
                    Bottom = m
                };
                points = new[]
                {
                    new Point(x0, y0), new Point(x1, y0), new Point(x1, y1), new Point(x2 + (m / 2), y1),
                    new Point(x2, y1 + m), new Point(x2 - (m / 2), y1), new Point(x0, y1)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Center && va == System.Windows.VerticalAlignment.Top)
            {
                double x0 = 0;
                double x1 = width;
                double x2 = (x0 + x1) / 2;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness {
                    Top = m
                };
                points = new[]
                {
                    new Point(x0, y0), new Point(x2 - (m / 2), y0), new Point(x2, 0), new Point(x2 + (m / 2), y0),
                    new Point(x1, y0), new Point(x1, y1), new Point(x0, y1)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Center)
            {
                double x0 = m;
                double x1 = m + width;
                double y0 = 0;
                double y1 = height;
                double y2 = (y0 + y1) / 2;
                margin = new Thickness {
                    Left = m
                };
                points = new[]
                {
                    new Point(0, y2), new Point(x0, y2 - (m / 2)), new Point(x0, y0), new Point(x1, y0),
                    new Point(x1, y1), new Point(x0, y1), new Point(x0, y2 + (m / 2))
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Center)
            {
                double x0 = 0;
                double x1 = width;
                double y0 = 0;
                double y1 = height;
                double y2 = (y0 + y1) / 2;
                margin = new Thickness {
                    Right = m
                };
                points = new[]
                {
                    new Point(x1 + m, y2), new Point(x1, y2 + (m / 2)), new Point(x1, y1), new Point(x0, y1),
                    new Point(x0, y0), new Point(x1, y0), new Point(x1, y2 - (m / 2))
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Top)
            {
                m *= 0.67;
                double x0 = m;
                double x1 = m + width;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness {
                    Left = m, Top = m
                };
                points = new[]
                {
                    new Point(0, 0), new Point(m * 2, y0), new Point(x1, y0), new Point(x1, y1), new Point(x0, y1),
                    new Point(x0, m * 2)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Top)
            {
                m *= 0.67;
                double x0 = 0;
                double x1 = width;
                double y0 = m;
                double y1 = m + height;
                margin = new Thickness {
                    Top = m, Right = m
                };
                points = new[]
                {
                    new Point(x1 + m, 0), new Point(x1, y0 + m), new Point(x1, y1), new Point(x0, y1),
                    new Point(x0, y0), new Point(x1 - m, y0)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Left && va == System.Windows.VerticalAlignment.Bottom)
            {
                m *= 0.67;
                double x0 = m;
                double x1 = m + width;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness {
                    Left = m, Bottom = m
                };
                points = new[]
                {
                    new Point(0, y1 + m), new Point(x0, y1 - m), new Point(x0, y0), new Point(x1, y0),
                    new Point(x1, y1), new Point(x0 + m, y1)
                };
            }

            if (ha == System.Windows.HorizontalAlignment.Right && va == System.Windows.VerticalAlignment.Bottom)
            {
                m *= 0.67;
                double x0 = 0;
                double x1 = width;
                double y0 = 0;
                double y1 = height;
                margin = new Thickness {
                    Right = m, Bottom = m
                };
                points = new[]
                {
                    new Point(x1 + m, y1 + m), new Point(x1 - m, y1), new Point(x0, y1), new Point(x0, y0),
                    new Point(x1, y0), new Point(x1, y1 - m)
                };
            }

            if (points == null)
            {
                return(null);
            }

            var pointCollection = new PointCollection();

            foreach (var point in points)
            {
                pointCollection.Add(point);
            }

            var segments = new PathSegmentCollection {
                new PolyLineSegment {
                    Points = pointCollection
                }
            };
            var pf = new PathFigure {
                StartPoint = points[0], Segments = segments, IsClosed = true
            };

            return(new PathGeometry {
                Figures = new PathFigureCollection {
                    pf
                }
            });
        }
예제 #10
0
 private static TControl VerticalContentAlignment <TControl>(this TControl @this, V verticalAlignment)
     where TControl : Control
 {
     @this.VerticalContentAlignment = verticalAlignment;
     return(@this);
 }
예제 #11
0
        public Anchor(Node node, string name, System.Windows.VerticalAlignment vertical, System.Windows.HorizontalAlignment horizontal, System.Windows.Thickness margin)
        {
            this.node = node;

            this.Name                = name;
            this.Background          = Brushes.Transparent;
            this.VerticalAlignment   = vertical;
            this.HorizontalAlignment = horizontal;
            this.Margin              = margin;
            this.Width               = 16;
            this.Height              = 16;

            //listeners

            Viewbox vb = new Viewbox();

            vb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            vb.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
            vb.Stretch             = Stretch.Fill;
            vb.Margin = new System.Windows.Thickness(3);

            Grid ingrid = new Grid();

            l1                 = new Line();
            l1.X1              = 0;
            l1.Y1              = 0;
            l1.X2              = 100;
            l1.Y2              = 100;
            l1.Stroke          = Brushes.Transparent;
            l1.StrokeThickness = 8;

            l2                 = new Line();
            l2.X1              = 0;
            l2.Y1              = 100;
            l2.X2              = 100;
            l2.Y2              = 0;
            l2.Stroke          = Brushes.Transparent;
            l2.StrokeThickness = 8;

            ingrid.Children.Add(l1);
            ingrid.Children.Add(l2);
            vb.Child = ingrid;
            this.Children.Add(vb);

            ContextMenu cm1   = new ContextMenu();
            MenuItem    item1 = new MenuItem();

            item1.Header = "Add Child";
            item1.Click += Anchor_OnAddChildClick;
            cm1.Items.Add(item1);
            this.ContextMenu = cm1;

            this.MouseEnter           += Anchor_MouseEnter;
            this.MouseLeave           += Anchor_MouseLeave;
            this.MouseRightButtonDown += Anchor_MouseRightButtonDown;
            this.MouseLeftButtonDown  += Anchor_MouseLeftButtonDown;
            //this.LayoutUpdated += Anchor_LayoutUpdated;

            this.AllowDrop = true;
            this.Drop     += Anchor_Drop;
        }
예제 #12
0
        private void createSensors()
        {
            if (ext.distanceSensors == null)
            {
                ext.distanceSensors = new List <DistanceSensor>();
            }
            else
            {
                ext.distanceSensors.Clear();
            }
            List <DistanceSensor> distanceSensors = ext.distanceSensors;
            DistanceSensor        distanceSensor  = new DistanceSensor()
            {
                Name  = "FrontRight",
                Angle = 45,
                Min   = 100,
                Max   = 800
            };

            distanceSensors.Add(distanceSensor);
            List <DistanceSensor> distanceSensors1 = ext.distanceSensors;
            DistanceSensor        distanceSensor1  = new DistanceSensor()
            {
                Name  = "FrontLeft",
                Angle = -45,
                Min   = 100,
                Max   = 800
            };

            distanceSensors1.Add(distanceSensor1);
            List <DistanceSensor> distanceSensors2 = ext.distanceSensors;
            DistanceSensor        distanceSensor2  = new DistanceSensor()
            {
                Name  = "SideRight",
                Angle = 90,
                Min   = 40,
                Max   = 400
            };

            distanceSensors2.Add(distanceSensor2);
            List <DistanceSensor> distanceSensors3 = ext.distanceSensors;
            DistanceSensor        distanceSensor3  = new DistanceSensor()
            {
                Name  = "SideLeft",
                Angle = -90,
                Min   = 40,
                Max   = 400
            };

            distanceSensors3.Add(distanceSensor3);
            foreach (DistanceSensor distanceSensor4 in ext.distanceSensors)
            {
                Ellipse ellipse  = new Ellipse();
                Ellipse ellipse1 = new Ellipse();
                double  num      = 8;
                double  num1     = num;
                ellipse1.Height = num;
                double num2 = num1;
                num1           = num2;
                ellipse1.Width = num2;
                double num3 = num1;
                num1           = num3;
                ellipse.Height = num3;
                ellipse.Width  = num1;
                int num4 = 0;
                System.Windows.HorizontalAlignment horizontalAlignment = (System.Windows.HorizontalAlignment)num4;
                ellipse.HorizontalAlignment  = (System.Windows.HorizontalAlignment)num4;
                ellipse1.HorizontalAlignment = horizontalAlignment;
                int num5 = 0;
                System.Windows.VerticalAlignment verticalAlignment = (System.Windows.VerticalAlignment)num5;
                ellipse.VerticalAlignment  = (System.Windows.VerticalAlignment)num5;
                ellipse1.VerticalAlignment = verticalAlignment;
                SolidColorBrush black = Brushes.Black;
                Brush           brush = black;
                ellipse.Stroke  = black;
                ellipse1.Stroke = brush;
                SolidColorBrush yellow = Brushes.Yellow;
                brush         = yellow;
                ellipse.Fill  = yellow;
                ellipse1.Fill = brush;
                double num6 = 1;
                num1 = num6;
                ellipse.StrokeThickness  = num6;
                ellipse1.StrokeThickness = num1;
                Line line = new Line()
                {
                    StrokeThickness = 3,
                    Stroke          = Brushes.Blue
                };
                distanceSensor4.setControls(ellipse, ellipse1, line);
                this.bigGrid.Children.Add(line);
                this.bigGrid.Children.Add(ellipse);
                this.bigGrid.Children.Add(ellipse1);
                Panel.SetZIndex(line, 10);
                Panel.SetZIndex(ellipse, 11);
                Panel.SetZIndex(ellipse1, 11);
            }
        }
예제 #13
0
        private System.Windows.Controls.Button ImageButtonHelper(double imageHeight, double imageWidth, string imageName,
                                                                 System.Windows.HorizontalAlignment horizontalAlignment, System.Windows.VerticalAlignment verticalAlignment)
        {
            System.Windows.Controls.Button button = new System.Windows.Controls.Button();
            button.Height = imageHeight;
            button.Width  = imageWidth;
            button.HorizontalAlignment = horizontalAlignment;
            button.VerticalAlignment   = verticalAlignment;

            try
            {
                button.Content = ImageHelper(imageName);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(button);
        }
예제 #14
0
        public static StackPanel GetHotkeyListAsButtonGrid(List <string> hotkeys, Style buttonStyle = null, Style labelStyle = null, double?spacing = null, System.Windows.HorizontalAlignment horizontalAlignment = System.Windows.HorizontalAlignment.Center, System.Windows.VerticalAlignment verticalAlignment = System.Windows.VerticalAlignment.Center)
        {
            var stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Horizontal;

            for (int i = 0; i < hotkeys.Count; i++)
            {
                var tempButton = new System.Windows.Controls.Button();
                tempButton.HorizontalAlignment = horizontalAlignment;
                tempButton.VerticalAlignment   = verticalAlignment;
                if (buttonStyle != null)
                {
                    tempButton.Style = buttonStyle;
                }

                tempButton.Content = hotkeys[i];

                stackPanel.Children.Add(tempButton);

                if (i != (hotkeys.Count - 1))
                {
                    // insert separator only if this is not the only (or the last) element
                    var label = new Label();
                    label.HorizontalAlignment = horizontalAlignment;
                    label.VerticalAlignment   = verticalAlignment;
                    label.Padding             = new System.Windows.Thickness(spacing ?? 1d);
                    label.Content             = "+";
                    if (labelStyle != null)
                    {
                        label.Style = labelStyle;
                    }

                    stackPanel.Children.Add(label);
                }
            }

            return(stackPanel);
        }