Example #1
0
        public static void ExecuteMouseGestureCommand(Control control, MouseGesture gesture)
        {
            var foo     = new List <InputBinding>(control.InputBindings.Cast <InputBinding>());
            var binding = foo.Where(x => x.Gesture is MouseGesture && (x.Gesture as MouseGesture).MouseAction == gesture.MouseAction && (x.Gesture as MouseGesture).Modifiers == gesture.Modifiers).FirstOrDefault();

            binding.Command.Execute(null);
        }
        /// <summary>
        /// Wires the trigger into the interactin hierarchy.
        /// </summary>
        /// <param name="node">The node.</param>
        public override void Attach(IInteractionNode node)
        {
            InputGesture gesture;

            if (Key != Key.None)
            {
                gesture = new UnrestrictedKeyGesture(Key, Modifiers);
            }
            else
            {
                gesture = new MouseGesture(MouseAction, Modifiers);
            }

            var uiElement = node.UIElement as UIElement;

            if (uiElement == null)
            {
                var ex = new CaliburnException(
                    string.Format(
                        "You cannot use a GestureMessageTrigger with an instance of {0}.  The source element must inherit from UIElement.",
                        node.UIElement.GetType().FullName
                        )
                    );

                Log.Error(ex);
                throw ex;
            }

            FindOrCreateLookup(uiElement, gesture)
            .AddTrigger(this);

            base.Attach(node);
        }
Example #3
0
        //Build full name of the resource
        private string getResourceName(MouseGesture mg, bool activeImage)
        {
            string gestureName = Enum.GetName(typeof(MouseGesture), (MouseGesture)mg);
            string returnValue = "WiiDesktop.Resources.Images." + gestureName + ".png";

            return(returnValue);
        }
Example #4
0
        public MainWindow()
        {
            InitializeComponent();

            // Клавиатурный жест Control+F
            InputGesture gesture = new KeyGesture(Key.F, ModifierKeys.Control, "Ctrl+F");

            ApplicationCommands.Find.InputGestures.Add(gesture);

            // Комбинированный жест Control+LeftClick
            gesture = new MouseGesture(MouseAction.LeftClick, ModifierKeys.Control);
            ApplicationCommands.Find.InputGestures.Add(gesture);

            // Клавиатурный жест Control+Q
            KeyGesture keyGesture = new KeyGesture(Key.Q, ModifierKeys.Control, "Ctrl+Q");

            ApplicationCommands.Find.InputGestures.Add(keyGesture);

            // Комбинированный жест Alt+LeftClick
            MouseGesture mouseGesture = new MouseGesture();

            mouseGesture.MouseAction = MouseAction.LeftClick;
            mouseGesture.Modifiers   = ModifierKeys.Alt;
            ApplicationCommands.Find.InputGestures.Add(mouseGesture);
        }
Example #5
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            this.MouseMove        += new MouseEventHandler(MouseMoveHighlightCapture);
            this.MouseDown        += new MouseButtonEventHandler(MyMouseDown);
            this.GotMouseCapture  += new MouseEventHandler(MyGotMouseCapture);
            this.LostMouseCapture += new MouseEventHandler(MyLostMouseCapture);

            CaptureMouseCommand = new RoutedCommand();


            MouseGesture CaptureMouseGesture           = new MouseGesture(MouseAction.WheelClick, ModifierKeys.Control);
            KeyGesture   CaptureMouseCommandKeyGesture = new KeyGesture(Key.A, ModifierKeys.Alt);

            CommandBinding CaptureMouseCommandBinding = new CommandBinding
                                                            (CaptureMouseCommand, CaptureMouseCommandExecuted, CaptureMouseCommandCanExecute);

            InputBinding CaptureMouseCommandInputBinding = new InputBinding
                                                               (CaptureMouseCommand, CaptureMouseGesture);
            InputBinding CaptureMouseCommandKeyBinding = new InputBinding
                                                             (CaptureMouseCommand, CaptureMouseCommandKeyGesture);

            this.CommandBindings.Add(CaptureMouseCommandBinding);
            this.InputBindings.Add(CaptureMouseCommandInputBinding);
            this.InputBindings.Add(CaptureMouseCommandKeyBinding);
        }
Example #6
0
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        MouseGesture gesture = (MouseGesture)value;

        string hotkey = new MGlobalHotkeys.WPF.Hotkey(Key.None, gesture.Modifiers).ToString();

        return($"{hotkey}+{gesture.MouseAction}");
    }
Example #7
0
        public string ResolveCommand(MouseGesture mGesture)
        {
            string command = String.Empty;

            configMap.TryGetValue(mGesture, out command);

            return(command);
        }
Example #8
0
 public ApplicationsComboBox(MouseGesture gesture)
     : base()
 {
     this.gesture               = gesture;
     this.DataSource            = ApplicationsFinder.GetAvailableApplications();
     this.SelectedIndexChanged += new System.EventHandler(this.OnChange);
     this.SelectedIndex         = -1;
 }
Example #9
0
        public static IScriptCommand IfMouseGesture(MouseGesture gesture,
                                                    IScriptCommand nextCommand = null, IScriptCommand otherwiseCommand = null)
        {
            string MouseGestureVariable = "{IfMouseGesture-Gesture}";

            return
                (ScriptCommands.Assign(MouseGestureVariable, gesture, false,
                                       HubScriptCommands.IfMouseGesture(MouseGestureVariable, nextCommand, otherwiseCommand)));
        }
Example #10
0
        // </SnippetKeyDownHandlerKeyGestureMatches>

        // <SnippetKeyDownHandlerMouseGestureMatches>
        private void OnMouseDown(object sender, MouseEventArgs e)
        {
            MouseGesture mouseGesture = new MouseGesture(MouseAction.MiddleClick, ModifierKeys.Control);

            if (mouseGesture.Matches(null, e))
            {
                MessageBox.Show("Trapped Mouse Gesture");
            }
        }
        public void MouseGesture_TryParse_FailsForInvalidStringsWithRepeatedModifiers()
        {
            RuntimeHelpers.RunClassConstructor(typeof(UltravioletStrings).TypeHandle);

            var gesture = default(MouseGesture);
            var result  = MouseGesture.TryParse("Ctrl+Ctrl+LeftClick", out gesture);

            TheResultingValue(result).ShouldBe(false);
            TheResultingObject(gesture).ShouldBeNull();
        }
Example #12
0
        private static void GenerateInputBindings(CodeMemberMethod method, FrameworkElement element)
        {
            for (int i = 0; i < element.InputBindings.Count; i++)
            {
                CodeVariableDeclarationStatement bindingVar = null;
                string       bindingVarName = element.Name + "_IB_" + i;
                var          bindingVarRef  = new CodeVariableReferenceExpression(bindingVarName);
                MouseBinding mouseBinding   = element.InputBindings[i] as MouseBinding;
                if (mouseBinding != null)
                {
                    bindingVar = new CodeVariableDeclarationStatement("MouseBinding", bindingVarName, new CodeObjectCreateExpression("MouseBinding"));
                    method.Statements.Add(bindingVar);

                    MouseGesture mouseGesture = mouseBinding.Gesture as MouseGesture;
                    if (mouseGesture != null)
                    {
                        method.Statements.Add(new CodeAssignStatement(
                                                  new CodeFieldReferenceExpression(bindingVarRef, "Gesture"),
                                                  new CodeObjectCreateExpression("MouseGesture",
                                                                                 new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(MouseAction).Name), mouseGesture.MouseAction.ToString()),
                                                                                 new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(ModifierKeys).Name), mouseGesture.Modifiers.ToString())
                                                                                 )));
                    }
                }

                KeyBinding keyBinding = element.InputBindings[i] as KeyBinding;
                if (keyBinding != null)
                {
                    bindingVar = new CodeVariableDeclarationStatement("KeyBinding", bindingVarName, new CodeObjectCreateExpression("KeyBinding"));
                    method.Statements.Add(bindingVar);

                    KeyGesture keyGesture = keyBinding.Gesture as KeyGesture;
                    if (keyGesture != null)
                    {
                        method.Statements.Add(new CodeAssignStatement(
                                                  new CodeFieldReferenceExpression(bindingVarRef, "Gesture"),
                                                  new CodeObjectCreateExpression("KeyGesture",
                                                                                 new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("KeyCode"), keyGesture.Key.ToString()),
                                                                                 new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(ModifierKeys).Name), keyGesture.Modifiers.ToString()),
                                                                                 new CodePrimitiveExpression(keyGesture.DisplayString)
                                                                                 )));
                    }
                }

                if (bindingVar != null)
                {
                    DependencyObject depObject = element.InputBindings[i] as DependencyObject;
                    CodeComHelper.GenerateField <object>(method, bindingVarRef, depObject, InputBinding.CommandParameterProperty);
                    CodeComHelper.GenerateBindings(method, bindingVarRef, depObject, bindingVarName);

                    method.Statements.Add(new CodeMethodInvokeExpression(
                                              new CodeVariableReferenceExpression(element.Name), "InputBindings.Add", new CodeVariableReferenceExpression(bindingVarName)));
                }
            }
        }
        public void MouseGesture_TryParse_SucceedsForValidStrings_WithModifierKeys()
        {
            RuntimeHelpers.RunClassConstructor(typeof(UltravioletStrings).TypeHandle);

            var gesture = default(MouseGesture);
            var result  = MouseGesture.TryParse("Ctrl+Alt+MiddleDoubleClick", out gesture);

            TheResultingValue(result).ShouldBe(true);
            TheResultingValue(gesture.MouseAction).ShouldBe(MouseAction.MiddleDoubleClick);
            TheResultingValue(gesture.Modifiers).ShouldBe(ModifierKeys.Control | ModifierKeys.Alt);
        }
Example #14
0
        public void FillMapFromFile()
        {
            configMap.Clear();
            PropertiesReader propertiesReader = new PropertiesReader(Settings.CONFIGURATION_DATA_PATH + GESTURES_FILE_NAME);

            foreach (DictionaryEntry item in propertiesReader)
            {
                Debug.Write(item.Key.ToString() + "=" + item.Value.ToString());
                MouseGesture mouseGesture = (MouseGesture)Enum.Parse(typeof(MouseGesture), item.Key.ToString());
                configMap.Add(mouseGesture, item.Value.ToString());
            }
        }
Example #15
0
        private void PrepararImagemDeCompraDeCartas()
        {
            Image img = ObterImagem("cartasCompra.png");

            img.Width        = 130;
            _imagemDeExemplo = img;

            MouseGesture cmdMouseGesture = new MouseGesture(MouseAction.LeftClick, ModifierKeys.None);
            MouseBinding cmdMouseBinding = new MouseBinding(PedirCartaCommand, cmdMouseGesture);

            img.InputBindings.Add(cmdMouseBinding);

            _stackCompraCartas.Children.Add(img);
        }
