private void OnBgDraw(Context ctx, ImageSurface surface, ElementBounds currentBounds) { // 1. Fire ctx.Save(); Matrix m = ctx.Matrix; m.Translate(GuiElement.scaled(5), GuiElement.scaled(53 + 70)); m.Scale(GuiElement.scaled(0.25), GuiElement.scaled(0.25)); ctx.Matrix = m; capi.Gui.Icons.DrawFlame(ctx); double dy = 210 - 210 * (Attributes.GetFloat("fuelBurnTime", 0) / Attributes.GetFloat("maxFuelBurnTime", 1)); ctx.Rectangle(0, dy, 200, 210 - dy); ctx.Clip(); LinearGradient gradient = new LinearGradient(0, GuiElement.scaled(250), 0, 0); gradient.AddColorStop(0, new Color(1, 1, 0, 1)); gradient.AddColorStop(1, new Color(1, 0, 0, 1)); ctx.SetSource(gradient); capi.Gui.Icons.DrawFlame(ctx, 0, false, false); gradient.Dispose(); ctx.Restore(); // 2. Arrow Right ctx.Save(); m = ctx.Matrix; m.Translate(GuiElement.scaled(63), GuiElement.scaled(1 + 72)); m.Scale(GuiElement.scaled(0.6), GuiElement.scaled(0.6)); ctx.Matrix = m; capi.Gui.Icons.DrawArrowRight(ctx, 2); double cookingRel = Attributes.GetFloat("oreCookingTime") / Attributes.GetFloat("maxOreCookingTime", 1); ctx.Rectangle(5, 0, 125 * cookingRel, 100); ctx.Clip(); gradient = new LinearGradient(0, 0, 200, 0); gradient.AddColorStop(0, new Color(0, 0.4, 0, 1)); gradient.AddColorStop(1, new Color(0.2, 0.6, 0.2, 1)); ctx.SetSource(gradient); capi.Gui.Icons.DrawArrowRight(ctx, 0, false, false); gradient.Dispose(); ctx.Restore(); }
public override void Finish() { if (downview != null) { FinishCountDown(); } else { timer.Enabled = false; } if (gradient != null) { gradient.Dispose(); gradient = null; } }
//--------------------------------------------------------------------- private static void Gradient() { Action <Surface> draw = surface => { using (var c = new Context(surface)) { Gradient pat = new LinearGradient(0.0, 0.0, 0.0, 256.0); pat.AddColorStopRgba(1, 0, 0, 0, 1); pat.AddColorStopRgba(0, 1, 1, 1, 1); c.Rectangle(0, 0, 256, 256); c.SetSource(pat); c.Fill(); pat.Dispose(); pat = new RadialGradient(115.2, 102.4, 25.6, 102.4, 102.4, 128.0); pat.AddColorStopRgba(0, 1, 1, 1, 1); pat.AddColorStopRgba(1, 0, 0, 0, 1); c.SetSource(pat); c.Arc(128.0, 128.0, 76.8, 0, 2 * Math.PI); c.Fill(); pat.Dispose(); } }; using (Surface surface = new ImageSurface(Format.Argb32, 500, 500)) { draw(surface); surface.WriteToPng("gradient.png"); } using (Surface surface = new PdfSurface("gradient.pdf", 500, 500)) { draw(surface); surface.WriteToPng("gradient1.png"); } using (Surface surface = new SvgSurface("gradient.svg", 500, 500)) { draw(surface); surface.WriteToPng("gradient2.png"); } }
private void DoDraw(Gdk.Window window, Rectangle[] rects, double borderWidth) { Context cr = Gdk.CairoHelper.Create(window); // draw progress Color color1 = ChangeColorBrightness(this.ForeColor, 0.25f); Color color2 = ChangeColorBrightness(this.ForeColor, -0.25f); // a linear gradient for progress bar fill var grd = new LinearGradient(0, 0, _direction == DirectionMode.Horizontal ? 1 : Allocation.Width, _direction == DirectionMode.Horizontal ? Allocation.Height : 1); grd.AddColorStopRgb(0, color1); grd.AddColorStopRgb(1, color2); if (_direction == DirectionMode.Horizontal) { DrawRectangleH(cr, 0, Allocation.Height, grd); } else { DrawRectangleV(cr, 0, Allocation.Width, grd); } grd.Dispose(); // draw border around widget // - sets line width to 2 points cr.LineWidth = 2; // - set brush/source color cr.SetSourceRGBA(0, 0, 0, 1); // - draw a virtual rect cr.Rectangle(new Rectangle(cr.LineWidth, cr.LineWidth, Allocation.Width - cr.LineWidth, Allocation.Height - cr.LineWidth)); // - stroke it. cr.Stroke(); cr.GetTarget().Dispose(); cr.Dispose(); }
public override void DrawHeaderBackground(Cairo.Context cr, Gdk.Rectangle alloc) { var gtk_background_color = Colors.GetWidgetColor(GtkColorClass.Background, StateType.Normal); var light_color = CairoExtensions.ColorShade(gtk_background_color, 1.1); var dark_color = CairoExtensions.ColorShade(gtk_background_color, 0.95); var corners = CairoCorners.TopLeft | CairoCorners.TopRight; var grad = new LinearGradient(alloc.X, alloc.Y, alloc.X, alloc.Bottom); grad.AddColorStop(0, light_color); grad.AddColorStop(0.75, dark_color); grad.AddColorStop(0, light_color); cr.SetSource(grad); CairoExtensions.RoundedRectangle(cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, Context.Radius, corners); cr.Fill(); cr.SetSourceColor(border_color); cr.Rectangle(alloc.X, alloc.Bottom, alloc.Width, BorderWidth); cr.Fill(); grad.Dispose(); }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { if (evnt.Window != GdkWindow) { return(base.OnExposeEvent(evnt)); } Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window); if (reflect) { CairoExtensions.PushGroup(cr); } cr.Operator = Operator.Over; cr.Translate(Allocation.X + h_padding, Allocation.Y); cr.Rectangle(0, 0, Allocation.Width - h_padding, Math.Max(2 * bar_height, bar_height + bar_label_spacing + layout_height)); cr.Clip(); Pattern bar = RenderBar(Allocation.Width - 2 * h_padding, bar_height); cr.Save(); cr.SetSource(bar); cr.Paint(); cr.Restore(); if (reflect) { cr.Save(); cr.Rectangle(0, bar_height, Allocation.Width - h_padding, bar_height); cr.Clip(); var matrix = new Matrix(); matrix.InitScale(1, -1); matrix.Translate(0, -(2 * bar_height) + 1); cr.Transform(matrix); cr.SetSource(bar); var mask = new LinearGradient(0, 0, 0, bar_height); mask.AddColorStop(0.25, new Color(0, 0, 0, 0)); mask.AddColorStop(0.5, new Color(0, 0, 0, 0.125)); mask.AddColorStop(0.75, new Color(0, 0, 0, 0.4)); mask.AddColorStop(1.0, new Color(0, 0, 0, 0.7)); cr.Mask(mask); mask.Dispose(); cr.Restore(); CairoExtensions.PopGroupToSource(cr); cr.Paint(); } if (show_labels) { cr.Translate((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2, (reflect ? Allocation.Y : 0) + bar_height + bar_label_spacing); RenderLabels(cr); } bar.Dispose(); CairoExtensions.DisposeContext(cr); return(true); }
/// <summary> /// Recomposes a multi-line message. /// </summary> /// <param name="versionnumber">The version number of the new version.</param> public void RecomposeMultiLine(string versionnumber) { text = Lang.Get("versionavailable", versionnumber); Bounds.fixedHeight = GetMultilineTextHeight() / RuntimeEnv.GUIScale; Bounds.CalcWorldBounds(); offsetY = -2 * Bounds.fixedHeight; ImageSurface surface = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth, (int)Bounds.OuterHeight + shadowHeight); Context ctx = genContext(surface); double iconX = scaled(15); double iconSize = scaled(14); double iconY = (Bounds.InnerHeight - iconSize) / 2; double[] bgc = GuiStyle.DarkBrownColor; bgc[0] /= 2; bgc[1] /= 2; bgc[2] /= 2; LinearGradient gradient = new LinearGradient(0, Bounds.OuterHeightInt, 0, Bounds.OuterHeightInt + 10); gradient.AddColorStop(0, new Color(bgc[0], bgc[1], bgc[2], 1)); gradient.AddColorStop(1, new Color(bgc[0], bgc[1], bgc[2], 0)); ctx.SetSource(gradient); ctx.Rectangle(0, Bounds.OuterHeightInt, Bounds.OuterWidthInt, Bounds.OuterHeightInt + 10); ctx.Fill(); gradient.Dispose(); gradient = new LinearGradient(0, 0, Bounds.OuterWidth, 0); gradient.AddColorStop(0, new Color(backColor[0], backColor[1], backColor[2], 1)); gradient.AddColorStop(0.99, new Color(backColor[0], backColor[1], backColor[2], 1)); gradient.AddColorStop(1, new Color(backColor[0], backColor[1], backColor[2], 0)); ctx.SetSource(gradient); ctx.Rectangle(0, 0, Bounds.OuterWidthInt, Bounds.OuterHeightInt); ctx.Fill(); gradient.Dispose(); ctx.Arc(Bounds.drawX + iconX, Bounds.OuterHeight / 2, iconSize / 2 + scaled(4), 0, Math.PI * 2); ctx.SetSourceRGBA(GuiStyle.DarkBrownColor); ctx.Fill(); double fontheight = Font.GetFontExtents().Height; byte[] pngdata = api.Assets.Get("textures/gui/newversion.png").Data; BitmapExternal bitmap = (BitmapExternal)api.Render.BitmapCreateFromPng(pngdata); surface.Image(bitmap.bmp, (int)(Bounds.drawX + iconX - iconSize / 2), (int)(Bounds.drawY + iconY), (int)iconSize, (int)iconSize); bitmap.Dispose(); DrawMultilineTextAt(ctx, Bounds.drawX + iconX + 20, Bounds.drawY); generateTexture(surface, ref texture); ctx.Dispose(); surface.Dispose(); surface = new ImageSurface(Format.Argb32, (int)Bounds.OuterWidth, (int)Bounds.OuterHeight); ctx = genContext(surface); ctx.SetSourceRGBA(1, 1, 1, 0.1); ctx.Paint(); generateTexture(surface, ref hoverTexture); ctx.Dispose(); surface.Dispose(); }
public override void ComposeTextElements(Context ctx, ImageSurface surface) { if (!didInit) { SetUpMovableState(null); didInit = true; } RoundRectangle(ctx, Bounds.bgDrawX, Bounds.bgDrawY, Bounds.OuterWidth, Bounds.OuterHeight, GuiStyle.DialogBGRadius); //ctx.SetSourceRGBA(GuiStyle.DialogDefaultBgColor[0], GuiStyle.DialogDefaultBgColor[1], GuiStyle.DialogDefaultBgColor[2], 1); //ctx.FillPreserve(); LinearGradient gradient = new LinearGradient(0, 0, Bounds.InnerWidth, 0); gradient.AddColorStop(0, new Color(GuiStyle.DialogDefaultBgColor[0] * 1.4, GuiStyle.DialogDefaultBgColor[1] * 1.4, GuiStyle.DialogDefaultBgColor[2] * 1.4, 1)); gradient.AddColorStop(0.5, new Color(GuiStyle.DialogDefaultBgColor[0] * 1.1, GuiStyle.DialogDefaultBgColor[1] * 1.1, GuiStyle.DialogDefaultBgColor[2] * 1.1, 1)); gradient.AddColorStop(1, new Color(GuiStyle.DialogDefaultBgColor[0] * 1.4, GuiStyle.DialogDefaultBgColor[1] * 1.4, GuiStyle.DialogDefaultBgColor[2] * 1.4, 1)); ctx.SetSource(gradient); ctx.FillPreserve(); gradient.Dispose(); Bounds.CalcWorldBounds(); double radius = GuiStyle.DialogBGRadius; ctx.NewPath(); ctx.MoveTo(Bounds.drawX, Bounds.drawY + Bounds.InnerHeight); ctx.LineTo(Bounds.drawX, Bounds.drawY + radius); ctx.Arc(Bounds.drawX + radius, Bounds.drawY + radius, radius, 180 * GameMath.DEG2RAD, 270 * GameMath.DEG2RAD); ctx.Arc(Bounds.drawX + Bounds.OuterWidth - radius, Bounds.drawY + radius, radius, -90 * GameMath.DEG2RAD, 0 * GameMath.DEG2RAD); ctx.LineTo(Bounds.drawX + Bounds.OuterWidth, Bounds.drawY + Bounds.InnerHeight); ctx.SetSourceRGBA(GuiStyle.TitleBarColor); ctx.FillPreserve(); ctx.SetSourceRGBA(new double[] { 45 / 255.0, 35 / 255.0, 33 / 255.0, 1 }); ctx.LineWidth = 6; ctx.Stroke(); Font.SetupContext(ctx); DrawTextLineAt(ctx, text, scaled(GuiStyle.ElementToDialogPadding), (Bounds.InnerHeight - Font.GetFontExtents().Height) / 2 + scaled(2)); double crossSize = scaled(unscaledCloseIconSize); double menuSize = scaled(unscaledCloseIconSize + 2); double crossX = Bounds.drawX + Bounds.OuterWidth - crossSize - scaled(12); double iconY = Bounds.drawY + scaled(7); double crossWidth = scaled(2); double menuX = Bounds.drawX + Bounds.OuterWidth - crossSize - menuSize - scaled(20); menuIconRect = new Rectangled(Bounds.OuterWidth - crossSize - menuSize - scaled(20), scaled(6), crossSize, crossSize); closeIconRect = new Rectangled(Bounds.OuterWidth - crossSize - scaled(12), scaled(5), menuSize, menuSize); ctx.Operator = Operator.Over; ctx.SetSourceRGBA(0, 0, 0, 0.3); api.Gui.Icons.DrawCross(ctx, crossX + 2, iconY + 2, crossWidth, crossSize); ctx.Operator = Operator.Source; ctx.SetSourceRGBA(GuiStyle.DialogDefaultTextColor); api.Gui.Icons.DrawCross(ctx, crossX, iconY, crossWidth, crossSize); ctx.Operator = Operator.Over; api.Gui.Icons.Drawmenuicon_svg(ctx, (int)menuX + 2, (int)iconY + 2, (int)menuSize, (int)menuSize, new double[] { 0, 0, 0, 0.3 }); ctx.Operator = Operator.Source; api.Gui.Icons.Drawmenuicon_svg(ctx, (int)menuX, (int)iconY + 1, (int)menuSize, (int)menuSize, GuiStyle.DialogDefaultTextColor); ctx.Operator = Operator.Over; ComposeHoverIcons(); listMenu.Bounds.fixedX = (Bounds.absX + menuIconRect.X - Bounds.absX) / RuntimeEnv.GUIScale; listMenu.ComposeDynamicElements(); }