コード例 #1
0
ファイル: RadialMenu.cs プロジェクト: seasailor/designscript
        public int HandleClick(Point mousePosition)
        {
            if (null == visibleMenuItems || (visibleMenuItems.Count <= 0))
            {
                return(-1);
            }
            mousePosition.X -= radialMenuVisual.Transform.Value.OffsetX;
            mousePosition.Y -= radialMenuVisual.Transform.Value.OffsetY;

            if (upScroller != null && downScroller != null)
            {
                Scroller tempScroller = new Scroller(ScrollerType.None);
                bool     result       = ScrollerHitTest(mousePosition, out tempScroller);

                if (tempScroller.Type == ScrollerType.Up)
                {
                    this.HandleScrollUp();
                    return(0);
                }
                else if (tempScroller.Type == ScrollerType.Down)
                {
                    this.HandleScrollDown();
                    return(0);
                }
            }
            if (IsWithinHitTestRegion(mousePosition) == false)
            {
                return(-1);
            }

            int    itemIndex;
            double min;

            GetClosestItemToAnchor(out itemIndex, out min);
            MenuItemInfo item = visibleMenuItems.ElementAt(itemIndex);
            Point        temp;
            int          tempId;

            HandleMouseMove(mousePosition, out temp, out tempId);
            return(item.MenuId);
        }
コード例 #2
0
ファイル: RadialMenu.cs プロジェクト: seasailor/designscript
        private bool ScrollerHitTest(Point mousePosition, out Scroller hitScroller)
        {
            //hitScroller.state = ScrollerStates.None;
            //hitScroller.Position = new Point();
            bool  result = false;
            Point pt     = upScroller.position;

            hitScroller = new Scroller(ScrollerType.None);

            if (IsWithinSrollerRegion(pt, mousePosition))
            {
                hitScroller = upScroller;
                result      = true;
            }
            pt = downScroller.position;
            if (IsWithinSrollerRegion(pt, mousePosition))
            {
                hitScroller = downScroller;
                result      = true;
            }
            return(result);
        }
コード例 #3
0
ファイル: RadialMenu.cs プロジェクト: seasailor/designscript
        private void DrawScroller(DrawingContext context, Scroller tempScroller)
        {
            if (upScroller.state == ScrollerStates.None || downScroller.state == ScrollerStates.None)
            {
                return;
            }
            double width  = 20;
            double height = 10;
            Rect   rect   = new Rect();

            rect.Size = new Size(width, height);
            Point center = tempScroller.position;

            center.Offset(-width / 2, -height / 2);
            rect.Location = center;

            Brush b = Brushes.White;

            if (tempScroller.state == ScrollerStates.Hovered)
            {
                b = Brushes.Red;
            }
            else if (tempScroller.state == ScrollerStates.Edge)
            {
                b = Brushes.Blue;
            }
            else if (tempScroller.state == ScrollerStates.Normal)
            {
                b = Brushes.Green;
            }

            context.DrawRectangle(b, null, rect);

            Rect r = new Rect(tempScroller.position, new Size(1, 1));

            context.DrawRectangle(Brushes.Black, null, r);
        }
コード例 #4
0
ファイル: RadialMenu.cs プロジェクト: samuto/designscript
 private void ValidateScrollers()
 {
     //Checks to see if scrollers are required or not
     if (reducedList.Count > Configurations.RadialMenuMaxItems)
     {
         upScroller = new Scroller(ScrollerType.Up);
         downScroller = new Scroller(ScrollerType.Down);
         GetScrollerPosition(out upScroller.position, out downScroller.position);
     }
     else
     {
         upScroller = null;
         downScroller = null;
     }
 }
コード例 #5
0
ファイル: RadialMenu.cs プロジェクト: samuto/designscript
        private bool ScrollerHitTest(Point mousePosition, out Scroller hitScroller)
        {
            //hitScroller.state = ScrollerStates.None;
            //hitScroller.Position = new Point();
            bool result = false;
            Point pt = upScroller.position;
            hitScroller = new Scroller(ScrollerType.None);

            if (IsWithinSrollerRegion(pt, mousePosition))
            {
                hitScroller = upScroller;
                result = true;
            }
            pt = downScroller.position;
            if (IsWithinSrollerRegion(pt, mousePosition))
            {
                hitScroller = downScroller;
                result = true;
            }
            return result;
        }