Example #16
0
 public void UpdateCommand(MouseGesture gesture, String application)
 {
     try
     {
         if (!application.Equals(SYSTEM_IDLE_PROCESS))
         {
             configMap.Add(gesture, application);
         }
     }
     catch (ArgumentException)
     {
         configMap.Remove(gesture);
         configMap.Add(gesture, application);
     }
 }
        private void LedMatrixInit()
        {
            BrushConverter bc = new BrushConverter();

            int[] ledColors = InitialColors;
            Grid  grid      = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center
            };

            for (int i = 0; i < 8; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                for (int j = 0; j < 8; j++)
                {
                    grid.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    });
                    Rectangle rect = new Rectangle()
                    {
                        Fill   = new SolidColorBrush(Color.FromArgb(153, (byte)((ledColors[i * 8 + j] >> 16) & 0xFF), (byte)((ledColors[i * 8 + j] >> 8) & 0xFF), (byte)((ledColors[i * 8 + j] >> 0) & 0xFF))),
                        Width  = 30,
                        Height = 30,
                        Margin = new Thickness(5, 5, 5, 5),
                    };

                    LedClicked = new LedCommand(this, i, j);
                    MouseAction  action  = MouseAction.LeftClick;
                    MouseGesture gesture = new MouseGesture(action);
                    MouseBinding binding = new MouseBinding(LedClicked, gesture);
                    rect.InputBindings.Add(binding);

                    Grid.SetRow(rect, i);
                    Grid.SetColumn(rect, j);
                    grid.Children.Add(rect);
                    ledMatrix.Add(Tuple.Create(i, j), rect);
                    ledMatrixData[i * 8 + j] = initialColor;
                }
            }

            ViewLedMatrix = grid;
        }
Example #18
0
        private void MyCommandExecute(object sender, ExecutedRoutedEventArgs e)
        {
            RoutedUICommand srcCommand = e.Command as RoutedUICommand;

            txtGesture.Text       = string.Empty;
            txtGesture.FontWeight = FontWeights.Heavy;
            txtGesture.Text      += "Command:  " + srcCommand.Name + "\n";
            txtGesture.Text      += "Owner Type:  " + srcCommand.OwnerType.ToString() + "\n";
            txtGesture.Text      += "Text :  " + srcCommand.Text + "\n" + "\n" + "\n";
            txtGesture.FontWeight = FontWeights.Normal;
            if (srcCommand != null)
            {
                txtGesture.Text += "Number of Gestures: " + srcCommand.InputGestures.Count.ToString() + "\n";
                if (srcCommand.InputGestures.Count == 0)
                {
                    txtGesture.Text += "\n" + "No Gestures";
                }
                else
                {
                    foreach (InputGesture gesture in srcCommand.InputGestures)
                    {
                        txtGesture.Text += "\n" + gesture.ToString() + "\n";

                        KeyGesture keyGesture = gesture as KeyGesture;
                        if (keyGesture != null)
                        {
                            txtGesture.Text += "Key: " + keyGesture.Key.ToString() + "\n";
                            txtGesture.Text += "Modifers: " + keyGesture.Modifiers.ToString() + "\n";
                        }

                        txtGesture.Text += "\n";

                        MouseGesture mouseGesture = gesture as MouseGesture;
                        if (mouseGesture != null)
                        {
                            txtGesture.Text += "Mouse Action: " + mouseGesture.MouseAction.ToString() + "\n";
                            txtGesture.Text += "Modifers: " + mouseGesture.Modifiers.ToString() + "\n";
                        }
                        if (mouseGesture == null)
                        {
                            txtGesture.Text += "No Mouse Gestures" + "\n";
                        }
                    }
                }
                //   cmdButton.Command = srcCommand;
            }
        }
Example #19
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // NON-PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Handles the <c>Checked</c> event of the <see cref="logoRadioButton"/> or <see cref="buttonRadioButton"/> control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void OnRadioButtonChecked(object sender, RoutedEventArgs e)
        {
            if (null == this.zoomContentControl)
            {
                return;
            }

            // Remove the MouseBinding that is bound to the LeftClick action
            for (int i = 0; i < this.zoomContentControl.InputBindings.Count; i++)
            {
                MouseBinding binding = this.zoomContentControl.InputBindings[i] as MouseBinding;
                if (null != binding)
                {
                    MouseGesture gesture = binding.Gesture as MouseGesture;
                    if (null != gesture && MouseAction.LeftClick == gesture.MouseAction && ModifierKeys.None == gesture.Modifiers)
                    {
                        this.zoomContentControl.InputBindings.RemoveAt(i);
                        break;
                    }
                }
            }

            // Add in a new MouseBinding for the LeftClick action
            this.zoomContentControl.InputBindings.Clear();
            if (true == this.panDragRadioButton.IsChecked)
            {
                this.zoomContentControl.InputBindings.Add(new MouseBinding(ZoomContentControlCommands.StartPanDrag,
                                                                           new MouseGesture(MouseAction.LeftClick)));
            }
            else if (true == this.zoomInRadioButton.IsChecked)
            {
                this.zoomContentControl.InputBindings.Add(new MouseBinding(ZoomContentControlCommands.StartZoomIn,
                                                                           new MouseGesture(MouseAction.LeftClick)));
            }
            else if (true == this.zoomOutRadioButton.IsChecked)
            {
                this.zoomContentControl.InputBindings.Add(new MouseBinding(ZoomContentControlCommands.StartZoomOut,
                                                                           new MouseGesture(MouseAction.LeftClick)));
            }
            else if (true == this.zoomDragRadioButton.IsChecked)
            {
                this.zoomContentControl.InputBindings.Add(new MouseBinding(ZoomContentControlCommands.StartZoomDrag,
                                                                           new MouseGesture(MouseAction.LeftClick)));
            }

            this.zoomContentControl.UpdateCursor();
        }
Example #20
0
        private void addEllipseClick()
        {
            foreach (string s in nodeList)
            {
                object obj = _xaml.FindName(s);
                if (!(obj is Ellipse))
                {
                    throw new XamlParseException($"{s} is Not a Ellipse.");
                }

                Ellipse      ellipse = (Ellipse)obj;
                MouseGesture gesture = new MouseGesture(MouseAction.LeftClick);
                MouseBinding binding = new MouseBinding(new NodeClickCommand(), gesture);
                binding.CommandParameter = new Tuple <ScenicMap, Ellipse>(this, ellipse);
                ellipse.InputBindings.Add(binding);
            }
        }
Example #21
0
        /// <summary>
        /// メインフォーム
        /// </summary>
        public DrawingForm()
        {
            InitializeComponent();
            this.DoubleBuffered = true;

            var drawingManager = new DrawingManager(new RectanglePen(Color.Blue));

            drawingManager.Start(this, MouseButtons.Left);

            var gesture = new MouseGesture();

            gesture.DirectionCaptured += (o, e) => this.Text = e.Gesture;
            gesture.Add("→←→",
                        () =>
            {
                drawingManager.Clear();
                this.Text = "クリア";
                this.Refresh();
            });
            gesture.Add("↑↓",
                        () =>
            {
                drawingManager.DefaultItem = new EllipsePen(Color.Red);
                this.Text = "楕円";
                this.Refresh();
            });
            gesture.Add("↑→↓←",
                        () =>
            {
                drawingManager.DefaultItem = new RectanglePen(Color.Blue);
                this.Text = "四角形";
                this.Refresh();
            });
            gesture.Add("↓→↑",
                        () =>
            {
                drawingManager.DefaultItem = DrawingManager.Selector;
                this.Text = "選択";
                this.Refresh();
            });
            gesture.Start(this, MouseButtons.Right, 30);


            this.Paint += (o, e) => drawingManager.Draw(e.Graphics);
        }
Example #22
0
        private Image ObterImagemDaCarta(Carta carta, string commandParameterName)
        {
            Image novaCarta = ObterImagem($"{carta.Simbolo.ToString().ToLower()}{carta.Nipe}.png");

            novaCarta.Width = 90;
            string nomeDoCommandParameter = commandParameterName;

            novaCarta.Name   = $"carta{nomeDoCommandParameter}_{carta.Simbolo.ToString().ToLower()}_{carta.Nipe}";
            novaCarta.Margin = new Thickness(10, 0, 0, 0);

            MouseGesture mouseGesture = new MouseGesture(MouseAction.LeftClick, ModifierKeys.None);
            MouseBinding mouseBinding = new MouseBinding(SelectCardCommand, mouseGesture);

            mouseBinding.CommandParameter = novaCarta;

            novaCarta.InputBindings.Add(mouseBinding);

            return(novaCarta);
        }
Example #23
0
        public override IScriptCommand Execute(ParameterDic pm)
        {
            MouseEventArgs mouseEvent = pm.GetValue <MouseEventArgs>(RoutedEventArgsKey);
            UIElement      sender     = pm.GetValue <UIElement>(SenderKey);

            if (mouseEvent == null)
            {
                return(OtherwiseCommand);
            }

            object       MouseGestureObject = !MouseGestureKey.StartsWith("{") ? MouseGestureKey : pm.GetValue(MouseGestureKey);
            MouseGesture gesture            = null;

            if (MouseGestureObject is MouseGesture)
            {
                gesture = (MouseGesture)MouseGestureObject;
            }

            if (MouseGestureObject is string)
            {
                gesture = (MouseGesture)converter.ConvertFrom(MouseGestureObject);
            }


            bool match = false;

            if (gesture != null && gesture.Modifiers == Keyboard.Modifiers)
            {
                switch (gesture.MouseAction)
                {
                case MouseAction.LeftClick: match = mouseEvent.LeftButton == MouseButtonState.Pressed; break;

                case MouseAction.RightClick: match = mouseEvent.RightButton == MouseButtonState.Pressed; break;

                case MouseAction.MiddleClick: match = mouseEvent.MiddleButton == MouseButtonState.Pressed; break;

                default: match = gesture.MouseAction == GetMouseAction(mouseEvent); break;
                }
            }
            return(match ? NextCommand : OtherwiseCommand);
        }
