Пример #1
0
        private void UpdatePositionAndBorder()
        {
            if (parent == null)
            {
                return;
            }

            var width       = parent.ActualWidth;
            var height      = parent.ActualHeight;
            var lineExtents = LineExtents;
            var pos         = Position;

            if (horizontalLine != null)
            {
                if (LineExtents.Width > 0)
                {
                    horizontalLine.X1 = lineExtents.Left;
                    horizontalLine.X2 = lineExtents.Right;
                    pos.Y             = MathUtil.Clamp(pos.Y, lineExtents.Top, lineExtents.Bottom);
                }
                else
                {
                    horizontalLine.X1 = 0;
                    horizontalLine.X2 = width;
                }

                horizontalLine.Y1 = pos.Y;
                horizontalLine.Y2 = pos.Y;
            }

            if (verticalLine != null)
            {
                if (LineExtents.Width > 0)
                {
                    verticalLine.Y1 = lineExtents.Top;
                    verticalLine.Y2 = lineExtents.Bottom;
                    pos.X           = MathUtil.Clamp(pos.X, lineExtents.Left, lineExtents.Right);
                }
                else
                {
                    verticalLine.Y1 = 0;
                    verticalLine.Y2 = height;
                }
                verticalLine.X1 = pos.X;
                verticalLine.X2 = pos.X;
            }
        }
Пример #2
0
        public override void Update()
        {
            // Await pressure plate state changes
            bool newState;

            if (triggerEventReceiver.TryReceive(out newState))
            {
                if (Enabled)
                {
                    if (newState != nextState)
                    {
                        nextState = newState;
                    }
                }
            }

            // Button smoothing
            currentValue += currentDirection * (float)Game.UpdateTime.Elapsed.TotalSeconds;
            currentValue  = MathUtil.Clamp(currentValue, 0.0f, TransitionTime);

            // Trigger a new state or a toggle when fully pressed down or released
            if (nextState != currentState)
            {
                currentValue += currentDirection * (float)Game.UpdateTime.Elapsed.TotalSeconds;
                if (nextState)
                {
                    if (currentValue >= TransitionTime)
                    {
                        // Disable after one press if single activation is on
                        if (SingleActivation)
                        {
                            Enabled = false;
                        }

                        currentState = true;
                        currentValue = TransitionTime;

                        toggledState = !toggledState;

                        Changed.Broadcast(CurrentState);
                        PlayStateSound();
                        UpdateVisuals();
                    }
                }
                else
                {
                    if (currentValue <= 0.0f)
                    {
                        currentState = false;
                        currentValue = 0.0f;

                        // Toggle only changed when activated
                        if (!Toggle)
                        {
                            Changed.Broadcast(CurrentState);
                            PlayStateSound();
                        }

                        UpdateVisuals();
                    }
                }
            }
        }