コード例 #1
0
        private MenuItem createMenuItemForPathType(PathType?type)
        {
            int totalCount   = Pieces.Count(p => p.IsSelected.Value);
            int countOfState = Pieces.Where(p => p.IsSelected.Value).Count(p => p.ControlPoint.Type == type);

            var item = new TernaryStateRadioMenuItem(type == null ? "Inherit" : type.ToString().Humanize(), MenuItemType.Standard, _ =>
            {
                foreach (var p in Pieces.Where(p => p.IsSelected.Value))
                {
                    updatePathType(p, type);
                }
            });

            if (countOfState == totalCount)
            {
                item.State.Value = TernaryState.True;
            }
            else if (countOfState > 0)
            {
                item.State.Value = TernaryState.Indeterminate;
            }
            else
            {
                item.State.Value = TernaryState.False;
            }

            return(item);
        }
コード例 #2
0
        private TernaryStateRadioMenuItem createMenuItem(float opacity)
        {
            var item = new TernaryStateRadioMenuItem($"{opacity * 100}%", MenuItemType.Standard, _ => updateOpacity(opacity));

            menuItemLookup[opacity] = item;
            return(item);
        }
コード例 #3
0
        protected override IEnumerable <MenuItem> GetContextMenuItemsForSelection(IEnumerable <SelectionBlueprint <ISkinnableDrawable> > selection)
        {
            var closestItem = new TernaryStateRadioMenuItem("Closest", MenuItemType.Standard, _ => applyClosestAnchors())
            {
                State = { Value = GetStateFromSelection(selection, c => !c.Item.UsesFixedAnchor) }
            };

            yield return(new OsuMenuItem("Anchor")
            {
                Items = createAnchorItems((d, a) => d.UsesFixedAnchor && ((Drawable)d).Anchor == a, applyFixedAnchors)
                        .Prepend(closestItem)
                        .ToArray()
            });

            yield return(new OsuMenuItem("Origin")
            {
                Items = createAnchorItems((d, o) => ((Drawable)d).Origin == o, applyOrigins).ToArray()
            });

            yield return(new OsuMenuItem("Reset position", MenuItemType.Standard, () =>
            {
                foreach (var blueprint in SelectedBlueprints)
                {
                    ((Drawable)blueprint.Item).Position = Vector2.Zero;
                }
            }));

            foreach (var item in base.GetContextMenuItemsForSelection(selection))
            {
                yield return(item);
            }

            IEnumerable <TernaryStateMenuItem> createAnchorItems(Func <ISkinnableDrawable, Anchor, bool> checkFunction, Action <Anchor> applyFunction)
            {
                var displayableAnchors = new[]
                {
                    Anchor.TopLeft,
                    Anchor.TopCentre,
                    Anchor.TopRight,
                    Anchor.CentreLeft,
                    Anchor.Centre,
                    Anchor.CentreRight,
                    Anchor.BottomLeft,
                    Anchor.BottomCentre,
                    Anchor.BottomRight,
                };

                return(displayableAnchors.Select(a =>
                {
                    return new TernaryStateRadioMenuItem(a.ToString(), MenuItemType.Standard, _ => applyFunction(a))
                    {
                        State = { Value = GetStateFromSelection(selection, c => checkFunction(c.Item, a)) }
                    };
                }));
            }
        }