Esempio n. 1
0
        protected override void InternalDraw(IGraphicsFragment fragment, IGameEngineTime time)
        {
            var texture     = GetStyleStateTexture();
            var color       = Style.Get <Color>($"{UiStyleKeys.Target.Button}\\{(Enabled ? UiStyleKeys.Color.Enabled : UiStyleKeys.Color.Disabled)}");
            var center      = Style.Get <Rectangle>($"{UiStyleKeys.Target.Button}\\{UiStyleKeys.Source.Center}");
            var font        = Style.Get <SpriteFont>($"{UiStyleKeys.Target.Button}\\{UiStyleKeys.Font.Normal}");
            var destination = GetRenderDestinationRectangle();
            var offset      = GetStyleStateOffset();

            destination.X += offset.X;
            destination.Y += offset.Y;

            fragment.DrawSurface(texture, center, destination, color);

            if (string.IsNullOrEmpty(Text))
            {
                return;
            }

            var position = new Vector2(destination.X, destination.Y) + UiCanvas.ToScreenUnits(ActualSize) * 0.5f - font.MeasureString(Text) * 0.5f;

            fragment.DrawSpriteText(position,
                                    Vector2.One,
                                    0.0f,
                                    Vector2.Zero,
                                    font.MeasureString(Text),
                                    Text,
                                    font,
                                    color);
        }
Esempio n. 2
0
        protected override void InternalUpdate(IGameEngineTime time, IKeyboardDevice device)
        {
            // Escape was pressed, defocus current.
            if (device.IsKeyPressed(Keys.Escape))
            {
                Context.Keyboard?.Defocus();

                return;
            }

            // No tab pressed, skip updates.
            if (!device.IsKeyPressed(Keys.Tab))
            {
                return;
            }

            // Find next focused control.
            var container = Context.Mouse as IStaticContainerControl ?? Root;
            var index     = Context.Keyboard?.TabIndex ?? -1;

            if (Context.Keyboard != null && !container.Controls.Contains(Context.Keyboard))
            {
                Context.Keyboard.Defocus();
            }
            else
            {
                index = Context.Mouse?.TabIndex ?? container.TabIndex;
            }

            Context.Mouse?.Defocus();

            Focus(container, index);
        }
Esempio n. 3
0
        public void Update(IGameEngineTime time, IEnumerable <T> inactiveStates, IEnumerable <T> activeStates)
        {
            foreach (var inactiveState in inactiveStates)
            {
                if (!inactivityTimers.ContainsKey(inactiveState))
                {
                    inactivityTimers.Add(inactiveState, TimeSpan.Zero);
                }

                inactivityTimers[inactiveState] += time.Elapsed;

                activityTimers.Remove(inactiveState);
            }

            foreach (var activeState in activeStates)
            {
                if (!activityTimers.ContainsKey(activeState))
                {
                    activityTimers.Add(activeState, TimeSpan.Zero);
                }

                activityTimers[activeState] += time.Elapsed;

                inactivityTimers.Remove(activeState);
            }
        }
Esempio n. 4
0
        public void Poll(IGameEngineTime time)
        {
            // Poll MonoGame mouse state.
            var state   = Mouse.GetState();
            var buttons = MouseButton.None;

            // Determine button states.
            if (state.LeftButton == ButtonState.Pressed)
            {
                buttons |= MouseButton.Left;
            }
            if (state.MiddleButton == ButtonState.Pressed)
            {
                buttons |= MouseButton.Middle;
            }
            if (state.RightButton == ButtonState.Pressed)
            {
                buttons |= MouseButton.Right;
            }
            if (state.XButton1 == ButtonState.Pressed)
            {
                buttons |= MouseButton.X1;
            }
            if (state.XButton2 == ButtonState.Pressed)
            {
                buttons |= MouseButton.X2;
            }

            // Create new state.
            mouseStateBuffer.Push(new MouseState(new Point(state.X, state.Y), buttons, state.ScrollWheelValue));

            buttonWatcher.Update(time, GetButtonsUp(), GetButtonsDown());
        }