Example #24
0
        //-------------------------------------------------------------
        // イベントの初期化
        //-------------------------------------------------------------
        private void InitEvent()
        {
            // スレッドビューワを開く
            openViewerToolStripButton.Click += (sender, e) => shortcut.ExecCommand(Commands.OpenPeerstViewer);
            // 最小化ボタン
            minToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.MinButtonClick);
            // 最大化ボタン
            maxToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.MaxButtonClick);
            // 閉じるボタン
            closeToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.CloseButtonClick);
            // 音量クリック
            statusBar.VolumeClick += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.Mute);
            // ダブルクリック
            pecaPlayer.DoubleClickEvent += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.DoubleClick);
            // マウスホイール
            MouseWheel += (sender, e) =>
            {
                if ((Control.MouseButtons & MouseButtons.Right) == MouseButtons.Right)
                {
                    // 右クリックマウスホイール
                    if (e.Delta > 0)
                    {
                        shortcut.RaiseEvent(ShortcutEvents.RightClickWheelUp);
                    }
                    else if (e.Delta < 0)
                    {
                        shortcut.RaiseEvent(ShortcutEvents.RightClickWheelDown);
                    }
                }
                else
                {
                    // マウスホイール
                    if (e.Delta > 0)
                    {
                        shortcut.RaiseEvent(ShortcutEvents.WheelUp);
                    }
                    else if (e.Delta < 0)
                    {
                        shortcut.RaiseEvent(ShortcutEvents.WheelDown);
                    }
                }
            };

            // チャンネル情報更新
            bool isFirst = true;

            pecaPlayer.ChannelInfoChange += (sender, e) =>
            {
                ChannelInfo info = pecaPlayer.ChannelInfo;
                // TODO 文字が空の場合は、スペースを空けない
                UpdateChannelDetail(info);

                // タイトル設定
                string chName = getChannelName(info);
                Win32API.SetWindowText(Handle, String.Format("{0} - PeerstPlayer", chName));

                // 初回のみの設定
                if (isFirst)
                {
                    // コンタクトURL設定
                    // TODO コンタクトURLが変更されたら、通知後にURL変更
                    // コンタクトURLが空の場合、引数からコンタクトURLを取得する
                    if (string.IsNullOrEmpty(info.Url))
                    {
                        var commandLine = Environment.GetCommandLineArgs();
                        if (Environment.GetCommandLineArgs().Length > 4)
                        {
                            var url = commandLine[4];
                            statusBar.SelectThreadUrl = url;
                        }
                        else
                        {
                            // コンタクトURLが空の場合
                            statusBar.SelectThreadUrl = String.Empty;
                        }
                    }
                    else
                    {
                        statusBar.SelectThreadUrl = info.Url;
                    }
                    isFirst = false;
                }
            };

            // ステータスバーのサイズ変更
            statusBar.HeightChanged += (sender, e) =>
            {
                // 最大化時はサイズ変更しない
                if (WindowState == FormWindowState.Maximized)
                {
                    return;
                }

                // Formサイズ変更
                if (FrameInvisible)
                {
                    Size = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
                }
                else
                {
                    ClientSize = new Size(ClientSize.Width, (pecaPlayer.Height + statusBar.Height));
                }
            };

            // ステータスバーのクリックイベント
            statusBar.ChannelDetailClick += (sender, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    shortcut.RaiseEvent(ShortcutEvents.StatusbarLeftClick);
                }
                else if (e.Button == MouseButtons.Right)
                {
                    shortcut.RaiseEvent(ShortcutEvents.StatusbarRightClick);
                }
            };

            // サイズ変更
            SizeChanged += (sender, e) =>
            {
                if ((ClientSize.Width) == 0 || (ClientSize.Height == 0))
                {
                    return;
                }

                // 幅
                pecaPlayer.Width = ClientSize.Width;
                statusBar.Width  = ClientSize.Width;

                // 高さ
                pecaPlayer.Height = ClientSize.Height - statusBar.Height;
                statusBar.Top     = pecaPlayer.Bottom;
            };

            // 動画サイズ変更
            pecaPlayer.MovieSizeChange += (sender, e) =>
            {
                // Formサイズ変更
                if (FrameInvisible)
                {
                    Size = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
                }
                else
                {
                    ClientSize = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
                }

                // 幅
                statusBar.Width = pecaPlayer.Width;

                // 高さ
                statusBar.Top = pecaPlayer.Bottom;
            };

            // 音量変更イベント
            pecaPlayer.VolumeChange += (sender, e) => statusBar.Volume = (pecaPlayer.Mute ? "-" : pecaPlayer.Volume.ToString());

            // スレッドタイトル右クリックイベント
            statusBar.ThreadTitleRightClick += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.ThreadTitleRightClick);

            // マウスジェスチャー
            MouseGesture mouseGesture = new MouseGesture();

            mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
            bool isGesturing = false;

            // タイマーイベント
            Timer timer = new Timer();

            timer.Interval = MovieStatusUpdateInterval;
            timer.Tick    += (sender, e) =>
            {
                // 自動表示ボタンの表示切り替え
                if (toolStrip.Visible && !IsVisibleToolStrip(PointToClient(MousePosition)))
                {
                    toolStrip.Visible = false;
                }

                // 画面外に出たらマウスジェスチャー解除
                if (!RectangleToScreen(ClientRectangle).Contains(MousePosition))
                {
                    isGesturing = false;
                }

                // 動画ステータスを表示
                if (pecaPlayer.Duration.Length == 0)
                {
                    switch (pecaPlayer.PlayState)
                    {
                    case WMPPlayState.wmppsUndefined: statusBar.MovieStatus = "";                   break;

                    case WMPPlayState.wmppsStopped: statusBar.MovieStatus = "停止";         break;

                    case WMPPlayState.wmppsPaused: statusBar.MovieStatus = "一時停止";       break;

                    case WMPPlayState.wmppsPlaying: statusBar.MovieStatus = "再生中";                break;

                    case WMPPlayState.wmppsScanForward: statusBar.MovieStatus = "早送り";                break;

                    case WMPPlayState.wmppsScanReverse: statusBar.MovieStatus = "巻き戻し";       break;

                    case WMPPlayState.wmppsWaiting: statusBar.MovieStatus = "接続待機";       break;

                    case WMPPlayState.wmppsMediaEnded: statusBar.MovieStatus = "再生完了";       break;

                    case WMPPlayState.wmppsTransitioning: statusBar.MovieStatus = "準備中";            break;

                    case WMPPlayState.wmppsReady: statusBar.MovieStatus = "準備完了";       break;

                    case WMPPlayState.wmppsReconnecting: statusBar.MovieStatus = "再接続";                break;

                    case WMPPlayState.wmppsBuffering: statusBar.MovieStatus = string.Format("バッファ{0}%", pecaPlayer.BufferingProgress); break;
                    }
                }
                // 再生時間を表示
                else
                {
                    statusBar.MovieStatus = pecaPlayer.Duration;
                }

                // 動画情報を更新
                ChannelInfo info = pecaPlayer.ChannelInfo ?? new ChannelInfo();
                statusBar.UpdateMovieInfo(
                    new MovieInfo()
                {
                    NowFps         = pecaPlayer.NowFrameRate,
                    Fps            = pecaPlayer.FrameRate,
                    NowBitrate     = pecaPlayer.NowBitrate,
                    Bitrate        = pecaPlayer.Bitrate,
                    ListenerNumber = info.Listeners,
                    RelayNumber    = info.Relays,
                    Status         = info.Status,
                    StreamType     = info.Type,
                });
            };
            timer.Start();

            // マウスダウンイベント
            pecaPlayer.MouseDownEvent += (sender, e) =>
            {
                if (e.nButton == (short)Keys.LButton)
                {
                    // マウスドラッグ
                    FormUtility.WindowDragStart(this.Handle);
                }
                else if (e.nButton == (short)Keys.RButton)
                {
                    // マウスジェスチャー開始
                    mouseGesture.Start();
                    isGesturing = true;
                }
                else if (e.nButton == (short)Keys.MButton)
                {
                    // 中クリック
                    shortcut.RaiseEvent(ShortcutEvents.MiddleClick);
                }
            };

            // マウスアップイベント
            pecaPlayer.MouseUpEvent += (sender, e) =>
            {
                if (e.nButton == (short)Keys.RButton)
                {
                    // チャンネル詳細を再描画
                    ChannelInfo info = pecaPlayer.ChannelInfo;
                    if (info != null)
                    {
                        UpdateChannelDetail(info);
                    }

                    // マウスジェスチャーが実行されていなければ
                    string gesture = mouseGesture.ToString();
                    if (string.IsNullOrEmpty(gesture))
                    {
                        // コンテキストメニュー表示
                        contextMenuStrip.Show(MousePosition);
                    }
                    else if (isGesturing)
                    {
                        // マウスジェスチャー実行
                        shortcut.ExecGesture(gesture);
                    }

                    isGesturing = false;
                }
            };

            // マウス移動イベント
            pecaPlayer.MouseMoveEvent += (sender, e) =>
            {
                // 自動表示ボタンの表示切り替え
                if (toolStrip.Visible != IsVisibleToolStrip(new Point(e.fX, e.fY)))
                {
                    toolStrip.Visible = !toolStrip.Visible;
                }

                if (isGesturing)
                {
                    // ジェスチャー表示
                    mouseGesture.Moving(new Point(e.fX, e.fY));

                    string gesture = mouseGesture.ToString();
                    string detail  = shortcut.GetGestureDetail(gesture);
                    if (!String.IsNullOrEmpty(gesture))
                    {
                        string message = string.Format("ジェスチャ: {0} {1}", gesture, (String.IsNullOrEmpty(detail) ? "" : "(" + detail + ")"));
                        ToastMessage.Show(message);
                    }
                }
            };

            // キー押下イベント
            pecaPlayer.KeyDownEvent += (sender, e) => shortcut.RaiseKeyEvent(e);

            // ステータスバー マウスホバーイベント
            statusBar.MouseHoverEvent += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.StatusbarHover);

            // 終了処理
            FormClosed += (sender, e) =>
            {
                Logger.Instance.Debug("FormClosed");
                pecaPlayer.Close();
                statusBar.Close();
            };

            // グローウィンドウの弊害で消えなくなっていたので自分で消えるようにする
            Deactivate += (sender, e) =>
            {
                contextMenuStrip.Hide();
            };

            // 動画再生イベント
            pecaPlayer.MovieStart += (sender, e) =>
            {
                pecaPlayer.UpdateChannelInfo();
                shortcut.ExecCommand(PlayerSettings.MovieStartCommand);
            };

            // コマンド実行内容の表示
            shortcut.CommandExecuted += (sender, e) =>
            {
                CommnadExecutedEventArgs args = (CommnadExecutedEventArgs)e;

                // ステータスバー表示切り替えはメッセージを出さない
                if (args.Command != Commands.VisibleStatusBar)
                {
                    ToastMessage.Show(string.Format("コマンド: {0}", args.Detail));
                }
            };

            //-----------------------------------------------------
            // コンテキストメニュー
            //-----------------------------------------------------

            // 拡大率
            scale25PerToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowScale25Per);
            scale50PerToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowScale50Per);
            scale75PerToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowScale75Per);
            scale100PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale100Per);
            scale150PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale150Per);
            scale200PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale200Per);

            // サイズ変更
            size160x120ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize160x120);
            size320x240ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize320x240);
            size480x360ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize480x360);
            size640x480ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize640x480);
            size800x600ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.WindowSize800x600);
            fitMovieSizeToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.FitMovieSize);

            // 画面分割
            screenSplitWidthx5ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx5);
            screenSplitWidthx4ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx4);
            screenSplitWidthx3ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx3);
            screenSplitWidthx2ToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx2);
            screenSplitHeightx5ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx5);
            screenSplitHeightx4ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx4);
            screenSplitHeightx3ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx3);
            screenSplitHeightx2ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx2);

            // 機能
            topMostToolStripMenuItem.Click           += (sender, e) => shortcut.ExecCommand(Commands.TopMost);
            updateChannelInfoToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.UpdateChannelInfo);
            bumpToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.Bump);
            functionToolStripMenuItem.DropDownOpening   += (sender, e) => topMostToolStripMenuItem.Checked = TopMost;
            screenshotToolStripMenuItem.Click           += (sender, e) => shortcut.ExecCommand(Commands.Screenshot);
            openScreenshotFolderToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.OpenScreenshotFolder);
            retryPlayerToolStripMenuItem.Click          += (sender, e) => shortcut.ExecCommand(Commands.RetryPlayer);
            // ファイルから開く
            openFromFileToolStripMenuItem.Click += (sender, e) =>
            {
                var dialog = new OpenFileDialog();
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // TODO スレッド選択を解除
                    // TODO ステータスバーを変更
                    Open(dialog.FileName);
                }
            };
            // URLから開く
            openFromUrlToolStripTextBox.KeyDown += (sender, e) =>
            {
                if (e.KeyCode == Keys.Return)
                {
                    // TODO FLV or WMVの判定をして、PecaPlayerコントロールを再初期化する
                    // TODO スレッド選択を解除 + 新しいスレッドへ移動
                    // TODO ステータスバーを変更
                    Open(((ToolStripTextBox)sender).Text);
                    contextMenuStrip.Close();
                }
            };
            // クリップボードから開く
            openFromClipboardToolStripMenuItem.Click += (sender, e) =>
            {
                try
                {
                    if (Clipboard.ContainsText())
                    {
                        // TODO FLV or WMVの判定をして、PecaPlayerコントロールを再初期化する
                        // TODO スレッド選択を解除 + 新しいスレッドへ移動
                        // TODO ステータスバーを変更
                        Open(Clipboard.GetText());
                    }
                }
                catch (System.Runtime.InteropServices.ExternalException)
                {
                    MessageBox.Show("クリップボードのオープンに失敗しました");
                }
            };

            // 音量
            volumeUpToolStripMenuItem.Click            += (sender, e) => shortcut.ExecCommand(Commands.VolumeUp);
            volumeDownToolStripMenuItem.Click          += (sender, e) => shortcut.ExecCommand(Commands.VolumeDown);
            muteToolStripMenuItem.Click                += (sender, e) => shortcut.ExecCommand(Commands.Mute);
            volumeBalanceLeftToolStripMenuItem.Click   += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceLeft);
            volumeBalanceMiddleToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceMiddle);
            volumeBalanceRightToolStripMenuItem.Click  += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceRight);
            volumeToolStripMenuItem.DropDownOpening    += (sender, e) => muteToolStripMenuItem.Checked = pecaPlayer.Mute;
            volumeToolStripMenuItem.DropDownOpening    += (sender, e) => volumeBalanceLeftToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceLeft);
            volumeToolStripMenuItem.DropDownOpening    += (sender, e) => volumeBalanceMiddleToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceMiddle);
            volumeToolStripMenuItem.DropDownOpening    += (sender, e) => volumeBalanceRightToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceRight);

            // 設定メニュー押下
            settingToolStripMenuItem.Click += (sender, e) =>
            {
                PlayerSettingView view = new PlayerSettingView(shortcut);
                view.TopMost = TopMost;
                view.ShowDialog();
            };

            // WMPメニュー押下
            wmpMenuToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WmpMenu);
            // 動画情報表示押下
            showDebugToolStripMenuItem.Click += (sender, e) => pecaPlayer.ShowDebug();
        }
