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); }
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); }
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); } }
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()); }
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); } } }
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; } }
public override void Update(IGameEngineTime time) { foreach (var device in devices) { device.Poll(time); } }
/// <summary> /// Update focus state by device state. /// </summary> public void Update(IGameEngineTime time, T device) { Updating = true; InternalUpdate(time, device); Updating = false; }
public override void Update(IGameEngineTime time, IKeyboardDevice device) { Pressed = device.GetKeysPressed(); Down = device.GetKeysDown(); Released = device.GetKeysReleased(); Up = device.GetKeysUp(); base.Update(time, device); }
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); }
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); }
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))); }
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()); }
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); } }
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); } }
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); }
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); }
public override void Update(IGameEngineTime time) => manager.Update(time);
public void BeforeDraw(IGraphicsFragment fragment, IGameEngineTime time) => Root.BeforeDraw(fragment, time);
protected abstract void InternalUpdate(IGameEngineTime time, T device);
public void AfterDraw(IGraphicsFragment fragment, IGameEngineTime time) => Root.AfterDraw(fragment, time);
public override void Update(IGameEngineTime time) => update?.Invoke(time);
public override void Update(IGameEngineTime time) => scheduler.Tick(time.Elapsed);
public abstract void Update(IGameEngineTime time);