Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableImageBrush"/> class.
 /// </summary>
 /// <param name="source">The image to draw.</param>
 /// <param name="alignmentX">The horizontal alignment of a tile in the destination.</param>
 /// <param name="alignmentY">The vertical alignment of a tile in the destination.</param>
 /// <param name="destinationRect">The rectangle on the destination in which to paint a tile.</param>
 /// <param name="opacity">The opacity of the brush.</param>
 /// <param name="transform">The transform of the brush.</param>
 /// <param name="transformOrigin">The transform origin of the brush</param>
 /// <param name="sourceRect">The rectangle of the source image that will be displayed.</param>
 /// <param name="stretch">
 /// How the source rectangle will be stretched to fill the destination rect.
 /// </param>
 /// <param name="tileMode">The tile mode.</param>
 /// <param name="bitmapInterpolationMode">The bitmap interpolation mode.</param>
 public ImmutableImageBrush(
     IBitmap source,
     AlignmentX alignmentX        = AlignmentX.Center,
     AlignmentY alignmentY        = AlignmentY.Center,
     RelativeRect?destinationRect = null,
     double opacity = 1,
     ImmutableTransform?transform  = null,
     RelativePoint transformOrigin = new RelativePoint(),
     RelativeRect?sourceRect       = null,
     Stretch stretch   = Stretch.Uniform,
     TileMode tileMode = TileMode.None,
     BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default)
     : base(
         alignmentX,
         alignmentY,
         destinationRect ?? RelativeRect.Fill,
         opacity,
         transform,
         transformOrigin,
         sourceRect ?? RelativeRect.Fill,
         stretch,
         tileMode,
         bitmapInterpolationMode)
 {
     Source = source;
 }
Esempio n. 2
0
        private static LinearGradientBrush ParseLinearGradientBrush(XmlReader reader)
        {
            LinearGradientBrush brush = new LinearGradientBrush();

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "StartPoint": brush.StartPoint = RelativePoint.Parse(reader.Value); break;

                case "EndPoint": brush.EndPoint = RelativePoint.Parse(reader.Value); break;
                }
            }
            reader.MoveToElement();
            reader = reader.ReadSubtree();
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "LinearGradientBrush.GradientStops": brush.GradientStops = ParseGradientStops(reader.ReadSubtree()); break;
                    }
                }
            }
            return(brush);
        }
Esempio n. 3
0
        protected void SetupCredits(int layerIndex)
        {
            float startParam = RelativeSize.BorderHeight.Paramater;

            float baseCharHeight = RelativeSize.BorderHeight.Paramater * 0.75f;

            string[] lines = Resources.Credits.Split("\r\n".ToCharArray());
            Array.Reverse(lines);
            foreach (var line in lines)
            {
                bool   bold       = false;
                string actualLine = line;
                if (line.StartsWith("$"))
                {
                    bold       = true;
                    actualLine = line.Substring(1);
                }

                float height = baseCharHeight;
                if (bold)
                {
                    height *= 1.25f;
                }

                if (!string.IsNullOrEmpty(line))
                {
                    RelativePoint p = new RelativePoint(RelativeLoc.XRightBorder, new RelativeLoc(startParam, RelativeLoc.Edge.Minimal));

                    AddElement(new UILabel(bold ? MenuManager.BoldFont : MenuManager.MainFont, actualLine, Color.FromArgb(128, Color.WhiteSmoke), p, new RelativeSize(height * 1.15f, false), null, OriginLocation.LowerRight), layerIndex);
                }

                startParam += height * 0.75f;
            }
        }
Esempio n. 4
0
        public static RelativePoint LineIntersection(RelativePoint a, RelativePoint b, RelativePoint c, RelativePoint d)
        {
            if (!IsRelated(a, b, c, d))
            {
                throw new Exception("Points are unrelated");
            }

            // Line AB represented as a1x + b1y = c1
            double a1 = b.Norm.Y - a.Norm.Y;
            double b1 = a.Norm.X - b.Norm.X;
            double c1 = a1 * (a.Norm.X) + b1 * (a.Norm.Y);

            // Line CD represented as a2x + b2y = c2
            double a2 = d.Norm.Y - c.Norm.Y;
            double b2 = c.Norm.X - d.Norm.X;
            double c2 = a2 * (c.Norm.X) + b2 * (c.Norm.Y);

            double determinant = a1 * b2 - a2 * b1;

            if (determinant == 0)
            {
                throw new Exception("Lines are parallel");
            }
            else
            {
                int x = (int)((b2 * c1 - b1 * c2) / determinant);
                int y = (int)((a1 * c2 - a2 * c1) / determinant);
                return(RelativePoint.FromNorm(new Point(x, y), a.FrameWidth, a.FrameHeight));
            }
        }
        private void SetCurrentDropTarget(IDropTarget value, RelativePoint mousePosition, bool raiseDragEvents)
        {
            if (value == m_currentDropTarget)
            {
                return;
            }

            var element = this.DraggedElement;

            if (m_currentDropTarget != null)
            {
                if (raiseDragEvents)
                {
                    m_currentDropTarget.DragLeave(element);
                }

                m_currentDropTarget = null;
            }

            if ((value != null) && value.CanDropElement(element, mousePosition))
            {
                m_currentDropTarget = value;

                if (raiseDragEvents)
                {
                    m_currentDropTarget.DragEnter(element);
                }
            }

            this.OnPropertyChanged("CurrentDropTarget");
        }
Esempio n. 6
0
        public void Render(DrawingContext context, Size size, Thickness depth, Thickness extent, CornerRadius radii, Color bg)
        {
            Color bgTrans = new Color(0, bg.R, bg.G, bg.B);

            GradientStops stops = new GradientStops()
            {
                new GradientStop(bg, 0),
                new GradientStop(bgTrans, 1)
            };

            Grid grid = new Grid()
            {
                ColumnDefinitions = new ColumnDefinitions(depth.Left + ", Auto, " + depth.Right),
                RowDefinitions    = new RowDefinitions(depth.Top + ", Auto, " + depth.Bottom)
            };

            RelativePoint tlCenter = new RelativePoint(1, 1, RelativeUnit.Relative);
            Rectangle     tl       = new Rectangle()
            {
                Fill = new RadialGradientBrush()
                {
                    Center         = tlCenter,
                    GradientOrigin = tlCenter,
                    GradientStops  = stops
                }
            };
            RelativePoint trCenter = new RelativePoint(0, 1, RelativeUnit.Relative);
            Rectangle     tr       = new Rectangle()
            {
                Fill = new RadialGradientBrush()
                {
                    Center         = trCenter,
                    GradientOrigin = trCenter,
                    GradientStops  = stops
                }
            };
            RelativePoint brCenter = new RelativePoint(0, 0, RelativeUnit.Relative);
            Rectangle     br       = new Rectangle()
            {
                Fill = new RadialGradientBrush()
                {
                    Center         = brCenter,
                    GradientOrigin = brCenter,
                    GradientStops  = stops
                }
            };
            RelativePoint blCenter = new RelativePoint(1, 1, RelativeUnit.Relative);
            Rectangle     bl       = new Rectangle()
            {
                Fill = new RadialGradientBrush()
                {
                    Center         = blCenter,
                    GradientOrigin = blCenter,
                    GradientStops  = stops
                }
            };
            VisualBrush brush = new VisualBrush();
        }