Example #25
0
		//-------------------------------------------------------------
		// イベントの初期化
		//-------------------------------------------------------------
		private void InitEvent()
		{
			// スレッドビューワを開く
			openViewerToolStripButton.Click += (sender, e) => shortcut.ExecCommand(Commands.OpenPeerstViewer);
			// 最小化ボタン
			minToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.MinButtonClick);
			// 最大化ボタン
			maxToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.MaxButtonClick);
			// 閉じるボタン
			closeToolStripButton.Click += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.CloseButtonClick);
			// 音量クリック
			statusBar.VolumeClick += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.Mute);
			// ダブルクリック
			pecaPlayer.DoubleClickEvent += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.DoubleClick);
			// マウスホイール
			MouseWheel += (sender, e) =>
			{
				if ((Control.MouseButtons & MouseButtons.Right) == MouseButtons.Right)
				{
					// 右クリックマウスホイール
					if (e.Delta > 0)
					{
						shortcut.RaiseEvent(ShortcutEvents.RightClickWheelUp);
					}
					else if (e.Delta < 0)
					{
						shortcut.RaiseEvent(ShortcutEvents.RightClickWheelDown);
					}
				}
				else
				{
					// マウスホイール
					if (e.Delta > 0)
					{
						shortcut.RaiseEvent(ShortcutEvents.WheelUp);
					}
					else if (e.Delta < 0)
					{
						shortcut.RaiseEvent(ShortcutEvents.WheelDown);
					}
				}
			};

			// チャンネル情報更新
			bool isFirst = true;
			pecaPlayer.ChannelInfoChange += (sender, e) =>
			{
				ChannelInfo info = pecaPlayer.ChannelInfo;
				// TODO 文字が空の場合は、スペースを空けない
				UpdateChannelDetail(info);

				// タイトル設定
				string chName = getChannelName(info);
				Win32API.SetWindowText(Handle, String.Format("{0} - PeerstPlayer", chName));

				// 初回のみの設定
				if (isFirst)
				{
					// コンタクトURL設定
					// TODO コンタクトURLが変更されたら、通知後にURL変更
					// コンタクトURLが空の場合、引数からコンタクトURLを取得する
					if (string.IsNullOrEmpty(info.Url))
					{
						var commandLine = Environment.GetCommandLineArgs();
						if (Environment.GetCommandLineArgs().Length > 4)
						{
							var url = commandLine[4];
							statusBar.SelectThreadUrl = url;
						}
						else
						{
							// コンタクトURLが空の場合
							statusBar.SelectThreadUrl = String.Empty;
						}
					}
					else
					{
						statusBar.SelectThreadUrl = info.Url;
					}
					isFirst = false;
				}
			};

			// ステータスバーのサイズ変更
			statusBar.HeightChanged += (sender, e) =>
			{
				// 最大化時はサイズ変更しない
				if (WindowState == FormWindowState.Maximized)
				{
					return;
				}

				// Formサイズ変更
				if (FrameInvisible)
				{
					Size = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
				}
				else
				{
					ClientSize = new Size(ClientSize.Width, (pecaPlayer.Height + statusBar.Height));
				}
			};

			// ステータスバーのクリックイベント
			statusBar.ChannelDetailClick += (sender, e) =>
			{
				if (e.Button == MouseButtons.Left)
				{
					shortcut.RaiseEvent(ShortcutEvents.StatusbarLeftClick);
				}
				else if (e.Button == MouseButtons.Right)
				{
					shortcut.RaiseEvent(ShortcutEvents.StatusbarRightClick);
				}
			};

			// サイズ変更
			SizeChanged += (sender, e) =>
			{
				if ((ClientSize.Width) == 0 || (ClientSize.Height == 0))
				{
					return;
				}

				// 幅
				pecaPlayer.Width = ClientSize.Width;
				statusBar.Width = ClientSize.Width;

				// 高さ
				pecaPlayer.Height = ClientSize.Height - statusBar.Height;
				statusBar.Top = pecaPlayer.Bottom;
			};

			// 動画サイズ変更
			pecaPlayer.MovieSizeChange += (sender, e) =>
			{
				// Formサイズ変更
				if (FrameInvisible)
				{
					Size = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
				}
				else
				{
					ClientSize = new Size(pecaPlayer.Width, pecaPlayer.Height + statusBar.Height);
				}

				// 幅
				statusBar.Width = pecaPlayer.Width;

				// 高さ
				statusBar.Top = pecaPlayer.Bottom;
			};

			// 音量変更イベント
			pecaPlayer.VolumeChange += (sender, e) => statusBar.Volume = (pecaPlayer.Mute ? "-" : pecaPlayer.Volume.ToString());

			// スレッドタイトル右クリックイベント
			statusBar.ThreadTitleRightClick += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.ThreadTitleRightClick);

			// マウスジェスチャー
			MouseGesture mouseGesture = new MouseGesture();
			mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
			bool isGesturing = false;

			// タイマーイベント
			Timer timer = new Timer();
			timer.Interval = MovieStatusUpdateInterval;
			timer.Tick += (sender, e) =>
			{
				// 自動表示ボタンの表示切り替え
				if (toolStrip.Visible && !IsVisibleToolStrip(PointToClient(MousePosition)))
				{
					toolStrip.Visible = false;
				}

				// 画面外に出たらマウスジェスチャー解除
				if (!RectangleToScreen(ClientRectangle).Contains(MousePosition))
				{
					isGesturing = false;
				}

				// 動画ステータスを表示
				if (pecaPlayer.Duration.Length == 0)
				{
					switch (pecaPlayer.PlayState)
					{
						case WMPPlayState.wmppsUndefined: statusBar.MovieStatus		= "";			break;
						case WMPPlayState.wmppsStopped: statusBar.MovieStatus		= "停止";		break;
						case WMPPlayState.wmppsPaused: statusBar.MovieStatus		= "一時停止";	break;
						case WMPPlayState.wmppsPlaying: statusBar.MovieStatus		= "再生中";		break;
						case WMPPlayState.wmppsScanForward: statusBar.MovieStatus	= "早送り";		break;
						case WMPPlayState.wmppsScanReverse: statusBar.MovieStatus	= "巻き戻し";	break;
						case WMPPlayState.wmppsWaiting: statusBar.MovieStatus		= "接続待機";	break;
						case WMPPlayState.wmppsMediaEnded: statusBar.MovieStatus	= "再生完了";	break;
						case WMPPlayState.wmppsTransitioning: statusBar.MovieStatus = "準備中";		break;
						case WMPPlayState.wmppsReady: statusBar.MovieStatus			= "準備完了";	break;
						case WMPPlayState.wmppsReconnecting: statusBar.MovieStatus	= "再接続";		break;
						case WMPPlayState.wmppsBuffering: statusBar.MovieStatus		= string.Format("バッファ{0}%", pecaPlayer.BufferingProgress); break;
					}
				}
				// 再生時間を表示
				else
				{
					statusBar.MovieStatus = pecaPlayer.Duration;
				}

				// 動画情報を更新
				ChannelInfo info = pecaPlayer.ChannelInfo ?? new ChannelInfo();
				statusBar.UpdateMovieInfo(
					new MovieInfo()
					{
						NowFps = pecaPlayer.NowFrameRate,
						Fps = pecaPlayer.FrameRate,
						NowBitrate = pecaPlayer.NowBitrate,
						Bitrate = pecaPlayer.Bitrate,
						ListenerNumber = info.Listeners,
						RelayNumber = info.Relays,
						Status = info.Status,
						StreamType = info.Type,
					});
			};
			timer.Start();

			// マウスダウンイベント
			pecaPlayer.MouseDownEvent += (sender, e) =>
			{
				if (e.nButton == (short)Keys.LButton)
				{
					// マウスドラッグ
					FormUtility.WindowDragStart(this.Handle);
				}
				else if (e.nButton == (short)Keys.RButton)
				{
					// マウスジェスチャー開始
					mouseGesture.Start();
					isGesturing = true;
				}
				else if (e.nButton == (short)Keys.MButton)
				{
					// 中クリック
					shortcut.RaiseEvent(ShortcutEvents.MiddleClick);
				}
			};

			// マウスアップイベント
			pecaPlayer.MouseUpEvent += (sender, e) =>
			{
				if (e.nButton == (short)Keys.RButton)
				{
					// チャンネル詳細を再描画
					ChannelInfo info = pecaPlayer.ChannelInfo;
					if (info != null)
					{
						UpdateChannelDetail(info);
					}

					// マウスジェスチャーが実行されていなければ
					string gesture = mouseGesture.ToString();
					if (string.IsNullOrEmpty(gesture))
					{
						// コンテキストメニュー表示
						contextMenuStrip.Show(MousePosition);
					}
					else if (isGesturing)
					{
						// マウスジェスチャー実行
						shortcut.ExecGesture(gesture);
					}

					isGesturing = false;
				}
			};

			// マウス移動イベント
			pecaPlayer.MouseMoveEvent += (sender, e) =>
			{
				// 自動表示ボタンの表示切り替え
				if (toolStrip.Visible != IsVisibleToolStrip(new Point(e.fX, e.fY)))
				{
					toolStrip.Visible = !toolStrip.Visible;
				}

				if (isGesturing)
				{
					// ジェスチャー表示
					mouseGesture.Moving(new Point(e.fX, e.fY));

					string gesture = mouseGesture.ToString();
					string detail = shortcut.GetGestureDetail(gesture);
					if (!String.IsNullOrEmpty(gesture))
					{
						string message = string.Format("ジェスチャ: {0} {1}", gesture, (String.IsNullOrEmpty(detail) ? "" : "(" + detail + ")"));
						ToastMessage.Show(message);
					}
				}
			};

			// キー押下イベント
			pecaPlayer.KeyDownEvent += (sender, e) => shortcut.RaiseKeyEvent(e);

			// ステータスバー マウスホバーイベント
			statusBar.MouseHoverEvent += (sender, e) => shortcut.RaiseEvent(ShortcutEvents.StatusbarHover);

			// 終了処理
			FormClosed += (sender, e) =>
			{
				Logger.Instance.Debug("FormClosed");
				pecaPlayer.Close();
				statusBar.Close();
			};

			// グローウィンドウの弊害で消えなくなっていたので自分で消えるようにする
			Deactivate += (sender, e) =>
			{
				contextMenuStrip.Hide();
			};

			// 動画再生イベント
			pecaPlayer.MovieStart += (sender, e) =>
			{
				pecaPlayer.UpdateChannelInfo();
				shortcut.ExecCommand(PlayerSettings.MovieStartCommand);
			};

			// コマンド実行内容の表示
			shortcut.CommandExecuted += (sender, e) =>
			{
				CommnadExecutedEventArgs args = (CommnadExecutedEventArgs)e;

				// ステータスバー表示切り替えはメッセージを出さない
				if (args.Command != Commands.VisibleStatusBar)
				{
					ToastMessage.Show(string.Format("コマンド: {0}", args.Detail));
				}
			};

			//-----------------------------------------------------
			// コンテキストメニュー
			//-----------------------------------------------------

			// 拡大率
			scale25PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale25Per);
			scale50PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale50Per);
			scale75PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale75Per);
			scale100PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale100Per);
			scale150PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale150Per);
			scale200PerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowScale200Per);

			// サイズ変更
			size160x120ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize160x120);
			size320x240ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize320x240);
			size480x360ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize480x360);
			size640x480ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize640x480);
			size800x600ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WindowSize800x600);
			fitMovieSizeToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.FitMovieSize);

			// 画面分割
			screenSplitWidthx5ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx5);
			screenSplitWidthx4ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx4);
			screenSplitWidthx3ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx3);
			screenSplitWidthx2ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitWidthx2);
			screenSplitHeightx5ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx5);
			screenSplitHeightx4ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx4);
			screenSplitHeightx3ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx3);
			screenSplitHeightx2ToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.ScreenSplitHeightx2);

			// 機能
			topMostToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.TopMost);
			updateChannelInfoToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.UpdateChannelInfo);
			bumpToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.Bump);
			functionToolStripMenuItem.DropDownOpening += (sender, e) => topMostToolStripMenuItem.Checked = TopMost;
			screenshotToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.Screenshot);
			openScreenshotFolderToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.OpenScreenshotFolder);
			retryPlayerToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.RetryPlayer);
			// ファイルから開く
			openFromFileToolStripMenuItem.Click += (sender, e) =>
			{
				var dialog = new OpenFileDialog();
				if (dialog.ShowDialog() == DialogResult.OK)
				{
					// TODO スレッド選択を解除
					// TODO ステータスバーを変更
					Open(dialog.FileName);
				}
			};
			// URLから開く
			openFromUrlToolStripTextBox.KeyDown += (sender, e) =>
			{
				if (e.KeyCode == Keys.Return)
				{
					// TODO FLV or WMVの判定をして、PecaPlayerコントロールを再初期化する
					// TODO スレッド選択を解除 + 新しいスレッドへ移動
					// TODO ステータスバーを変更
					Open(((ToolStripTextBox)sender).Text);
					contextMenuStrip.Close();
				}
			};
			// クリップボードから開く
			openFromClipboardToolStripMenuItem.Click += (sender, e) =>
			{
				try
				{
					if (Clipboard.ContainsText())
					{
						// TODO FLV or WMVの判定をして、PecaPlayerコントロールを再初期化する
						// TODO スレッド選択を解除 + 新しいスレッドへ移動
						// TODO ステータスバーを変更
						Open(Clipboard.GetText());
					}
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					MessageBox.Show("クリップボードのオープンに失敗しました");
				}
			};

			// 音量
			volumeUpToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeUp);
			volumeDownToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeDown);
			muteToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.Mute);
			volumeBalanceLeftToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceLeft);
			volumeBalanceMiddleToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceMiddle);
			volumeBalanceRightToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.VolumeBalanceRight);
			volumeToolStripMenuItem.DropDownOpening += (sender, e) => muteToolStripMenuItem.Checked = pecaPlayer.Mute;
			volumeToolStripMenuItem.DropDownOpening += (sender, e) => volumeBalanceLeftToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceLeft);
			volumeToolStripMenuItem.DropDownOpening += (sender, e) => volumeBalanceMiddleToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceMiddle);
			volumeToolStripMenuItem.DropDownOpening += (sender, e) => volumeBalanceRightToolStripMenuItem.Checked = (pecaPlayer.VolumeBalance == VolumeBalanceCommandArgs.BalanceRight);

			// 設定メニュー押下
			settingToolStripMenuItem.Click += (sender, e) =>
			{
				PlayerSettingView view = new PlayerSettingView(shortcut);
				view.TopMost = TopMost;
				view.ShowDialog();
			};

			// WMPメニュー押下
			wmpMenuToolStripMenuItem.Click += (sender, e) => shortcut.ExecCommand(Commands.WmpMenu);
			// 動画情報表示押下
			showDebugToolStripMenuItem.Click += (sender, e) => pecaPlayer.ShowDebug();
		}
