public int GetQuantityTextLines(CairoFont font, string text, double boxWidth) => GetQuantityTextLines(font, text, new TextFlowPath[] { new TextFlowPath(boxWidth) });
/// <summary> /// Adds a text input to the GUI /// </summary> /// <param name="capi">The Client API</param> /// <param name="bounds">The bounds of the text input.</param> /// <param name="OnTextChanged">The event fired when the text is changed.</param> /// <param name="font">The font of the text.</param> public GuiElementTextInput(ICoreClientAPI capi, ElementBounds bounds, Action <string> OnTextChanged, CairoFont font) : base(capi, font, bounds) { MouseOverCursor = "textselect"; this.OnTextChanged = OnTextChanged; highlightTexture = new LoadedTexture(capi); }
/// <summary> /// Creates a collection of horizontal tabs. /// </summary> /// <param name="capi">The client API</param> /// <param name="tabs">A collection of GUI tabs.</param> /// <param name="font">The font for the name of each tab.</param> /// <param name="bounds">The bounds of each tab.</param> /// <param name="onTabClicked">The event fired whenever the tab is clicked.</param> public GuiElementHorizontalTabs(ICoreClientAPI capi, GuiTab[] tabs, CairoFont font, CairoFont selectedFont, ElementBounds bounds, API.Common.Action <int> onTabClicked) : base(capi, "", font, bounds) { this.selectedFont = selectedFont; this.tabs = tabs; handler = onTabClicked; hoverTextures = new LoadedTexture[tabs.Length]; for (int i = 0; i < tabs.Length; i++) { hoverTextures[i] = new LoadedTexture(capi); } tabWidths = new int[tabs.Length]; baseTexture = new LoadedTexture(capi); }
// Single rectangle shape /// <summary> /// Adds a dialog title bar to the GUI. /// </summary> /// <param name="text">The text of 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 static GuiComposer AddDialogTitleBar(this GuiComposer composer, string text, Action OnClose = null, CairoFont font = null, ElementBounds bounds = null) { if (!composer.composed) { composer.AddInteractiveElement(new GuiElementDialogTitleBar(composer.Api, text, composer, OnClose, font, bounds)); } return(composer); }
/// <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 numerical input field. /// </summary> /// <param name="capi">The Client API</param> /// <param name="bounds">The bounds of the GUI.</param> /// <param name="OnTextChanged">The event fired when the number is changed.</param> /// <param name="font">The font of the numbers.</param> public GuiElementNumberInput(ICoreClientAPI capi, ElementBounds bounds, Action <string> OnTextChanged, CairoFont font) : base(capi, bounds, OnTextChanged, font) { buttonHighlightTexture = new LoadedTexture(capi); }
/// <summary> /// Adds a static text component to the GUI /// </summary> /// <param name="text">The text of the text component.</param> /// <param name="font">The font of the text.</param> /// <param name="orientation">The orientation of the text.</param> /// <param name="bounds">The bounds of the text container.</param> /// <param name="key">The name of the component.</param> public static GuiComposer AddStaticText(this GuiComposer composer, string text, CairoFont font, EnumTextOrientation orientation, ElementBounds bounds, string key = null) { if (!composer.Composed) { composer.AddStaticElement(new GuiElementStaticText(composer.Api, text, orientation, bounds, font), key); } return(composer); }
/// <summary> /// Adds an embossed text component to the GUI. /// </summary> /// <param name="text">The text of the component.</param> /// <param name="font">The font of the text.</param> /// <param name="bounds">The bounds of the component.</param> /// <param name="key">The name of the component.</param> public static GuiComposer AddEmbossedText(this GuiComposer composer, string text, CairoFont font, ElementBounds bounds, string key = null) { if (!composer.composed) { composer.AddInteractiveElement(new GuiElementEmbossedText(composer.Api, text, font, bounds), key); } return(composer); }
/// <summary> /// Creates a new embossed text element. /// </summary> /// <param name="capi">The Client API</param> /// <param name="text">The text of the component.</param> /// <param name="font">The font of the text.</param> /// <param name="bounds">The bounds of the component.</param> public GuiElementEmbossedText(ICoreClientAPI capi, string text, CairoFont font, ElementBounds bounds) : base(capi, text, font, bounds) { texture = new LoadedTexture(capi); enabled = true; }
/// <summary> /// Creates a button with text. /// </summary> /// <param name="capi">The Client API</param> /// <param name="text">The text of the button.</param> /// <param name="font">The font of the text.</param> /// <param name="hoverFont">The font of the text when the player is hovering over the button.</param> /// <param name="onClick">The event fired when the button is clicked.</param> /// <param name="bounds">The bounds of the button.</param> /// <param name="style">The style of the button.</param> public GuiElementTextButton(ICoreClientAPI capi, string text, CairoFont font, CairoFont hoverFont, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal) : base(capi, bounds) { hoverTexture = new LoadedTexture(capi); normalTexture = new LoadedTexture(capi); disabledTexture = new LoadedTexture(capi); this.buttonStyle = style; normalText = new GuiElementStaticText(capi, text, EnumTextOrientation.Center, bounds.CopyOnlySize(), font); normalText.AutoBoxSize(true); pressedText = new GuiElementStaticText(capi, text, EnumTextOrientation.Center, bounds.CopyOnlySize(), hoverFont); this.onClick = onClick; }
/// <summary> /// Creates a new stat bar for the GUI. /// </summary> /// <param name="capi">The client API</param> /// <param name="bounds">The bounds of the stat bar.</param> /// <param name="color">The color of the stat bar.</param> /// <param name="rightToLeft">Determines the direction that the bar fills.</param> public GuiElementStatbar(ICoreClientAPI capi, ElementBounds bounds, double[] color, bool rightToLeft) : base(capi, "", CairoFont.WhiteDetailText(), bounds) { barTexture = new LoadedTexture(capi); flashTexture = new LoadedTexture(capi); valueTexture = new LoadedTexture(capi); this.color = color; this.rightToLeft = rightToLeft; //value = new Random(Guid.NewGuid().GetHashCode()).Next(100); onGetStatbarValue = () => { return((int)value + " / " + (int)this.maxValue); }; }
/// <summary> /// Creates a button for the current GUI. /// </summary> /// <param name="text">The text on the button.</param> /// <param name="onClick">The event fired when the button is clicked.</param> /// <param name="bounds">The bounds of the button.</param> /// <param name="style">The style of the button. (Default: Normal)</param> /// <param name="orientation">The orientation of the text. (Default: center)</param> /// <param name="key">The internal name of the button.</param> public static GuiComposer AddButton(this GuiComposer composer, string text, ActionConsumable onClick, ElementBounds bounds, EnumButtonStyle style = EnumButtonStyle.Normal, EnumTextOrientation orientation = EnumTextOrientation.Center, string key = null) { if (!composer.Composed) { GuiElementTextButton elem = new GuiElementTextButton(composer.Api, text, CairoFont.ButtonText(), CairoFont.ButtonPressedText(), onClick, bounds, style); elem.SetOrientation(orientation); composer.AddInteractiveElement(elem, key); } return(composer); }
/// <summary> /// Creates a button for the current GUI. /// </summary> /// <param name="text">The text on the button.</param> /// <param name="onClick">The event fired when the button is clicked.</param> /// <param name="bounds">The bounds of the button.</param> /// <param name="buttonFont">The font of the button.</param> /// <param name="style">The style of the button. (Default: Normal)</param> /// <param name="orientation">The orientation of the text. (Default: center)</param> /// <param name="key">The internal name of the button.</param> public static GuiComposer AddButton(this GuiComposer composer, string text, ActionConsumable onClick, ElementBounds bounds, CairoFont buttonFont, EnumButtonStyle style = EnumButtonStyle.Normal, EnumTextOrientation orientation = EnumTextOrientation.Center, string key = null) { if (!composer.Composed) { CairoFont hoverFont = buttonFont.Clone().WithColor(GuiStyle.ActiveButtonTextColor); GuiElementTextButton elem = new GuiElementTextButton(composer.Api, text, buttonFont, hoverFont, onClick, bounds, style); elem.SetOrientation(orientation); composer.AddInteractiveElement(elem, key); } return(composer); }
public double GetMultilineTextHeight(CairoFont font, string text, double boxWidth) => GetQuantityTextLines(font, text, boxWidth) * GetLineHeight(font);
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(); }
private void ComposeElement(GuiComposer composer, JsonDialogSettings settings, DialogElement elem, int elemKey, double x, double y) { double factor = settings.SizeMultiplier; double labelWidth = 0; if (elem.Label != null) { CairoFont font = CairoFont.WhiteSmallText(); font.UnscaledFontsize *= factor; TextExtents extents = font.GetTextExtents(elem.Label); labelWidth = extents.Width / factor / RuntimeEnv.GUIScale + 1; FontExtents fext = font.GetFontExtents(); ElementBounds labelBounds = ElementBounds.Fixed(x, y + Math.Max(0, (elem.Height * factor - fext.Height / RuntimeEnv.GUIScale) / 2), labelWidth, elem.Height).WithScale(factor); composer.AddStaticText(elem.Label, font, labelBounds); labelWidth += 8; if (elem.Tooltip != null) { CairoFont tfont = CairoFont.WhiteSmallText(); tfont.UnscaledFontsize *= factor; composer.AddHoverText(elem.Tooltip, tfont, 350, labelBounds.FlatCopy(), "tooltip-" + elem.Code); composer.GetHoverText("tooltip-" + elem.Code).SetAutoWidth(true); } } ElementBounds bounds = ElementBounds.Fixed(x + labelWidth, y, elem.Width - labelWidth, elem.Height).WithScale(factor); string currentValue = settings.OnGet?.Invoke(elem.Code); switch (elem.Type) { case EnumDialogElementType.Slider: { string key = "slider-" + elemKey; composer.AddSlider((newval) => { settings.OnSet?.Invoke(elem.Code, newval + ""); return(true); }, bounds, key); int curVal = 0; int.TryParse(currentValue, out curVal); composer.GetSlider(key).SetValues(curVal, elem.MinValue, elem.MaxValue, elem.Step); composer.GetSlider(key).Scale = factor; //composer.GetSlider(key).TriggerOnlyOnMouseUp(true); break; } case EnumDialogElementType.Switch: { string key = "switch-" + elemKey; composer.AddSwitch((newval) => { settings.OnSet?.Invoke(elem.Code, newval ? "1" : "0"); }, bounds, key, 30 * factor, 5 * factor); composer.GetSwitch(key).SetValue(currentValue == "1"); } break; case EnumDialogElementType.Input: { string key = "input-" + elemKey; CairoFont font = CairoFont.WhiteSmallText(); font.UnscaledFontsize *= factor; composer.AddTextInput(bounds, (newval) => { settings.OnSet?.Invoke(elem.Code, newval); }, font, key); composer.GetTextInput(key).SetValue(currentValue); break; } case EnumDialogElementType.NumberInput: { string key = "numberinput-" + elemKey; CairoFont font = CairoFont.WhiteSmallText(); font.UnscaledFontsize *= factor; composer.AddNumberInput(bounds, (newval) => { settings.OnSet?.Invoke(elem.Code, newval); }, font, key); composer.GetNumberInput(key).SetValue(currentValue); break; } case EnumDialogElementType.Button: if (elem.Icon != null) { composer.AddIconButton(elem.Icon, (val) => { settings.OnSet?.Invoke(elem.Code, null); }, bounds); } else { CairoFont font = CairoFont.ButtonText(); font.WithFontSize(elem.FontSize); composer.AddButton(elem.Text, () => { settings.OnSet?.Invoke(elem.Code, null); return(true); }, bounds.WithFixedPadding(8, 0), font); } if (elem.Tooltip != null && elem.Label == null) { CairoFont tfont = CairoFont.WhiteSmallText(); tfont.UnscaledFontsize *= factor; composer.AddHoverText(elem.Tooltip, tfont, 350, bounds.FlatCopy(), "tooltip-" + elem.Code); composer.GetHoverText("tooltip-" + elem.Code).SetAutoWidth(true); } break; case EnumDialogElementType.Text: composer.AddStaticText(elem.Text, CairoFont.WhiteMediumText().WithFontSize(elem.FontSize), bounds); break; case EnumDialogElementType.Select: case EnumDialogElementType.DynamicSelect: { string[] values = elem.Values; string[] names = elem.Names; if (elem.Type == EnumDialogElementType.DynamicSelect) { string[] compos = currentValue.Split(new string[] { "\n" }, StringSplitOptions.None); values = compos[0].Split(new string[] { "||" }, StringSplitOptions.None); names = compos[1].Split(new string[] { "||" }, StringSplitOptions.None); currentValue = compos[2]; } int selectedIndex = Array.FindIndex(values, w => w.Equals(currentValue)); if (elem.Mode == EnumDialogElementMode.DropDown) { string key = "dropdown-" + elemKey; composer.AddDropDown(values, names, selectedIndex, (newval, on) => { settings.OnSet?.Invoke(elem.Code, newval); }, bounds, key); composer.GetDropDown(key).Scale = factor; composer.GetDropDown(key).Font.UnscaledFontsize *= factor; } else { if (elem.Icons != null && elem.Icons.Length > 0) { ElementBounds[] manybounds = new ElementBounds[elem.Icons.Length]; double elemHeight = (elem.Height - 4 * elem.Icons.Length) / elem.Icons.Length; for (int i = 0; i < manybounds.Length; i++) { manybounds[i] = bounds.FlatCopy().WithFixedHeight(elemHeight - 4).WithFixedOffset(0, i * (4 + elemHeight)).WithScale(factor); } string key = "togglebuttons-" + elemKey; CairoFont font = CairoFont.WhiteSmallText(); font.UnscaledFontsize *= factor; composer.AddIconToggleButtons(elem.Icons, font, (newval) => { settings.OnSet?.Invoke(elem.Code, elem.Values[newval]); }, manybounds, key); if (currentValue != null && currentValue.Length > 0) { composer.ToggleButtonsSetValue(key, selectedIndex); } if (elem.Tooltips != null) { for (int i = 0; i < elem.Tooltips.Length; i++) { CairoFont tfont = CairoFont.WhiteSmallText(); tfont.UnscaledFontsize *= factor; composer.AddHoverText(elem.Tooltips[i], tfont, 350, manybounds[i].FlatCopy()); } } } } } break; } elementNumber++; }
public IconComponent(ICoreClientAPI capi, string iconName, CairoFont font) : base(capi) { this.capi = capi; this.iconName = iconName; this.font = font; }
/// <summary> /// Reloads the values in the GUI. /// </summary> public void ReloadValues() { GuiComposer composer = Composers["cmdDlg" + settings.Code]; int elemKey = 1; for (int i = 0; i < settings.Rows.Length; i++) { DialogRow row = settings.Rows[i]; for (int j = 0; j < row.Elements.Length; j++) { DialogElement elem = row.Elements[j]; string currentValue = settings.OnGet?.Invoke(elem.Code); switch (elem.Type) { case EnumDialogElementType.Slider: { string key = "slider-" + elemKey; int curVal = 0; int.TryParse(currentValue, out curVal); composer.GetSlider(key).SetValues(curVal, elem.MinValue, elem.MaxValue, elem.Step); break; } case EnumDialogElementType.Switch: { string key = "switch-" + elemKey; composer.GetSwitch(key).SetValue(currentValue == "1"); } break; case EnumDialogElementType.Input: { string key = "input-" + elemKey; CairoFont font = CairoFont.WhiteSmallText(); composer.GetTextInput(key).SetValue(currentValue); break; } case EnumDialogElementType.NumberInput: { string key = "numberinput-" + elemKey; composer.GetNumberInput(key).SetValue(currentValue); break; } case EnumDialogElementType.Button: break; case EnumDialogElementType.Text: break; case EnumDialogElementType.Select: case EnumDialogElementType.DynamicSelect: { string[] values = elem.Values; if (elem.Type == EnumDialogElementType.DynamicSelect) { string[] compos = currentValue.Split(new string[] { "\n" }, StringSplitOptions.None); values = compos[0].Split(new string[] { "||" }, StringSplitOptions.None); string[] names = compos[1].Split(new string[] { "||" }, StringSplitOptions.None); currentValue = compos[2]; string key = "dropdown-" + elemKey; composer.GetDropDown(key).SetList(values, names); } int selectedIndex = Array.FindIndex(values, w => w.Equals(currentValue)); if (elem.Mode == EnumDialogElementMode.DropDown) { string key = "dropdown-" + elemKey; composer.GetDropDown(key).SetSelectedIndex(selectedIndex); } else { if (elem.Icons != null && elem.Icons.Length > 0) { string key = "togglebuttons-" + elemKey; if (currentValue != null && currentValue.Length > 0) { composer.ToggleButtonsSetValue(key, selectedIndex); } } } } break; } elemKey++; } } }
/// <summary> /// Creates a new GUIElementStaticText. /// </summary> /// <param name="capi">The Client API</param> /// <param name="text">The text of the Element</param> /// <param name="orientation">The orientation of the text.</param> /// <param name="bounds">The bounds of the element.</param> /// <param name="font">The font of the text.</param> public GuiElementStaticText(ICoreClientAPI capi, string text, EnumTextOrientation orientation, ElementBounds bounds, CairoFont font) : base(capi, text, font, bounds) { this.orientation = orientation; }
public ClearFloatTextComponent(ICoreClientAPI api, float marginTop = 0) : base(api, "", CairoFont.WhiteDetailText()) { this.Float = EnumFloat.None; MarginTop = marginTop; }
/// <summary> /// Adds a static text component to the GUI that automatically resizes as necessary. /// </summary> /// <param name="text">The text of the text component.</param> /// <param name="font">The font of the text.</param> /// <param name="orientation">The orientation of the text.</param> /// <param name="bounds">The bounds of the text container.</param> /// <param name="key">The name of the component.</param> public static GuiComposer AddStaticTextAutoBoxSize(this GuiComposer composer, string text, CairoFont font, EnumTextOrientation orientation, ElementBounds bounds, string key = null) { if (!composer.Composed) { GuiElementStaticText elem = new GuiElementStaticText(composer.Api, text, orientation, bounds, font); composer.AddStaticElement(elem, key); elem.AutoBoxSize(); } return(composer); }
void ComposeInteractiveElements() { slotBounds = new ElementBounds[availableSlots.Count]; scissorBounds = new ElementBounds[availableSlots.Count]; slotQuantityTextures = new LoadedTexture[availableSlots.Count]; for (int k = 0; k < slotQuantityTextures.Length; k++) { slotQuantityTextures[k] = new LoadedTexture(this.api); } this.rows = (int)Math.Ceiling(1f * availableSlots.Count / cols); Bounds.CalcWorldBounds(); double unscaledSlotWidth = GuiElementPassiveItemSlot.unscaledSlotSize; double unscaledSlotHeight = GuiElementPassiveItemSlot.unscaledSlotSize; // Slot sizes double absSlotPadding = scaled(unscaledSlotPadding); double absSlotWidth = scaled(GuiElementPassiveItemSlot.unscaledSlotSize); double absSlotHeight = scaled(GuiElementPassiveItemSlot.unscaledSlotSize); ElementBounds textBounds = ElementBounds .Fixed(0, GuiElementPassiveItemSlot.unscaledSlotSize - GuiStyle.SmallishFontSize - 2, GuiElementPassiveItemSlot.unscaledSlotSize - 5, GuiElementPassiveItemSlot.unscaledSlotSize - 5) .WithEmptyParent(); CairoFont font = CairoFont.WhiteSmallText().WithFontSize((float)GuiStyle.SmallishFontSize); font.FontWeight = FontWeight.Bold; font.Color = new double[] { 1, 1, 1, 1 }; font.StrokeColor = new double[] { 0, 0, 0, 1 }; font.StrokeWidth = RuntimeEnv.GUIScale; textComposer = new GuiElementStaticText(api, "", EnumTextOrientation.Right, textBounds, font); // 1. draw generic slot ImageSurface slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth, (int)absSlotWidth); Context slotCtx = genContext(slotSurface); slotCtx.SetSourceRGBA(GuiStyle.DialogSlotBackColor); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius); slotCtx.Fill(); slotCtx.SetSourceRGBA(GuiStyle.DialogSlotFrontColor); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius); slotCtx.LineWidth = scaled(4.5); slotCtx.Stroke(); slotSurface.Blur(scaled(4), true); slotSurface.Blur(scaled(4), true); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1); slotCtx.LineWidth = scaled(4.5); slotCtx.SetSourceRGBA(0, 0, 0, 0.8); slotCtx.Stroke(); generateTexture(slotSurface, ref slotTexture, true); slotCtx.Dispose(); slotSurface.Dispose(); // 2. draw slots with backgrounds foreach (var val in availableSlots) { ItemSlot slot = val.Value; string key = slot.BackgroundIcon + "-" + slot.HexBackgroundColor; if ((slot.BackgroundIcon == null && slot.HexBackgroundColor == null) || slotTextureIdsByBgIconAndColor.ContainsKey(key)) { continue; } slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth, (int)absSlotWidth); slotCtx = genContext(slotSurface); if (slot.HexBackgroundColor != null) { double[] bgcolor = ColorUtil.Hex2Doubles(slot.HexBackgroundColor); slotCtx.SetSourceRGBA(bgcolor); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius); slotCtx.Fill(); slotCtx.SetSourceRGBA(bgcolor[0] * 0.25, bgcolor[1] * 0.25, bgcolor[2] * 0.25, 1); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius); slotCtx.LineWidth = scaled(4.5); slotCtx.Stroke(); slotSurface.Blur(scaled(4), true); slotSurface.Blur(scaled(4), true); slotCtx.SetSourceRGBA(0, 0, 0, 0.8); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1); slotCtx.LineWidth = scaled(4.5); slotCtx.Stroke(); } else { slotCtx.SetSourceRGBA(GuiStyle.DialogSlotBackColor); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius); slotCtx.Fill(); slotCtx.SetSourceRGBA(GuiStyle.DialogSlotFrontColor); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, GuiStyle.ElementBGRadius); slotCtx.LineWidth = scaled(4.5); slotCtx.Stroke(); slotSurface.Blur(scaled(4), true); slotSurface.Blur(scaled(4), true); RoundRectangle(slotCtx, 0, 0, absSlotWidth, absSlotHeight, 1); slotCtx.LineWidth = scaled(4.5); slotCtx.SetSourceRGBA(0, 0, 0, 0.8); slotCtx.Stroke(); } if (slot.BackgroundIcon != null) { DrawIconHandler?.Invoke( slotCtx, slot.BackgroundIcon, 2 * (int)absSlotPadding, 2 * (int)absSlotPadding, (int)(absSlotWidth - 4 * absSlotPadding), (int)(absSlotHeight - 4 * absSlotPadding), new double[] { 0, 0, 0, 0.2 } ); } int texId = 0; generateTexture(slotSurface, ref texId, true); slotCtx.Dispose(); slotSurface.Dispose(); slotTextureIdsByBgIconAndColor[key] = texId; } // 3. Crossed out overlay int csize = (int)absSlotWidth - 4; slotSurface = new ImageSurface(Format.Argb32, (int)csize, (int)csize); slotCtx = genContext(slotSurface); slotCtx.SetSourceRGBA(0, 0, 0, 0.8); api.Gui.Icons.DrawCross(slotCtx, 4, 4, 7, csize - 18, true); slotCtx.SetSourceRGBA(1, 0.2, 0.2, 0.8); slotCtx.LineWidth = 2; slotCtx.Stroke(); generateTexture(slotSurface, ref crossedOutTexture); slotCtx.Dispose(); slotSurface.Dispose(); // 4. Slot highlight overlay slotSurface = new ImageSurface(Format.Argb32, (int)absSlotWidth + 4, (int)absSlotWidth + 4); slotCtx = genContext(slotSurface); slotCtx.SetSourceRGBA(GuiStyle.ActiveSlotColor); RoundRectangle(slotCtx, 0, 0, absSlotWidth + 4, absSlotHeight + 4, GuiStyle.ElementBGRadius); slotCtx.LineWidth = scaled(9); slotCtx.StrokePreserve(); slotSurface.Blur(scaled(6), true); slotCtx.StrokePreserve(); slotSurface.Blur(scaled(6), true); slotCtx.LineWidth = scaled(3); slotCtx.Stroke(); slotCtx.LineWidth = scaled(1); slotCtx.SetSourceRGBA(GuiStyle.ActiveSlotColor); slotCtx.Stroke(); generateTexture(slotSurface, ref highlightSlotTexture); slotCtx.Dispose(); slotSurface.Dispose(); int slotIndex = 0; foreach (var val in availableSlots) { int col = slotIndex % cols; int row = slotIndex / cols; double x = col * (unscaledSlotWidth + unscaledSlotPadding); double y = row * (unscaledSlotHeight + unscaledSlotPadding); ItemSlot slot = inventory[val.Key]; slotBounds[slotIndex] = ElementBounds.Fixed(x, y, unscaledSlotWidth, unscaledSlotHeight).WithParent(Bounds); slotBounds[slotIndex].CalcWorldBounds(); scissorBounds[slotIndex] = ElementBounds.Fixed(x + 2, y + 2, unscaledSlotWidth - 4, unscaledSlotHeight - 4).WithParent(Bounds); scissorBounds[slotIndex].CalcWorldBounds(); ComposeSlotOverlays(slot, val.Key, slotIndex); slotIndex++; } }
// Single rectangle shape /// <summary> /// Adds a dialog title bar to the GUI with a background. /// </summary> /// <param name="text">The text of 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 static GuiComposer AddDialogTitleBarWithBg(this GuiComposer composer, string text, Action OnClose = null, CairoFont font = null, ElementBounds bounds = null) { if (!composer.composed) { GuiElementDialogTitleBar elem = new GuiElementDialogTitleBar(composer.Api, text, composer, OnClose, font, bounds); elem.drawBg = true; composer.AddInteractiveElement(elem); } return(composer); }
public static GuiComposer AddAutoSizeHoverText(this GuiComposer composer, string text, CairoFont font, int width, ElementBounds bounds, string key = null) { if (!composer.composed) { GuiElementHoverText elem = new GuiElementHoverText(composer.Api, text, font, width, bounds, null); elem.SetAutoWidth(true); composer.AddInteractiveElement(elem, key); } return(composer); }
/// <summary> /// Adds a text input to the current GUI. /// </summary> /// <param name="bounds">The bounds of the text input.</param> /// <param name="OnTextChanged">The event fired when the text is changed.</param> /// <param name="font">The font of the text.</param> /// <param name="key">The name of this text component.</param> public static GuiComposer AddTextInput(this GuiComposer composer, ElementBounds bounds, Action <string> OnTextChanged, CairoFont font = null, string key = null) { if (font == null) { font = CairoFont.TextInput(); } if (!composer.Composed) { composer.AddInteractiveElement(new GuiElementTextInput(composer.Api, bounds, OnTextChanged, font), key); } return(composer); }
/// <summary> /// Adds a hover text to the GUI. /// </summary> /// <param name="text">The text of the text.</param> /// <param name="font">The font of the text.</param> /// <param name="width">The width of the text.</param> /// <param name="bounds">The bounds of the text.</param> /// <param name="key">The name of this hover text component.</param> public static GuiComposer AddHoverText(this GuiComposer composer, string text, CairoFont font, int width, ElementBounds bounds, TextBackground background, string key = null) { if (!composer.composed) { GuiElementHoverText elem = new GuiElementHoverText(composer.Api, text, font, width, bounds, background); composer.AddInteractiveElement(elem, key); } return(composer); }
/// <summary> /// Adds a set of horizontal tabs to the GUI. /// </summary> /// <param name="tabs">The collection of tabs.</param> /// <param name="bounds">The bounds of the horizontal tabs.</param> /// <param name="OnTabClicked">The event fired when the tab is clicked.</param> /// <param name="font">The font of the tabs.</param> /// <param name="key">The key for the added horizontal tabs.</param> public static GuiComposer AddHorizontalTabs(this GuiComposer composer, GuiTab[] tabs, ElementBounds bounds, API.Common.Action <int> OnTabClicked, CairoFont font, CairoFont selectedFont, string key = null) { if (!composer.composed) { composer.AddInteractiveElement(new GuiElementHorizontalTabs(composer.Api, tabs, font, selectedFont, bounds, OnTabClicked), key); } return(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, API.Common.Action <string> OnTextChanged, CairoFont font) : base(capi, font, bounds) { highlightTexture = new LoadedTexture(capi); multilineMode = true; minHeight = bounds.fixedHeight; this.OnTextChanged = OnTextChanged; }
/// <summary> /// Adds a multiple select dropdown to the current GUI instance. /// </summary> /// <param name="values">The values of the current drodown.</param> /// <param name="names">The names of those values.</param> /// <param name="selectedIndex">The default selected index.</param> /// <param name="onSelectionChanged">The event fired when the index is changed.</param> /// <param name="bounds">The bounds of the index.</param> /// <param name="key">The name of this dropdown.</param> public static GuiComposer AddMultiSelectDropDown(this GuiComposer composer, string[] values, string[] names, int selectedIndex, SelectionChangedDelegate onSelectionChanged, ElementBounds bounds, string key = null) { if (!composer.composed) { composer.AddInteractiveElement(new GuiElementDropDown(composer.Api, values, names, selectedIndex, onSelectionChanged, bounds, CairoFont.WhiteSmallText(), true), key); } return(composer); }
/// <summary> /// Get the final height of the text. /// </summary> /// <param name="font">The font of the text.</param> /// <param name="text">The text itself.</param> /// <param name="flowPath">The path for the text.</param> /// <param name="lineY">The height of the line</param> /// <returns>The final height of the text.</returns> public double GetMultilineTextHeight(CairoFont font, string text, TextFlowPath[] flowPath, double lineY = 0) { return(GetQuantityTextLines(font, text, flowPath, lineY) * GetLineHeight(font)); }