Esempio n. 7
0
 /// コンストラクタ
 public RelativeMouseOffset(LayoutElement layoutElement,
                            RelativePoint mousePoint)
     : base(mousePoint.X - layoutElement.BoundRelativeLeft,
            mousePoint.Y - layoutElement.BoundRelativeTop,
            mousePoint.X - layoutElement.BoundRelativeRight,
            mousePoint.Y - layoutElement.BoundRelativeBottom)
 {
     // nop
 }
        private RelativePoint GetRelativePoint(MouseEventArgs e)
        {
            var viewPoint  = e.GetPosition(frameHolder);
            var imagePoint = new OpenCvSharp.Point(
                frameHolder.Source.Width * (viewPoint.X / frameHolder.ActualWidth),
                frameHolder.Source.Height * (viewPoint.Y / frameHolder.ActualHeight));

            return(RelativePoint.FromFrame(imagePoint, frameHolder.Source.Width, frameHolder.Source.Height));
        }
Esempio n. 9
0
        public static double GetDistance(RelativePoint pointA, RelativePoint pointB)
        {
            if (!IsRelated(pointA, pointB))
            {
                throw new Exception("Points are unrelated");
            }

            double a = pointB.Norm.X - pointA.Norm.X;
            double b = pointB.Norm.Y - pointA.Norm.Y;

            return(Math.Sqrt(a * a + b * b));
        }
Esempio n. 10
0
        public static RelativePoint GetPoint(RelativePoint a, RelativePoint b, double offSet)
        {
            var points = new List <RelativePoint> {
                a, b
            };

            if (!IsRelated(points.ToArray()))
            {
                throw new Exception("Points are unrelated");
            }
            return(RelativePoint.FromNorm(new Point(GetPointX(a, b, offSet), GetPointY(a, b, offSet)), a.FrameWidth, a.FrameHeight));
        }
Esempio n. 11
0
        public static bool IsInside(RelativePoint interest, RelativePoint point, double normalRadius)
        {
            var points = new List <RelativePoint> {
                interest, point
            };

            if (!IsRelated(points.ToArray()))
            {
                throw new Exception("Points are unrelated");
            }
            return(GetDistance(interest, point) <= normalRadius);
        }
Esempio n. 12
0
        //===================================================================
        // ヒットテスト
        //===================================================================

        /// ヒットテスト
        public static bool TryHitTest(Profile profile, RelativePoint mousePoint,
                                      out LayoutElement hitElement, out HitModes hitMode)
        {
            // 計算途中の結果をまとめるスタック
            var moveStack = new Stack <LayoutElement>();
            var sizeStack = new Stack <LayoutElement>();

            // レイアウト要素を線形探索
            foreach (var layoutElement in profile.LayoutElements)
            {
                // ヒットテスト対象外判定
                var maximumBoundRect = HitTest.GetMaximumBoundRect(layoutElement);
                if (!maximumBoundRect.Contains(mousePoint))
                {
                    continue;
                }

                var moveRect = HitTest.GetMoveRect(layoutElement);
                if (moveRect.Contains(mousePoint))
                {
                    // 移動用領域
                    moveStack.Push(layoutElement);
                }
                else
                {
                    // 移動用領域でない=サイズ変更用領域
                    sizeStack.Push(layoutElement);
                }
            }

            // sizeStack優先
            foreach (var layoutElement in sizeStack)
            {
                // 見つかり次第終了
                hitMode    = HitTest.GetHitMode(layoutElement, mousePoint);
                hitElement = layoutElement;
                return(true);
            }

            // moveStack
            foreach (var layoutElement in moveStack)
            {
                // 見つかり次第終了
                hitMode    = HitModes.Move;
                hitElement = layoutElement;
                return(true);
            }

            hitElement = null;
            hitMode    = HitModes.Neutral;
            return(false);
        }
Esempio n. 13
0
        public UIImage(RelativePoint origin, string texture) : base()
        {
            IgnoreMouse     = true;
            DefaultMaterial = new GUIMaterial(texture, Color.White);
            CheckMaterial();

            Rect.X = origin.X;
            Rect.Y = origin.Y;

            Rect.Width.Raw        = true;
            Rect.Width.Paramater  = CurrentMaterial.DiffuseTexture.PixelSize.X;
            Rect.Height.Raw       = true;
            Rect.Height.Paramater = CurrentMaterial.DiffuseTexture.PixelSize.Y;
        }
Esempio n. 14
0
        public UILabel(int font, string text, Color color, RelativePoint origin, RelativeSize height, RelativeSize width = null, OriginLocation anchor = OriginLocation.Center, TextFittingModes mode = TextFittingModes.ByHeightExtend) : base()
        {
            IgnoreMouse = true;
            FittingMode = mode;
            Text        = text;
            Font        = font;

            if (width == null)
            {
                width = RelativeSize.FullWidth;
            }

            DefaultMaterial.Color = color;
            Rect = new RelativeRect(origin.X, origin.Y, width, height, anchor);
        }
Esempio n. 15
0
        public static bool IsParallel(RelativePoint a, RelativePoint b, RelativePoint c, RelativePoint d)
        {
            if (!IsRelated(a, b, c, d))
            {
                throw new Exception("Points are unrelated");
            }

            double a1 = b.Norm.Y - a.Norm.Y;
            double b1 = a.Norm.X - b.Norm.X;
            double a2 = d.Norm.Y - c.Norm.Y;
            double b2 = c.Norm.X - d.Norm.X;

            double determinant = a1 * b2 - a2 * b1;

            return(determinant == 0);
        }
Esempio n. 16
0
        //===================================================================
        // 動作
        //===================================================================

        /// 開始
        public void Start(LayoutElement target, HitModes hitMode,
                          RelativePoint mousePoint, SnapGuide snapGuide)
        {
            this.target       = target;
            this.hitMode      = hitMode;
            this.mouseOffset  = new RelativeMouseOffset(target, mousePoint);
            this.originalLTRB = new RelativeLTRB(target.BoundRelativeLeft,
                                                 target.BoundRelativeTop,
                                                 target.BoundRelativeRight,
                                                 target.BoundRelativeBottom);
            this.snapGuide         = snapGuide;
            this.lastUpdateControl = Environment.TickCount;

            this.MousePoint          = mousePoint;
            this.ShouldUpdateControl = false;
        }
Esempio n. 17
0
        //===================================================================
        // ヒットテスト
        //===================================================================
        /// ヒットテスト
        public static bool TryHitTest(Profile profile, RelativePoint mousePoint,
            out LayoutElement hitElement, out HitModes hitMode)
        {
            // 計算途中の結果をまとめるスタック
            var moveStack = new Stack<LayoutElement>();
            var sizeStack = new Stack<LayoutElement>();

            // レイアウト要素を線形探索
            foreach (var layoutElement in profile.LayoutElements) {
              // ヒットテスト対象外判定
              var maximumBoundRect = HitTest.GetMaximumBoundRect(layoutElement);
              if (!maximumBoundRect.Contains(mousePoint)) continue;

              var moveRect = HitTest.GetMoveRect(layoutElement);
              if (moveRect.Contains(mousePoint)) {
            // 移動用領域
            moveStack.Push(layoutElement);
              } else {
            // 移動用領域でない=サイズ変更用領域
            sizeStack.Push(layoutElement);
              }
            }

            // sizeStack優先
            foreach (var layoutElement in sizeStack) {
              // 見つかり次第終了
              hitMode = HitTest.GetHitMode(layoutElement, mousePoint);
              hitElement = layoutElement;
              return true;
            }

            // moveStack
            foreach (var layoutElement in moveStack) {
              // 見つかり次第終了
              hitMode = HitModes.Move;
              hitElement = layoutElement;
              return true;
            }

            hitElement = null;
            hitMode = HitModes.Neutral;
            return false;
        }
