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); }
/// <summary> /// Sets up the renderer, canvas, stage and puts in a table filling the whole screen. /// </summary> private void SetUp() { renderer = new ScreenSpaceRenderer(0, UIRenderLayer); Entity.Scene.AddRenderer(renderer); Canvas = new UiCanvas(); Canvas.SetRenderLayer(UIRenderLayer); Entity.AddComponent(Canvas); Table = new Table(); Canvas.Stage.AddElement(Table); Table.SetFillParent(true); }
void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } }
public Vector2 Transform(IControl parent) { if (parent is IStaticContainerControl container && container.UseRenderTarget) { // If the container is using render targets, we must apply view offset // to the mouse states position as transformation. This transformation // must be inverse relative to the parent as the parent control does // normal transformation. return(UiCanvas.ToLocalUnits(CurrentLocalPosition.X - container.ViewOffset.X, CurrentLocalPosition.Y - container.ViewOffset.Y)); } return(CurrentLocalPosition); }
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 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); }
private Vector2 GetCollapsedSize() { var size = Size; size.X = ActualSize.X; var itemSource = Style.Get <Rectangle>($"{UiStyleKeys.Target.ListBox}\\{UiStyleKeys.Source.Text}"); var tuples = GetItemTuples(); var itemAreaTop = tuples.First().Rectangle.Bottom; var itemAreaBottom = tuples.Last().Rectangle.Bottom; var itemArea = itemAreaBottom - itemAreaTop - itemSource.Y; size += UiCanvas.ToLocalUnits(itemArea * Vector2.UnitY); return(size); }
public bool IsHovering(Rectf area) => Rectf.Intersects(area, new Rectf(CurrentLocalPosition, UiCanvas.ToLocalUnits(Vector2.One)));
public bool IsHovering(Rectangle area) => area.Intersects(new Rectangle( (int)Math.Floor(UiCanvas.ToHorizontalScreenUnits(CurrentLocalPosition.X)), (int)Math.Floor(UiCanvas.ToVerticalScreenUnits(CurrentLocalPosition.Y)), 1, 1));
private void OnSceneChange(Scene prevScene, Scene nextScene) { foregroundCanvas = null; backgroundCanvas = null; }