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 override void BeforeCalcBounds() { normalText.AutoBoxSize(true); Bounds.fixedWidth = normalText.Bounds.fixedWidth; Bounds.fixedHeight = normalText.Bounds.fixedHeight; pressedText.Bounds = normalText.Bounds.CopyOnlySize(); }
/// <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); }
/// <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); disabledTexture = new LoadedTexture(capi); this.buttonStyle = style; normalText = new GuiElementStaticText(capi, text, EnumTextOrientation.Center, bounds, font); normalText.AutoBoxSize(true); pressedText = new GuiElementStaticText(capi, text, EnumTextOrientation.Center, bounds.CopyOnlySize(), hoverFont); bounds = normalText.Bounds; this.onClick = onClick; }
internal void ComposeHoverTextElement() { ElementBounds bounds = new ElementBounds().WithFixedPadding(7).WithParent(ElementBounds.Empty); textElem = new GuiElementStaticText(api, currentValue + unit, EnumTextOrientation.Center, bounds, CairoFont.WhiteMediumText()); 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(0, 0, 0, 0.3); RoundRectangle(ctx, 0, 0, bounds.OuterWidth, bounds.OuterHeight, GuiStyle.ElementBGRadius); ctx.Fill(); textElem.ComposeElements(ctx, surface); generateTexture(surface, ref hoverTextTextureId); ctx.Dispose(); surface.Dispose(); }
void ComposeButton(Context ctx, ImageSurface surface, bool pressed) { double embossHeight = scaled(2.5); if (buttonStyle == EnumButtonStyle.Normal) { embossHeight = scaled(1.5); } Bounds.CalcWorldBounds(); normalText.AutoBoxSize(true); pressedText.Bounds = normalText.Bounds.CopyOnlySize(); if (buttonStyle != EnumButtonStyle.None) { // Brown background Rectangle(ctx, Bounds.bgDrawX, Bounds.bgDrawY, Bounds.OuterWidth, Bounds.OuterHeight); ctx.SetSourceRGBA(69 / 255.0, 52 / 255.0, 36 / 255.0, 1); ctx.Fill(); } if (buttonStyle == EnumButtonStyle.MainMenu) { // Top shine Rectangle(ctx, Bounds.bgDrawX, Bounds.bgDrawY, Bounds.OuterWidth, embossHeight); ctx.SetSourceRGBA(1, 1, 1, 0.15); ctx.Fill(); } if (buttonStyle == EnumButtonStyle.Normal) { // Top shine Rectangle(ctx, Bounds.bgDrawX, Bounds.bgDrawY, Bounds.OuterWidth - embossHeight, embossHeight); ctx.SetSourceRGBA(1, 1, 1, 0.15); ctx.Fill(); // Left shine Rectangle(ctx, Bounds.bgDrawX, Bounds.bgDrawY + embossHeight, embossHeight, Bounds.OuterHeight - embossHeight); ctx.SetSourceRGBA(1, 1, 1, 0.15); ctx.Fill(); } // Pretty elaborate way of vertically centering the text. Le sigh. FontExtents fontex = normalText.Font.GetFontExtents(); TextExtents textex = normalText.Font.GetTextExtents(normalText.GetText()); double resetY = -fontex.Ascent - textex.YBearing; textOffsetY = resetY + (normalText.Bounds.InnerHeight + textex.YBearing) / 2; normalText.Bounds.fixedY += textOffsetY; normalText.ComposeElements(ctx, surface); normalText.Bounds.fixedY -= textOffsetY; // ShowMultilineText changes height Bounds.CalcWorldBounds(); if (buttonStyle == EnumButtonStyle.MainMenu) { // Bottom shade Rectangle(ctx, Bounds.bgDrawX, Bounds.bgDrawY + Bounds.OuterHeight - embossHeight, Bounds.OuterWidth, embossHeight); ctx.SetSourceRGBA(0, 0, 0, 0.2); ctx.Fill(); } if (buttonStyle == EnumButtonStyle.Normal) { // Bottom shade Rectangle(ctx, Bounds.bgDrawX + embossHeight, Bounds.bgDrawY + Bounds.OuterHeight - embossHeight, Bounds.OuterWidth - 2 * embossHeight, embossHeight); ctx.SetSourceRGBA(0, 0, 0, 0.2); ctx.Fill(); // Right shade Rectangle(ctx, Bounds.bgDrawX + Bounds.OuterWidth - embossHeight, Bounds.bgDrawY, embossHeight, Bounds.OuterHeight); ctx.SetSourceRGBA(0, 0, 0, 0.2); ctx.Fill(); } if (buttonStyle == EnumButtonStyle.Normal) { //EmbossRoundRectangleElement(ctx, bounds.bgDrawX, bounds.bgDrawY, bounds.OuterWidth, bounds.OuterHeight, false, 2); } }