コード例 #1
0
ファイル: ToolBuilder.cs プロジェクト: mistix/NPaint
 /// <summary>
 /// Create new instance of tool for creating lines
 /// </summary>
 /// <returns></returns>
 public Commands.ICommand CreateLineTool()
 {
     _tool = new Tools.LineTool();
     _cmd = new Commands.LineCommand((Tools.LineTool)_tool);
     _lastTool = ToolList.LineTool;
     return _cmd;
 }
コード例 #2
0
ファイル: PhysxScene.cs プロジェクト: swipswaps/halcyon
        private bool CheckDelayedCommand(Commands.ICommand cmd)
        {
            if (cmd.AffectsMultiplePrims())
            {
                bool delay = false;

                Commands.IMultiPrimCommand mpCommand = (Commands.IMultiPrimCommand)cmd;

                IEnumerable <PhysxPrim> targets = mpCommand.GetTargetPrims();
                foreach (PhysxPrim target in targets)
                {
                    delay |= CheckAddDelay(cmd, target);
                }

                //if (delay) m_log.DebugFormat("[InWorldz.PhysX] Delaying physics command pending command completion");
                return(delay);
            }
            else
            {
                PhysxPrim target = cmd.GetTargetPrim();
                if (target == null)
                {
                    return(false);
                }

                return(CheckAddDelay(cmd, target));
            }
        }
コード例 #3
0
ファイル: PhysxScene.cs プロジェクト: swipswaps/halcyon
        internal void BeginDelayCommands(PhysxPrim prim, Commands.ICommand initiator)
        {
            DelayedCommandInfo info = new DelayedCommandInfo {
                Commands = new LinkedList <Commands.ICommand>(), Initiator = initiator
            };

            _delayedCommands.Add(prim, info);
        }
コード例 #4
0
ファイル: PhysxScene.cs プロジェクト: swipswaps/halcyon
 private void DelayOrExecuteCommand(Commands.ICommand cmd)
 {
     if (!this.CheckDelayedCommand(cmd))
     {
         //Util.DebugOut(cmd.ToString());
         cmd.Execute(this);
     }
 }
コード例 #5
0
ファイル: Menu.cs プロジェクト: iammeatchunky/ChunkyConsole
 static bool EXE_Prompt(Commands.ICommand cmd)
 {
     if (cmd is Commands.IHasPrompter)
     {
         Console.Clear();
         return((cmd as Commands.IHasPrompter).Prompter.Prompt());
     }
     return(true);
 }
コード例 #6
0
ファイル: Menu.cs プロジェクト: iammeatchunky/ChunkyConsole
        static bool EXE_mnu(Commands.ICommand cmd)
        {
            if (cmd is Commands.IHasMenu && (cmd as Commands.IHasMenu).Menu.MenuItems.Count > 0)
            {
                (cmd as Commands.IHasMenu).Menu.Print();
            }

            return(true);
        }
コード例 #7
0
ファイル: PhysxScene.cs プロジェクト: swipswaps/halcyon
        private bool CheckAddDelay(Commands.ICommand cmd, PhysxPrim target)
        {
            DelayedCommandInfo delayInfo;

            if (_delayedCommands.TryGetValue(target, out delayInfo) && delayInfo.Initiator != cmd)
            {
                //if we're already the last delayed command delayed behind the other command
                //for the given prim, we only need to be added once per command so we can safely
                //just return
                if (delayInfo.Commands.Count > 0 && delayInfo.Commands.Last.Value == cmd)
                {
                    return(true);
                }

                //before adding this new command to wait, check to see if it is cullable.
                //if the command is cullable, and has the same targets, we replace it with this command
                //maintaining its position in the queue
                LinkedListNode <Commands.ICommand> cmdNode;
                if (cmd.IsCullable &&
                    delayInfo.TopCullables != null && delayInfo.TopCullables.TryGetValue(cmd.GetType(), out cmdNode) &&
                    HasSameTargets(cmdNode.Value, cmd))
                {
                    cmdNode.Value = cmd;
                    if (cmd.AffectsMultiplePrims())
                    {
                        ((Commands.IMultiPrimCommand)cmd).AddDelay();
                    }

                    return(true);
                }
                else
                {
                    cmdNode = delayInfo.Commands.AddLast(cmd);
                    if (cmd.AffectsMultiplePrims())
                    {
                        ((Commands.IMultiPrimCommand)cmd).AddDelay();
                    }

                    if (cmd.IsCullable)
                    {
                        if (delayInfo.TopCullables == null)
                        {
                            delayInfo.TopCullables = new Dictionary <Type, LinkedListNode <Commands.ICommand> >();
                        }

                        delayInfo.TopCullables.Add(cmd.GetType(), cmdNode);
                    }

                    return(true);
                }
            }

            return(false);
        }
