Dreamine.UI.WinForms 1.0.1
Dreamine.UI.WinForms 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
DreamineDrawHelper.cs
이 파일의 문서화 페이지로 가기
1using System.Drawing;
2using System.Drawing.Drawing2D;
3
5
14public static class DreamineDrawHelper
15{
48 public static GraphicsPath RoundedRect(RectangleF r, float radius)
49 {
50 if (radius <= 0) { var p = new GraphicsPath(); p.AddRectangle(r); return p; }
51 float d = radius * 2f;
52 var path = new GraphicsPath();
53 path.AddArc(r.X, r.Y, d, d, 180, 90);
54 path.AddArc(r.Right - d, r.Y, d, d, 270, 90);
55 path.AddArc(r.Right - d, r.Bottom - d, d, d, 0, 90);
56 path.AddArc(r.X, r.Bottom - d, d, d, 90, 90);
57 path.CloseFigure();
58 return path;
59 }
60
93 public static GraphicsPath RoundedRect(Rectangle r, float radius)
94 => RoundedRect((RectangleF)r, radius);
95
144 public static void FillRoundedRect(Graphics g, Brush fill, Pen? border,
145 Rectangle rect, float radius)
146 {
147 g.SmoothingMode = SmoothingMode.AntiAlias;
148 using var path = RoundedRect(rect, radius);
149 g.FillPath(fill, path);
150 if (border != null) g.DrawPath(border, path);
151 }
152
209 public static void FillRoundedGradient(Graphics g, Color top, Color bottom, Pen? border,
210 Rectangle rect, float radius)
211 {
212 if (rect.Width <= 0 || rect.Height <= 0) return;
213 g.SmoothingMode = SmoothingMode.AntiAlias;
214 using var path = RoundedRect(rect, radius);
215 using var brush = new LinearGradientBrush(rect, top, bottom, LinearGradientMode.Vertical);
216 g.FillPath(brush, path);
217 if (border != null) g.DrawPath(border, path);
218 }
219
260 public static void DrawShineOverlay(Graphics g, Color shineColor, Rectangle rect, float radius)
261 {
262 if (rect.Width <= 0 || rect.Height <= 0) return;
263 var shineRect = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height / 2);
264 if (shineRect.Width <= 0 || shineRect.Height <= 0) return;
265 using var path = RoundedRect(shineRect, radius * 0.7f);
266 var c1 = Color.FromArgb(80, shineColor);
267 var c2 = Color.FromArgb(0, shineColor);
268 using var brush = new LinearGradientBrush(shineRect, c1, c2, LinearGradientMode.Vertical);
269 g.FillPath(brush, path);
270 }
271
320 public static void DrawCenteredText(Graphics g, string text, Font font, Color color, Rectangle rect)
321 {
322 using var brush = new SolidBrush(color);
323 var sf = new StringFormat
324 {
325 Alignment = StringAlignment.Center,
326 LineAlignment = StringAlignment.Center,
327 Trimming = StringTrimming.EllipsisCharacter
328 };
329 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
330 g.DrawString(text, font, brush, rect, sf);
331 }
332
373 public static Color Blend(Color base_, Color overlay, float alpha)
374 {
375 int r = (int)(base_.R + (overlay.R - base_.R) * alpha);
376 int g_ = (int)(base_.G + (overlay.G - base_.G) * alpha);
377 int b = (int)(base_.B + (overlay.B - base_.B) * alpha);
378 return Color.FromArgb(255,
379 Math.Clamp(r, 0, 255),
380 Math.Clamp(g_, 0, 255),
381 Math.Clamp(b, 0, 255));
382 }
383}
static void FillRoundedRect(Graphics g, Brush fill, Pen? border, Rectangle rect, float radius)
static GraphicsPath RoundedRect(Rectangle r, float radius)
static GraphicsPath RoundedRect(RectangleF r, float radius)
static Color Blend(Color base_, Color overlay, float alpha)
static void FillRoundedGradient(Graphics g, Color top, Color bottom, Pen? border, Rectangle rect, float radius)
static void DrawCenteredText(Graphics g, string text, Font font, Color color, Rectangle rect)
static void DrawShineOverlay(Graphics g, Color shineColor, Rectangle rect, float radius)