コード例 #6
0
ファイル: RadialMenu.cs プロジェクト: samuto/designscript
        private void DrawScroller(DrawingContext context, Scroller tempScroller)
        {
            if (upScroller.state == ScrollerStates.None || downScroller.state == ScrollerStates.None)
                return;
            double width = 20;
            double height = 10;
            Rect rect = new Rect();
            rect.Size = new Size(width, height);
            Point center = tempScroller.position;
            center.Offset(-width / 2, -height / 2);
            rect.Location = center;

            Brush b = Brushes.White;
            if (tempScroller.state == ScrollerStates.Hovered)
                b = Brushes.Red;
            else if (tempScroller.state == ScrollerStates.Edge)
                b = Brushes.Blue;
            else if (tempScroller.state == ScrollerStates.Normal)
                b = Brushes.Green;

            context.DrawRectangle(b, null, rect);

            Rect r = new Rect(tempScroller.position, new Size(1, 1));
            context.DrawRectangle(Brushes.Black, null, r);
        }
コード例 #7
0
ファイル: RadialMenu.cs プロジェクト: samuto/designscript
        public bool HandleMouseMove(Point mousePosition, out Point newRadialMenuPoint, out int selectedItemId)
        {
            newRadialMenuPoint = new Point();
            selectedItemId = int.MinValue;
            if (null == visibleMenuItems || (visibleMenuItems.Count <= 0))
                return false;
            mousePosition.X -= radialMenuVisual.Transform.Value.OffsetX;
            mousePosition.Y -= radialMenuVisual.Transform.Value.OffsetY;

            if (upScroller != null && downScroller != null)
            {
                Scroller tempScroller = new Scroller(ScrollerType.None);
                if (ScrollerHitTest(mousePosition, out tempScroller))
                {
                    if (tempScroller.state != ScrollerStates.Edge)
                        tempScroller.state = ScrollerStates.Hovered;
                }
                else
                {
                    if (upScroller.state != ScrollerStates.Edge)
                        upScroller.state = ScrollerStates.Normal;
                    if (downScroller.state != ScrollerStates.Edge)
                        downScroller.state = ScrollerStates.Normal;
                }
            }
            if (IsWithinHitTestRegion(mousePosition) == false)
            {
                InitializeMenuItems();
                UpdateItemsArrangement(-1);
                InitializeItemWeight();
                Compose();
                return false;
            }

            int anchorIndex;
            double minWeight;
            double increment;
            Point anchorPoint = GetHorizontalProjectionOnCircle(mousePosition);
            double anchorWeight = NormalizePoint(anchorPoint);
            //GetClosestItemToAnchor(out anchorIndex, out minWeight);

            foreach (MenuItemInfo item in visibleMenuItems)
            {
                item.NormalizedDisplacement = item.NormalizedWeight - anchorWeight;
                increment = Configurations.MaxHeightIncrement * Utilities.GetGaussianValue(item.NormalizedDisplacement * Configurations.AmplifyingFactor);//+some value from gaussian function
                item.ItemHeight = Configurations.MinimumTextSize + increment;
                item.ItemColor = Configurations.NormalTextColor;
                item.SeletedFlag = false;
            }
            GetClosestItemToAnchor(out anchorIndex, out minWeight);
            visibleMenuItems.ElementAt(anchorIndex).ItemColor = Configurations.SelectedTextColor;
            visibleMenuItems.ElementAt(anchorIndex).SeletedFlag = true;
            newRadialMenuPoint = visibleMenuItems.ElementAt(anchorIndex).GetNewRadialMenuPosition();
            selectedItemId = visibleMenuItems.ElementAt(anchorIndex).MenuId;
            //UpdateItemsArrangement(anchorIndex);
            Compose();
            return true;
        }