Example #26
0
        public PlayerSettingView(ShortcutManager shortcut)
        {
            this.shortcut = shortcut;

            InitializeComponent();

            // 親ウィンドウの中心に表示
            StartPosition = FormStartPosition.CenterParent;

            // 初期化
            Shown += (sender, e) =>
            {
                // チェックボックスの表示
                disconnectRealyOnCloseCheckBox.Checked = PlayerSettings.DisconnectRealyOnClose;
                returnPositionOnStartCheckBox.Checked  = PlayerSettings.ReturnPositionOnStart;
                returnSizeOnStartCheckBox.Checked      = PlayerSettings.ReturnSizeOnStart;
                windowSnapEnableCheckBox.Checked       = PlayerSettings.WindowSnapEnable;
                aspectRateFixCheckBox.Checked          = PlayerSettings.AspectRateFix;
                frameInvisibleCheckBox.Checked         = PlayerSettings.FrameInvisible;
                topMostCheckBox.Checked            = PlayerSettings.TopMost;
                writeFieldVisibleCheckBox.Checked  = PlayerSettings.WriteFieldVisible;
                initVolumeTextBox.Text             = PlayerSettings.InitVolume.ToString();
                saveReturnPositionCheckBox.Checked = PlayerSettings.SaveReturnPositionOnClose;
                saveReturnSizeCheckBox.Checked     = PlayerSettings.SaveReturnSizeOnClose;
                exitedViewerCloseCheckBox.Checked  = PlayerSettings.ExitedViewerClose;

                // チェックボックスの設定(ステータスバー)
                displayFpsCheckBox.Checked     = PlayerSettings.DisplayFps;
                displayBitrateCheckBox.Checked = PlayerSettings.DisplayBitrate;
                listenerNumberCheckBox.Checked = PlayerSettings.DisplayListenerNumber;

                // 音量変化
                volumeChangeNoneTextBox.Text  = PlayerSettings.VolumeChangeNone.ToString();
                volumeChangeCtrlTextBox.Text  = PlayerSettings.VolumeChangeCtrl.ToString();
                volumeChangeShiftTextBox.Text = PlayerSettings.VolumeChangeShift.ToString();

                // スクリーンショット
                screenshotFolderTextBox.Text = PlayerSettings.ScreenshotFolder;
                foreach (var item in screenshotExtensionComboBox.Items)
                {
                    if (item.ToString() == PlayerSettings.ScreenshotExtension)
                    {
                        screenshotExtensionComboBox.SelectedItem = item;
                    }
                }
                // 拡張子が選択されていなければpngを選ばせる
                if (screenshotExtensionComboBox.SelectedItem == null)
                {
                    screenshotExtensionComboBox.SelectedIndex = screenshotExtensionComboBox.FindString("png");
                }
                // 書式
                screenshotFormatTextBox.Text = PlayerSettings.ScreenshotFormat;
                screenshotSampleTextBox.Text = Shortcut.Command.ScreenshotCommand.Format(screenshotFormatTextBox.Text, null);

                // スレッド
                autoReadThreadCheckBox.Checked = PlayerSettings.AutoReadThread;

                // FLV
                flvGpuCheckBox.Checked    = PlayerSettings.Gpu;
                useRtmpCheckBox.Checked   = PlayerSettings.Rtmp;
                bufferTimeTextBox.Text    = PlayerSettings.BufferTime.ToString();
                bufferTimeMaxTextBox.Text = PlayerSettings.BufferTimeMax.ToString();

                // 動画再生開始時のコマンド
                movieStartComboBox.Items.Clear();
                foreach (Commands command in movieStartCommandList)
                {
                    string detail = shortcut.CommandMap[command].Detail;
                    movieStartComboBox.Items.Add(detail);

                    if (PlayerSettings.MovieStartCommand == command)
                    {
                        movieStartComboBox.SelectedIndex = (movieStartComboBox.Items.Count - 1);
                    }
                }

                // ショートカット・ジェスチャー表示
                shortcutListView.Items.Clear();
                foreach (KeyValuePair <Commands, ShortcutCommand> commandPair in shortcut.CommandMap)
                {
                    // ショートカットのアイテム追加
                    ListViewItem keyItem = CreateKeyItem(shortcut, commandPair);
                    shortcutListView.Items.Add(keyItem);
                }
            };

            // スクリーンショットを保存するフォルダを選ぶダイアログを表示するボタン
            browseScreenshotFolderButton.Click += (sender, args) =>
            {
                folderBrowserDialog.RootFolder   = Environment.SpecialFolder.Desktop;
                folderBrowserDialog.SelectedPath = PlayerSettings.ScreenshotFolder;
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    screenshotFolderTextBox.Text = folderBrowserDialog.SelectedPath;
                }
            };

            // スクリーンショットファイル名の書式
            screenshotFormatTextBox.TextChanged += (sender, args) =>
            {
                screenshotSampleTextBox.Text = Shortcut.Command.ScreenshotCommand.Format(screenshotFormatTextBox.Text, null);
            };
            // 書式の補助メニュー
            screenshotFormatButton.Click += (sender, args) => screenshotContextMenuStrip.Show(screenshotFormatButton, 0, 0);
            Action <string> formatHelper = (x) =>
            {
                // 選択されているテキストの位置を取得しておく
                var selectionStart = screenshotFormatTextBox.SelectionStart;
                screenshotFormatTextBox.Text = screenshotFormatTextBox.Text.Insert(screenshotFormatTextBox.SelectionStart, x);
                // 追加した文字列の後ろにカーソルを移動
                screenshotFormatTextBox.SelectionStart = selectionStart + x.Length;
                screenshotFormatTextBox.Focus();
            };

            year2ToolStripMenuItem.Click       += (sender, args) => formatHelper("yy");
            year4ToolStripMenuItem.Click       += (sender, args) => formatHelper("yyyy");
            monthToolStripMenuItem.Click       += (sender, args) => formatHelper("MM");
            dayToolStripMenuItem.Click         += (sender, args) => formatHelper("dd");
            hourToolStripMenuItem.Click        += (sender, args) => formatHelper("hh");
            minuteToolStripMenuItem.Click      += (sender, args) => formatHelper("mm");
            secondToolStripMenuItem.Click      += (sender, args) => formatHelper("ss");
            channelNameToolStripMenuItem.Click += (sender, args) => formatHelper("$0");

            // Tab遷移しないようにする
            shortcutListView.PreviewKeyDown += (sender, e) => e.IsInputKey = true;

            // ショートカット設定時にエラー音がならないようにする
            shortcutListView.KeyPress += (sender, e) => e.Handled = true;

            // ショートカット入力
            shortcutListView.KeyDown += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0)
                {
                    return;
                }
                if (e.KeyData == Keys.ProcessKey)
                {
                    return;
                }

                // 同じキー入力を削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    object tag = item.SubItems[1].Tag;                          // KeyInput

                    if ((tag == null))
                    {
                        continue;
                    }

                    KeyInput keyInput = (KeyInput)tag;

                    if ((keyInput.Key == e.KeyCode) && (keyInput.Modifiers == e.Modifiers))
                    {
                        item.SubItems[1].Text = "-";
                        item.SubItems[1].Tag  = null;
                    }
                }

                // ショートカット登録
                KeyInput input = new KeyInput(e.Modifiers, e.KeyCode);
                int      index = shortcutListView.SelectedIndices[0];
                shortcutListView.Items[index].SubItems[1].Text = ConvertKeyInputToString(input);
                shortcutListView.Items[index].SubItems[1].Tag  = input;

                // キー入力を無視
                e.Handled = true;
            };

            // ダブルクリックでコマンド削除
            shortcutListView.MouseDoubleClick += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0)
                {
                    return;
                }

                if (e.Button == MouseButtons.Left)
                {
                    int index = shortcutListView.SelectedIndices[0];
                    shortcutListView.Items[index].SubItems[1].Text = "-";
                    shortcutListView.Items[index].SubItems[1].Tag  = null;
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    int index = shortcutListView.SelectedIndices[0];
                    shortcutListView.Items[index].SubItems[2].Text = "-";
                    shortcutListView.Items[index].SubItems[2].Tag  = null;
                }
            };

            // マウスジェスチャ
            MouseGesture mouseGesture = new MouseGesture();

            mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
            bool gestureing = false;

            shortcutListView.MouseDown += (sender, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    mouseGesture.Start();
                    gestureing = true;
                }
            };
            shortcutListView.MouseMove += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0)
                {
                    return;
                }
                if (gestureing == false)
                {
                    return;
                }

                mouseGesture.Moving(e.Location);
                string gesture = mouseGesture.ToString();

                int index = shortcutListView.SelectedIndices[0];
                if (string.IsNullOrEmpty(gesture))
                {
                    return;
                }
                if (shortcutListView.Items[index].SubItems[2].Text == mouseGesture.ToString())
                {
                    return;
                }

                // ジェスチャを登録
                shortcutListView.Items[index].SubItems[2].Text = gesture;
                shortcutListView.Items[index].SubItems[2].Tag  = null;
            };
            shortcutListView.MouseUp += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0)
                {
                    return;
                }
                if (gestureing == false)
                {
                    return;
                }

                mouseGesture.Moving(e.Location);
                string gesture = mouseGesture.ToString();

                int index = shortcutListView.SelectedIndices[0];
                if (string.IsNullOrEmpty(gesture))
                {
                    return;
                }

                // 同じジェスチャを削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    string text = item.SubItems[2].Text;
                    if (gesture == text)
                    {
                        item.SubItems[2].Text = "-";
                        item.SubItems[2].Tag  = null;
                    }
                }

                // ジェスチャを登録
                shortcutListView.Items[index].SubItems[2].Text = gesture;
                shortcutListView.Items[index].SubItems[2].Tag  = null;
            };
            shortcutListView.MouseUp += (sender, e) => gestureing = false;
        }
 /// <summary>
 /// Initializes new instance of MouseGestureEventArgs
 /// </summary>
 /// <param name="gesture">The type of the gesture performed.</param>
 /// <param name="beginning">The point, where user started the gesture.</param>
 public MouseGestureEventArgs(MouseGesture gesture, Point beginning)
 {
     Gesture = gesture;
     Beginning = beginning;
 }