Esempio n. 18
0
        internal static IEnumerable <DropTargetInfo> GetDropTargetAtPoint(
            UIElement draggedElement,
            UIElement container,
            Func <IInputElement, Point> getPosition)
        {
            if (container == null)
            {
                yield break;
            }

            var mousePosition = new RelativePoint(container, getPosition.Invoke(container));
            var hitTest       = container.InputHitTest(mousePosition.GetPoint(container));

            if (hitTest == null)
            {
                yield break;
            }

            var parent = hitTest as DependencyObject;

            while (parent != null)
            {
                var dropTarget = parent as IDropTarget;
                if (dropTarget != null)
                {
                    var element = parent as UIElement;
                    if (element != null)
                    {
                        var dropTargetPosition = mousePosition.TranslateTo(element);
                        var canDrop            = dropTarget.CanDropElement(draggedElement, dropTargetPosition);

                        yield return(new DropTargetInfo(dropTarget, dropTargetPosition, canDrop));
                    }
                }

                parent = Xceed.Utils.Wpf.TreeHelper.GetParent(parent);
            }
        }
        protected override void OnDrop(Func <IInputElement, Point> getPosition)
        {
            var dropTarget = this.CurrentDropTarget;

            if (dropTarget != null)
            {
                var element = dropTarget as UIElement;
                if (element != null)
                {
                    var mousePosition = new RelativePoint(element, getPosition.Invoke(element));

                    dropTarget.Drop(this.DraggedElement, mousePosition);
                }

                this.SetCurrentDropTarget(null, default(RelativePoint), false);
            }
            else
            {
                this.OnDroppedOutside();
            }

            base.OnDrop(getPosition);
        }