コード例 #8
0
        private static void AddSubMenuItems([NotNull] MenuItem menuItem, [NotNull] Commands.ICommand parentCommand, [NotNull] object context)
        {
            Debug.ArgumentNotNull(menuItem, nameof(menuItem));
            Debug.ArgumentNotNull(parentCommand, nameof(parentCommand));
            Debug.ArgumentNotNull(context, nameof(context));

            var commands = parentCommand.GetSubmenuCommands(context);

            if (!commands.Any())
            {
                return;
            }

            commands = Commands.CommandManager.Sort(commands);

            string group       = null;
            var    isSeparator = true;

            foreach (var command in commands)
            {
                if (command is CommandSeparator)
                {
                    AddSeparator(menuItem.Items, ref isSeparator);
                    continue;
                }

                if (string.Compare(command.Group, group, StringComparison.InvariantCulture) != 0)
                {
                    AddSeparator(menuItem.Items, ref isSeparator);
                    group = command.Group;
                }

                isSeparator = false;

                var newItem = GetMenuItem(command, context);

                menuItem.Items.Add(newItem);

                AddSubMenuItems(newItem, command, context);
            }
        }
コード例 #9
0
ファイル: PhysxScene.cs プロジェクト: swipswaps/halcyon
        private bool HasSameTargets(Commands.ICommand cmd1, Commands.ICommand cmd2)
        {
            if (cmd1.AffectsMultiplePrims() != cmd2.AffectsMultiplePrims())
            {
                m_log.ErrorFormat("[InWorldz.PhysxPhysics] Asked to check command targets for different command types!");
                return(false);
            }

            if (cmd1.AffectsMultiplePrims())
            {
                IEnumerator <PhysxPrim> cmd1prims = ((Commands.IMultiPrimCommand)cmd1).GetTargetPrims().GetEnumerator();
                IEnumerator <PhysxPrim> cmd2prims = ((Commands.IMultiPrimCommand)cmd2).GetTargetPrims().GetEnumerator();

                bool cmd1end = false;
                bool cmd2end = false;

                while (true)
                {
                    cmd1end = cmd1prims.MoveNext();
                    cmd2end = cmd2prims.MoveNext();

                    if (cmd1end || cmd2end)
                    {
                        break;
                    }

                    if (cmd1prims.Current != cmd2prims.Current)
                    {
                        return(false);
                    }
                }

                return(cmd1end == cmd2end);
            }
            else
            {
                return(cmd1.GetTargetPrim() == cmd2.GetTargetPrim());
            }
        }
コード例 #10
0
ファイル: PhysxScene.cs プロジェクト: swipswaps/halcyon
 /// <summary>
 /// Enqueues commands to be processed FIRST on the next physics spin
 /// This ensures that commands that were blocked and delayed for a specific
 /// object run first before other commands that may have gotten in just after
 /// the delay was released
 /// </summary>
 /// <param name="cmd"></param>
 private void EnqueueFreedCommand(Commands.ICommand cmd)
 {
     _freedCommands.Enqueue(cmd);
 }
コード例 #11
0
ファイル: PhysxScene.cs プロジェクト: swipswaps/halcyon
 public void QueueCommand(Commands.ICommand command)
 {
     _currentCommandQueue.Enqueue(command);
     _timingSignal.Set();
 }
コード例 #12
0
        private static MenuItem GetMenuItem([NotNull] Commands.ICommand command, [NotNull] object context)
        {
            Debug.ArgumentNotNull(command, nameof(command));
            Debug.ArgumentNotNull(context, nameof(context));

            var text = command.Text;

            if (AppHost.Settings.Options.ShowGroupAndSortingValue)
            {
                text = string.Format(@"[{0} {1}]    {2}", command.SortingValue, command.Group, text);
            }

            var menuItem = new MenuItem
            {
                Header    = text,
                Icon      = command.Icon,
                IsChecked = command.IsChecked,
                Tag       = command

                            // InputGestureText = command.InputGestureText,
            };

            if (!string.IsNullOrEmpty(command.ToolTip))
            {
                menuItem.ToolTip = command.ToolTip;
            }

            var commandFullName = command.GetType().FullName;
            var shortcut        = KeyboardManager.Shortcuts.FirstOrDefault(s => s.CommandName == commandFullName);

            if (shortcut != null)
            {
                menuItem.InputGestureText = shortcut.FormattedKeys;
            }

            menuItem.Click += delegate
            {
                AppHost.Usage.ReportCommand(command, context);
                command.Execute(context);
            };

            if (command.Icon != null)
            {
                menuItem.Icon = new Image
                {
                    Source = command.Icon.GetSource(),
                    Width  = 16,
                    Height = 16
                };
            }

            if (command.SubmenuOpened != null)
            {
                var loading = new MenuItem
                {
                    Header     = Resources.Loading,
                    Tag        = @"loading",
                    Foreground = SystemColors.GrayTextBrush
                };

                menuItem.Items.Add(loading);
                menuItem.SubmenuOpened += command.SubmenuOpened;
            }

            return(menuItem);
        }
コード例 #13
0
ファイル: Menu.cs プロジェクト: iammeatchunky/ChunkyConsole
 static bool EXE_exe(Commands.ICommand cmd)
 {
     Console.Clear();
     cmd.Execute();
     return(true);
 }
コード例 #14
0
ファイル: ToolBuilder.cs プロジェクト: mistix/NPaint
 public ToolBuilder()
 {
     _tool = new Tools.LineTool();
     _cmd = new Commands.LineCommand((Tools.LineTool)_tool);
     _lastTool = ToolList.LineTool;
 }