public AtlasTexture(Texture texture, UIBox2 subRegion) : base((Vector2i)subRegion.Size) { DebugTools.Assert(SubRegion.Right < texture.Width); DebugTools.Assert(SubRegion.Bottom < texture.Height); DebugTools.Assert(SubRegion.Left >= 0); DebugTools.Assert(SubRegion.Top >= 0); SubRegion = subRegion; SourceTexture = texture; }
protected override void SortChildren() { foreach (var child in Children) { var childSize = child.CombinedMinimumSize; var childPos = (Size - childSize) / 2; FitChildInBox(child, UIBox2.FromDimensions(childPos, childSize)); } }
protected override Vector2 ArrangeOverride(Vector2 finalSize) { var contentBox = ActualStyleBox.GetContentBox(UIBox2.FromDimensions(Vector2.Zero, finalSize * UIScale)); foreach (var child in Children) { child.ArrangePixel((UIBox2i)contentBox); } return(finalSize); }
protected override Vector2 ArrangeOverride(Vector2 finalSize) { var box = GetMargin().Deflate(UIBox2.FromDimensions(Vector2.Zero, finalSize)); foreach (var child in Children) { child.Arrange(box); } return(finalSize); }
public void Draw(DrawingHandleScreen handle, UIBox2 box) { if (GameController.OnGodot) { GodotStyleBox.Draw(handle.Item, box.Convert()); } else { DoDraw(handle, box); } }
protected override void Open() { base.Open(); SendMessage(new PDARequestUpdateInterfaceMessage()); _menu = new PDAMenu(this, _prototypeManager); _menu.OpenToLeft(); _menu.OnClose += Close; _menu.FlashLightToggleButton.OnToggled += args => { SendMessage(new PDAToggleFlashlightMessage()); }; _menu.EjectIDButton.OnPressed += args => { SendMessage(new PDAEjectIDMessage()); }; _menu.EjectPenButton.OnPressed += args => { SendMessage(new PDAEjectPenMessage()); }; _menu.MasterTabContainer.OnTabChanged += i => { var tab = _menu.MasterTabContainer.GetChild(i); if (tab == _menu.UplinkTabContainer) { SendMessage(new PDARequestUpdateInterfaceMessage()); } }; _menu.OnListingButtonPressed += (args, listing) => { if (_menu.CurrentLoggedInAccount.DataBalance < listing.Price) { _failPopup = new PDAMenuPopup(Loc.GetString("Insufficient funds!")); _userInterfaceManager.ModalRoot.AddChild(_failPopup); _failPopup.Open(UIBox2.FromDimensions(_menu.Position.X + 150, _menu.Position.Y + 60, 156, 24)); _menu.OnClose += () => { _failPopup.Dispose(); }; } SendMessage(new PDAUplinkBuyListingMessage(listing.ItemId)); }; _menu.OnCategoryButtonPressed += (args, category) => { _menu.CurrentFilterCategory = category; SendMessage(new PDARequestUpdateInterfaceMessage()); }; }
protected override Vector2 ArrangeOverride(Vector2 finalSize) { foreach (var child in Children) { var size = child.DesiredSize; var offset = child.GetValue <Vector2>(PopupOriginProperty); var altPos = child.GetValue <Vector2?>(AltOriginProperty); var(r, b) = size + offset; // bottom right corner. var isAltPos = false; // Clamp the right edge. if (r > Width) { // Try to position at alt pos. if (altPos != null && altPos.Value.X - size.X > 0) { // There is horizontal room at the alt pos so there we go. isAltPos = true; offset = (altPos.Value.X - size.X, altPos.Value.Y); (_, b) = size + offset; } else { offset -= (r - Width, 0); } } // Clamp the bottom edge. if (b > Height) { offset -= (0, b - Height); } // Try to clamp the left edge. if (offset.X < 0 && !isAltPos) { offset -= (offset.X, 0); } // Try to clamp the top edge. if (offset.Y < 0) { offset -= (0, offset.Y); } child.Arrange(UIBox2.FromDimensions(offset, size)); } return(finalSize); }
protected override void Draw(DrawingHandleBase handle) { var screenHandle = (DrawingHandleScreen)handle; var mousePos = IoCManager.Resolve <IInputManager>().MouseScreenPosition; if (_system.UseOrAttackIsDown && _system._timeHeld > AttackTimeThreshold) { var tex = ResC.GetTexture($"/Textures/Objects/Tools/toolbox_r.png"); screenHandle.DrawTextureRect(tex, UIBox2.FromDimensions(mousePos, tex.Size * 2)); } }
public void DrawTextureRect(Texture texture, UIBox2 rect, bool tile, Color?modulate = null, bool transpose = false, Texture normalMap = null) { CheckDisposed(); if (_renderHandle != null) { _renderHandle.DrawTextureRect(texture, rect.TopLeft, rect.BottomRight, modulate, _handleId); } else if (Item != null) { texture.GodotTexture.DrawRect(Item, rect.Convert(), tile, modulate?.Convert(), transpose, normalMap); } }
protected override Vector2 ArrangeOverride(Vector2 finalSize) { var pixelSize = finalSize * UIScale; var ourSize = UIBox2.FromDimensions(Vector2.Zero, pixelSize); var contentBox = _getStyleBox()?.GetContentBox(ourSize) ?? ourSize; foreach (var child in Children) { child.ArrangePixel((UIBox2i)contentBox); } return(finalSize); }
public void DrawTextureRectRegion(Texture texture, UIBox2 rect, UIBox2 subRegion, Color?modulate = null) { CheckDisposed(); var actualModulate = (modulate ?? Color.White) * Modulate; if (_renderHandle != null) { _renderHandle.DrawTextureRect(texture, rect.TopLeft, rect.BottomRight, actualModulate, subRegion, _handleId); } else if (Item != null) { texture.GodotTexture.DrawRect(Item, rect.Convert(), false, actualModulate.Convert()); } }
public UIBox2 GetContentBox(UIBox2 baseBox) { var left = baseBox.Left + GetContentMargin(Margin.Left); var top = baseBox.Top + GetContentMargin(Margin.Top); var right = baseBox.Right - GetContentMargin(Margin.Right); var bottom = baseBox.Bottom - GetContentMargin(Margin.Bottom); if (left > right || top > bottom) { throw new ArgumentException("Box is too small!", nameof(baseBox)); } return(new UIBox2(left, top, right, bottom)); }
protected override void LayoutUpdateOverride() { var top = MarginTopOverride ?? 0; var bottom = MarginBottomOverride ?? 0; var left = MarginLeftOverride ?? 0; var right = MarginRightOverride ?? 0; var box = UIBox2.FromDimensions(left, top, Width - right - left, Height - bottom - top); foreach (var child in Children) { FitChildInBox(child, box); } }
public void DrawRect(UIBox2 rect, Color color, bool filled = true) { CheckDisposed(); if (filled) { VS.CanvasItemAddRect(Item, rect.Convert(), color.Convert()); } else { DrawLine(rect.TopLeft, rect.TopRight, color); DrawLine(rect.TopRight, rect.BottomRight, color); DrawLine(rect.BottomRight, rect.BottomLeft, color); DrawLine(rect.BottomLeft, rect.TopLeft, color); } }
protected override Vector2 ArrangeOverride(Vector2 finalSize) { var max = Vector2.Zero; foreach (var child in Children) { var childSize = child.DesiredSize; var childPos = (finalSize - childSize) / 2; child.Arrange(UIBox2.FromDimensions(childPos, childSize)); max = Vector2.ComponentMax(max, childSize); } return(max); }
protected override void Draw(DrawingHandleScreen handle) { if (!TryGetHands(out IHandsComponent hands)) { return; } var leftActive = hands.ActiveIndex == "left"; var handL = new UIBox2(_handL.TopLeft * UIScale, _handL.BottomRight * UIScale); var handR = new UIBox2(_handR.TopLeft * UIScale, _handR.BottomRight * UIScale); handle.DrawStyleBox(handBox, leftActive ? handL : handR); handle.DrawStyleBox(inactiveHandBox, leftActive ? handR : handL); }
public void Test() { var container = new CenterContainer(); var child = new Control { MinSize = (50, 50) }; container.AddChild(child); container.Arrange(UIBox2.FromDimensions(0, 0, 100, 100)); Assert.That(container.DesiredSize, Is.EqualTo(new Vector2(50, 50))); Assert.That(child.Position, Is.EqualTo(new Vector2(25, 25))); Assert.That(child.Size, Is.EqualTo(new Vector2(50, 50))); }
protected internal override void Draw(DrawingHandleScreen handle) { var offset = 0; var icon = _getIcon(); if (icon != null) { offset += _getIcon().Width + _getHSeparation(); var vOffset = (PixelHeight - _getIcon().Height) / 2; handle.DrawTextureRect(icon, UIBox2.FromDimensions((0, vOffset), icon.Size * UIScale), false); } var box = new UIBox2(offset, 0, PixelWidth, PixelHeight); DrawTextInternal(handle, box); }
private void OpenPopupFor(MenuBarTopButton button) { _popupVBox.RemoveAllChildren(); var menu = button.Menu; ConstructMenu(menu, _popupVBox); var globalPos = button.GlobalPosition; globalPos += new Vector2(0, button.Height); _popup.Open(UIBox2.FromDimensions(globalPos, _popupVBox.Size)); // Set this after running open so that if this is called from MouseEntered, // It won't get set to false by Open() closing the popup to move it. _popupOpen = true; }
public void DrawStyleBox(StyleBox styleBox, UIBox2 box) { if (styleBox == null) { throw new ArgumentNullException(nameof(styleBox)); } CheckDisposed(); if (GameController.OnGodot) { styleBox.GodotStyleBox.Draw(Item, box.Convert()); } else { styleBox.Draw(this, box); } }
public void Draw( DrawingHandleScreen handle, IFontLibrary font, UIBox2 drawBox, float verticalOffset, float uiScale, Color defColor) { var flib = font.StartFont(); foreach (var wd in _ld) { var s = Message.Sections[wd.section]; var baseLine = drawBox.TopLeft + new Vector2((float)wd.x, verticalOffset + (float)wd.y); foreach (var rune in s .Content[wd.charOffs..(wd.charOffs + wd.length)]
public static void Read(Stream stream, out UIBox2 value) { var buffer = new byte[sizeof(float)]; stream.Read(buffer, 0, buffer.Length); var left = BitConverter.ToSingle(buffer, 0); stream.Read(buffer, 0, buffer.Length); var right = BitConverter.ToSingle(buffer, 0); stream.Read(buffer, 0, buffer.Length); var top = BitConverter.ToSingle(buffer, 0); stream.Read(buffer, 0, buffer.Length); var bottom = BitConverter.ToSingle(buffer, 0); value = new UIBox2(left, top, right, bottom); }
private static UIBox2 CalcChildRect(Vector2 ourSize, float uiScale, Control child, out UIBox2 anchorSize) { // Calculate where the control "wants" to be by its anchors/margins. var growHorizontal = child.GetValue <GrowDirection>(GrowHorizontalProperty); var growVertical = child.GetValue <GrowDirection>(GrowVerticalProperty); anchorSize = CalcAnchorMargins(ourSize, uiScale, child); // This intentionally results in negatives if the right bound is < the left bound. // Which then causes HandleLayoutOverflow to CORRECTLY work from the right bound instead. var(wSizeX, wSizeY) = (anchorSize.Right - anchorSize.Left, anchorSize.Bottom - anchorSize.Top); var(minSizeX, minSizeY) = child.DesiredPixelSize; HandleLayoutOverflow(growHorizontal, minSizeX, anchorSize.Left, wSizeX, out var posX, out var sizeX); HandleLayoutOverflow(growVertical, minSizeY, anchorSize.Top, wSizeY, out var posY, out var sizeY); return(UIBox2.FromDimensions(posX / uiScale, posY / uiScale, sizeX / uiScale, sizeY / uiScale)); }
public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates) { if (_currentVerbListRoot != null) { CloseVerbMenu(); } _currentEntity = entity.Uid; _currentVerbListRoot = new VerbPopup(); _userInterfaceManager.ModalRoot.AddChild(_currentVerbListRoot); _currentVerbListRoot.OnPopupHide += CloseVerbMenu; _currentVerbListRoot.List.AddChild(new Label {Text = "Waiting on Server..."}); RaiseNetworkEvent(new VerbSystemMessages.RequestVerbsMessage(_currentEntity)); var box = UIBox2.FromDimensions(screenCoordinates.Position, (1, 1)); _currentVerbListRoot.Open(box); }
protected internal override void Draw(DrawingHandleScreen handle) { base.Draw(handle); if (!VisibleInTree) { return; } var(x, y) = GlobalPixelPosition; var renderBox = new UIBox2( _uiBox.Left - x, _uiBox.Top - y, _uiBox.Right - x, _uiBox.Bottom - y); handle.DrawRect(renderBox, Color.Red, false); }
public AtlasTexture(Texture texture, UIBox2 subRegion) { DebugTools.Assert(SubRegion.Right < texture.Width); DebugTools.Assert(SubRegion.Bottom < texture.Height); DebugTools.Assert(SubRegion.Left >= 0); DebugTools.Assert(SubRegion.Top >= 0); if (GameController.OnGodot) { GodotTexture = new Godot.AtlasTexture { Atlas = texture, Region = subRegion.Convert() }; } SubRegion = subRegion; SourceTexture = texture; }
protected void FitChildInBox(Control child, UIBox2 box) { DebugTools.Assert(child.Parent == this); var(minX, minY) = child.CombinedMinimumSize; var newPosX = box.Left; var newSizeX = minX; if (child.SizeFlagsHorizontal == SizeFlags.ShrinkEnd) { newPosX += (box.Width - minX); } else if (child.SizeFlagsHorizontal == SizeFlags.ShrinkCenter) { newPosX += (box.Width - minX) / 2; } else if ((child.SizeFlagsHorizontal & SizeFlags.Fill) != 0) { newSizeX = box.Width; } var newPosY = box.Top; var newSizeY = minY; if (child.SizeFlagsVertical == SizeFlags.ShrinkEnd) { newPosY += (box.Height - minY); } else if (child.SizeFlagsVertical == SizeFlags.ShrinkCenter) { newPosY += (box.Height - minY) / 2; } else if ((child.SizeFlagsVertical & SizeFlags.Fill) != 0) { newSizeY = box.Height; } child.SetAnchorPreset(LayoutPreset.TopLeft, true); child.Position = new Vector2(newPosX, newPosY); child.Size = new Vector2(newSizeX, newSizeY); }
protected internal override void Draw(DrawingHandleScreen handle) { if (GameController.OnGodot) { return; } var offset = 0; var icon = _getIcon(); if (icon != null) { offset += _getIcon().Width + _getHSeparation(); handle.DrawTexture(icon, Vector2.Zero); } var box = new UIBox2(offset, 0, Width, Height); DrawTextInternal(handle, box); }
private void _genTextureAtlas() { var defList = TileDefs.Where(t => !string.IsNullOrEmpty(t.SpriteName)).ToList(); const int tileSize = EyeManager.PIXELSPERMETER; var dimensionX = (int)Math.Ceiling(Math.Sqrt(defList.Count)); var dimensionY = (int)Math.Ceiling((float)defList.Count / dimensionX); var sheet = new Image <Rgba32>(dimensionX * tileSize, dimensionY * tileSize); for (var i = 0; i < defList.Count; i++) { var def = defList[i]; var column = i % dimensionX; var row = i / dimensionX; Image <Rgba32> image; using (var stream = _resourceCache.ContentFileRead($"/Textures/Tiles/{def.SpriteName}.png")) { image = Image.Load(stream); } if (image.Width != tileSize || image.Height != tileSize) { throw new NotImplementedException("Unable to use tiles with a dimension other than 32x32."); } var point = new Point(column * tileSize, row * tileSize); sheet.Mutate(x => x.DrawImage(image, point, PixelColorBlendingMode.Overlay, 1)); _tileRegions.Add(def.TileId, UIBox2.FromDimensions( point.X / (float)sheet.Width, point.Y / (float)sheet.Height, tileSize / (float)sheet.Width, tileSize / (float)sheet.Height)); } TileTextureAtlas = Texture.LoadFromImage(sheet, "Tile Atlas"); }
private void DrawJpsRoutes(DrawingHandleScreen screenHandle, Box2 viewport) { foreach (var route in JpsRoutes) { // Draw box on each tile of route foreach (var position in route.Route) { if (!viewport.Contains(position)) { continue; } var screenTile = _eyeManager.WorldToScreen(position); // worldHandle.DrawLine(position, nextWorld.Value, Color.Blue); var box = new UIBox2( screenTile.X - 15.0f, screenTile.Y - 15.0f, screenTile.X + 15.0f, screenTile.Y + 15.0f); screenHandle.DrawRect(box, Color.Orange.WithAlpha(0.25f)); } } }