Esempio n. 20
0
        /// <summary>
        /// sets the Angle tot he rotate transform if not null
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResizeThumb_DragStarted(object sender, VectorEventArgs e)
        {
            _designerItem = DataContext as ContentControl;

            if (_designerItem != null)
            {
                _canvas = TreeExtensions.TryFindParent <Canvas>(_designerItem);
                if (_canvas != null)
                {
                    _transformOrigin = _designerItem.RenderTransformOrigin;

                    _rotateTransform = _designerItem.RenderTransform as RotateTransform;
                    if (_rotateTransform != null)
                    {
                        _angle = _rotateTransform.Angle * Math.PI / 180.0;
                    }
                    else
                    {
                        _angle = 0.0d;
                    }
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageBrush"/> class.
 /// </summary>
 /// <param name="alignmentX">The horizontal alignment of a tile in the destination.</param>
 /// <param name="alignmentY">The vertical alignment of a tile in the destination.</param>
 /// <param name="destinationRect">The rectangle on the destination in which to paint a tile.</param>
 /// <param name="opacity">The opacity of the brush.</param>
 /// <param name="transform">The transform of the brush.</param>
 /// <param name="transformOrigin">The transform origin of the brush</param>
 /// <param name="sourceRect">The rectangle of the source image that will be displayed.</param>
 /// <param name="stretch">
 /// How the source rectangle will be stretched to fill the destination rect.
 /// </param>
 /// <param name="tileMode">The tile mode.</param>
 /// <param name="bitmapInterpolationMode">The bitmap interpolation mode.</param>
 protected ImmutableTileBrush(
     AlignmentX alignmentX,
     AlignmentY alignmentY,
     RelativeRect destinationRect,
     double opacity,
     ImmutableTransform?transform,
     RelativePoint transformOrigin,
     RelativeRect sourceRect,
     Stretch stretch,
     TileMode tileMode,
     BitmapInterpolationMode bitmapInterpolationMode)
 {
     AlignmentX              = alignmentX;
     AlignmentY              = alignmentY;
     DestinationRect         = destinationRect;
     Opacity                 = opacity;
     Transform               = transform;
     TransformOrigin         = transformOrigin;
     SourceRect              = sourceRect;
     Stretch                 = stretch;
     TileMode                = tileMode;
     BitmapInterpolationMode = bitmapInterpolationMode;
 }
Esempio n. 22
0
        public UIImage(string texture, RelativePoint origin, OriginLocation anchor = OriginLocation.Center, RelativeSize _width = null, RelativeSize _height = null) : base()
        {
            IgnoreMouse = true;

            RelativeSize height = _height;
            RelativeSize width  = _width;

            DefaultMaterial = new GUIMaterial(texture, Color.White);
            CheckMaterial();

            if (CurrentMaterial == null || CurrentMaterial.DiffuseTexture == null || CurrentMaterial.DiffuseTexture.PixelSize.X == 0 || CurrentMaterial.DiffuseTexture.PixelSize.Y == 0)
            {
                return;
            }

            if (width == null && height == null)
            {
                // going raw.
                width           = new RelativeSize();
                width.Raw       = true;
                width.Paramater = CurrentMaterial.DiffuseTexture.PixelSize.X;

                height           = new RelativeSize();
                height.Raw       = true;
                height.Paramater = CurrentMaterial.DiffuseTexture.PixelSize.Y;
            }
            else if (width == null)
            {
                width = RelativeTools.GetRelativeWidthInAspect(height, CurrentMaterial.DiffuseTexture.PixelSize.X, CurrentMaterial.DiffuseTexture.PixelSize.Y);
            }
            else if (height == null)
            {
                height = RelativeTools.GetRelativeHeightInAspect(width, CurrentMaterial.DiffuseTexture.PixelSize.X, CurrentMaterial.DiffuseTexture.PixelSize.Y);
            }

            Rect = new RelativeRect(origin.X, origin.Y, width, height, anchor);
        }
Esempio n. 23
0
        public static bool IsInside(RelativePoint interest, params RelativePoint[] polygon)
        {
            var points = new List <RelativePoint> {
                interest
            };

            points.AddRange(polygon);
            if (!IsRelated(points.ToArray()))
            {
                throw new Exception("Points are unrelated");
            }

            bool isInside = false;

            for (int i = 0, j = polygon.Length - 1; i < polygon.Length; j = i++)
            {
                if (((polygon[i].Norm.Y > interest.Norm.Y) != (polygon[j].Norm.Y > interest.Norm.Y)) &&
                    (interest.Norm.X < (polygon[j].Norm.X - polygon[i].Norm.X) * (interest.Norm.Y - polygon[i].Norm.Y) / (polygon[j].Norm.Y - polygon[i].Norm.Y) + polygon[i].Norm.X))
                {
                    isInside = !isInside;
                }
            }
            return(isInside);
        }
Esempio n. 24
0
        private static void AddColorHexagon(int i, Palette palette, Canvas container, PaletteSelector owner, List <PaletteColorInfo> infos, Func <Color, Color> colourBlindnessFunction)
        {
            AnimatableTransform transform = new AnimatableTransform(new Matrix(1, 0, 0, 1, 0, 0));

            PaletteColorInfo info = new PaletteColorInfo()
            {
                Index = i, OriginalIndex = i, Transform = transform
            };

            infos.Insert(i, info);

            double centerX = (1.5 + 2.5 * i) * HexagonRadius + 6.93;
            double centerY = HexagonRadius * Math.Cos(Math.PI / 6) * (i % 2 == 0 ? 1 : 2);

            PathGeometry leftHexagon   = GetHexagonPath(new Point(centerX - 0.5 * HexagonRadius, centerY), HexagonRadius);
            PathGeometry centerHexagon = GetHexagonPath(new Point(centerX, centerY), HexagonRadius);
            PathGeometry rightHexagon  = GetHexagonPath(new Point(centerX + 0.5 * HexagonRadius, centerY), HexagonRadius);


            Color color        = palette.Colors[i % palette.Colors.Count];
            Color lighterColor = ColorPicker.GetLighterColor(color);
            Color darkerColor  = ColorPicker.GetDarkerColor(color);


            Avalonia.Controls.Shapes.Path leftPath = new Avalonia.Controls.Shapes.Path()
            {
                Data = leftHexagon, Fill = new ColorVisualBrush(colourBlindnessFunction(lighterColor)), Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
            };
            Avalonia.Controls.Shapes.Path rightPath = new Avalonia.Controls.Shapes.Path()
            {
                Data = rightHexagon, Fill = new ColorVisualBrush(colourBlindnessFunction(darkerColor)), Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
            };
            Avalonia.Controls.Shapes.Path centerPath = new Avalonia.Controls.Shapes.Path()
            {
                Data = centerHexagon, Fill = new ColorVisualBrush(colourBlindnessFunction(color)), Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
            };

            if (!ColorPicker.TransitionsDisabled)
            {
                leftPath.Transitions = new Transitions
                {
                    new ThicknessTransition()
                    {
                        Property = Avalonia.Controls.Shapes.Path.MarginProperty, Duration = new TimeSpan(0, 0, 0, 0, 100)
                    }
                };

                rightPath.Transitions = new Transitions
                {
                    new ThicknessTransition()
                    {
                        Property = Avalonia.Controls.Shapes.Path.MarginProperty, Duration = new TimeSpan(0, 0, 0, 0, 100)
                    }
                };
            }

            leftPath.Classes.Add("HexagonLeftPalette");
            rightPath.Classes.Add("HexagonRightPalette");
            centerPath.Classes.Add("HexagonCenter");

            rightPath.PointerEnter += (s, e) =>
            {
                rightPath.ZIndex  = 10;
                centerPath.ZIndex = 10;
            };

            rightPath.PointerLeave += async(s, e) =>
            {
                await Task.Delay(100);

                rightPath.ZIndex  = 0;
                centerPath.ZIndex = 0;
            };

            leftPath.PointerPressed += (s, e) =>
            {
                owner.ColorSelected?.Invoke(owner, new ColorSelectedEventArgs(lighterColor));
            };

            rightPath.PointerPressed += (s, e) =>
            {
                owner.ColorSelected?.Invoke(owner, new ColorSelectedEventArgs(darkerColor));
            };

            centerPath.PointerPressed += (s, e) =>
            {
                owner.ColorSelected?.Invoke(owner, new ColorSelectedEventArgs(color));
            };

            Point p1, p2, p3, p4;

            if (i % 2 == 0)
            {
                p1 = new Point(centerX + HexagonRadius * Math.Cos(Math.PI * 2 / 3) - HexagonRadius * 0.5, centerY + HexagonRadius * Math.Sin(Math.PI * 2 / 3));
                p2 = new Point(centerX + HexagonRadius * Math.Cos(Math.PI * 1 / 3) + HexagonRadius * 0.5, centerY + HexagonRadius * Math.Sin(Math.PI * 1 / 3));
                p3 = p2 + new Point(-Math.Cos(Math.PI / 3), Math.Sin(Math.PI / 3)) * HexagonRadius * 0.6;
                p4 = p1 + new Point(Math.Cos(Math.PI / 3), Math.Sin(Math.PI / 3)) * HexagonRadius * 0.6;
            }
            else
            {
                p1 = new Point(centerX + HexagonRadius * Math.Cos(Math.PI * 4 / 3) - HexagonRadius * 0.5, centerY + HexagonRadius * Math.Sin(Math.PI * 4 / 3));
                p2 = new Point(centerX + HexagonRadius * Math.Cos(Math.PI * 5 / 3) + HexagonRadius * 0.5, centerY + HexagonRadius * Math.Sin(Math.PI * 5 / 3));
                p3 = p2 + new Point(-Math.Cos(Math.PI / 3), -Math.Sin(Math.PI / 3)) * HexagonRadius * 0.6;
                p4 = p1 + new Point(Math.Cos(Math.PI / 3), -Math.Sin(Math.PI / 3)) * HexagonRadius * 0.6;
            }


            AnimatablePath4Points deleteBG = new AnimatablePath4Points(p1, p2, p2, p1);

            AnimatableColorBrush bgFill = new AnimatableColorBrush(Color.FromRgb(180, 180, 180), col => deleteBG.Path.Fill = new SolidColorBrush(col));

            deleteBG.Path.Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand);

            PathGeometry deleteGeometry = new PathGeometry();
            PathFigure   seg1           = new PathFigure()
            {
                StartPoint = new Point(centerX - HexagonRadius * 0.15, centerY - HexagonRadius * 0.15), IsClosed = false
            };

            seg1.Segments.Add(new LineSegment()
            {
                Point = seg1.StartPoint + new Point(HexagonRadius * 0.3, HexagonRadius * 0.3)
            });
            PathFigure seg2 = new PathFigure()
            {
                StartPoint = new Point(centerX + HexagonRadius * 0.15, centerY - HexagonRadius * 0.15), IsClosed = false
            };

            seg2.Segments.Add(new LineSegment()
            {
                Point = seg2.StartPoint + new Point(-HexagonRadius * 0.3, HexagonRadius * 0.3)
            });
            deleteGeometry.Figures.Add(seg1);
            deleteGeometry.Figures.Add(seg2);

            RelativePoint renderTransformOrigin = new RelativePoint(centerX, centerY, RelativeUnit.Absolute);


            leftPath.RenderTransform            = transform.MatrixTransform;
            leftPath.RenderTransformOrigin      = renderTransformOrigin;
            rightPath.RenderTransform           = transform.MatrixTransform;
            rightPath.RenderTransformOrigin     = renderTransformOrigin;
            centerPath.RenderTransform          = transform.MatrixTransform;
            centerPath.RenderTransformOrigin    = renderTransformOrigin;
            deleteBG.Path.RenderTransform       = transform.MatrixTransform;
            deleteBG.Path.RenderTransformOrigin = renderTransformOrigin;
            AnimatableTransform fgTransform = new AnimatableTransform(new Matrix(1, 0, 0, 1, 0, (info.Index % 2 == 0 ? 1 : -1) * HexagonRadius * Math.Sin(Math.PI / 3) * 0.7));

            TransformGroup fgTransforms = new TransformGroup();

            fgTransforms.Children.Add(transform.MatrixTransform);
            fgTransforms.Children.Add(fgTransform.MatrixTransform);

            Avalonia.Controls.Shapes.Path deleteFG = new Avalonia.Controls.Shapes.Path()
            {
                Data = deleteGeometry, StrokeThickness = HexagonRadius * 0.1, IsHitTestVisible = false, RenderTransform = fgTransforms, RenderTransformOrigin = renderTransformOrigin
            };

            info.DeleteBGPath      = deleteBG;
            info.DeleteFBTransform = fgTransform;

            AnimatableColorBrush fgStroke = new AnimatableColorBrush(Color.FromRgb(255, 255, 255), col => deleteFG.Stroke = new SolidColorBrush(col));

            deleteBG.Path.PointerEnter += (s, e) =>
            {
                bgFill.Update(Color.FromRgb(240, 240, 240), false);
                fgStroke.Update(Color.FromRgb(128, 128, 128), false);
            };

            deleteBG.Path.PointerLeave += (s, e) =>
            {
                bgFill.Update(Color.FromRgb(180, 180, 180), false);
                fgStroke.Update(Colors.White, false);
            };

            container.Children.Add(deleteBG.Path);
            container.Children.Add(deleteFG);

            bool deleteVisible = false;

            centerPath.PointerEnter += async(s, e) =>
            {
                if (!deleteVisible)
                {
                    double _centerX = (1.5 + 2.5 * info.OriginalIndex) * HexagonRadius + 6.93;
                    double _centerY = HexagonRadius * Math.Cos(Math.PI / 6) * (info.OriginalIndex % 2 == 0 ? 1 : 2);

                    Point _p1, _p2, _p3, _p4;

                    if (info.Index % 2 == 0)
                    {
                        _p1 = new Point(_centerX + HexagonRadius * Math.Cos(Math.PI * 2 / 3) - HexagonRadius * 0.5, _centerY + HexagonRadius * Math.Sin(Math.PI * 2 / 3));
                        _p2 = new Point(_centerX + HexagonRadius * Math.Cos(Math.PI * 1 / 3) + HexagonRadius * 0.5, _centerY + HexagonRadius * Math.Sin(Math.PI * 1 / 3));
                        _p3 = _p2 + new Point(-Math.Cos(Math.PI / 3), Math.Sin(Math.PI / 3)) * HexagonRadius * 0.6;
                        _p4 = _p1 + new Point(Math.Cos(Math.PI / 3), Math.Sin(Math.PI / 3)) * HexagonRadius * 0.6;
                    }
                    else
                    {
                        _p1 = new Point(_centerX + HexagonRadius * Math.Cos(Math.PI * 4 / 3) - HexagonRadius * 0.5, _centerY + HexagonRadius * Math.Sin(Math.PI * 4 / 3));
                        _p2 = new Point(_centerX + HexagonRadius * Math.Cos(Math.PI * 5 / 3) + HexagonRadius * 0.5, _centerY + HexagonRadius * Math.Sin(Math.PI * 5 / 3));
                        _p3 = _p2 + new Point(-Math.Cos(Math.PI / 3), -Math.Sin(Math.PI / 3)) * HexagonRadius * 0.6;
                        _p4 = _p1 + new Point(Math.Cos(Math.PI / 3), -Math.Sin(Math.PI / 3)) * HexagonRadius * 0.6;
                    }

                    deleteVisible      = true;
                    deleteBG.Points    = new PointCollection4(_p1, _p2, _p3, _p4);
                    fgTransform.Matrix = new Matrix(1, 0, 0, 1, 0, (info.Index % 2 == 0 ? 1 : -1) * HexagonRadius * Math.Sin(Math.PI / 3) * 1.3);
                    await Task.Delay(100);

                    deleteBG.Path.ZIndex = 11;
                    deleteFG.ZIndex      = 11;
                    await Task.Delay(1000);

                    deleteBG.Path.ZIndex = 0;
                    deleteFG.ZIndex      = 0;
                    fgTransform.Matrix   = new Matrix(1, 0, 0, 1, 0, (info.Index % 2 == 0 ? 1 : -1) * HexagonRadius * Math.Sin(Math.PI / 3) * 0.7);
                    deleteBG.Points      = new PointCollection4(_p1, _p2, _p2, _p1);
                    deleteVisible        = false;
                }
            };

            container.Children.Add(leftPath);
            container.Children.Add(rightPath);
            container.Children.Add(centerPath);


            deleteBG.Path.PointerPressed += async(s, e) =>
            {
                transform.Matrix = new Matrix(0, 0, 0, 0, transform.Matrix.M31, transform.Matrix.M32);

                for (int j = info.Index + 1; j < infos.Count; j++)
                {
                    infos[j].Transform.Matrix = new Matrix(1, 0, 0, 1, infos[j].Transform.Matrix.M31 - HexagonRadius * 2.5, infos[j].Transform.Matrix.M32 + HexagonRadius * Math.Sin(Math.PI / 3) * (j % 2 == 0 ? 1 : -1));
                    infos[j].Index--;

                    if (infos[j].DeleteBGPath != null)
                    {
                        double _centerX = (1.5 + 2.5 * infos[j].OriginalIndex) * HexagonRadius + 6.93;
                        double _centerY = HexagonRadius * Math.Cos(Math.PI / 6) * (infos[j].OriginalIndex % 2 == 0 ? 1 : 2);

                        Point _p1, _p2;

                        if (infos[j].Index % 2 == 0)
                        {
                            _p1 = new Point(_centerX + HexagonRadius * Math.Cos(Math.PI * 2 / 3) - HexagonRadius * 0.5, _centerY + HexagonRadius * Math.Sin(Math.PI * 2 / 3));
                            _p2 = new Point(_centerX + HexagonRadius * Math.Cos(Math.PI * 1 / 3) + HexagonRadius * 0.5, _centerY + HexagonRadius * Math.Sin(Math.PI * 1 / 3));
                        }
                        else
                        {
                            _p1 = new Point(_centerX + HexagonRadius * Math.Cos(Math.PI * 4 / 3) - HexagonRadius * 0.5, _centerY + HexagonRadius * Math.Sin(Math.PI * 4 / 3));
                            _p2 = new Point(_centerX + HexagonRadius * Math.Cos(Math.PI * 5 / 3) + HexagonRadius * 0.5, _centerY + HexagonRadius * Math.Sin(Math.PI * 5 / 3));
                        }

                        infos[j].DeleteBGPath.Points      = new PointCollection4(_p1, _p2, _p2, _p1);
                        infos[j].DeleteFBTransform.Matrix = new Matrix(1, 0, 0, 1, 0, -infos[j].DeleteFBTransform.Matrix.M32);
                    }
                }

                await Task.Delay(100);

                container.Width -= HexagonRadius * 2.5;

                infos.RemoveAt(info.Index);
                palette.Colors.RemoveAt(info.Index);

                container.Children.Remove(leftPath);
                container.Children.Remove(rightPath);
                container.Children.Remove(centerPath);
                container.Children.Remove(deleteBG.Path);
                container.Children.Remove(deleteFG);
            };
        }
 public GraphPanel()
 {
     RenderTransformOrigin = new RelativePoint(0, 0, RelativeUnit.Absolute);
 }
        public static bool TryConvert(AstTransformationContext context, IXamlAstValueNode node, string text, IXamlType type, AvaloniaXamlIlWellKnownTypes types, out IXamlAstValueNode result)
        {
            if (type.FullName == "System.TimeSpan")
            {
                var tsText = text.Trim();

                if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan))
                {
                    // // shorthand seconds format (ie. "0.25")
                    if (!tsText.Contains(":") && double.TryParse(tsText,
                                                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                                                 CultureInfo.InvariantCulture, out var seconds))
                    {
                        timeSpan = TimeSpan.FromSeconds(seconds);
                    }
                    else
                    {
                        throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node);
                    }
                }

                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.FindMethod("FromTicks", type, false, types.Long),
                                                                      new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) });
                return(true);
            }

            if (type.Equals(types.FontFamily))
            {
                result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node);
                return(true);
            }

            if (type.Equals(types.Thickness))
            {
                try
                {
                    var thickness = Thickness.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Thickness, types.ThicknessFullConstructor,
                                                                         new[] { thickness.Left, thickness.Top, thickness.Right, thickness.Bottom });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a thickness", node);
                }
            }

            if (type.Equals(types.Point))
            {
                try
                {
                    var point = Point.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor,
                                                                         new[] { point.X, point.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a point", node);
                }
            }

            if (type.Equals(types.Vector))
            {
                try
                {
                    var vector = Vector.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor,
                                                                         new[] { vector.X, vector.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a vector", node);
                }
            }

            if (type.Equals(types.Size))
            {
                try
                {
                    var size = Size.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor,
                                                                         new[] { size.Width, size.Height });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a size", node);
                }
            }

            if (type.Equals(types.Matrix))
            {
                try
                {
                    var matrix = Matrix.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Matrix, types.MatrixFullConstructor,
                                                                         new[] { matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32 });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a matrix", node);
                }
            }

            if (type.Equals(types.CornerRadius))
            {
                try
                {
                    var cornerRadius = CornerRadius.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.CornerRadius, types.CornerRadiusFullConstructor,
                                                                         new[] { cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a corner radius", node);
                }
            }

            if (type.Equals(types.Color))
            {
                if (!Color.TryParse(text, out Color color))
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a color", node);
                }

                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.GetMethod(
                                                                          new FindMethodMethodSignature("FromUInt32", type, types.UInt)
                {
                    IsStatic = true
                }),
                                                                      new[] { new XamlConstantNode(node, types.UInt, color.ToUint32()) });

                return(true);
            }

            if (type.Equals(types.RelativePoint))
            {
                try
                {
                    var relativePoint = RelativePoint.Parse(text);

                    var relativePointTypeRef = new XamlAstClrTypeReference(node, types.RelativePoint, false);

                    result = new XamlAstNewClrObjectNode(node, relativePointTypeRef, types.RelativePointFullConstructor, new List <IXamlAstValueNode>
                    {
                        new XamlConstantNode(node, types.XamlIlTypes.Double, relativePoint.Point.X),
                        new XamlConstantNode(node, types.XamlIlTypes.Double, relativePoint.Point.Y),
                        new XamlConstantNode(node, types.RelativeUnit, (int)relativePoint.Unit),
                    });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a relative point", node);
                }
            }

            if (type.Equals(types.GridLength))
            {
                try
                {
                    var gridLength = GridLength.Parse(text);

                    result = new AvaloniaXamlIlGridLengthAstNode(node, types, gridLength);

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a grid length", node);
                }
            }

            if (type.Equals(types.Cursor))
            {
                if (TypeSystemHelpers.TryGetEnumValueNode(types.StandardCursorType, text, node, out var enumConstantNode))
                {
                    var cursorTypeRef = new XamlAstClrTypeReference(node, types.Cursor, false);

                    result = new XamlAstNewClrObjectNode(node, cursorTypeRef, types.CursorTypeConstructor, new List <IXamlAstValueNode> {
                        enumConstantNode
                    });

                    return(true);
                }
            }

            if (type.Equals(types.ColumnDefinitions))
            {
                return(ConvertDefinitionList(node, text, types, types.ColumnDefinitions, types.ColumnDefinition, "column definitions", out result));
            }

            if (type.Equals(types.RowDefinitions))
            {
                return(ConvertDefinitionList(node, text, types, types.RowDefinitions, types.RowDefinition, "row definitions", out result));
            }

            if (type.Equals(types.Classes))
            {
                var classes    = text.Split(' ');
                var classNodes = classes.Select(c => new XamlAstTextNode(node, c, type: types.XamlIlTypes.String)).ToArray();

                result = new AvaloniaXamlIlAvaloniaListConstantAstNode(node, types, types.Classes, types.XamlIlTypes.String, classNodes);
                return(true);
            }

            if (types.IBrush.IsAssignableFrom(type))
            {
                if (Color.TryParse(text, out Color color))
                {
                    var brushTypeRef = new XamlAstClrTypeReference(node, types.ImmutableSolidColorBrush, false);

                    result = new XamlAstNewClrObjectNode(node, brushTypeRef,
                                                         types.ImmutableSolidColorBrushConstructorColor,
                                                         new List <IXamlAstValueNode> {
                        new XamlConstantNode(node, types.UInt, color.ToUint32())
                    });

                    return(true);
                }
            }

            if (type.Equals(types.TextTrimming))
            {
                foreach (var property in types.TextTrimming.Properties)
                {
                    if (property.PropertyType == types.TextTrimming && property.Name.Equals(text, StringComparison.OrdinalIgnoreCase))
                    {
                        result = new XamlStaticOrTargetedReturnMethodCallNode(node, property.Getter, Enumerable.Empty <IXamlAstValueNode>());

                        return(true);
                    }
                }
            }

            if (type.Equals(types.TextDecorationCollection))
            {
                foreach (var property in types.TextDecorations.Properties)
                {
                    if (property.PropertyType == types.TextDecorationCollection && property.Name.Equals(text, StringComparison.OrdinalIgnoreCase))
                    {
                        result = new XamlStaticOrTargetedReturnMethodCallNode(node, property.Getter, Enumerable.Empty <IXamlAstValueNode>());

                        return(true);
                    }
                }
            }

            result = null;
            return(false);
        }
