void Recompose() { descriptionElement.SetNewText(text, Font); RecalcBounds(); Bounds.CalcWorldBounds(); ElementBounds textBounds = Bounds.CopyOnlySize(); textBounds.CalcWorldBounds(); ImageSurface surface = new ImageSurface(Format.Argb32, (int)Math.Ceiling(hoverWidth), (int)Math.Ceiling(hoverHeight)); Context ctx = genContext(surface); ctx.SetSourceRGBA(0, 0, 0, 0); ctx.Paint(); if (Background?.FillColor != null) { ctx.SetSourceRGBA(Background.FillColor); RoundRectangle(ctx, 0, 0, hoverWidth, hoverHeight, Background.Radius); ctx.Fill(); } if (Background?.Shade == true) { ctx.SetSourceRGBA(GuiStyle.DialogLightBgColor[0] * 1.4, GuiStyle.DialogStrongBgColor[1] * 1.4, GuiStyle.DialogStrongBgColor[2] * 1.4, 1); RoundRectangle(ctx, 0, 0, hoverWidth, hoverHeight, Background.Radius); ctx.LineWidth = Background.BorderWidth * 1.75; ctx.Stroke(); surface.Blur(8.2); } if (Background?.BorderColor != null) { ctx.SetSourceRGBA(Background.BorderColor); RoundRectangle(ctx, 0, 0, hoverWidth, hoverHeight, Background.Radius); ctx.LineWidth = Background.BorderWidth; ctx.Stroke(); } generateTexture(surface, ref hoverTexture); ctx.Dispose(); surface.Dispose(); }
void Recompose() { if (curSlot?.Itemstack == null) { return; } readyToRender = false; string title = curSlot.GetStackName(); string desc = OnRequireInfoText(curSlot); desc.TrimEnd(); titleElement.SetNewText(title, titleFont); descriptionElement.SetNewText(desc, Font); RecalcBounds(title, desc); Bounds.CalcWorldBounds(); ElementBounds textBounds = Bounds.CopyOnlySize(); textBounds.CalcWorldBounds(); TyronThreadPool.QueueTask(() => { /*int i = 0; * while (i < 5 && titleElement.HalfComposed) System.Threading.Thread.Sleep(5);*/ ImageSurface surface = new ImageSurface(Format.Argb32, Bounds.OuterWidthInt, Bounds.OuterHeightInt); Context ctx = genContext(surface); ctx.SetSourceRGBA(0, 0, 0, 0); ctx.Paint(); ctx.SetSourceRGBA(backTint[0], backTint[1], backTint[2], backTint[3]); RoundRectangle(ctx, textBounds.bgDrawX, textBounds.bgDrawY, textBounds.OuterWidthInt, textBounds.OuterHeightInt, GuiStyle.DialogBGRadius); ctx.FillPreserve(); ctx.SetSourceRGBA(GuiStyle.DialogLightBgColor[0] * 1.4, GuiStyle.DialogStrongBgColor[1] * 1.4, GuiStyle.DialogStrongBgColor[2] * 1.4, 1); ctx.LineWidth = 3 * 1.75; ctx.StrokePreserve(); surface.Blur(8.2); ctx.SetSourceRGBA(backTint[0] / 2, backTint[1] / 2, backTint[2] / 2, backTint[3]); ctx.Stroke(); int w = (int)(scaled(ItemStackSize) + scaled(40)); int h = (int)(scaled(ItemStackSize) + scaled(40)); ImageSurface shSurface = new ImageSurface(Format.Argb32, w, h); Context shCtx = genContext(shSurface); shCtx.SetSourceRGBA(GuiStyle.DialogSlotBackColor); RoundRectangle(shCtx, 0, 0, w, h, 0); shCtx.FillPreserve(); shCtx.SetSourceRGBA(GuiStyle.DialogSlotFrontColor); shCtx.LineWidth = 5; shCtx.Stroke(); shSurface.Blur(7); shSurface.Blur(7); shSurface.Blur(7); EmbossRoundRectangleElement(shCtx, 0, 0, w, h, true); ctx.SetSourceSurface(shSurface, (int)(textBounds.drawX), (int)(textBounds.drawY + scaled(MarginTop))); ctx.Rectangle(textBounds.drawX, textBounds.drawY + scaled(MarginTop), w, h); ctx.Fill(); shCtx.Dispose(); shSurface.Dispose(); api.Event.EnqueueMainThreadTask(() => { //titleElement.genTexture(); //descriptionElement.genTexture(); titleElement.Compose(false); descriptionElement.Compose(false); generateTexture(surface, ref texture); ctx.Dispose(); surface.Dispose(); double offset = (int)(30 + ItemStackSize / 2); scissorBounds = ElementBounds.Fixed(4 + offset - ItemStackSize, 2 + offset + MarginTop - ItemStackSize, ItemStackSize + 38, ItemStackSize + 38).WithParent(Bounds); scissorBounds.CalcWorldBounds(); readyToRender = true; }, "genstackinfotexture"); }); }