Example #28
0
        // </SnippetKeyGestureGetProperties>

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            // <SnippetKeyBindingKeyGestureSetProperties>
            // Defining the KeyGesture.
            KeyGesture FindCmdKeyGesture = new KeyGesture(Key.F,
                                                          (ModifierKeys.Shift | ModifierKeys.Alt));

            // Defining the KeyBinding.
            KeyBinding FindKeyBinding = new KeyBinding(
                ApplicationCommands.Find, FindCmdKeyGesture);

            // Binding the KeyBinding to the Root Window.
            this.InputBindings.Add(FindKeyBinding);
            // </SnippetKeyBindingKeyGestureSetProperties>

            // <SnippetKeyBindingWithNoModifier>
            KeyGesture OpenCmdKeyGesture = new KeyGesture(Key.F12);
            KeyBinding OpenKeyBinding    = new KeyBinding(
                ApplicationCommands.Open,
                OpenCmdKeyGesture);

            this.InputBindings.Add(OpenKeyBinding);
            // </SnippetKeyBindingWithNoModifier>

            // <SnippetKeyBindingWithKeyAndModifiers>
            KeyGesture CloseCmdKeyGesture = new KeyGesture(
                Key.L, ModifierKeys.Alt);

            KeyBinding CloseKeyBinding = new KeyBinding(
                ApplicationCommands.Close, CloseCmdKeyGesture);

            this.InputBindings.Add(CloseKeyBinding);
            // </SnippetKeyBindingWithKeyAndModifiers>

            // <SnippetKeyBindingMultipleModifiers>
            KeyBinding CopyKeyBinding = new KeyBinding(
                ApplicationCommands.Copy, Key.D,
                (ModifierKeys.Control | ModifierKeys.Shift));

            this.InputBindings.Add(CopyKeyBinding);
            // </SnippetKeyBindingMultipleModifiers>

            // <SnippetKeyBindingDefatulCtor>
            KeyBinding RedoKeyBinding = new KeyBinding();

            RedoKeyBinding.Modifiers = ModifierKeys.Alt;
            RedoKeyBinding.Key       = Key.F;
            RedoKeyBinding.Command   = ApplicationCommands.Redo;

            this.InputBindings.Add(RedoKeyBinding);
            // </SnippetKeyBindingDefatulCtor>

            // <SnippetMouseBindingAddedToInputBinding>
            MouseGesture OpenCmdMouseGesture = new MouseGesture();

            OpenCmdMouseGesture.MouseAction = MouseAction.WheelClick;
            OpenCmdMouseGesture.Modifiers   = ModifierKeys.Control;

            MouseBinding OpenCmdMouseBinding = new MouseBinding();

            OpenCmdMouseBinding.Gesture = OpenCmdMouseGesture;
            OpenCmdMouseBinding.Command = ApplicationCommands.Open;

            this.InputBindings.Add(OpenCmdMouseBinding);
            // </SnippetMouseBindingAddedToInputBinding>

            // <SnippetMouseBindingAddedCommand>
            MouseGesture PasteCmdMouseGesture = new MouseGesture(
                MouseAction.MiddleClick, ModifierKeys.Alt);

            ApplicationCommands.Paste.InputGestures.Add(PasteCmdMouseGesture);
            // </SnippetMouseBindingAddedCommand>

            KeyGesture pasteBind = new KeyGesture(Key.V, ModifierKeys.Alt);

            ApplicationCommands.Paste.InputGestures.Add(pasteBind);

            // <SnippetInputBindingAddingComand>
            KeyGesture HelpCmdKeyGesture = new KeyGesture(Key.H,
                                                          ModifierKeys.Alt);

            InputBinding inputBinding;

            inputBinding = new InputBinding(ApplicationCommands.Help,
                                            HelpCmdKeyGesture);

            this.InputBindings.Add(inputBinding);
            // </SnippetInputBindingAddingComand>

            // <SnippetMouseBindingMouseAction>
            MouseGesture CutCmdMouseGesture = new MouseGesture(
                MouseAction.MiddleClick);

            MouseBinding CutMouseBinding = new MouseBinding(
                ApplicationCommands.Cut,
                CutCmdMouseGesture);

            // RootWindow is an instance of Window.
            RootWindow.InputBindings.Add(CutMouseBinding);
            // </SnippetMouseBindingMouseAction>

            // <SnippetMouseBindingGesture>
            MouseGesture NewCmdMouseGesture = new MouseGesture();

            NewCmdMouseGesture.Modifiers   = ModifierKeys.Alt;
            NewCmdMouseGesture.MouseAction = MouseAction.MiddleClick;

            MouseBinding NewMouseBinding = new MouseBinding();

            NewMouseBinding.Command = ApplicationCommands.New;
            NewMouseBinding.Gesture = NewCmdMouseGesture;

            // RootWindow is an instance of Window.
            RootWindow.InputBindings.Add(NewMouseBinding);
            // </SnippetMouseBindingGesture>
        }