Esempio n. 27
0
        public void Parse_Should_Accept_Absolute_Value()
        {
            var result = RelativePoint.Parse("4,5");

            Assert.Equal(new RelativePoint(4, 5, RelativeUnit.Absolute), result);
        }
Esempio n. 28
0
        public void Parse_Should_Accept_Relative_Value()
        {
            var result = RelativePoint.Parse("25%, 50%");

            Assert.Equal(new RelativePoint(0.25, 0.5, RelativeUnit.Relative), result);
        }
Esempio n. 29
0
        public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg)
        {
            XamlIlTypes               = cfg.WellKnownTypes;
            AvaloniaObject            = cfg.TypeSystem.GetType("Avalonia.AvaloniaObject");
            IAvaloniaObject           = cfg.TypeSystem.GetType("Avalonia.IAvaloniaObject");
            AvaloniaObjectExtensions  = cfg.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions");
            AvaloniaProperty          = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty");
            AvaloniaPropertyT         = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty`1");
            AvaloniaAttachedPropertyT = cfg.TypeSystem.GetType("Avalonia.AttachedProperty`1");
            BindingPriority           = cfg.TypeSystem.GetType("Avalonia.Data.BindingPriority");
            IBinding                 = cfg.TypeSystem.GetType("Avalonia.Data.IBinding");
            IDisposable              = cfg.TypeSystem.GetType("System.IDisposable");
            ICommand                 = cfg.TypeSystem.GetType("System.Windows.Input.ICommand");
            Transitions              = cfg.TypeSystem.GetType("Avalonia.Animation.Transitions");
            AssignBindingAttribute   = cfg.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute");
            DependsOnAttribute       = cfg.TypeSystem.GetType("Avalonia.Metadata.DependsOnAttribute");
            DataTypeAttribute        = cfg.TypeSystem.GetType("Avalonia.Metadata.DataTypeAttribute");
            AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject,
                                                                           AvaloniaProperty,
                                                                           IBinding, cfg.WellKnownTypes.Object);
            UnsetValueType     = cfg.TypeSystem.GetType("Avalonia.UnsetValueType");
            StyledElement      = cfg.TypeSystem.GetType("Avalonia.StyledElement");
            IStyledElement     = cfg.TypeSystem.GetType("Avalonia.IStyledElement");
            INameScope         = cfg.TypeSystem.GetType("Avalonia.Controls.INameScope");
            INameScopeRegister = INameScope.GetMethod(
                new FindMethodMethodSignature("Register", XamlIlTypes.Void,
                                              XamlIlTypes.String, XamlIlTypes.Object)
            {
                IsStatic      = false,
                DeclaringOnly = true,
                IsExactMatch  = true
            });
            INameScopeComplete = INameScope.GetMethod(
                new FindMethodMethodSignature("Complete", XamlIlTypes.Void)
            {
                IsStatic      = false,
                DeclaringOnly = true,
                IsExactMatch  = true
            });
            NameScope             = cfg.TypeSystem.GetType("Avalonia.Controls.NameScope");
            NameScopeSetNameScope = NameScope.GetMethod(new FindMethodMethodSignature("SetNameScope",
                                                                                      XamlIlTypes.Void, StyledElement, INameScope)
            {
                IsStatic = true
            });
            AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", IDisposable,
                                                                     false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority);
            IPropertyInfo               = cfg.TypeSystem.GetType("Avalonia.Data.Core.IPropertyInfo");
            ClrPropertyInfo             = cfg.TypeSystem.GetType("Avalonia.Data.Core.ClrPropertyInfo");
            PropertyPath                = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPath");
            PropertyPathBuilder         = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPathBuilder");
            IPropertyAccessor           = cfg.TypeSystem.GetType("Avalonia.Data.Core.Plugins.IPropertyAccessor");
            PropertyInfoAccessorFactory = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.PropertyInfoAccessorFactory");
            CompiledBindingPathBuilder  = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPathBuilder");
            CompiledBindingPath         = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPath");
            CompiledBindingExtension    = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension");
            ResolveByNameExtension      = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ResolveByNameExtension");
            DataTemplate                = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Templates.DataTemplate");
            IDataTemplate               = cfg.TypeSystem.GetType("Avalonia.Controls.Templates.IDataTemplate");
            IItemsPresenterHost         = cfg.TypeSystem.GetType("Avalonia.Controls.Presenters.IItemsPresenterHost");
            ItemsRepeater               = cfg.TypeSystem.GetType("Avalonia.Controls.ItemsRepeater");
            ReflectionBindingExtension  = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension");
            RelativeSource              = cfg.TypeSystem.GetType("Avalonia.Data.RelativeSource");
            UInt       = cfg.TypeSystem.GetType("System.UInt32");
            Int        = cfg.TypeSystem.GetType("System.Int32");
            Long       = cfg.TypeSystem.GetType("System.Int64");
            Uri        = cfg.TypeSystem.GetType("System.Uri");
            FontFamily = cfg.TypeSystem.GetType("Avalonia.Media.FontFamily");
            FontFamilyConstructorUriName = FontFamily.GetConstructor(new List <IXamlType> {
                Uri, XamlIlTypes.String
            });

            (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount)
            {
                var type = cfg.TypeSystem.GetType(name);
                var ctor = type.GetConstructor(Enumerable.Range(0, componentCount).Select(_ => componentType).ToList());

                return(type, ctor);
            }

            (Thickness, ThicknessFullConstructor)       = GetNumericTypeInfo("Avalonia.Thickness", XamlIlTypes.Double, 4);
            (Point, PointFullConstructor)               = GetNumericTypeInfo("Avalonia.Point", XamlIlTypes.Double, 2);
            (Vector, VectorFullConstructor)             = GetNumericTypeInfo("Avalonia.Vector", XamlIlTypes.Double, 2);
            (Size, SizeFullConstructor)                 = GetNumericTypeInfo("Avalonia.Size", XamlIlTypes.Double, 2);
            (Matrix, MatrixFullConstructor)             = GetNumericTypeInfo("Avalonia.Matrix", XamlIlTypes.Double, 6);
            (CornerRadius, CornerRadiusFullConstructor) = GetNumericTypeInfo("Avalonia.CornerRadius", XamlIlTypes.Double, 4);

            RelativeUnit  = cfg.TypeSystem.GetType("Avalonia.RelativeUnit");
            RelativePoint = cfg.TypeSystem.GetType("Avalonia.RelativePoint");
            RelativePointFullConstructor = RelativePoint.GetConstructor(new List <IXamlType> {
                XamlIlTypes.Double, XamlIlTypes.Double, RelativeUnit
            });

            GridLength = cfg.TypeSystem.GetType("Avalonia.Controls.GridLength");
            GridLengthConstructorValueType = GridLength.GetConstructor(new List <IXamlType> {
                XamlIlTypes.Double, cfg.TypeSystem.GetType("Avalonia.Controls.GridUnitType")
            });
            Color = cfg.TypeSystem.GetType("Avalonia.Media.Color");
            StandardCursorType    = cfg.TypeSystem.GetType("Avalonia.Input.StandardCursorType");
            Cursor                = cfg.TypeSystem.GetType("Avalonia.Input.Cursor");
            CursorTypeConstructor = Cursor.GetConstructor(new List <IXamlType> {
                StandardCursorType
            });
            ColumnDefinition             = cfg.TypeSystem.GetType("Avalonia.Controls.ColumnDefinition");
            ColumnDefinitions            = cfg.TypeSystem.GetType("Avalonia.Controls.ColumnDefinitions");
            RowDefinition                = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinition");
            RowDefinitions               = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinitions");
            Classes                      = cfg.TypeSystem.GetType("Avalonia.Controls.Classes");
            StyledElementClassesProperty =
                StyledElement.Properties.First(x => x.Name == "Classes" && x.PropertyType.Equals(Classes));
            ClassesBindMethod = cfg.TypeSystem.GetType("Avalonia.StyledElementExtensions")
                                .FindMethod("BindClass", IDisposable, false, IStyledElement,
                                            cfg.WellKnownTypes.String,
                                            IBinding, cfg.WellKnownTypes.Object);

            IBrush = cfg.TypeSystem.GetType("Avalonia.Media.IBrush");
            ImmutableSolidColorBrush = cfg.TypeSystem.GetType("Avalonia.Media.Immutable.ImmutableSolidColorBrush");
            ImmutableSolidColorBrushConstructorColor = ImmutableSolidColorBrush.GetConstructor(new List <IXamlType> {
                UInt
            });
            TypeUtilities            = cfg.TypeSystem.GetType("Avalonia.Utilities.TypeUtilities");
            TextDecorationCollection = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorationCollection");
            TextDecorations          = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorations");
            TextTrimming             = cfg.TypeSystem.GetType("Avalonia.Media.TextTrimming");
            ISetter = cfg.TypeSystem.GetType("Avalonia.Styling.ISetter");
        }
