protected virtual void Mouse_WheelChanged(object sender, OpenTK.Input.MouseWheelEventArgs e)
 {
     if (FocusedElement != null)
     {
         FocusedElement.MouseWheel(e);
     }
 }
        protected virtual void Keyboard_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == OpenTK.Input.Key.LShift)
            {
                _modifierKeys -= ModifierKeys.LShift;
            }
            if (e.Key == OpenTK.Input.Key.RShift)
            {
                _modifierKeys -= ModifierKeys.RShift;
            }
            if (e.Key == OpenTK.Input.Key.LControl)
            {
                _modifierKeys -= ModifierKeys.LControl;
            }
            if (e.Key == OpenTK.Input.Key.RControl)
            {
                _modifierKeys -= ModifierKeys.RControl;
            }
            if (e.Key == OpenTK.Input.Key.LAlt)
            {
                _modifierKeys -= ModifierKeys.LAlt;
            }
            if (e.Key == OpenTK.Input.Key.RAlt)
            {
                _modifierKeys -= ModifierKeys.RAlt;
            }

            if (FocusedElement != null)
            {
                FocusedElement.KeyUp(e, _modifierKeys);
            }
        }
Ejemplo n.º 3
0
        protected override void OnGotFocus(RoutedEventArgs e)
        {
            base.OnGotFocus(e);

            Action action = () =>
            {
                if (FocusedElement != null)
                {
                    _hasChildren = true;
                    FocusedElement.Focus();
                }
                else
                {
                    //Focus first Focusable Child element of ChildWindow
                    var focusableChild = TreeHelper.FindChild <FrameworkElement>(this.Content as DependencyObject, x => x.Focusable);
                    if (focusableChild != null)
                    {
                        _hasChildren = true;
                        focusableChild.Focus();
                    }
                    else
                    {
                        _hasChildren = false;
                    }
                }
            };

            Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, action);
        }
        protected virtual void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == OpenTK.Input.Key.LShift)
            {
                _modifierKeys |= ModifierKeys.LShift;
            }
            if (e.Key == OpenTK.Input.Key.RShift)
            {
                _modifierKeys |= ModifierKeys.RShift;
            }
            if (e.Key == OpenTK.Input.Key.LControl)
            {
                _modifierKeys |= ModifierKeys.LControl;
            }
            if (e.Key == OpenTK.Input.Key.RControl)
            {
                _modifierKeys |= ModifierKeys.RControl;
            }
            if (e.Key == OpenTK.Input.Key.LAlt)
            {
                _modifierKeys |= ModifierKeys.LAlt;
            }
            if (e.Key == OpenTK.Input.Key.RAlt)
            {
                _modifierKeys |= ModifierKeys.RAlt;
            }

            if (FocusedElement != null)
            {
                if (FocusedElement.ReceiveMouseClicks)
                {
                    if (e.Key == LeftMouseKey)
                    {
                        FocusedElement.MouseDown(LEFT_CLICK_DOWN);
                        FocusedElement.MouseDown(LEFT_CLICK_UP);
                    }
                    else if (e.Key == RightMouseKey)
                    {
                        FocusedElement.MouseDown(RIGHT_CLICK_DOWN);
                        FocusedElement.MouseDown(RIGHT_CLICK_UP);
                    }
                    else if (e.Key == MiddleMouseKey)
                    {
                        FocusedElement.MouseDown(MIDDLE_CLICK_DOWN);
                        FocusedElement.MouseDown(MIDDLE_CLICK_UP);
                    }
                }

                else if (FocusedElement.ReceiveKeys)
                {
                    FocusedElement.KeyDown(e, _modifierKeys);
                }
            }

            if (Receiver != null && ShouldNotifyReceiver())
            {
                Receiver.KeyDown(e, _modifierKeys);
            }
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public void Dispose()
 {
     try
     {
         FocusedElement?.Focus();
     }
     catch (COMException) { }
 }
        protected virtual void Mouse_ButtonUp(object sender, OpenTK.Input.MouseButtonEventArgs e)
        {
            if (FocusedElement != null)
            {
                FocusedElement.MouseUp(e);
            }

            //Mouse_Move(sender, new OpenTK.Input.MouseMoveEventArgs(e.X, e.Y, 0, 0));
        }
        public void FocusOn(Widget inWidget)
        {
            if (FocusedElement != null)
            {
                FocusedElement.MouseLeave();
            }

            FocusedElement = inWidget;
        }
        private UIElement GetAccentedParent(DependencyObject d)
        {
            if (FocusedElement == null)
            {
                return(null);
            }

            return(FocusedElement.TraverseUpVisual()
                   .Where(x => FocusAccentAdorner.GetAccented(x))
                   .OfType <UIElement>().FirstOrDefault());
        }
