Ejemplo n.º 1
0
 public void Press()
 {
     Pressed?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 2
0
 /// <summary>Called when the button is pressed</summary>
 protected override void OnPressed()
 {
     Pressed?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 3
0
 public Container(string pTextureName, Vector2 pPosition, Pressed pOnContainerPressed)
 {
     init(pTextureName, true, pPosition);
     _onContainerPressed = pOnContainerPressed;
 }
Ejemplo n.º 4
0
 protected void CallPressed()
 {
     Pressed?.Invoke(this, this);
 }
        /// <inheritdoc />
        protected override void DataAvailable(object sender, DataAvailableEventArgs <EvEvent> e)
        {
            var data = e.Data;

            var eventType = (DigitizerEventType)data.Type;

            switch (eventType)
            {
            case DigitizerEventType.Syn:
                State = new StylusState(_currentTool, _currentPosition, _currentPressure, _currentDistance, _currentTilt);
                StylusUpdate?.Invoke(null, State);
                break;

            case DigitizerEventType.Key:
                var key   = (DigitizerEventKeyCode)data.Code;
                var state = (ButtonState)data.Value;

                ButtonStates[key] = state;

                switch (key)
                {
                case DigitizerEventKeyCode.BtnToolPen:
                    _currentTool = StylusTool.Pen;
                    ToolChanged?.Invoke(null, _currentTool);
                    break;

                case DigitizerEventKeyCode.BtnToolRubber:
                    _currentTool = StylusTool.Eraser;
                    ToolChanged?.Invoke(null, _currentTool);
                    break;

                case DigitizerEventKeyCode.BtnTouch:
                case DigitizerEventKeyCode.BtnStylus:
                case DigitizerEventKeyCode.BtnStylus2:
                    if (state == ButtonState.Pressed)
                    {
                        Pressed?.Invoke(null, key);
                    }
                    else
                    {
                        Released?.Invoke(null, key);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(key), key, key.GetType().Name);
                }

                break;

            case DigitizerEventType.Abs:
                var eventCode = (DigitizerEventAbsCode)data.Code;

                switch (eventCode)
                {
                case DigitizerEventAbsCode.AbsX:
                    _currentPosition.X = data.Value;
                    break;

                case DigitizerEventAbsCode.AbsY:
                    _currentPosition.Y = data.Value;
                    break;

                case DigitizerEventAbsCode.AbsPressure:
                    _currentPressure = data.Value;
                    break;

                case DigitizerEventAbsCode.AbsDistance:
                    _currentDistance = data.Value;
                    break;

                case DigitizerEventAbsCode.AbsTiltX:
                    _currentTilt.X = data.Value;
                    break;

                case DigitizerEventAbsCode.AbsTiltY:
                    _currentTilt.Y = data.Value;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(eventCode), eventCode, eventCode.GetType().Name);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(eventType), eventType, eventType.GetType().Name);
            }
        }
Ejemplo n.º 6
0
 public void Dispose()
 {
     _texture = null;
     _hoverOverlay = null;
     this._onContainerPressed = null;
     _texture = null;
     foreach (Container c in _children)
         c.Dispose();
     _children.Clear();
 }
 private void Press()
 {
     Task.Run(() => Pressed?.Invoke(this, EventArgs.Empty));
 }
Ejemplo n.º 8
0
 private void Click()
 {
     Pressed.Fire();
 }
Ejemplo n.º 9
0
 void IButtonController.PropagateUpPressed() => Pressed?.Invoke(this, EventArgs.Empty);
Ejemplo n.º 10
0
 private void OnMouseDown()
 {
     Pressed?.Invoke();
     _startTime = Time.time;
 }
Ejemplo n.º 11
0
        public ButtonContent()
        {
            _frame = new Frame()
            {
                Padding           = 0,
                HasShadow         = false,
                CornerRadius      = CornerRadius,
                BackgroundColor   = Color.Transparent,
                InputTransparent  = true,
                IsEnabled         = false,
                IsClippedToBounds = true,
            };
            _frame.SetBinding(ContentView.ContentProperty,
                              new Binding(nameof(Content))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _frame.SetBinding(PaddingProperty, new Binding(nameof(Padding))
            {
                Source = this, Mode = BindingMode.OneWay
            });

            _button = new BlankButton
            {
                HeightRequest   = 0,
                BackgroundColor = BackgroundColor,
                TextColor       = TextColor,
                BorderColor     = BorderColor,
            };

            _button.SetBinding(Button.CommandProperty,
                               new Binding(nameof(Command))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _button.SetBinding(Button.CommandParameterProperty,
                               new Binding(nameof(CommandParameter))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _button.SetBinding(Button.BorderWidthProperty,
                               new Binding(nameof(BorderWidth))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _button.SetBinding(Button.ImageProperty,
                               new Binding(nameof(Image))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _button.SetBinding(Button.FontFamilyProperty,
                               new Binding(nameof(FontFamily))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _button.SetBinding(Button.FontAttributesProperty,
                               new Binding(nameof(FontAttributes))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _button.SetBinding(Button.FontSizeProperty,
                               new Binding(nameof(FontSize))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _button.SetBinding(Button.TextProperty,
                               new Binding(nameof(Text))
            {
                Source = this, Mode = BindingMode.OneWay
            });
            _button.SetBinding(Button.FontAttributesProperty,
                               new Binding(nameof(FontAttributes))
            {
                Source = this, Mode = BindingMode.OneWay
            });

            _loader = new ActivityIndicator
            {
                Margin            = 0,
                IsRunning         = true,
                IsVisible         = false,
                InputTransparent  = true,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center
            };
            _loader.SetBinding(ActivityIndicator.ColorProperty,
                               new Binding(nameof(LoaderColor))
            {
                Source = this, Mode = BindingMode.OneWay
            });

            _button.SetBinding(Button.PaddingProperty, new Binding(nameof(Padding))
            {
                Source = this, Mode = BindingMode.OneWay
            });

            _button.Pressed  += Button_Pressed;
            _button.Released += Button_Released;

            _button.Clicked  += (sender, e) => { Clicked?.Invoke(this, new EventArgs()); };
            _button.Released += (sender, e) => { Released?.Invoke(this, new EventArgs()); };
            _button.Pressed  += (sender, e) => { Pressed?.Invoke(this, new EventArgs()); };

            Children.Add(_button, 0, 0);
            Children.Add(_frame, 0, 0);
            Children.Add(_loader, 0, 0);
        }
Ejemplo n.º 12
0
 public void RaisePressed() => Pressed?.Invoke(this, EventArgs.Empty);
Ejemplo n.º 13
0
        // update
        // - check for mouse hovering and click (select)
        public void Update(GameTime gameTime, KeyboardState keyboardState, Camera camera, GameState state)
        {
            _previousTouch = _currentTouch;
            _currentTouch  = state.CurrentTouch;

            // update tile?
            IsGlowing        = false;
            IsPreviewingRoad = false;

            #region TOUCH INTERACTION LOGIC
            if (IsVisible)
            {
                if (_touchRemainingDelay > 0)
                {
                    var touch_timer = (float)gameTime.ElapsedGameTime.TotalSeconds;
                    _touchRemainingDelay -= touch_timer;
                    if (_touchRemainingDelay <= 0)
                    {
                        _touchRemainingDelay = 0;
                    }
                }
                else
                {
                    foreach (var tl in _currentTouch)
                    {
                        // get the screen position of the touch
                        var t_screenPosition = new Vector2(tl.Position.X, tl.Position.Y);
                        // construct rect to represent touch
                        var t_screenRect = new Rectangle((int)t_screenPosition.X, (int)t_screenPosition.Y, 1, 1);
                        // dont continue if touch intersects hud/ui
                        if (t_screenRect.Intersects(state.GameHUD.DisplayRect) || t_screenRect.Intersects(state.Gamepad.GamePadUnionHitbox))
                        {
                            continue;
                        }
                        // convert touch screen pos to in-world pos
                        var t_worldPosition = Vector2.Zero;
                        camera.ToWorld(ref t_screenPosition, out t_worldPosition);
                        // adjust output of world position (why this works idfk)
                        t_worldPosition.X -= camera.Width / 2f;
                        t_worldPosition.Y -= camera.Height / 2f;
                        // create rect to represent inworld touch location
                        var tlrect = new Rectangle((int)t_worldPosition.X, (int)t_worldPosition.Y, 1, 1);
                        // if touch doesn't intersect tile hitbox
                        if (!tlrect.Intersects(TouchHitbox))
                        {
                            continue;
                        }

                        // if touchstate is moved/moving or pressed
                        if (tl.State == TouchLocationState.Moved || tl.State == TouchLocationState.Pressed)
                        {
                            // set states currently hovered tile
                            state.CurrentlyHoveredTile  = this;
                            state.CurrentlySelectedTile = this;
                            Log.Info("CitySim-Tile", $"Tile {TileIndex} Press Registered");
                            Pressed?.Invoke(this, new EventArgs());
                        }
                        // else if touch was released on this tile
                        else if (tl.State == TouchLocationState.Released)
                        {
                            // try to get previous touch and see if it wasn't moving before released
                            TouchLocation prevLoc;
                            if (!tl.TryGetPreviousLocation(out prevLoc) || prevLoc.State != TouchLocationState.Moved)
                            {
                                continue;
                            }
                            // set states currently selected tile
                            state.CurrentlySelectedTile = this;
                            // reset timer on touch (only can touch every two seconds)
                            _touchRemainingDelay = _touchTimeCycleDelay;
                            Log.Info("CitySim-Tile", $"Tile {TileIndex} Press-Release Registered");
                            Click?.Invoke(this, new EventArgs());
                        }
                    }
                }
            }

            #endregion


            if (Object is Residence r)
            {
                //Console.Out.WriteLine("Listing residents for tile: {0}", TileIndex.ToString());
                foreach (var res in r.Residents)
                {
                    //Console.Out.WriteLine("res.Name = {0}", res.Name);
                }
            }

            if (HasAnimatedTexture == false)
            {
                CheckForAnimatedTexture();
            }

            _gameState = state;
        }
Ejemplo n.º 14
0
 public void OnPress(SKPoint rect)
 {
     Pressed?.Invoke(rect);
 }
Ejemplo n.º 15
0
        private async void _DispatcherTimer_Tick()
        {
            if (_NowUpdating)
            {
                return;
            }

            using (var releaser = await _UpdateLock.LockAsync())
            {
                try
                {
                    _NowUpdating = true;

                    // コントローラー入力をチェック
                    foreach (var controller in UINavigationController.UINavigationControllers.Take(1))
                    {
                        var currentInput = controller.GetCurrentReading();

                        // ボタンを離した瞬間を検出
                        var pressing = RequiredUINavigationButtonsHelper.ToUINavigationButtons(currentInput.RequiredButtons)
                                       | OptionalUINavigationButtonsHelper.ToUINavigationButtons(currentInput.OptionalButtons);

                        //                var trigger = pressing & (_PrevPressingButtons ^ pressing);
                        var released = _PrevPressingButtons & (_PrevPressingButtons ^ pressing);

                        if (released != UINavigationButtons.None)
                        {
                            Pressed?.Invoke(this, released);
                        }

                        // ホールド入力の検出
                        UINavigationButtons holdingButtons = UINavigationButtons.None;
                        foreach (var target in __InputDetectTargets)
                        {
                            if (pressing.HasFlag(target))
                            {
                                if (!_ProcessedHoldingButtons.HasFlag(target))
                                {
                                    var time = _ButtonHold[target] += __InputPollingInterval;

                                    if (time > __HoldDetectTime)
                                    {
                                        holdingButtons           |= target;
                                        _ProcessedHoldingButtons |= target;
                                    }
                                }
                            }
                            else
                            {
                                _ButtonHold[target]      = TimeSpan.Zero;
                                _ProcessedHoldingButtons = (((UINavigationButtons)0) ^ target) & _ProcessedHoldingButtons;
                            }
                        }

                        if (holdingButtons != UINavigationButtons.None)
                        {
                            Holding?.Invoke(this, holdingButtons);
                        }

                        // トリガー検出用に前フレームの入力情報を保存
                        _PrevPressingButtons = pressing;
                    }
                }
                finally
                {
                    _NowUpdating = false;
                }
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Raises the <see cref="Pressed" /> event.
 /// </summary>
 /// <param name="e">The event data for the <see cref="Pressed" /> event.</param>
 protected virtual void OnPressed(HotKeyEventArgs e)
 {
     Pressed?.Invoke(this, e);
 }
Ejemplo n.º 17
0
 private void OnTouchPerformed(InputAction.CallbackContext context)
 {
     Pressed?.Invoke(m_Controls.Touch.Position.ReadValue <Vector2>(), context.time);
 }
Ejemplo n.º 18
0
 private void OnPress()
 {
     state = ButtonState.Pressing;
     Manager.OnAnyButtonPress();
     Pressed?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 19
0
 private void OnHotKeyPressed()
 {
     Pressed?.Invoke(this);
 }
Ejemplo n.º 20
0
 void IButton.Pressed() => Pressed?.Invoke();
Ejemplo n.º 21
0
 void Button_Activated(object sender, EventArgs e)
 {
     Pressed?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 22
0
 public void SetOnContainerPressedDelegate(Pressed pDelegateFunction)
 {
     _onContainerPressed = pDelegateFunction;
 }
Ejemplo n.º 23
0
 private void Awake()
 {
     Click = new Pressed();
 }
Ejemplo n.º 24
0
 void IButtonController.SendPressed()
 {
     Pressed?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 25
0
        // update
        // - check for mouse hovering and click (select)
        public void Update(GameTime gameTime, KeyboardState keyboardState, Camera camera, GameState state)
        {
            // update tile?
            IsGlowing        = false;
            IsPreviewingRoad = false;

            #region MOUSE INTERACTION LOGIC
            var currentMouse = Mouse.GetState();

            // convert mouse screen position to world position
            var m_screenPosition = new Vector2(currentMouse.X, currentMouse.Y);
            var m_worldPosition  = Vector2.Zero;
            camera.ToWorld(ref m_screenPosition, out m_worldPosition);

            // apply offset (why the f**k this is needed I absolutely do not know but I randomly f*****g figured out this formula and somehow it works so for the love of f**k - do not change this until a superior solution is TESTED and delivered
            m_worldPosition.X -= camera.Width / 2f;
            m_worldPosition.Y -= camera.Height / 2f;

            //m_worldPosition.X += (GraphicsDevice_.Viewport.Width * 0.25f);
            //m_worldPosition.Y += (GraphicsDevice_.Viewport.Height * 0.25f);

            // get bounds for mouse world position
            var mouseRectangle = new Rectangle((int)m_worldPosition.X, (int)m_worldPosition.Y, 1, 1);

            // check if mouse bounds intersects with tile touchbox bounds
            if (mouseRectangle.Intersects(TouchHitbox) && IsVisible.Equals(true))
            {
                state.CurrentlyHoveredTile = this;
                //Console.WriteLine($"Hover:: Mp=>{currentMouse.Position.ToString()} :: Mwp=>{m_worldPosition.ToString()} :: Tp=>{Position.ToString()}");
                //Console.WriteLine($"Hovering Over Tile: {TileIndex.ToString()}");

                switch (currentMouse.LeftButton)
                {
                case ButtonState.Pressed when _previousMouseState.LeftButton == ButtonState.Pressed:
                    if (!(state.CurrentlyPressedTile.TileIndex.Equals(TileIndex)))
                    {
                        Pressing?.Invoke(this, new EventArgs());
                    }
                    break;

                case ButtonState.Pressed when _previousMouseState.LeftButton == ButtonState.Released:
                    Pressed?.Invoke(this, new EventArgs());
                    break;

                case ButtonState.Released when _previousMouseState.LeftButton == ButtonState.Pressed:
                    Click?.Invoke(this, new EventArgs());
                    break;
                }

                if (currentMouse.RightButton == ButtonState.Released && _previousMouseState.RightButton == ButtonState.Pressed)
                {
                    //camera.Position = Position + new Vector2(0, 150);
                    RightClick?.Invoke(this, new EventArgs());
                }
            }

            #endregion


            if (Object is Residence r)
            {
                //Console.Out.WriteLine("Listing residents for tile: {0}", TileIndex.ToString());
                foreach (var res in r.Residents)
                {
                    //Console.Out.WriteLine("res.Name = {0}", res.Name);
                }
            }

            if (HasAnimatedTexture == false)
            {
                CheckForAnimatedTexture();
            }

            // save mouse state as previous mousestate for next update call
            _previousMouseState = currentMouse;

            _gameState = state;
        }
Ejemplo n.º 26
0
 void IButton.Pressed() => Pressed?.Invoke(this, EventArgs.Empty);
Ejemplo n.º 27
0
 /// <summary>
 /// Raises the <see cref="Pressed"/> event.
 /// </summary>
 protected virtual void OnPressed() =>
 Pressed?.Invoke(this);
 public virtual void OnPressed()
 {
     Pressed?.Invoke(this, EventArgs.Empty);
 }
        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            ResetStyle();

            Pressed?.Invoke();
        }
Ejemplo n.º 30
0
 protected virtual void OnPressed()
 {
     Pressed?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 31
0
 /// <include file="../../docs/Microsoft.Maui.Controls/ImageButton.xml" path="//Member[@MemberName='PropagateUpPressed']/Docs" />
 public void PropagateUpPressed() =>
 Pressed?.Invoke(this, EventArgs.Empty);
Ejemplo n.º 32
0
 void IButtonElement.PropagateUpPressed() => Pressed?.Invoke(this, EventArgs.Empty);
Ejemplo n.º 33
0
 protected virtual void OnPressed(HardwareButtonEventArgs e)
 {
     Pressed?.Invoke(this, e);
 }