Esempio n. 30
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     return(RelativePoint.Parse((string)value, culture));
 }
Esempio n. 31
0
        //===================================================================
        // ヒットモード計算
        //===================================================================
        /// レイアウト要素とマウス座標(相対座標系)からHitModesを調べる
        /// @param layoutElement レイアウト要素
        /// @param mousePoint マウス座標(相対座標系)
        /// @return HitModes.SizeXXXのいずれか
        private static HitModes GetHitMode(LayoutElement layoutElement,
            RelativePoint mousePoint)
        {
            // ---------------
            // |  |1     |2  |
            // ---------------

            // H1
            var borderWRight = layoutElement.BoundRelativeLeft +
                       Constants.BorderRelativeThickness;
            // H2
            var borderELeft = layoutElement.BoundRelativeRight -
                      Constants.BorderRelativeThickness;

            // V1
            var borderNBottom = layoutElement.BoundRelativeTop +
                        Constants.BorderRelativeThickness;
            // v2
            var borderSTop = layoutElement.BoundRelativeBottom -
                     Constants.BorderRelativeThickness;

            // X座標→Y座標
            /// @attention 浮動小数点数の比較
            if (mousePoint.X < borderWRight) {          // W
              if (mousePoint.Y < borderNBottom) {       // N
            return HitModes.SizeNW;
              } else if (mousePoint.Y < borderSTop) {   // (N)-(S)
            return HitModes.SizeW;
              } else {                                  // S
            return HitModes.SizeSW;
              }
            } else if (mousePoint.X < borderELeft) {    // (W)-(E)
              if (mousePoint.Y < borderNBottom) {       // N
            return HitModes.SizeN;
              } else if (mousePoint.Y < borderSTop) {   // (N)-(S)
            Debug.Fail("Move?", "HitTest.GetHitMode");
            return HitModes.Move;
              } else {                                  // S
            return HitModes.SizeS;
              }
            } else {                                    // E
              if (mousePoint.Y < borderNBottom) {       // N
            return HitModes.SizeNE;
              } else if (mousePoint.Y < borderSTop) {   // (N)-(S)
            return HitModes.SizeE;
              } else {                                  // S
            return HitModes.SizeSE;
              }
            }
        }