Ejemplo n.º 9
0
        protected override void OnGotFocus(RoutedEventArgs e)
        {
            Action action = () =>
            {
                if (FocusedElement != null)
                {
                    FocusedElement.Focus();
                }
            };

            Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, action);
        }
        protected virtual void Mouse_WheelChanged(object sender, OpenTK.Input.MouseWheelEventArgs e)
        {
            if (FocusedElement != null && FocusedElement.ReceiveMouseWheel)
            {
                FocusedElement.MouseWheel(e);
            }

            if (Receiver != null && ShouldNotifyReceiver())
            {
                Receiver.MouseWheel(e);
            }
        }
        protected virtual void Mouse_Move(object sender, OpenTK.Input.MouseMoveEventArgs e)
        {
            if (FocusedElement != null)
            {
                FocusedElement.MouseMove(e);
            }

            _currentMousePosition.X = e.X;
            _currentMousePosition.Y = e.Y;

            IEnumerable <Widget> activeGUIComponents  = Scene.Current.ActiveObjects.GetComponents <Widget>();
            IEnumerable <Widget> hoveredGUIComponents = activeGUIComponents.Where(gc => gc.ActiveArea != ActiveArea.None && gc.GetAreaOnScreen(GameObj.Camera).Contains(_currentMousePosition));

            Widget hgc = null;

            if (hoveredGUIComponents.Count() > 0)
            {
                float closestZ = hoveredGUIComponents.Min(gc => gc.GameObj.Transform.Pos.Z);
                hgc = hoveredGUIComponents.Where(gc => gc.GameObj.Transform.Pos.Z == closestZ).FirstOrDefault();

                if (hgc != null && !hgc.GetActiveAreaOnScreen(GameObj.Camera).Contains(_currentMousePosition))
                {
                    hgc = null;
                }

                if (hgc != null && _currentDialog != null)
                {
                    if (hgc.GameObj.FindAncestorWithComponent <SkinnedWindow>() != _currentDialog.GameObj)
                    {
                        hgc = null;
                    }
                }
            }

            if (HoveredElement != hgc)
            {
                if (HoveredElement != null)
                {
                    HoveredElement.MouseLeave();
                }

                if (hgc != null)
                {
                    hgc.MouseEnter();
                }
            }

            HoveredElement = hgc;
        }
        protected virtual void Mouse_ButtonUp(object sender, OpenTK.Input.MouseButtonEventArgs e)
        {
            _draggedElement = null;

            if (FocusedElement != null && FocusedElement.ReceiveMouseClicks)
            {
                FocusedElement.MouseUp(e);
            }

            if (Receiver != null && ShouldNotifyReceiver())
            {
                Receiver.MouseUp(e);
            }

            Mouse_Move(sender, new OpenTK.Input.MouseMoveEventArgs(e.X, e.Y, 0, 0));
        }
        protected virtual void Mouse_ButtonDown(object sender, OpenTK.Input.MouseButtonEventArgs e)
        {
            if (FocusedElement != HoveredElement)
            {
                if (FocusedElement != null)
                {
                    FocusedElement.Deactivate();
                }

                FocusedElement = HoveredElement;
            }

            if (FocusedElement != null)
            {
                FocusedElement.Activate();
                FocusedElement.MouseDown(e);
            }

            //Mouse_Move(sender, new OpenTK.Input.MouseMoveEventArgs(e.X, e.Y, 0, 0));
        }
Ejemplo n.º 14
0
        void IDesktopOverlay.ProcessKeyDown(KeyEventArgs e)
        {
            // If an element as captured the pointer, send the event to it first
            if (CaptureElement != null)
            {
                e.Handled = CaptureElement.ProcessKeyDown(e);
            }

            if (e.Handled)
            {
                return;
            }

            // Then, send it to the currently focused control
            if (FocusedElement != null)
            {
                e.Handled = FocusedElement.ProcessKeyDown(e);
            }

            if (e.Handled)
            {
                return;
            }

            //Proceeds with the rest
            foreach (UIElement control in TreeTraversal.PostOrderInteractionVisit(this))
            {
                e.Handled = control.ProcessKeyDown(e);
                if (e.Handled)
                {
                    break;
                }
            }

            if (e.Handled)
            {
                return;
            }

            e.Handled = ProcessKeyDown(e);
        }
Ejemplo n.º 15
0
        void IDesktopOverlay.ProcessKeyUp(KeyEventArgs e)
        {
            // If an element as captured the pointer, send the event to it first
            if (CaptureElement != null)
            {
                e.Handled = CaptureElement.ProcessKeyUp(e);
            }

            if (e.Handled)
            {
                return;
            }

            // Then, send it to the currently focused control
            if (FocusedElement != null)
            {
                e.Handled = FocusedElement.ProcessKeyUp(e);
            }

            e.Handled = ProcessKeyUp(e);
        }
        protected virtual void Mouse_ButtonDown(object sender, OpenTK.Input.MouseButtonEventArgs e)
        {
            FocusedElement = HoveredElement;

            if (FocusedElement != null && FocusedElement.Draggable)
            {
                _lastMousePosition.X = e.X;
                _lastMousePosition.Y = e.Y;

                _draggedElement = FocusedElement;
            }
            else if (FocusedElement != null && FocusedElement.ReceiveMouseClicks)
            {
                FocusedElement.MouseDown(e);
            }

            if (Receiver != null && ShouldNotifyReceiver())
            {
                Receiver.MouseDown(e);
            }

            Mouse_Move(sender, new OpenTK.Input.MouseMoveEventArgs(e.X, e.Y, 0, 0));
        }