Esempio n. 5
0
        public void Update(IGameEngineTime time)
        {
            for (var i = 0; i < bindings.Count; i++)
            {
                var binding   = bindings[i];
                var triggered = false;

                switch (binding.State)
                {
                case InputTriggerState.Released:
                    triggered = IsTriggerReleased(binding.Triggers);
                    break;

                case InputTriggerState.Up:
                    triggered = IsTriggerUp(binding.Triggers);
                    break;

                case InputTriggerState.Pressed:
                    triggered = IsTriggerPressed(binding.Triggers);
                    break;

                case InputTriggerState.Down:
                    triggered = IsTriggerDown(binding.Triggers);
                    break;
                }

                if (triggered)
                {
                    binding.Callback(time);
                }
            }
        }
Esempio n. 6
0
        protected sealed override void InternalReceiveMouseInput(IGameEngineTime time, IMouseDevice mouse)
        {
            if (!HasFocus)
            {
                return;
            }

            if (Mouse.IsDown(MouseButton.Left))
            {
                if (state == ButtonState.Released)
                {
                    InternalClick();

                    state = ButtonState.Down;
                }
                else
                {
                    InternalDown();
                }
            }
            else
            {
                if (state == ButtonState.Released)
                {
                    return;
                }

                InternalReleased();

                state = ButtonState.Released;
            }
        }
