protected override void OnPaintBackground(PaintEventArgs pevent) { // 这里调用父类,主要用来处理透明色(圆角之后的问题) base.OnPaintBackground(pevent); if (circleButton) { this.Height = this.Width; this.radius = this.Height / 2; this.radiusMode = Forms.RadiusMode.All; } Color c1 = Color.Empty; if (this.status == ButtonStatus.Default) { c1 = this.BorderColor; } else if (this.status == ButtonStatus.Hover) { c1 = this.BorderHoverColor; } else if (this.status == ButtonStatus.Press) { c1 = this.BorderPressColor; } if (this.status == ButtonStatus.Default || this.HoverBackColor == null || this.HoverBackColor.FromColor.IsEmpty) { RadiusDrawable.DrawRadius(pevent.Graphics, this.ClientRectangle, RadiusMode, this.Radius, this.BackgroundColor.FromColor, this.BackgroundColor.ToColor, this.BackgroundColor.GradientMode, c1, this.borderWidth); } else { RadiusDrawable.DrawRadius(pevent.Graphics, this.ClientRectangle, RadiusMode, this.Radius, this.HoverBackColor.FromColor, this.HoverBackColor.ToColor, this.HoverBackColor.GradientMode, c1, this.borderWidth); } }
public static void DrawRadius(Graphics g, System.Drawing.Rectangle rect, RadiusMode radiusMode, int radius, Color c1, Color c2, GradientMode linearGradientMode, Color borderColor, int borderWidth) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; using (System.Drawing.Drawing2D.GraphicsPath graphPath = GetPath(rect, radiusMode, radius)) { if (rect.Width == 0) { rect.Width += 1; } if (rect.Height == 0) { rect.Height += 1; } System.Drawing.Drawing2D.LinearGradientBrush brush; if (linearGradientMode == GradientMode.None) { brush = new System.Drawing.Drawing2D.LinearGradientBrush(rect, c1, c1, System.Drawing.Drawing2D.LinearGradientMode.Vertical); } else { brush = new System.Drawing.Drawing2D.LinearGradientBrush(rect, c1, c2.IsEmpty ? c1 : c2, ((System.Drawing.Drawing2D.LinearGradientMode)linearGradientMode)); } if (radiusMode != RadiusMode.None && radius > 0) { g.FillPath(brush, graphPath); using (System.Drawing.Pen borderPen = new System.Drawing.Pen(borderColor, borderWidth)) { g.DrawPath(borderPen, graphPath); borderPen.Dispose(); } } else { g.FillRectangle(brush, rect); if (borderWidth > 0 && !borderColor.IsEmpty) { ControlPaint.DrawBorder(g, rect, borderColor, ButtonBorderStyle.Solid); } } brush.Dispose(); } }
private static int GetAdjustedCurve(System.Drawing.Rectangle rect, RadiusMode radiusMode, int radius) { int curve = 0; if (radiusMode != RadiusMode.None) { if (radius > (rect.Width / 2)) { curve = DoubleToInt(rect.Width / 2); } else { curve = radius; } if (curve > (rect.Height / 2)) { curve = DoubleToInt(rect.Height / 2); } } return(curve); }
private static System.Drawing.Drawing2D.GraphicsPath GetPath(System.Drawing.Rectangle rect, RadiusMode radiusMode, int radius) { System.Drawing.Drawing2D.GraphicsPath graphPath = new System.Drawing.Drawing2D.GraphicsPath(); try { int curve = 0; int offset = 0; curve = GetAdjustedCurve(rect, radiusMode, radius); if (curve == 0) { graphPath.AddRectangle(System.Drawing.Rectangle.Inflate(rect, -offset, -offset)); } else { int rectWidth = rect.Width - 1 - offset; int rectHeight = rect.Height - 1 - offset; int curveWidth = 1; if ((radiusMode & RadiusMode.TopRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth + rect.X, offset + rect.Y, curveWidth, curveWidth, 270, 90); if ((radiusMode & RadiusMode.BottomRight) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(rectWidth - curveWidth + rect.X, rectHeight - curveWidth + rect.Y, curveWidth, curveWidth, 0, 90); if ((radiusMode & RadiusMode.BottomLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset + rect.X, rectHeight - curveWidth + rect.Y, curveWidth, curveWidth, 90, 90); if ((radiusMode & RadiusMode.TopLeft) != 0) { curveWidth = (curve * 2); } else { curveWidth = 1; } graphPath.AddArc(offset + rect.X, offset + rect.Y, curveWidth, curveWidth, 180, 90); graphPath.CloseFigure(); } } catch (System.Exception) { graphPath.AddRectangle(rect); } return(graphPath); }
public static void DrawRadius(Graphics graphics, Rectangle rect, RadiusMode radiusMode, int radius, Color backColor, Color backColorGradient, GradientMode gradient, object color, int width) { throw new NotImplementedException(); }
private async Task ProcessLocation(long radiusId, RadiusMode mode, JsonZKill.Killmail kill, RadiusGroup @group, string groupName) { var isUrlOnly = group.FeedUrlsOnly; var radius = group.Radius; var minimumValue = group.MinimumValue; if (radiusId <= 0) { await LogHelper.LogError("Radius feed must have systemId, constId or regionId defined!", Category); return; } var km = new KillDataEntry(); await km.Refresh(Reason, kill); //validity check if (minimumValue > 0 && km.value < minimumValue) { return; } var routeLength = 0; JsonClasses.ConstellationData rConst = null; JsonClasses.RegionData rRegion; var srcSystem = mode == RadiusMode.Range ? await APIHelper.ESIAPI.GetSystemData(Reason, radiusId) : null; if (radiusId == km.systemId) { //right there rConst = km.rSystem.constellation_id == 0 ? null : await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id); rRegion = rConst?.region_id == null || rConst.region_id == 0 ? null : await APIHelper.ESIAPI.GetRegionData(Reason, rConst.region_id); } else { if (radius == 0 || km.isUnreachableSystem || (srcSystem?.IsUnreachable() ?? false)) //Thera WH Abyss { return; } switch (mode) { case RadiusMode.Range: var route = await APIHelper.ESIAPI.GetRawRoute(Reason, radiusId, km.systemId); if (string.IsNullOrEmpty(route)) { return; } JArray data; try { data = JArray.Parse(route); } catch (Exception ex) { await LogHelper.LogEx("Route parse: " + ex.Message, ex, Category); return; } routeLength = data.Count - 1; //not in range if (routeLength > radius) { return; } var rSystemName = radiusId > 0 ? srcSystem?.name ?? LM.Get("Unknown") : LM.Get("Unknown"); km.dic.Add("{radiusSystem}", rSystemName); km.dic.Add("{radiusJumps}", routeLength.ToString()); break; case RadiusMode.Constellation: if (km.rSystem.constellation_id != radiusId) { return; } break; case RadiusMode.Region: rConst = await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id); if (rConst == null || rConst.region_id != radiusId) { return; } break; } rConst = rConst ?? await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id); rRegion = await APIHelper.ESIAPI.GetRegionData(Reason, rConst.region_id); } //var rSystemName = rSystem?.name ?? LM.Get("Unknown"); km.dic.Add("{isRangeMode}", (mode == RadiusMode.Range).ToString()); km.dic.Add("{isConstMode}", (mode == RadiusMode.Constellation).ToString()); km.dic.Add("{isRegionMode}", (mode == RadiusMode.Region).ToString()); km.dic.Add("{constName}", rConst?.name); km.dic.Add("{regionName}", rRegion?.name); var template = isUrlOnly ? null : await TemplateHelper.GetTemplatedMessage(MessageTemplateType.KillMailRadius, km.dic); foreach (var channel in group.RadiusChannels) { if (isUrlOnly) { await APIHelper.DiscordAPI.SendMessageAsync(channel, kill.zkb.url); } else { if (template != null) { await APIHelper.DiscordAPI.SendMessageAsync(channel, group.ShowGroupName?groupName : " ", template).ConfigureAwait(false); } else { var jumpsText = routeLength > 0 ? $"{routeLength} {LM.Get("From")} {srcSystem?.name}" : $"{LM.Get("InSmall")} {km.sysName} ({km.systemSecurityStatus})"; await APIHelper.DiscordAPI.SendEmbedKillMessage(channel, new Color(0x989898), km, jumpsText, group.ShowGroupName?groupName : " "); } } } await LogHelper.LogInfo($"Posting Radius Kill: {kill.killmail_id} Value: {km.value:n0} ISK", Category); }
/// <summary> /// 绘制一个带有圆角背景颜色的文字块 /// </summary> /// <param name="g"></param> /// <param name="rect"></param> /// <param name="font"></param> /// <param name="text"></param> /// <param name="foreColor"></param> /// <param name="backColor"></param> /// <param name="raidusMode"></param> /// <param name="radius"></param> public static void DrawString(Graphics g, Rectangle rect, Font font, string text, Color foreColor, Color backColor, TextAlignment align, RadiusMode raidusMode, int radius) { // 先绘制圆角 RadiusDrawable.DrawRadius(g, rect, raidusMode, radius, backColor, Color.Empty, GradientMode.None, Color.Empty, 0); DrawString(g, rect, font, text, foreColor, align); }