/// <summary> /// 本ボタンパラメータを元に、Disabled時のパラメータを作成する /// </summary> public ButtonFace MakeDisabledFace() { ButtonFace face = new ButtonFace(this); face.ChangeSV(0.1, 0.5); return(face); }
/// <summary> /// ボタンパラメータの複製を作成する /// </summary> public ButtonFace Copy() { ButtonFace face = new ButtonFace(); face.CopyFrom(this); return(face); }
/// <summary> /// ボタンパラメータを複製する /// </summary> public void CopyFrom(ButtonFace src) { this.TextFont = src.TextFont; // this.TextPenの幅が変わらないように先にセットする this.FontRatio = src.FontRatio; this.TextPen = src.TextPen; this.TextBrush = src.TextBrush; this.UpperBrush = src.UpperBrush; this.LowerBrush = src.LowerBrush; this.TopLeftPen = src.TopLeftPen; this.BottomRightPen = src.BottomRightPen; this.TextOffset = src.TextOffset; }
/// <summary> /// ボタンを描画する /// </summary> public static void DrawButton(this Graphics g, Rectangle rect, float radius, string text, ButtonFace face) { if (String.IsNullOrEmpty(text)) { g.DrawButton(rect, radius, new string[0], face); } else { g.DrawButton(rect, radius, text.Split("\n".ToCharArray()), face); } }
/// <summary> /// テキスト属性指定ボタンを描画する /// </summary> public static void DrawButton(this Graphics g, Rectangle rect, float radius, string text, MPAttribute attr, ButtonFace face) { if (String.IsNullOrEmpty(text)) { g.DrawButton(rect, radius, new string[0], attr, face); } else { g.DrawButton(rect, radius, g.SplitXMLText(text), attr, face); } }
/// <summary> /// 本ボタンパラメータを元に、押下時のパラメータを作成する /// </summary> public ButtonFace MakePushedFace() { ButtonFace face = new ButtonFace(); face.TextFont = textFont; // face.TextPenの幅が変わらないように先にセットする face.FontRatio = fontRatio; face.TextPen = textPen; face.TextBrush = textBrush; face.UpperBrush = lowerBrush; face.LowerBrush = upperBrush; face.TopLeftPen = bottomRightPen; face.BottomRightPen = topLeftPen; if (face.TopLeftPen != null) { face.TextOffset = new PointF(textOffset.X + face.TopLeftPen.Width / 2F, textOffset.Y + face.TopLeftPen.Width / 2F); } return(face); }
/// <summary> /// ボタンを描画する /// </summary> public static void DrawButton(this Graphics g, Rectangle rect, float radius, string[] text, MPAttribute attr, ButtonFace face) { g.DrawButton(rect, radius, new string[0], face); // 文字描画 if ((text != null) && (text.Length > 0)) { // テキスト描画エリア int mgn = (int)(radius / (1.41421356F * 2F)); if (mgn < (int)face.BorderWidth * 2) { mgn = (int)face.BorderWidth * 2; } Rectangle tRect = new Rectangle(rect.X + mgn + (int)face.TextOffset.X, rect.Y + mgn + (int)face.TextOffset.Y, rect.Width - mgn * 2, rect.Height - mgn * 2); g.DrawText(text, attr, tRect); } }
/// <summary> /// ボタンを描画する /// </summary> public static void DrawButton(this Graphics g, Rectangle rect, float radius, string[] text, ButtonFace face) { if (face.TextFont == null) { face.TextFont = System.Windows.Forms.Control.DefaultFont; } // 内接長方形 Rectangle iRect = new Rectangle(rect.X, rect.Y, rect.Width, rect.Height); if ((face.TopLeftPen != null) && (face.TopLeftPen.Width > 0)) { int sz = (int)Math.Ceiling(face.TopLeftPen.Width / 2F); iRect.X += sz; iRect.Y += sz; iRect.Width -= sz; iRect.Height -= sz; } if ((face.BottomRightPen != null) && (face.BottomRightPen.Width > 0)) { int sz = (int)Math.Ceiling(face.BottomRightPen.Width / 2F); iRect.Width -= sz; iRect.Height -= sz; } // 内接長方形に合わせて角丸半径を調整 if ((int)radius > iRect.Width / 2) { radius = (float)iRect.Width / 2.0F; } if ((int)radius > iRect.Height / 2) { radius = (float)iRect.Height / 2.0F; } // パスの作成 int rr = (int)(radius * 2F); if (rr <= 0) { rr = 1; } GraphicsPath upperPath = new GraphicsPath(); upperPath.StartFigure(); upperPath.AddArc(iRect.X, iRect.Y, rr, rr, 180F, 90F); upperPath.AddArc(iRect.X + iRect.Width - rr, iRect.Y, rr, rr, -90F, 90F); upperPath.AddLine(iRect.X + iRect.Width, iRect.Y + rr / 2 + 1, iRect.X, iRect.Y + iRect.Height - rr / 2 + 1); upperPath.CloseFigure(); GraphicsPath lowerPath = new GraphicsPath(); lowerPath.StartFigure(); lowerPath.AddLine(iRect.X, iRect.Y + iRect.Height - rr / 2, iRect.X + iRect.Width, iRect.Y + rr / 2); lowerPath.AddArc(iRect.X + iRect.Width - rr, iRect.Y + iRect.Height - rr, rr, rr, 0F, 90F); lowerPath.AddArc(iRect.X, iRect.Y + iRect.Height - rr, rr, rr, 90F, 90F); lowerPath.CloseFigure(); GraphicsPath topLeftPath = new GraphicsPath(); topLeftPath.StartFigure(); topLeftPath.AddArc(iRect.X, iRect.Y + iRect.Height - rr, rr, rr, 135F, 45F); topLeftPath.AddArc(iRect.X, iRect.Y, rr, rr, 180F, 90F); topLeftPath.AddArc(iRect.X + iRect.Width - rr, iRect.Y, rr, rr, -90F, 45F); GraphicsPath bottomRightPath = new GraphicsPath(); bottomRightPath.StartFigure(); bottomRightPath.AddArc(iRect.X + iRect.Width - rr, iRect.Y, rr, rr, -45F, 45F); bottomRightPath.AddArc(iRect.X + iRect.Width - rr, iRect.Y + iRect.Height - rr, rr, rr, 0F, 90F); bottomRightPath.AddArc(iRect.X, iRect.Y + iRect.Height - rr, rr, rr, 90F, 45F); // ボタン背景描画 if (face.UpperBrush != null) { g.FillPath(face.UpperBrush, upperPath); } if (face.LowerBrush != null) { g.FillPath(face.LowerBrush, lowerPath); } if (face.TopLeftPen != null) { g.DrawPath(face.TopLeftPen, topLeftPath); } if (face.BottomRightPen != null) { g.DrawPath(face.BottomRightPen, bottomRightPath); } upperPath.Dispose(); lowerPath.Dispose(); topLeftPath.Dispose(); bottomRightPath.Dispose(); // 文字描画 if ((text != null) && (text.Length > 0)) { // テキスト描画エリア int mgn = (int)(radius / (1.41421356F * 2F)); if (mgn < (int)face.BorderWidth * 2) { mgn = (int)face.BorderWidth * 2; } Rectangle tRect = new Rectangle(rect.X + mgn + (int)face.TextOffset.X, rect.Y + mgn + (int)face.TextOffset.Y, rect.Width - mgn * 2, rect.Height - mgn * 2); g.DrawText(text, face.TextFont, face.TextPen, face.TextBrush, tRect, TextHPosition.CenterShrink, TextVPosition.Proportional, 1.0F, face.FontRatio); } }
/// <summary> /// コピーコンストラクタ /// </summary> public ButtonFace(ButtonFace face) { CopyFrom(face); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.SmoothingMode = SmoothingMode.AntiAlias; Color backColor; if (nState <= 0) { // 通常のボタン色 //if(this.UseVisualStyleBackColor) { // backColor = DefaultButtonColor; //} else { backColor = this.BackColor; //} } else { // マルチステートボタン色 if (State <= 0) { backColor = StateColor[0]; } else if (State < nState) { backColor = StateColor[State]; } else { backColor = StateColor[nState - 1]; } } ButtonFace face = new ButtonFace(this.Font, backColor, this.ShadowStrength, this.BorderWidth); if (!this.AutoForeColor) { face.SetTextColor(this.ForeColor); } if (this.UseEnabledColor || this.Enabled) { if ((ButtonStatus == ButtonStatusCode.Hover) && (HoverColor.A > 0)) { face.SetBorderColor(HoverColor); } else if (ButtonStatus == ButtonStatusCode.Clicked) { ButtonFace xface = face.MakePushedFace(); face.Dispose(); face = xface; } else if (this.Focused && (FocusColor.A > 0)) { face.SetBorderColor(FocusColor, ColorUtil.DarkColor(FocusColor, 0.2)); } } else { ButtonFace xface = face.MakeDisabledFace(); face.Dispose(); face = xface; } if (TextAttribute == null) { g.DrawButton(this.ClientRectangle, Radius, this.Text, face); } else { g.DrawButton(this.ClientRectangle, Radius, this.Text, TextAttribute, face); } face.Dispose(); }