Ejemplo n.º 17
0
 void IInputListener <KeyboardState> .OnInputReceived(KeyboardState state)
 {
     if (FocusedElement != null)
     {
         bool controlKeyDown = state.IsPressed(Key.LeftControl) || state.IsPressed(Key.RightControl);
         bool altKeyDown     = state.IsPressed(Key.LeftAlt) || state.IsPressed(Key.RightAlt);
         bool shiftKeyDown   = state.IsPressed(Key.LeftShift) || state.IsPressed(Key.RightShift);
         bool winKeyDown     = state.IsPressed(Key.LeftWindowsKey) || state.IsPressed(Key.RightWindowsKey);
         if (state.PressedKeys.Length > pressedKeys.Length)
         {
             Key key = state.PressedKeys.Except(pressedKeys).First();
             KeyboardEventArgs args = new KeyboardEventArgs(key, controlKeyDown, altKeyDown, shiftKeyDown, winKeyDown);
             FocusedElement.OnKeyDown(args);
         }
         else if (state.PressedKeys.Length < pressedKeys.Length)
         {
             Key key = pressedKeys.Except(state.PressedKeys).First();
             KeyboardEventArgs args = new KeyboardEventArgs(key, controlKeyDown, altKeyDown, shiftKeyDown, winKeyDown);
             FocusedElement.OnKeyUp(args);
         }
         pressedKeys = state.PressedKeys;
     }
 }
        protected virtual void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            if (e.Key == OpenTK.Input.Key.LShift)
            {
                _modifierKeys |= ModifierKeys.LShift;
            }
            if (e.Key == OpenTK.Input.Key.RShift)
            {
                _modifierKeys |= ModifierKeys.RShift;
            }
            if (e.Key == OpenTK.Input.Key.LControl)
            {
                _modifierKeys |= ModifierKeys.LControl;
            }
            if (e.Key == OpenTK.Input.Key.RControl)
            {
                _modifierKeys |= ModifierKeys.RControl;
            }
            if (e.Key == OpenTK.Input.Key.LAlt)
            {
                _modifierKeys |= ModifierKeys.LAlt;
            }
            if (e.Key == OpenTK.Input.Key.RAlt)
            {
                _modifierKeys |= ModifierKeys.RAlt;
            }

            /**
             * Modifiers ok, testing keys
             **/
            if (e.Key == NextWidgetKey && IsModifierOk(NextWidgetKeyModifier))
            {
                if (FocusedElement == null)
                {
                    GameObject firstObject = FindFirstGameObject();

                    if (firstObject != null)
                    {
                        FocusedElement = firstObject.GetComponent <Widget>();
                        FocusedElement.MouseEnter();
                    }
                }
                else if (FocusedElement.NextWidget != null)
                {
                    FocusedElement.MouseLeave();
                    FocusedElement = FocusedElement.NextWidget;
                    FocusedElement.MouseEnter();
                }
            }
            if (e.Key == PreviousWidgetKey && IsModifierOk(PreviousWidgetKeyModifier))
            {
                if (FocusedElement == null)
                {
                    GameObject firstObject = FindFirstGameObject();

                    if (firstObject != null)
                    {
                        FocusedElement = firstObject.GetComponent <Widget>();
                        FocusedElement.MouseEnter();
                    }
                }
                else if (FocusedElement.PreviousWidget != null)
                {
                    FocusedElement.MouseLeave();
                    FocusedElement = FocusedElement.PreviousWidget;
                    FocusedElement.MouseEnter();
                }
            }

            if (FocusedElement != null)
            {
                if (e.Key == LeftMouseKey && IsModifierOk(LeftMouseKeyModifier))
                {
                    FocusedElement.MouseDown(LEFT_CLICK_DOWN);
                    FocusedElement.MouseUp(LEFT_CLICK_UP);
                }
                else if (e.Key == RightMouseKey && IsModifierOk(RightMouseKeyModifier))
                {
                    FocusedElement.MouseDown(RIGHT_CLICK_DOWN);
                    FocusedElement.MouseUp(RIGHT_CLICK_UP);
                }
                else if (e.Key == MiddleMouseKey && IsModifierOk(MiddleMouseKeyModifier))
                {
                    FocusedElement.MouseDown(MIDDLE_CLICK_DOWN);
                    FocusedElement.MouseUp(MIDDLE_CLICK_UP);
                }

                FocusedElement.KeyDown(e, _modifierKeys);
            }
        }