Example #29
0
        /// <summary>
        /// Recognizes complex MouseGesture from two simple gestures
        /// </summary>
        /// <param name="firstGesture">First simple gesture.</param>
        /// <param name="secondGesture">Second simple gesture</param>
        /// <returns>Returns complex MouseGesture or MouseGesture.Unknown if no gesture is recognized.</returns>
        protected MouseGesture RecognizeComplexGeasture(MouseGesture firstGesture, MouseGesture secondGesture)
        {
            if ( firstGesture == MouseGesture.Unknown || secondGesture == MouseGesture.Unknown )
            return MouseGesture.Unknown;

              //treats two simple gesture with the same direction with some unknown
              //segments between them as valid simple gesture
              //TODO consider disabling this
              if ( firstGesture == secondGesture )
            return firstGesture;

              //see MouseGesture.cs for referecne how to compute complex gesture
              return (firstGesture | (MouseGesture)(( int )secondGesture * 2));
        }
Example #30
0
 bool Equals(MouseGesture x, MouseGesture y)
 {
     return(x.Modifiers == y.Modifiers && x.MouseAction == y.MouseAction);
 }
Example #31
0
 int GetHashCode(MouseGesture gesture)
 {
     return(gesture.MouseAction.GetHashCode() * (int)Math.Pow(gesture.Modifiers.GetHashCode(), 2));
 }
Example #32
0
        public PlayerSettingView(ShortcutManager shortcut)
        {
            this.shortcut = shortcut;

            InitializeComponent();

            // 親ウィンドウの中心に表示
            StartPosition = FormStartPosition.CenterParent;

            // 初期化
            Shown += (sender, e) =>
            {
                // チェックボックスの表示
                disconnectRealyOnCloseCheckBox.Checked = PlayerSettings.DisconnectRealyOnClose;
                returnPositionOnStartCheckBox.Checked = PlayerSettings.ReturnPositionOnStart;
                returnSizeOnStartCheckBox.Checked = PlayerSettings.ReturnSizeOnStart;
                windowSnapEnableCheckBox.Checked = PlayerSettings.WindowSnapEnable;
                aspectRateFixCheckBox.Checked = PlayerSettings.AspectRateFix;
                frameInvisibleCheckBox.Checked = PlayerSettings.FrameInvisible;
                topMostCheckBox.Checked = PlayerSettings.TopMost;
                writeFieldVisibleCheckBox.Checked = PlayerSettings.WriteFieldVisible;
                initVolumeTextBox.Text = PlayerSettings.InitVolume.ToString();
                saveReturnPositionCheckBox.Checked = PlayerSettings.SaveReturnPositionOnClose;
                saveReturnSizeCheckBox.Checked = PlayerSettings.SaveReturnSizeOnClose;

                // チェックボックスの設定(ステータスバー)
                displayFpsCheckBox.Checked = PlayerSettings.DisplayFps;
                displayBitrateCheckBox.Checked = PlayerSettings.DisplayBitrate;
                listenerNumberCheckBox.Checked = PlayerSettings.DisplayListenerNumber;

                // 音量変化
                volumeChangeNoneTextBox.Text = PlayerSettings.VolumeChangeNone.ToString();
                volumeChangeCtrlTextBox.Text = PlayerSettings.VolumeChangeCtrl.ToString();
                volumeChangeShiftTextBox.Text = PlayerSettings.VolumeChangeShift.ToString();

                // 動画再生開始時のコマンド
                movieStartComboBox.Items.Clear();
                foreach (Commands command in movieStartCommandList)
                {
                    string detail = shortcut.CommandMap[command].Detail;
                    movieStartComboBox.Items.Add(detail);

                    if (PlayerSettings.MovieStartCommand == command)
                    {
                        movieStartComboBox.SelectedIndex = (movieStartComboBox.Items.Count - 1);
                    }
                }

                // ショートカット・ジェスチャー表示
                shortcutListView.Items.Clear();
                foreach (KeyValuePair<Commands, ShortcutCommand> commandPair in shortcut.CommandMap)
                {
                    // ショートカットのアイテム追加
                    ListViewItem keyItem = CreateKeyItem(shortcut, commandPair);
                    shortcutListView.Items.Add(keyItem);
                }
            };

            // Tab遷移しないようにする
            shortcutListView.PreviewKeyDown += (sender, e) => e.IsInputKey = true;

            // ショートカット設定時にエラー音がならないようにする
            shortcutListView.KeyPress += (sender, e) => e.Handled = true;

            // ショートカット入力
            shortcutListView.KeyDown += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0) return;
                if (e.KeyData == Keys.ProcessKey) return;

                // 同じキー入力を削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    object tag = item.SubItems[1].Tag;	// KeyInput

                    if ((tag == null))
                    {
                        continue;
                    }

                    KeyInput keyInput = (KeyInput)tag;

                    if ((keyInput.Key == e.KeyCode) && (keyInput.Modifiers == e.Modifiers))
                    {
                        item.SubItems[1].Text = "-";
                        item.SubItems[1].Tag = null;
                    }
                }

                // ショートカット登録
                KeyInput input = new KeyInput(e.Modifiers, e.KeyCode);
                int index = shortcutListView.SelectedIndices[0];
                shortcutListView.Items[index].SubItems[1].Text = ConvertKeyInputToString(input);
                shortcutListView.Items[index].SubItems[1].Tag = input;

                // キー入力を無視
                e.Handled = true;
            };

            // ダブルクリックでコマンド削除
            shortcutListView.MouseDoubleClick += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0) return;

                if (e.Button == MouseButtons.Left)
                {
                    int index = shortcutListView.SelectedIndices[0];
                    shortcutListView.Items[index].SubItems[1].Text = "-";
                    shortcutListView.Items[index].SubItems[1].Tag = null;
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    int index = shortcutListView.SelectedIndices[0];
                    shortcutListView.Items[index].SubItems[2].Text = "-";
                    shortcutListView.Items[index].SubItems[2].Tag = null;
                }
            };

            // マウスジェスチャ
            MouseGesture mouseGesture = new MouseGesture();
            mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
            bool gestureing = false;
            shortcutListView.MouseDown += (sender, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    mouseGesture.Start();
                    gestureing = true;
                }
            };
            shortcutListView.MouseMove += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0) return;
                if (gestureing == false) return;

                mouseGesture.Moving(e.Location);

                int index = shortcutListView.SelectedIndices[0];

                string gesture = mouseGesture.ToString();
                if (string.IsNullOrEmpty(gesture)) return;
                if (shortcutListView.Items[index].SubItems[2].Text == mouseGesture.ToString()) return;

                // 同じジェスチャを削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    string text = item.SubItems[2].Text;
                    if (gesture == text)
                    {
                        item.SubItems[2].Text = "-";
                        item.SubItems[2].Tag = null;
                    }
                }

                // ジェスチャを登録
                shortcutListView.Items[index].SubItems[2].Text = gesture;
                shortcutListView.Items[index].SubItems[2].Tag = null;
            };
            shortcutListView.MouseUp += (sender, e) => gestureing = false;
        }
Example #33
0
        /// <summary>
        /// Raises proper events
        /// </summary>
        /// <param name="gesture">Gesture performed.</param>
        private void RaiseGestureEvents(MouseGesture gesture)
        {
            if ( gesture != MouseGesture.Unknown ) {
            MouseGestureEventArgs eventArgs = new MouseGestureEventArgs(gesture, gestureStartLocation);

            //always raise general event
            RaiseGestureEvent(eventArgs);

            switch ( gesture ) {
              case MouseGesture.Up:
            RaiseGestureUpEvent(eventArgs);
            break;
              case MouseGesture.Right:
            RaiseGestureRightEvent(eventArgs);
            break;
              case MouseGesture.Down:
            RaiseGestureDownEvent(eventArgs);
            break;
              case MouseGesture.Left:
            RaiseGestureLeftEvent(eventArgs);
            break;
            }

            if ( enableComplexGestures ) {
              switch ( gesture ) {
            case MouseGesture.UpDown:
              RaiseGestureUpDownEvent(eventArgs);
              break;
            case MouseGesture.UpRight:
              RaiseGestureUpRightEvent(eventArgs);
              break;
            case MouseGesture.UpLeft:
              RaiseGestureUpLeftEvent(eventArgs);
              break;

            case MouseGesture.RightUp:
              RaiseGestureRightUpEvent(eventArgs);
              break;
            case MouseGesture.RightDown:
              RaiseGestureRightDownEvent(eventArgs);
              break;
            case MouseGesture.RightLeft:
              RaiseGestureRightLeftEvent(eventArgs);
              break;

            case MouseGesture.DownUp:
              RaiseGestureDownUpEvent(eventArgs);
              break;
            case MouseGesture.DownRight:
              RaiseGestureDownRightEvent(eventArgs);
              break;
            case MouseGesture.DownLeft:
              RaiseGestureDownLeftEvent(eventArgs);
              break;

            case MouseGesture.LeftUp:
              RaiseGestureLeftUpEvent(eventArgs);
              break;
            case MouseGesture.LeftRight:
              RaiseGestureLeftRightEvent(eventArgs);
              break;
            case MouseGesture.LeftDown:
              RaiseGestureLeftDownEvent(eventArgs);
              break;
              }
            }
              }
        }