コード例 #8
0
ファイル: RadialMenu.cs プロジェクト: samuto/designscript
        public int HandleClick(Point mousePosition)
        {
            if (null == visibleMenuItems || (visibleMenuItems.Count <= 0))
                return -1;
            mousePosition.X -= radialMenuVisual.Transform.Value.OffsetX;
            mousePosition.Y -= radialMenuVisual.Transform.Value.OffsetY;

            if (upScroller != null && downScroller != null)
            {
                Scroller tempScroller = new Scroller(ScrollerType.None);
                bool result = ScrollerHitTest(mousePosition, out tempScroller);

                if (tempScroller.Type == ScrollerType.Up)
                {
                    this.HandleScrollUp();
                    return 0;
                }
                else if (tempScroller.Type == ScrollerType.Down)
                {
                    this.HandleScrollDown();
                    return 0;
                }
            }
            if (IsWithinHitTestRegion(mousePosition) == false)
                return -1;

            int itemIndex;
            double min;
            GetClosestItemToAnchor(out itemIndex, out min);
            MenuItemInfo item = visibleMenuItems.ElementAt(itemIndex);
            Point temp;
            int tempId;
            HandleMouseMove(mousePosition, out temp, out tempId);
            return item.MenuId;
        }
コード例 #9
0
ファイル: RadialMenu.cs プロジェクト: seasailor/designscript
        public bool HandleMouseMove(Point mousePosition, out Point newRadialMenuPoint, out int selectedItemId)
        {
            newRadialMenuPoint = new Point();
            selectedItemId     = int.MinValue;
            if (null == visibleMenuItems || (visibleMenuItems.Count <= 0))
            {
                return(false);
            }
            mousePosition.X -= radialMenuVisual.Transform.Value.OffsetX;
            mousePosition.Y -= radialMenuVisual.Transform.Value.OffsetY;

            if (upScroller != null && downScroller != null)
            {
                Scroller tempScroller = new Scroller(ScrollerType.None);
                if (ScrollerHitTest(mousePosition, out tempScroller))
                {
                    if (tempScroller.state != ScrollerStates.Edge)
                    {
                        tempScroller.state = ScrollerStates.Hovered;
                    }
                }
                else
                {
                    if (upScroller.state != ScrollerStates.Edge)
                    {
                        upScroller.state = ScrollerStates.Normal;
                    }
                    if (downScroller.state != ScrollerStates.Edge)
                    {
                        downScroller.state = ScrollerStates.Normal;
                    }
                }
            }
            if (IsWithinHitTestRegion(mousePosition) == false)
            {
                InitializeMenuItems();
                UpdateItemsArrangement(-1);
                InitializeItemWeight();
                Compose();
                return(false);
            }

            int    anchorIndex;
            double minWeight;
            double increment;
            Point  anchorPoint  = GetHorizontalProjectionOnCircle(mousePosition);
            double anchorWeight = NormalizePoint(anchorPoint);

            //GetClosestItemToAnchor(out anchorIndex, out minWeight);

            foreach (MenuItemInfo item in visibleMenuItems)
            {
                item.NormalizedDisplacement = item.NormalizedWeight - anchorWeight;
                increment        = Configurations.MaxHeightIncrement * Utilities.GetGaussianValue(item.NormalizedDisplacement * Configurations.AmplifyingFactor);//+some value from gaussian function
                item.ItemHeight  = Configurations.MinimumTextSize + increment;
                item.ItemColor   = Configurations.NormalTextColor;
                item.SeletedFlag = false;
            }
            GetClosestItemToAnchor(out anchorIndex, out minWeight);
            visibleMenuItems.ElementAt(anchorIndex).ItemColor   = Configurations.SelectedTextColor;
            visibleMenuItems.ElementAt(anchorIndex).SeletedFlag = true;
            newRadialMenuPoint = visibleMenuItems.ElementAt(anchorIndex).GetNewRadialMenuPosition();
            selectedItemId     = visibleMenuItems.ElementAt(anchorIndex).MenuId;
            //UpdateItemsArrangement(anchorIndex);
            Compose();
            return(true);
        }