Esempio n. 7
0
 public override void Update(IGameEngineTime time)
 {
     foreach (var device in devices)
     {
         device.Poll(time);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Update focus state by device state.
        /// </summary>
        public void Update(IGameEngineTime time, T device)
        {
            Updating = true;

            InternalUpdate(time, device);

            Updating = false;
        }
Esempio n. 9
0
        public override void Update(IGameEngineTime time, IKeyboardDevice device)
        {
            Pressed  = device.GetKeysPressed();
            Down     = device.GetKeysDown();
            Released = device.GetKeysReleased();
            Up       = device.GetKeysUp();

            base.Update(time, device);
        }
Esempio n. 10
0
        protected override void InternalDraw(IGraphicsFragment fragment, IGameEngineTime time)
        {
            var texture     = Style.Get <Texture2D>($"{UiStyleKeys.Target.Panel}\\{UiStyleKeys.Texture.Normal}");
            var color       = Style.Get <Color>($"{UiStyleKeys.Target.Panel}\\{(Enabled ? UiStyleKeys.Color.Enabled : UiStyleKeys.Color.Disabled)}");
            var center      = Style.Get <Rectangle>($"{UiStyleKeys.Target.Panel}\\{UiStyleKeys.Source.Center}");
            var destination = GetRenderDestinationRectangle();

            fragment.DrawSurface(texture, center, destination, color);

            base.InternalDraw(fragment, time);
        }
Esempio n. 11
0
        public override void Update(IGameEngineTime time, IMouseDevice device)
        {
            Pressed  = device.GetButtonsPressed();
            Down     = device.GetButtonsDown();
            Released = device.GetButtonsReleased();
            Up       = device.GetButtonsUp();

            base.Update(time, device);

            CurrentLocalPosition = UiCanvas.ToLocalUnits(device.GetPosition().ToVector2());
            LastLocalPosition    = UiCanvas.ToLocalUnits(device.GetPosition(1).ToVector2());

            CurrentScrollValue = device.GetScrollWheelValue();
            LastScrollValue    = device.GetScrollWheelValue(1);
        }
Esempio n. 12
0
        protected override void InternalUpdate(IGameEngineTime time, IMouseDevice device)
        {
            // If no click has happened we don't update focus.
            // Focus requires a click to be applied.
            if (!device.IsButtonPressed(MouseButton.Left))
            {
                return;
            }

            // Defocus keyboards focus if mouse is gaining the focus.
            Context.Keyboard?.Defocus();

            // Find next focused control.
            Focus(Root, new Rectf(UiCanvas.ToLocalUnits(device.GetPosition().ToVector2()), UiCanvas.ToLocalUnits(Vector2.One)));
        }
Esempio n. 13
0
        public void Poll(IGameEngineTime time)
        {
            keyboardStateBuffer.Push(Keyboard.GetState());

            if (keyboardCharacterFrameBuffer.Length != 0)
            {
                keyboardCharacterBuffer.Push(keyboardCharacterFrameBuffer.ToString());

                keyboardCharacterFrameBuffer.Clear();
            }
            else
            {
                keyboardCharacterBuffer.Push(string.Empty);
            }

            keyWatcher.Update(time, GetKeysUp(), GetKeysDown());
        }
Esempio n. 14
0
        public override void Execute(IGameEngineTime time)
        {
            var fragment = Pipeline.FragmentAtIndex(Index);

            foreach (var ui in uis)
            {
                ui.BeforeDraw(fragment, time);

                fragment.Begin(ui.View);

                ui.Draw(fragment, time);

                fragment.End();

                ui.AfterDraw(fragment, time);
            }
        }
Esempio n. 15
0
        protected override void InternalDraw(IGraphicsFragment fragment, IGameEngineTime time)
        {
            if (Image == null)
            {
                return;
            }

            var destination = GetRenderDestinationRectangle();
            var imageOffset = Style.Get <Vector2>($"{UiStyleKeys.Target.ImageBox}\\{UiStyleKeys.Offset.Normal}");

            var imageWidth  = (int)Math.Floor(destination.Width * imageOffset.X);
            var imageHeight = (int)Math.Floor(destination.Height * imageOffset.Y);

            var imageX = destination.X + imageWidth * (1.0f - imageOffset.X) * 0.5f;
            var imageY = destination.Y + imageHeight * (1.0f - imageOffset.Y) * 0.5f;

            switch (ImageMode)
            {
            case ImageMode.Fit:
            case ImageMode.Normal:
                fragment.DrawSprite(new Vector2(imageX, imageY),
                                    Vector2.One,
                                    0.0f,
                                    Vector2.Zero,
                                    new Vector2(destination.Width, destination.Height),
                                    Image,
                                    ImageColor);
                break;

            case ImageMode.Source:

                fragment.DrawSprite(new Vector2(imageX, imageY),
                                    Vector2.One,
                                    0.0f,
                                    Vector2.Zero,
                                    new Vector2(destination.Width, destination.Height),
                                    ImageSource == Rectangle.Empty ? Image.Bounds : ImageSource,
                                    Image,
                                    ImageColor);
                break;

            default:
                throw new InvalidOrUnsupportedException(nameof(ImageMode), ImageMode);
            }
        }
Esempio n. 16
0
        public void Update(IGameEngineTime time)
        {
            // Update focus.
            mouseFocusManager.Update(time, mouse);
            keyboardFocusManager.Update(time, keyboard);

            // Update root.
            var text = keyboard.GetCharacters();

            Root.ReceiveMouseInput(time, mouse);
            Root.ReceiveKeyboardInput(time, keyboard);

            if (!string.IsNullOrEmpty(text))
            {
                Root.ReceiveTextInput(time, text);
            }

            // Do control specific updates.
            Root.Update(time);
        }
Esempio n. 17
0
        protected override void InternalDraw(IGraphicsFragment fragment, IGameEngineTime time)
        {
            var texture     = Style.Get <Texture2D>($"{UiStyleKeys.Target.Checkbox}\\{(Checked? UiStyleKeys.Texture.Checked : UiStyleKeys.Texture.Unchecked)}");
            var color       = Style.Get <Color>($"{UiStyleKeys.Target.Checkbox}\\{(Enabled ? UiStyleKeys.Color.Enabled : UiStyleKeys.Color.Disabled)}");
            var destination = GetRenderDestinationRectangle();
            var position    = new Vector2(destination.X, destination.Y);

            if (Mouse.IsHovering(this) && (Mouse.IsDown(MouseButton.Left) || Mouse.IsPressed(MouseButton.Left)))
            {
                var offset = Style.Get <Vector2>($"{UiStyleKeys.Target.Button}\\{UiStyleKeys.Offset.Click}");

                position.X += (int)Math.Floor(offset.X);
                position.Y += (int)Math.Floor(offset.Y);
            }

            fragment.DrawSprite(position,
                                Vector2.One,
                                0.0f,
                                Vector2.Zero,
                                new Vector2(destination.Width, destination.Height),
                                texture,
                                color);
        }
Esempio n. 18
0
 public override void Update(IGameEngineTime time)
 => manager.Update(time);
Esempio n. 19
0
 public void BeforeDraw(IGraphicsFragment fragment, IGameEngineTime time)
 => Root.BeforeDraw(fragment, time);
Esempio n. 20
0
 protected abstract void InternalUpdate(IGameEngineTime time, T device);
Esempio n. 21
0
 public void AfterDraw(IGraphicsFragment fragment, IGameEngineTime time)
 => Root.AfterDraw(fragment, time);
Esempio n. 22
0
 public override void Update(IGameEngineTime time)
 => update?.Invoke(time);
Esempio n. 23
0
 public override void Update(IGameEngineTime time)
 => scheduler.Tick(time.Elapsed);
Esempio n. 24
0
 public abstract void Update(IGameEngineTime time);