Example #34
0
 public MouseGestureButton(MouseGesture button)
 {
     CurrentState  = Mouse.GetState();
     PreviousState = CurrentState;
     Button        = button;
 }
Example #35
0
 public void RegisterMouseGestureAction(MouseGesture gesture, Action <MouseEventArgs> action)
 {
     using (registeredGestures.IgnoreFrameInRegistrationTrace())
         RegisterGestureAction(gesture, (e) => { action((MouseEventArgs)e); });
 }
Example #36
0
		public PlayerSettingView(ShortcutManager shortcut)
		{
			this.shortcut = shortcut;

			InitializeComponent();

			// 親ウィンドウの中心に表示
			StartPosition = FormStartPosition.CenterParent;

			// 初期化
			Shown += (sender, e) =>
			{
				// チェックボックスの表示
				disconnectRealyOnCloseCheckBox.Checked = PlayerSettings.DisconnectRealyOnClose;
				returnPositionOnStartCheckBox.Checked = PlayerSettings.ReturnPositionOnStart;
				returnSizeOnStartCheckBox.Checked = PlayerSettings.ReturnSizeOnStart;
				windowSnapEnableCheckBox.Checked = PlayerSettings.WindowSnapEnable;
				aspectRateFixCheckBox.Checked = PlayerSettings.AspectRateFix;
				frameInvisibleCheckBox.Checked = PlayerSettings.FrameInvisible;
				topMostCheckBox.Checked = PlayerSettings.TopMost;
				writeFieldVisibleCheckBox.Checked = PlayerSettings.WriteFieldVisible;
				initVolumeTextBox.Text = PlayerSettings.InitVolume.ToString();
				saveReturnPositionCheckBox.Checked = PlayerSettings.SaveReturnPositionOnClose;
				saveReturnSizeCheckBox.Checked = PlayerSettings.SaveReturnSizeOnClose;
				exitedViewerCloseCheckBox.Checked = PlayerSettings.ExitedViewerClose;

				// チェックボックスの設定(ステータスバー)
				displayFpsCheckBox.Checked = PlayerSettings.DisplayFps;
				displayBitrateCheckBox.Checked = PlayerSettings.DisplayBitrate;
				listenerNumberCheckBox.Checked = PlayerSettings.DisplayListenerNumber;

				// 音量変化
				volumeChangeNoneTextBox.Text = PlayerSettings.VolumeChangeNone.ToString();
				volumeChangeCtrlTextBox.Text = PlayerSettings.VolumeChangeCtrl.ToString();
				volumeChangeShiftTextBox.Text = PlayerSettings.VolumeChangeShift.ToString();

				// スクリーンショット
				screenshotFolderTextBox.Text = PlayerSettings.ScreenshotFolder;
				foreach (var item in screenshotExtensionComboBox.Items)
				{
					if (item.ToString() == PlayerSettings.ScreenshotExtension)
					{
						screenshotExtensionComboBox.SelectedItem = item;
					}
				}
				// 拡張子が選択されていなければpngを選ばせる
				if (screenshotExtensionComboBox.SelectedItem == null)
				{
					screenshotExtensionComboBox.SelectedIndex = screenshotExtensionComboBox.FindString("png");
				}
				// 書式
				screenshotFormatTextBox.Text = PlayerSettings.ScreenshotFormat;
				screenshotSampleTextBox.Text = Shortcut.Command.ScreenshotCommand.Format(screenshotFormatTextBox.Text, null);

				// スレッド
				autoReadThreadCheckBox.Checked = PlayerSettings.AutoReadThread;

				// FLV
				flvGpuCheckBox.Checked = PlayerSettings.Gpu;
				useRtmpCheckBox.Checked = PlayerSettings.Rtmp;
				bufferTimeTextBox.Text = PlayerSettings.BufferTime.ToString();
				bufferTimeMaxTextBox.Text = PlayerSettings.BufferTimeMax.ToString();

				// 動画再生開始時のコマンド
				movieStartComboBox.Items.Clear();
				foreach (Commands command in movieStartCommandList)
				{
					string detail = shortcut.CommandMap[command].Detail;
					movieStartComboBox.Items.Add(detail);

					if (PlayerSettings.MovieStartCommand == command)
					{
						movieStartComboBox.SelectedIndex = (movieStartComboBox.Items.Count - 1);
					}
				}

				// ショートカット・ジェスチャー表示
				shortcutListView.Items.Clear();
				foreach (KeyValuePair<Commands, ShortcutCommand> commandPair in shortcut.CommandMap)
				{
					// ショートカットのアイテム追加
					ListViewItem keyItem = CreateKeyItem(shortcut, commandPair);
					shortcutListView.Items.Add(keyItem);
				}
			};

			// スクリーンショットを保存するフォルダを選ぶダイアログを表示するボタン
			browseScreenshotFolderButton.Click += (sender, args) =>
			{
				folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
				folderBrowserDialog.SelectedPath = PlayerSettings.ScreenshotFolder;
				if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
				{
					screenshotFolderTextBox.Text = folderBrowserDialog.SelectedPath;
				}
			};

			// スクリーンショットファイル名の書式
			screenshotFormatTextBox.TextChanged += (sender, args) =>
			{
				screenshotSampleTextBox.Text = Shortcut.Command.ScreenshotCommand.Format(screenshotFormatTextBox.Text, null);
			};
			// 書式の補助メニュー
			screenshotFormatButton.Click += (sender, args) => screenshotContextMenuStrip.Show(screenshotFormatButton, 0, 0);
			Action<string> formatHelper = (x) =>
			{
				// 選択されているテキストの位置を取得しておく
				var selectionStart = screenshotFormatTextBox.SelectionStart;
				screenshotFormatTextBox.Text = screenshotFormatTextBox.Text.Insert(screenshotFormatTextBox.SelectionStart, x);
				// 追加した文字列の後ろにカーソルを移動
				screenshotFormatTextBox.SelectionStart = selectionStart + x.Length;
				screenshotFormatTextBox.Focus();
			};
			year2ToolStripMenuItem.Click += (sender, args) => formatHelper("yy");
			year4ToolStripMenuItem.Click += (sender, args) => formatHelper("yyyy");
			monthToolStripMenuItem.Click += (sender, args) => formatHelper("MM");
			dayToolStripMenuItem.Click += (sender, args) => formatHelper("dd");
			hourToolStripMenuItem.Click += (sender, args) => formatHelper("hh");
			minuteToolStripMenuItem.Click += (sender, args) => formatHelper("mm");
			secondToolStripMenuItem.Click += (sender, args) => formatHelper("ss");
			channelNameToolStripMenuItem.Click += (sender, args) => formatHelper("$0");

			// Tab遷移しないようにする
			shortcutListView.PreviewKeyDown += (sender, e) => e.IsInputKey = true;

			// ショートカット設定時にエラー音がならないようにする
			shortcutListView.KeyPress += (sender, e) => e.Handled = true;

			// ショートカット入力
			shortcutListView.KeyDown += (sender, e) =>
			{
				if (shortcutListView.SelectedIndices.Count <= 0) return;
				if (e.KeyData == Keys.ProcessKey) return;

				// 同じキー入力を削除
				foreach (ListViewItem item in shortcutListView.Items)
				{
					object tag = item.SubItems[1].Tag;	// KeyInput

					if ((tag == null))
					{
						continue;
					}

					KeyInput keyInput = (KeyInput)tag;

					if ((keyInput.Key == e.KeyCode) && (keyInput.Modifiers == e.Modifiers))
					{
						item.SubItems[1].Text = "-";
						item.SubItems[1].Tag = null;
					}
				}

				// ショートカット登録
				KeyInput input = new KeyInput(e.Modifiers, e.KeyCode);
				int index = shortcutListView.SelectedIndices[0];
				shortcutListView.Items[index].SubItems[1].Text = ConvertKeyInputToString(input);
				shortcutListView.Items[index].SubItems[1].Tag = input;

				// キー入力を無視
				e.Handled = true;
			};

			// ダブルクリックでコマンド削除
			shortcutListView.MouseDoubleClick += (sender, e) =>
			{
				if (shortcutListView.SelectedIndices.Count <= 0) return;

				if (e.Button == MouseButtons.Left)
				{
					int index = shortcutListView.SelectedIndices[0];
					shortcutListView.Items[index].SubItems[1].Text = "-";
					shortcutListView.Items[index].SubItems[1].Tag = null;
				}
				else if (e.Button == System.Windows.Forms.MouseButtons.Right)
				{
					int index = shortcutListView.SelectedIndices[0];
					shortcutListView.Items[index].SubItems[2].Text = "-";
					shortcutListView.Items[index].SubItems[2].Tag = null;
				}
			};

			// マウスジェスチャ
			MouseGesture mouseGesture = new MouseGesture();
			mouseGesture.Interval = PlayerSettings.MouseGestureInterval;
			bool gestureing = false;
			shortcutListView.MouseDown += (sender, e) =>
			{
				if (e.Button == MouseButtons.Right)
				{
					mouseGesture.Start();
					gestureing = true;
				}
			};
			shortcutListView.MouseMove += (sender, e) =>
			{
				if (shortcutListView.SelectedIndices.Count <= 0) return;
				if (gestureing == false) return;

				mouseGesture.Moving(e.Location);
                string gesture = mouseGesture.ToString();

				int index = shortcutListView.SelectedIndices[0];
				if (string.IsNullOrEmpty(gesture)) return;
				if (shortcutListView.Items[index].SubItems[2].Text == mouseGesture.ToString()) return;

				// ジェスチャを登録
				shortcutListView.Items[index].SubItems[2].Text = gesture;
				shortcutListView.Items[index].SubItems[2].Tag = null;
			};
            shortcutListView.MouseUp += (sender, e) =>
            {
                if (shortcutListView.SelectedIndices.Count <= 0) return;
                if (gestureing == false) return;

                mouseGesture.Moving(e.Location);
                string gesture = mouseGesture.ToString();

                int index = shortcutListView.SelectedIndices[0];
                if (string.IsNullOrEmpty(gesture)) return;

                // 同じジェスチャを削除
                foreach (ListViewItem item in shortcutListView.Items)
                {
                    string text = item.SubItems[2].Text;
                    if (gesture == text)
                    {
                        item.SubItems[2].Text = "-";
                        item.SubItems[2].Tag = null;
                    }
                }

                // ジェスチャを登録
                shortcutListView.Items[index].SubItems[2].Text = gesture;
                shortcutListView.Items[index].SubItems[2].Tag = null;
            };
			shortcutListView.MouseUp += (sender, e) => gestureing = false;
		}