Esempio n. 32
0
        private void AddColorHexagon(int i, Palette palette, Canvas container)
        {
            int rowInd = i / MaxColumns;
            int colInd = i % MaxColumns;

            double centerX;
            double centerY;

            if (i == 0 && palette.Colors.Count == 1)
            {
                centerX = HexagonRadius * (1.5 + colInd * 2.5);
                centerY = HexagonRadius * Math.Sin(Math.PI / 3) * (2 + 2 * rowInd - 1);
            }
            else if (colInd == 0)
            {
                centerX = HexagonRadius * (1.5 + 2.5);
                centerY = HexagonRadius * Math.Sin(Math.PI / 3) * (2 + 2 * rowInd - 1);
            }
            else if (colInd == 1)
            {
                centerX = HexagonRadius * 1.5;
                centerY = HexagonRadius * Math.Sin(Math.PI / 3) * (2 + 2 * rowInd);
            }
            else
            {
                centerX = HexagonRadius * (1.5 + colInd * 2.5);
                centerY = HexagonRadius * Math.Sin(Math.PI / 3) * (2 + 2 * rowInd - colInd % 2);
            }

            centerX += 4.33;

            PathGeometry leftHexagon   = GetHexagonPath(new Point(centerX - 0.5 * HexagonRadius, centerY), HexagonRadius);
            PathGeometry centerHexagon = GetHexagonPath(new Point(centerX, centerY), HexagonRadius);
            PathGeometry rightHexagon  = GetHexagonPath(new Point(centerX + 0.5 * HexagonRadius, centerY), HexagonRadius);


            Color color        = palette.Colors[i % palette.Colors.Count];
            Color lighterColor = ColorPicker.GetLighterColor(color);
            Color darkerColor  = ColorPicker.GetDarkerColor(color);


            Avalonia.Controls.Shapes.Path leftPath = new Avalonia.Controls.Shapes.Path()
            {
                Data = leftHexagon, Fill = new ColorVisualBrush(lighterColor), Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
            };
            Avalonia.Controls.Shapes.Path rightPath = new Avalonia.Controls.Shapes.Path()
            {
                Data = rightHexagon, Fill = new ColorVisualBrush(darkerColor), Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
            };
            Avalonia.Controls.Shapes.Path centerPath = new Avalonia.Controls.Shapes.Path()
            {
                Data = centerHexagon, Fill = new ColorVisualBrush(color), Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.Hand)
            };

            leftPath.Classes.Add("HexagonLeftButton");
            rightPath.Classes.Add("HexagonRightButton");
            centerPath.Classes.Add("HexagonCenterButton");

            rightPath.PointerEnter += (s, e) =>
            {
                rightPath.Classes.Add("rightOver");
                centerPath.Classes.Add("rightOver");
                leftPath.Classes.Add("rightOver");
            };

            rightPath.PointerLeave += async(s, e) =>
            {
                rightPath.Classes.Add("rightOverBlurring");
                centerPath.Classes.Add("rightOverBlurring");
                leftPath.Classes.Add("rightOverBlurring");
                rightPath.Classes.Remove("rightOver");
                centerPath.Classes.Remove("rightOver");
                leftPath.Classes.Remove("rightOver");

                await Task.Delay(100);

                rightPath.Classes.Remove("rightOverBlurring");
                centerPath.Classes.Remove("rightOverBlurring");
                leftPath.Classes.Remove("rightOverBlurring");
            };

            leftPath.PointerEnter += (s, e) =>
            {
                rightPath.Classes.Add("leftOver");
                centerPath.Classes.Add("leftOver");
                leftPath.Classes.Add("leftOver");
            };

            leftPath.PointerLeave += async(s, e) =>
            {
                rightPath.Classes.Add("leftOverBlurring");
                centerPath.Classes.Add("leftOverBlurring");
                leftPath.Classes.Add("leftOverBlurring");
                rightPath.Classes.Remove("leftOver");
                centerPath.Classes.Remove("leftOver");
                leftPath.Classes.Remove("leftOver");

                await Task.Delay(100);

                rightPath.Classes.Remove("leftOverBlurring");
                centerPath.Classes.Remove("leftOverBlurring");
                leftPath.Classes.Remove("leftOverBlurring");
            };

            centerPath.PointerEnter += (s, e) =>
            {
                rightPath.Classes.Add("centerOver");
                centerPath.Classes.Add("centerOver");
                leftPath.Classes.Add("centerOver");
            };

            centerPath.PointerLeave += async(s, e) =>
            {
                rightPath.Classes.Add("centerOverBlurring");
                centerPath.Classes.Add("centerOverBlurring");
                leftPath.Classes.Add("centerOverBlurring");
                rightPath.Classes.Remove("centerOver");
                centerPath.Classes.Remove("centerOver");
                leftPath.Classes.Remove("centerOver");

                await Task.Delay(100);

                rightPath.Classes.Remove("centerOverBlurring");
                centerPath.Classes.Remove("centerOverBlurring");
                leftPath.Classes.Remove("centerOverBlurring");
            };

            leftPath.PointerPressed += (s, e) =>
            {
                this.Color = lighterColor;
            };

            rightPath.PointerPressed += (s, e) =>
            {
                this.Color = darkerColor;
            };

            centerPath.PointerPressed += (s, e) =>
            {
                this.Color = color;
            };

            RelativePoint renderTransformOrigin = new RelativePoint(centerX, centerY, RelativeUnit.Absolute);

            leftPath.RenderTransformOrigin   = renderTransformOrigin;
            rightPath.RenderTransformOrigin  = renderTransformOrigin;
            centerPath.RenderTransformOrigin = renderTransformOrigin;

            container.Children.Add(leftPath);
            container.Children.Add(rightPath);
            container.Children.Add(centerPath);
        }
        //===================================================================
        // 動作
        //===================================================================
        /// 開始
        public void Start(LayoutElement target, HitModes hitMode,
            RelativePoint mousePoint, SnapGuide snapGuide)
        {
            this.target       = target;
            this.hitMode      = hitMode;
            this.mouseOffset  = new RelativeMouseOffset(target, mousePoint);
            this.originalLTRB = new RelativeLTRB(target.BoundRelativeLeft,
                                         target.BoundRelativeTop,
                                         target.BoundRelativeRight,
                                         target.BoundRelativeBottom);
            this.snapGuide            = snapGuide;
            this.lastUpdateControl    = Environment.TickCount;

            this.MousePoint           = mousePoint;
            this.ShouldUpdateControl  = false;
        }
Esempio n. 34
0
 /// コンストラクタ
 public RelativeMouseOffset(LayoutElement layoutElement,
     RelativePoint mousePoint)
     : base(mousePoint.X - layoutElement.BoundRelativeLeft,
      mousePoint.Y - layoutElement.BoundRelativeTop,
      mousePoint.X - layoutElement.BoundRelativeRight,
      mousePoint.Y - layoutElement.BoundRelativeBottom)
 {
     // nop
 }