public void Clear(ElementBounds newBounds) { foreach (var val in interactiveElements) { val.Value.Dispose(); } foreach (var val in staticElements) { val.Value.Dispose(); } interactiveElements.Clear(); interactiveElementsInDrawOrder.Clear(); staticElements.Clear(); conditionalAdds.Clear(); parentBoundsForNextElement.Clear(); this.bounds = newBounds; // The ultimate parent - the screen if (bounds.ParentBounds == null) { bounds.ParentBounds = Api.Gui.WindowBounds; } parentBoundsForNextElement.Push(bounds); lastAddedElementBounds = null; Composed = false; }
/// <summary> /// Automatically adjusts the height of the element. /// </summary> public void Autoheight() { double totalHeight = 0; double pad = scaled(unscaledPadding); Bounds.CalcWorldBounds(); bool first = true; foreach (ConfigItem item in items) { double lineHeight = Math.Max( textUtil.GetMultilineTextHeight(Font, item.Key, Bounds.InnerWidth * leftWidthRel), textUtil.GetMultilineTextHeight(Font, item.Value, Bounds.InnerWidth * rightWidthRel) ); if (!first && item.Type == EnumItemType.Title) { lineHeight += scaled(20); } totalHeight += pad + lineHeight + pad; first = false; } innerBounds = Bounds.FlatCopy(); innerBounds.fixedHeight = totalHeight / RuntimeEnv.GUIScale; // Unscaled value! innerBounds.CalcWorldBounds(); }
public override void RenderInteractiveElements(float deltaTime, double renderX, double renderY) { LineRectangled bounds = BoundsPerLine[0]; ItemStack itemstack = Itemstacks[curItemIndex]; if ((secondsVisible -= deltaTime) <= 0) { secondsVisible = 1; curItemIndex = (curItemIndex + 1) % Itemstacks.Length; } slot.Itemstack = itemstack; ElementBounds scibounds = ElementBounds.FixedSize((int)(bounds.Width / RuntimeEnv.GUIScale), (int)(bounds.Height / RuntimeEnv.GUIScale)); scibounds.ParentBounds = capi.Gui.WindowBounds; scibounds.CalcWorldBounds(); scibounds.absFixedX = renderX + bounds.X; scibounds.absFixedY = renderY + bounds.Y; api.Render.PushScissor(scibounds); api.Render.RenderItemstackToGui(slot, renderX + bounds.X + bounds.Width * 0.5f, renderY + bounds.Y + bounds.Height * 0.5f, 100, (float)bounds.Width * 0.58f, ColorUtil.WhiteArgb, true, false, ShowStackSize); api.Render.PopScissor(); int relx = (int)(api.Input.MouseX - renderX); int rely = (int)(api.Input.MouseY - renderY); if (bounds.PointInside(relx, rely)) { RenderItemstackTooltip(slot, renderX + relx, renderY + rely, deltaTime); } }
/// <summary> /// Creates a new title bar. /// </summary> /// <param name="capi">The Client API.</param> /// <param name="text">The text on the title bar.</param> /// <param name="composer">The GuiComposer for the title bar.</param> /// <param name="OnClose">The event fired when the title bar is closed.</param> /// <param name="font">The font of the title bar.</param> /// <param name="bounds">The bounds of the title bar.</param> public GuiElementDialogTitleBar(ICoreClientAPI capi, string text, GuiComposer composer, Action OnClose = null, CairoFont font = null, ElementBounds bounds = null) : base(capi, text, font, bounds) { closeIconHoverTexture = new LoadedTexture(capi); menuIconHoverTexture = new LoadedTexture(capi); if (bounds == null) { this.Bounds = ElementStdBounds.TitleBar(); } if (font == null) { this.Font = CairoFont.WhiteSmallText(); } this.OnClose = OnClose; ElementBounds dropDownBounds = ElementBounds.Fixed(0, 0, 100, 25); this.Bounds.WithChild(dropDownBounds); listMenu = new GuiElementListMenu(capi, new string[] { "auto", "manual" }, new string[] { Lang.Get("Fixed"), Lang.Get("Movable") }, 0, onSelectionChanged, dropDownBounds, CairoFont.WhiteSmallText(), false) { HoveredIndex = 0 }; baseComposer = composer; }
/// <summary> /// Creates a new text area. /// </summary> /// <param name="capi">The client API</param> /// <param name="bounds">The bounds of the text area.</param> /// <param name="OnTextChanged">The event fired when the text is changed.</param> /// <param name="font">The font of the text.</param> public GuiElementTextArea(ICoreClientAPI capi, ElementBounds bounds, Action <string> OnTextChanged, CairoFont font) : base(capi, font, bounds) { highlightTexture = new LoadedTexture(capi); multilineMode = true; minHeight = bounds.fixedHeight; this.OnTextChanged = OnTextChanged; }
public override void RenderInteractiveElements(float deltaTime) { if ((float)(alarmValue - minValue) / (maxValue - minValue) > 0 && alarmValueTexture.TextureId > 0) { float alarmValueRel = (float)alarmValue / maxValue; api.Render.RenderTexture(alarmValueTexture.TextureId, Bounds.renderX + alarmTextureRect.X, Bounds.renderY + alarmTextureRect.Y, alarmTextureRect.Width, alarmTextureRect.Height); } double sliderWidth = Bounds.InnerWidth - 2 * padding - handleWidth / 2; // Translate current value into position double handlePosition = sliderWidth * (1.0 * currentValue - minValue) / (maxValue - minValue); double insetHeight = Bounds.InnerHeight - 2 * padding; double dy = (handleHeight - Bounds.OuterHeight + padding) / 2; api.Render.Render2DTexturePremultipliedAlpha(waterTexture.TextureId, Bounds.renderX + padding, Bounds.renderY + padding, (int)(handlePosition + 5), (int)insetHeight); api.Render.Render2DTexturePremultipliedAlpha(handleTexture.TextureId, Bounds.renderX + handlePosition, Bounds.renderY - dy, (int)handleWidth + 4, (int)handleHeight + 4); if (mouseDownOnSlider || mouseOnSlider) { ElementBounds elemBounds = textElem.Bounds; api.Render.Render2DTexturePremultipliedAlpha( hoverTextTexture.TextureId, (int)(Bounds.renderX + padding + handlePosition - elemBounds.OuterWidth / 2 + handleWidth / 2), (int)(Bounds.renderY - scaled(20) - elemBounds.OuterHeight), elemBounds.OuterWidthInt, elemBounds.OuterHeightInt, 300 ); } }
/// <summary> /// Creates an ItemStackInfo element. /// </summary> /// <param name="capi">The client API</param> /// <param name="bounds">The bounds of the object.</param> /// <param name="OnRequireInfoText">The function that is called when an item information is called.</param> public GuiElementItemstackInfo(ICoreClientAPI capi, ElementBounds bounds, InfoTextDelegate OnRequireInfoText) : base(capi, "", CairoFont.WhiteSmallText(), bounds) { this.OnRequireInfoText = OnRequireInfoText; texture = new LoadedTexture(capi); ElementBounds textBounds = bounds.CopyOnlySize(); ElementBounds descBounds = textBounds.CopyOffsetedSibling(ItemStackSize + 50, MarginTop, -ItemStackSize - 50, 0); descBounds.WithParent(bounds); textBounds.WithParent(bounds); descriptionElement = new GuiElementRichtext(capi, new RichTextComponentBase[0], descBounds); //new GuiElementStaticText(capi, "", EnumTextOrientation.Left, textBounds.CopyOffsetedSibling(ItemStackSize + 50, MarginTop, -ItemStackSize - 50, 0), Font); descriptionElement.zPos = 1001; titleFont = Font.Clone(); titleFont.FontWeight = FontWeight.Bold; titleElement = new GuiElementRichtext(capi, new RichTextComponentBase[0], textBounds); titleElement.zPos = 1001; maxWidth = bounds.fixedWidth; }
internal void ComposeHoverTextElement() { ElementBounds bounds = new ElementBounds().WithFixedPadding(7).WithParent(ElementBounds.Empty); string text = currentValue + unit; if (OnSliderTooltip != null) { text = OnSliderTooltip(currentValue); } textElem = new GuiElementStaticText(api, text, EnumTextOrientation.Center, bounds, CairoFont.WhiteMediumText().WithFontSize((float)GuiStyle.SubNormalFontSize)); textElem.Font.UnscaledFontsize = GuiStyle.SmallishFontSize; textElem.AutoBoxSize(); textElem.Bounds.CalcWorldBounds(); ImageSurface surface = new ImageSurface(Format.Argb32, (int)bounds.OuterWidth, (int)bounds.OuterHeight); Context ctx = genContext(surface); ctx.SetSourceRGBA(1, 1, 1, 0); ctx.Paint(); ctx.SetSourceRGBA(GuiStyle.DialogStrongBgColor); RoundRectangle(ctx, 0, 0, bounds.OuterWidth, bounds.OuterHeight, GuiStyle.ElementBGRadius); ctx.FillPreserve(); double[] color = GuiStyle.DialogStrongBgColor; ctx.SetSourceRGBA(color[0] / 2, color[1] / 2, color[2] / 2, color[3]); ctx.Stroke(); textElem.ComposeElements(ctx, surface); generateTexture(surface, ref hoverTextTexture); ctx.Dispose(); surface.Dispose(); }
public ItemstackComponentBase(ICoreClientAPI capi) : base(capi) { this.capi = capi; dummyInv = new DummyInventory(capi); dummyInv.OnAcquireTransitionSpeed = (transType, stack, mul) => { return(0); }; renderedTooltipSlot = new DummySlot(null, dummyInv); stackInfoBounds = ElementBounds .FixedSize(EnumDialogArea.None, GuiElementItemstackInfo.BoxWidth, 0) .WithFixedPadding(10) .WithFixedPosition(20, 40) ; parentBounds = ElementBounds.Fixed(0, 0, 1, 1); parentBounds.WithParent(ElementBounds.Empty); stackInfoBounds.WithParent(parentBounds); stackInfo = new GuiElementItemstackInfo(capi, stackInfoBounds, OnRequireInfoText); stackInfo.SetSourceSlot(renderedTooltipSlot); stackInfo.ComposeElements(null, null); stackInfo.RecompCheckIgnoredStackAttributes = GlobalConstants.IgnoredStackAttributes; }
/// <summary> /// Adds a chat input element to the UI. /// </summary> /// <param name="capi">The client API</param> /// <param name="bounds">The bounds of the chat input.</param> /// <param name="OnTextChanged">The event fired when the text is altered.</param> public GuiElementChatInput(ICoreClientAPI capi, ElementBounds bounds, API.Common.Action <string> OnTextChanged) : base(capi, null, bounds) { highlightTexture = new LoadedTexture(capi); this.OnTextChanged = OnTextChanged; this.caretColor = new float[] { 1, 1, 1, 1 }; this.Font = CairoFont.WhiteSmallText(); }
/// <summary> /// Creates a new GUI Element List Menu /// </summary> /// <param name="capi">The Client API.</param> /// <param name="values">The values of the list.</param> /// <param name="names">The names for each of the values.</param> /// <param name="selectedIndex">The default selected index.</param> /// <param name="onSelectionChanged">The event fired when the selection is changed.</param> /// <param name="bounds">The bounds of the GUI element.</param> public GuiElementListMenu(ICoreClientAPI capi, string[] values, string[] names, int selectedIndex, SelectionChangedDelegate onSelectionChanged, ElementBounds bounds, CairoFont font, bool multiSelect) : base(capi, "", font, bounds) { if (values.Length != names.Length) { throw new ArgumentException("Values and Names arrays must be of the same length!"); } hoverTexture = new LoadedTexture(capi); dropDownTexture = new LoadedTexture(capi); scrollbarTexture = new LoadedTexture(capi); this.Values = values; this.Names = names; this.SelectedIndex = selectedIndex; this.multiSelect = multiSelect; this.onSelectionChanged = onSelectionChanged; HoveredIndex = selectedIndex; ElementBounds scrollbarBounds = ElementBounds.Fixed(0, 0, 0, 0).WithEmptyParent(); scrollbar = new GuiElementCompactScrollbar(api, OnNewScrollbarValue, scrollbarBounds); richtTextElem = new GuiElementRichtext[values.Length]; for (int i = 0; i < values.Length; i++) { ElementBounds textBounds = ElementBounds.Fixed(0, 0, 700, 100).WithEmptyParent(); richtTextElem[i] = new GuiElementRichtext(capi, new RichTextComponentBase[0], textBounds); } }
/// <summary> /// Creates a new elements bounds which acts as the child bounds of the current bounds. It will also arrange the fixedX/Y and Width/Height coords of both bounds so that the parent bounds surrounds the child bounds with given spacings. Uses fixed coords only! /// </summary> /// <param name="leftSpacing"></param> /// <param name="topSpacing"></param> /// <param name="rightSpacing"></param> /// <param name="bottomSpacing"></param> /// <returns></returns> public ElementBounds ForkContainingChild(double leftSpacing = 0, double topSpacing = 0, double rightSpacing = 0, double bottomSpacing = 0) { ElementBounds bounds = new ElementBounds() { Alignment = Alignment, verticalSizing = verticalSizing, horizontalSizing = horizontalSizing, fixedOffsetX = fixedOffsetX, fixedOffsetY = fixedOffsetY, fixedWidth = fixedWidth - 2 * fixedPaddingX - leftSpacing - rightSpacing, fixedHeight = fixedHeight - 2 * fixedPaddingY - topSpacing - bottomSpacing, fixedX = fixedX, fixedY = fixedY, percentHeight = percentHeight, percentWidth = percentWidth }; bounds.fixedX = leftSpacing; bounds.fixedY = topSpacing; percentWidth = 1; percentHeight = 1; ChildBounds.Add(bounds); bounds.ParentBounds = this; return(bounds); }
/// <summary> /// Creates a new elements bounds which acts as the parent bounds of the current bounds. It will also arrange the fixedX/Y and Width/Height coords of both bounds so that the parent bounds surrounds the child bounds with given spacings. Uses fixed coords only! /// </summary> /// <param name="leftSpacing"></param> /// <param name="topSpacing"></param> /// <param name="rightSpacing"></param> /// <param name="bottomSpacing"></param> /// <returns></returns> public ElementBounds ForkBoundingParent(double leftSpacing = 0, double topSpacing = 0, double rightSpacing = 0, double bottomSpacing = 0) { ElementBounds bounds = new ElementBounds() { Alignment = Alignment, verticalSizing = verticalSizing, horizontalSizing = horizontalSizing, fixedOffsetX = fixedOffsetX, fixedOffsetY = fixedOffsetY, fixedWidth = fixedWidth + 2 * fixedPaddingX + leftSpacing + rightSpacing, fixedHeight = fixedHeight + 2 * fixedPaddingY + topSpacing + bottomSpacing, fixedX = fixedX, fixedY = fixedY, percentHeight = percentHeight, percentWidth = percentWidth }; fixedX = leftSpacing; fixedY = topSpacing; percentWidth = 1; percentHeight = 1; ParentBounds = bounds; return(bounds); }
public override void RenderInteractiveElements(float deltaTime, double renderX, double renderY) { LineRectangled bounds = BoundsPerLine[0]; ElementBounds scibounds = ElementBounds.FixedSize((int)(bounds.Width / API.Config.RuntimeEnv.GUIScale), (int)(bounds.Height / API.Config.RuntimeEnv.GUIScale)); scibounds.ParentBounds = capi.Gui.WindowBounds; scibounds.CalcWorldBounds(); scibounds.absFixedX = renderX + bounds.X; scibounds.absFixedY = renderY + bounds.Y + offY; api.Render.PushScissor(scibounds, true); api.Render.RenderItemstackToGui( slot, renderX + bounds.X + bounds.Width * 0.5f + offX, renderY + bounds.Y + bounds.Height * 0.5f + offY, GuiElement.scaled(100), (float)size * 0.58f, ColorUtil.WhiteArgb, true, false, false); api.Render.PopScissor(); int relx = (int)(api.Input.MouseX - renderX); int rely = (int)(api.Input.MouseY - renderY); if (bounds.PointInside(relx, rely)) { RenderItemstackTooltip(slot, renderX + relx + offX, renderY + rely + offY, deltaTime); } }
public override void RenderInteractiveElements(float deltaTime) { if ((float)(alarmValue - minValue) / (maxValue - minValue) > 0) { float alarmValueRel = (float)alarmValue / maxValue; api.Render.RenderTexture(alarmValueTextureId, Bounds.renderX + alarmTextureRect.X, Bounds.renderY + alarmTextureRect.Y, alarmTextureRect.Width, alarmTextureRect.Height); } double sliderWidth = Bounds.InnerWidth - 2 * padding - handleWidth / 2; // Translate current value into position double handlePosition = sliderWidth * (1.0 * currentValue - minValue) / (maxValue - minValue); double dy = (handleHeight - Bounds.InnerHeight) / 2; api.Render.RenderTexture(handleTextureId, Bounds.renderX + padding + handlePosition, Bounds.renderY - dy, (int)handleWidth + 5, (int)handleHeight + 5); if (mouseDownOnSlider || Bounds.PointInside(api.Input.MouseX, api.Input.MouseY)) { ElementBounds elemBounds = textElem.Bounds; api.Render.RenderTexture( hoverTextTextureId, Bounds.renderX + padding + handlePosition - elemBounds.OuterWidth / 2 + handleWidth / 2, Bounds.renderY - scaled(20) - elemBounds.OuterHeight, elemBounds.OuterWidth, elemBounds.OuterHeight); } }
/// <summary> /// Adds an inset to the current GUI. /// </summary> /// <param name="bounds">The bounds of the inset.</param> /// <param name="depth">The depth of the inset.</param> /// <param name="brightness">The brightness of the inset.</param> public static GuiComposer AddInset(this GuiComposer composer, ElementBounds bounds, int depth = 4, float brightness = 0.85f) { if (!composer.Composed) { composer.AddStaticElement(new GuiElementInset(composer.Api, bounds, depth, brightness)); } return(composer); }
/// <summary> /// Adds a dynamic custom draw component to the GUI. /// </summary> /// <param name="bounds">The bounds of the component.</param> /// <param name="OnDraw">The event fired when the element is drawn.</param> /// <param name="key">The name of the element.</param> public static GuiComposer AddDynamicCustomDraw(this GuiComposer composer, ElementBounds bounds, DrawDelegateWithBounds OnDraw, string key = null) { if (!composer.Composed) { composer.AddInteractiveElement(new GuiElementCustomDraw(composer.Api, bounds, OnDraw, true), key); } return(composer); }
public override void BeforeCalcBounds() { base.BeforeCalcBounds(); insideBounds = new ElementBounds().WithFixedPadding(unscaledCellSpacing).WithEmptyParent(); insideBounds.CalcWorldBounds(); CalcTotalHeight(); }
/// <summary> /// Called whenever the scrollbar or mouse wheel is used. /// </summary> /// <param name="value">The new value of the scrollbar.</param> protected void OnNewScrollbarvalue(float value) { ElementBounds bounds = SingleComposer.GetSlotGrid("slotgrid").Bounds; bounds.fixedY = 10 - GuiElementItemSlotGrid.unscaledSlotPadding - value; bounds.CalcWorldBounds(); }
public void Recompose(ICoreClientAPI capi) { Texture?.Dispose(); Texture = new TextTextureUtil(capi).GenTextTexture(Stack.GetName(), CairoFont.WhiteSmallText()); scissorBounds = ElementBounds.FixedSize(50, 50); scissorBounds.ParentBounds = capi.Gui.WindowBounds; }
// Single rectangle shape /// <summary> /// Adds a single rectangle background to the GUI. /// </summary> /// <param name="bounds">The bounds of the GUI</param> /// <param name="withTitleBar">Minor style adjustments to accomodate titlebars</param> /// <param name="topPadding">The amount of padding at the top of the gui.</param> public static GuiComposer AddShadedDialogBG(this GuiComposer composer, ElementBounds bounds, bool withTitleBar = true, double strokeWidth = 5) { if (!composer.Composed) { composer.AddStaticElement(new GuiElementDialogBackground(composer.Api, bounds, withTitleBar, strokeWidth)); } return(composer); }
/// <summary> /// Adds a background to the current GUI /// </summary> /// <param name="bounds">The bounds of the background</param> /// <param name="textureLoc">The name of the background texture.</param> /// <param name="brightness">The brightness of the texture (default: 1f)</param> public static GuiComposer AddImageBG(this GuiComposer composer, ElementBounds bounds, AssetLocation textureLoc, float brightness = 1f) { if (!composer.Composed) { composer.AddStaticElement(new GuiElementImageBackground(composer.Api, bounds, textureLoc, brightness)); } return(composer); }
public static GuiComposer AddImage(this GuiComposer composer, ElementBounds bounds, AssetLocation imageAsset) { if (!composer.Composed) { composer.AddStaticElement(new GuiElementImage(composer.Api, bounds, imageAsset)); } return(composer); }
/// <summary> /// Adds a stat bar with filling in the opposite direction. Default values are from 0 to 100. /// </summary> /// <param name="bounds">the bounds of the stat bar.</param> /// <param name="color">the color of the stat bar.</param> /// <param name="key">The internal name of the stat bar.</param> public static GuiComposer AddInvStatbar(this GuiComposer composer, ElementBounds bounds, double[] color, string key = null) { if (!composer.composed) { composer.AddInteractiveElement(new GuiElementStatbar(composer.Api, bounds, color, true), key); } return(composer); }
public override void ComposeElements(Context ctx, ImageSurface surface) { insideBounds = new ElementBounds().WithFixedPadding(unscaledCellSpacing).WithEmptyParent(); insideBounds.CalcWorldBounds(); Bounds.CalcWorldBounds(); ComposeList(); }
/// <summary> /// Quick Method to create a new ElementBounds instance that draws a background for a dialog /// </summary> public static ElementBounds MainScreenRightPart() { ElementBounds bounds = ElementBounds.Percentual(EnumDialogArea.RightMiddle, 1, 1); bounds.horizontalSizing = ElementSizing.PercentualSubstractFixed; bounds.fixedWidth = mainMenuUnscaledLogoSize + mainMenuUnscaledLogoHorPadding * 2 + mainMenuUnscaledWoodPlankWidth; return(bounds); }
/// <summary> /// Adds a gray background to the current GUI. /// </summary> /// <param name="bounds">The bounds of the backgrounds.</param> public static GuiComposer AddGrayBG(this GuiComposer composer, ElementBounds bounds) { if (!composer.composed) { composer.AddStaticElement(new GuiElementGrayBackground(composer.Api, bounds)); } return(composer); }
internal GuiComposer(ICoreClientAPI api, ElementBounds bounds, string dialogName) { staticElementsTexture = new LoadedTexture(api); this.dialogName = dialogName; this.bounds = bounds; this.Api = api; parentBoundsForNextElement.Push(bounds); }
/// <summary> /// Adds a static custom draw component to the GUI. /// </summary> /// <param name="bounds">The bounds of the component.</param> /// <param name="OnDraw">The event fired when the element is drawn.</param> public static GuiComposer AddCustomRender(this GuiComposer composer, ElementBounds bounds, RenderDelegateWithBounds onRender) { if (!composer.composed) { composer.AddInteractiveElement(new GuiElementCustomRender(composer.Api, bounds, onRender)); } return(composer); }
/// <summary> /// Adds a static custom draw component to the GUI. /// </summary> /// <param name="bounds">The bounds of the component.</param> /// <param name="OnDraw">The event fired when the element is drawn.</param> public static GuiComposer AddStaticCustomDraw(this GuiComposer composer, ElementBounds bounds, DrawDelegateWithBounds OnDraw) { if (!composer.Composed) { composer.AddStaticElement(new GuiElementCustomDraw(composer.Api, bounds, OnDraw)); } return(composer); }