void ComposeFlashOverlay() { valueHeight = (int)Bounds.OuterHeight + 1; ImageSurface surface = new ImageSurface(Format.Argb32, Bounds.OuterWidthInt + 28, Bounds.OuterHeightInt + 28); Context ctx = new Context(surface); ctx.SetSourceRGBA(0, 0, 0, 0); ctx.Paint(); RoundRectangle(ctx, 12, 12, Bounds.OuterWidthInt + 4, Bounds.OuterHeightInt + 4, 1); ctx.SetSourceRGB(color[0], color[1], color[2]); ctx.FillPreserve(); surface.Blur(3, true); ctx.Fill(); surface.Blur(2, true); RoundRectangle(ctx, 15, 15, Bounds.OuterWidthInt - 2, Bounds.OuterHeightInt - 2, 1); ctx.Operator = Operator.Clear; ctx.SetSourceRGBA(0, 0, 0, 0); ctx.Fill(); api.Event.EnqueueMainThreadTask(() => { generateTexture(surface, ref flashTexture); ctx.Dispose(); surface.Dispose(); }, "recompstatbar"); }
public override void ComposeElements(Context ctx, ImageSurface surface) { Bounds.CalcWorldBounds(); double titleBarOffY = withTitlebar ? scaled(GuiStyle.TitleBarHeight) : 0; RoundRectangle(ctx, Bounds.bgDrawX, Bounds.bgDrawY + titleBarOffY, Bounds.OuterWidth, Bounds.OuterHeight - titleBarOffY, GuiStyle.DialogBGRadius); ctx.SetSourceRGBA(GuiStyle.DialogStrongBgColor[0], GuiStyle.DialogStrongBgColor[1], GuiStyle.DialogStrongBgColor[2], GuiStyle.DialogStrongBgColor[3] * Alpha); ctx.FillPreserve(); if (Shade) { ctx.SetSourceRGBA(GuiStyle.DialogLightBgColor[0] * 1.6, GuiStyle.DialogStrongBgColor[1] * 1.6, GuiStyle.DialogStrongBgColor[2] * 1.6, Alpha); ctx.LineWidth = strokeWidth * 1.75; ctx.StrokePreserve(); surface.Blur(5.2, (int)Bounds.bgDrawX, (int)(Bounds.bgDrawY + titleBarOffY), (int)(Bounds.bgDrawX + Bounds.OuterWidth), (int)(Bounds.bgDrawY + Bounds.OuterHeight - 1)); ctx.SetSourceRGBA(new double[] { 45 / 255.0, 35 / 255.0, 33 / 255.0, Alpha * Alpha }); ctx.LineWidth = strokeWidth; ctx.Stroke(); } else { ctx.SetSourceRGBA(new double[] { 45 / 255.0, 35 / 255.0, 33 / 255.0, Alpha }); ctx.LineWidth = 2; ctx.Stroke(); } /*double off = strokeWidth / 2 + 1; * RoundRectangle(ctx, Bounds.bgDrawX + off, Bounds.bgDrawY + titleBarOffY + (titleBarOffY > 0 ? 0 : off), Bounds.OuterWidth - 2*off, Bounds.OuterHeight - titleBarOffY - off - (titleBarOffY > 0 ? 0 : off), GuiStyle.DialogBGRadius); * ctx.SetSourceRGBA(0, 0, 0, 0.4); * ctx.LineWidth = 1.5; * ctx.Stroke();*/ }
//FreeTypeFontFace fontFace = FreeTypeFontFace.Create(LoadtimeSettings.AssetPath + "/font/" + LoadtimeSettings.GUIFontName, 0); //ctx.SetContextFontFace(fontFace); public override void ComposeTextElements(Context ctxStatic, ImageSurface surfaceStatic) { Font.SetupContext(ctxStatic); Bounds.CalcWorldBounds(); ImageSurface insetShadowSurface = new ImageSurface(Format.Argb32, Bounds.ParentBounds.OuterWidthInt, Bounds.ParentBounds.OuterHeightInt); Context ctxInsetShadow = new Context(insetShadowSurface); ctxInsetShadow.SetSourceRGB(0, 0, 0); ctxInsetShadow.Paint(); Font.Color = new double[] { 20, 20, 20, 0.35f }; Font.SetupContext(ctxInsetShadow); DrawMultilineTextAt(ctxInsetShadow, Bounds.drawX + scaled(2), Bounds.drawY + scaled(2), orientation); insetShadowSurface.Blur(7, (int)Math.Max(0, Bounds.drawX - 4), (int)Math.Max(0, Bounds.drawY - 4), (int)Math.Min(Bounds.ParentBounds.OuterWidth, Bounds.drawX + Font.GetTextExtents(text).Width + 6), (int)Math.Min(Bounds.ParentBounds.OuterHeight, Bounds.drawY + ctxInsetShadow.FontExtents.Height + 6) ); ImageSurface surface = new ImageSurface(Format.Argb32, Bounds.ParentBounds.OuterWidthInt, Bounds.ParentBounds.OuterHeightInt); Context ctxText = new Context(surface); ctxText.Operator = Operator.Source; ctxText.Antialias = Antialias.Best; Font.Color = new double[] { 0, 0, 0, 0.4 }; Font.SetupContext(ctxText); ctxText.SetSourceRGBA(0, 0, 0, 0.4); DrawMultilineTextAt(ctxText, Bounds.drawX - scaled(0.5), Bounds.drawY - scaled(0.5), orientation); ctxText.SetSourceRGBA(1, 1, 1, 1); DrawMultilineTextAt(ctxText, Bounds.drawX + scaled(1), Bounds.drawY + scaled(1), orientation); ctxText.Operator = Operator.Atop; ctxText.SetSourceSurface(insetShadowSurface, 0, 0); ctxText.Paint(); ctxInsetShadow.Dispose(); insetShadowSurface.Dispose(); ctxText.Operator = Operator.Over; Font.Color = new double[] { 0, 0, 0, 0.35 }; Font.SetupContext(ctxText); DrawMultilineTextAt(ctxText, (int)Bounds.drawX, (int)Bounds.drawY, orientation); ctxStatic.Antialias = Antialias.Best; ctxStatic.Operator = Operator.HardLight; ctxStatic.SetSourceSurface(surface, 0, 0); ctxStatic.Paint(); surface.Dispose(); ctxText.Dispose(); }
private void ComposeOverlays() { double radius = scaled(1); double spacing = scaled(unscaledTabSpacing); double padding = scaled(unscaledTabPadding); double width; for (int i = 0; i < tabs.Length; i++) { ImageSurface surface = new ImageSurface(Format.Argb32, tabWidths[i] + 1, (int)tabHeight + 1); Context ctx = genContext(surface); width = tabWidths[i] + 1; ctx.SetSourceRGBA(1, 1, 1, 0); ctx.Paint(); ctx.NewPath(); ctx.MoveTo(width, tabHeight + 1); ctx.LineTo(width, 0); ctx.LineTo(radius, 0); ctx.ArcNegative(0, radius, radius, 270 * GameMath.DEG2RAD, 180 * GameMath.DEG2RAD); ctx.ArcNegative(0, tabHeight - radius, radius, 180 * GameMath.DEG2RAD, 90 * GameMath.DEG2RAD); ctx.ClosePath(); double[] color = GuiStyle.DialogDefaultBgColor; ctx.SetSourceRGBA(color[0], color[1], color[2], color[3]); ctx.Fill(); ctx.NewPath(); ctx.LineTo(1 + width, 1); ctx.LineTo(1, 1); ctx.LineTo(1, tabHeight - 1); ctx.LineTo(1 + width, 1 + tabHeight - 1); float strokeWidth = 2; ctx.SetSourceRGBA(GuiStyle.DialogLightBgColor[0] * 1.6, GuiStyle.DialogStrongBgColor[1] * 1.6, GuiStyle.DialogStrongBgColor[2] * 1.6, 1); ctx.LineWidth = strokeWidth * 1.75; ctx.StrokePreserve(); surface.Blur(3, 0, 0, (int)width - 1, (int)tabHeight - 1); ctx.SetSourceRGBA(new double[] { 45 / 255.0, 35 / 255.0, 33 / 255.0, 1 }); ctx.LineWidth = strokeWidth; ctx.Stroke(); selectedFont.SetupContext(ctx); DrawTextLineAt(ctx, tabs[i].Name, padding + 2, textOffsetY); generateTexture(surface, ref hoverTextures[i]); ctx.Dispose(); surface.Dispose(); } }
void Compose() { Bounds.CalcWorldBounds(); double shadowOffset = scaled(1.5) / 2; double shineOffset = -scaled(1.5) / 2; double padding = scaled(Padding); if (!enabled) { shadowOffset /= 2; shineOffset /= 2; } ImageSurface surface = new ImageSurface(Format.Argb32, Bounds.OuterWidthInt, Bounds.OuterHeightInt); Context ctxText = new Context(surface); ctxText.SetSourceRGBA(0, 0, 0, 0); ctxText.Paint(); ctxText.Operator = Operator.Source; ctxText.Antialias = Antialias.Best; Font.Color = new double[] { 0, 0, 0, 0.4 }; Font.SetupContext(ctxText); ctxText.SetSourceRGBA(0, 0, 0, 0.95); ctxText.MoveTo(padding + shadowOffset, padding + shadowOffset); DrawTextLineAt(ctxText, text, 0, 0); ctxText.SetSourceRGBA(255, 255, 255, enabled ? 0.95 : 0.5); ctxText.MoveTo(padding + shineOffset, padding + shineOffset); DrawTextLineAt(ctxText, text, 0, 0); surface.Blur(3, 0, 0, Bounds.OuterWidthInt, Bounds.OuterHeightInt); ctxText.Operator = Operator.Source; if (enabled) { Font.Color = new double[] { 0, 0, 0, 0.5 }; } else { Font.Color = new double[] { 0.5, 0.5, 0.5, 0.75 }; } Font.SetupContext(ctxText); ctxText.MoveTo(padding, padding); DrawTextLineAt(ctxText, text, 0, 0); generateTexture(surface, ref texture); surface.Dispose(); ctxText.Dispose(); }
void ComposeValueOverlay() { double widthRel = (double)value / (maxValue - minValue); valueWidth = (int)(widthRel * Bounds.OuterWidth) + 1; valueHeight = (int)Bounds.OuterHeight + 1; ImageSurface surface = new ImageSurface(Format.Argb32, Bounds.OuterWidthInt + 1, valueHeight); Context ctx = new Context(surface); if (widthRel > 0.01) { double width = Bounds.OuterWidth * widthRel; double x = rightToLeft ? Bounds.OuterWidth - width : 0; RoundRectangle(ctx, x, 0, width, Bounds.OuterHeight, 1); ctx.SetSourceRGB(color[0], color[1], color[2]); ctx.FillPreserve(); ctx.SetSourceRGB(color[0] * 0.4, color[1] * 0.4, color[2] * 0.4); ctx.LineWidth = scaled(3); ctx.StrokePreserve(); surface.Blur(3); width = Bounds.InnerWidth * widthRel; x = rightToLeft ? Bounds.InnerWidth - width : 0; EmbossRoundRectangleElement(ctx, x, 0, width, Bounds.InnerHeight, false, 2, 1); } ctx.SetSourceRGBA(0, 0, 0, 0.5); ctx.LineWidth = scaled(2.2); int lines = Math.Min(50, (int)((maxValue - minValue) / lineInterval)); for (int i = 1; i < lines; i++) { ctx.NewPath(); ctx.SetSourceRGBA(0, 0, 0, 0.5); double x = (Bounds.InnerWidth * i) / lines; ctx.MoveTo(x, 0); ctx.LineTo(x, Math.Max(3, Bounds.InnerHeight - 1)); ctx.ClosePath(); ctx.Stroke(); } api.Event.EnqueueMainThreadTask(() => { generateTexture(surface, ref barTexture); ctx.Dispose(); surface.Dispose(); }, "recompstatbar"); }
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"); }); }
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++; } }
public override void ComposeElements(Context ctxStatic, ImageSurface surfaceStatic) { handleWidth = scaled(unscaledHandleWidth); handleHeight = scaled(unscaledHandleHeight); hoverTextWidth = scaled(unscaledHoverTextHeight); hoverTextHeight = scaled(unscaledHoverTextHeight); padding = scaled(unscaledPadding); Bounds.CalcWorldBounds(); // Wood bg RoundRectangle(ctxStatic, Bounds.drawX, Bounds.drawY, Bounds.InnerWidth, Bounds.InnerHeight, GuiStyle.ElementBGRadius); fillWithPattern(api, ctxStatic, woodTextureName); EmbossRoundRectangleElement(ctxStatic, Bounds.drawX, Bounds.drawY, Bounds.InnerWidth, Bounds.InnerHeight); double insetWidth = Bounds.InnerWidth - 2 * padding; double insetHeight = Bounds.InnerHeight - 2 * padding; // Wood Inset ctxStatic.SetSourceRGBA(0, 0, 0, 0.6); RoundRectangle(ctxStatic, Bounds.drawX + padding, Bounds.drawY + padding, insetWidth, insetHeight, GuiStyle.ElementBGRadius); ctxStatic.Fill(); EmbossRoundRectangleElement(ctxStatic, Bounds.drawX + padding, Bounds.drawY + padding, insetWidth, insetHeight, true); if (alarmValue > 0 && alarmValue < maxValue) { float alarmValueRel = (float)alarmValue / maxValue; alarmTextureRect = new Rectangled() { X = padding + (Bounds.InnerWidth - 2 * padding) * alarmValueRel, Y = padding, Width = (Bounds.InnerWidth - 2 * padding) * (1 - alarmValueRel), Height = Bounds.InnerHeight - 2 * padding }; ctxStatic.SetSourceRGBA(0.62, 0, 0, 0.4); RoundRectangle(ctxStatic, Bounds.drawX + padding + insetWidth * alarmValueRel, Bounds.drawY + padding, insetWidth * (1 - alarmValueRel), insetHeight, GuiStyle.ElementBGRadius); ctxStatic.Fill(); } /*** 2. Handle ***/ ImageSurface surface = new ImageSurface(Format.Argb32, (int)handleWidth + 5, (int)handleHeight + 5); Context ctx = genContext(surface); ctx.SetSourceRGBA(1, 1, 1, 0); ctx.Paint(); ctx.SetSourceRGBA(0, 0, 0, 0.5); RoundRectangle(ctx, 0, 0, handleWidth, handleHeight, GuiStyle.ElementBGRadius); ctx.Fill(); surface.Blur(3); RoundRectangle(ctx, 0, 0, handleWidth, handleHeight, GuiStyle.ElementBGRadius); fillWithPattern(api, ctx, woodTextureName); EmbossRoundRectangleElement(ctx, 0, 0, handleWidth, handleHeight, false); generateTexture(surface, ref handleTextureId); ctx.Dispose(); surface.Dispose(); ComposeHoverTextElement(); }
/// <summary> /// Takes a string of text and applies a texture to it. /// </summary> /// <param name="text">The text to texture.</param> /// <param name="font">The font of the text.</param> /// <param name="width">The width of the text.</param> /// <param name="height">The height of the text.</param> /// <param name="background">The background of the text. (default: none/null)</param> /// <returns>The texturized text.</returns> public LoadedTexture GenTextTexture(string text, CairoFont font, int width, int height, TextBackground background = null) { if (background == null) { background = defaultBackground; } ImageSurface surface = new ImageSurface(Format.Argb32, width, height); Context ctx = new Context(surface); if (background?.FillColor != null) { ctx.SetSourceRGBA(background.FillColor); GuiElement.RoundRectangle(ctx, 0, 0, width, height, 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); ctx.LineWidth = 5;// background.BorderWidth * 1.75; GuiElement.RoundRectangle(ctx, 0, 0, width, height, background.Radius); ctx.StrokePreserve(); surface.Blur(6.2); ctx.SetSourceRGBA(new double[] { 45 / 255.0, 35 / 255.0, 33 / 255.0, 1 }); ctx.LineWidth = background.BorderWidth; ctx.Stroke(); } if (background?.BorderColor != null) { ctx.SetSourceRGBA(background.BorderColor); GuiElement.RoundRectangle(ctx, 0, 0, width, height, background.Radius); ctx.LineWidth = background.BorderWidth; ctx.Stroke(); } font.SetupContext(ctx); double fontHeight = font.GetFontExtents().Height; string[] lines = text.Split('\n'); for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].TrimEnd(); ctx.MoveTo(background.Padding, background.Padding + ctx.FontExtents.Ascent + i * fontHeight); if (font.StrokeWidth > 0) { ctx.TextPath(lines[i]); ctx.LineWidth = font.StrokeWidth; ctx.SetSourceRGBA(font.StrokeColor); ctx.StrokePreserve(); ctx.SetSourceRGBA(font.Color); ctx.Fill(); } else { ctx.ShowText(lines[i]); if (font.RenderTwice) { ctx.ShowText(lines[i]); } } } int textureId = capi.Gui.LoadCairoTexture(surface, true); surface.Dispose(); ctx.Dispose(); return(new LoadedTexture(capi) { TextureId = textureId, Width = width, Height = height }); }
private void ComposeOverlays(bool isNotifyTabs = false) { double radius = scaled(1); double spacing = scaled(unscaledTabSpacing); double padding = scaled(unscaledTabPadding); for (int i = 0; i < tabs.Length; i++) { ImageSurface surface = new ImageSurface(Format.Argb32, tabWidths[i], (int)Bounds.InnerHeight + 1); Context ctx = genContext(surface); double degrees = Math.PI / 180.0; ctx.SetSourceRGBA(1, 1, 1, 0); ctx.Paint(); ctx.NewPath(); ctx.MoveTo(0, Bounds.InnerHeight + 1); ctx.LineTo(0, radius); ctx.Arc(radius, radius, radius, 180 * degrees, 270 * degrees); ctx.Arc(tabWidths[i] - radius, radius, radius, -90 * degrees, 0 * degrees); ctx.LineTo(tabWidths[i], surface.Height); ctx.ClosePath(); double[] color = GuiStyle.DialogDefaultBgColor; ctx.SetSourceRGBA(color[0], color[1], color[2], color[3] * 0.75); ctx.FillPreserve(); ctx.SetSourceRGBA(color[0] * 1.6, color[1] * 1.6, color[2] * 1.6, 1); ctx.LineWidth = 2 * 1.75; ctx.StrokePreserve(); surface.Blur(5.2, 0, 0, surface.Width, surface.Height); ctx.SetSourceRGBA(color[0], color[1], color[2], color[3] * 0.75); ctx.LineWidth = 1; ctx.StrokePreserve(); ctx.NewPath(); ctx.MoveTo(0, Bounds.InnerHeight); ctx.LineTo(0, radius); ctx.Arc(radius, radius, radius, 180 * degrees, 270 * degrees); ctx.Arc(tabWidths[i] - radius, radius, radius, -90 * degrees, 0 * degrees); ctx.LineTo(tabWidths[i], Bounds.InnerHeight); ShadePath(ctx, 2); if (isNotifyTabs) { notifyFont.SetupContext(ctx); } else { selectedFont.SetupContext(ctx); } ctx.Operator = Operator.Clear; ctx.Rectangle(0, surface.Height - 1, surface.Width, 1); ctx.Fill(); ctx.Operator = Operator.Over; DrawTextLineAt(ctx, tabs[i].Name, padding, (surface.Height - fontHeight) / 2); if (isNotifyTabs) { generateTexture(surface, ref notifyTextures[i]); } else { generateTexture(surface, ref hoverTextures[i]); } ctx.Dispose(); surface.Dispose(); } }