1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Drawing.Drawing2D;
|
---|
4 | using System.Drawing.Imaging;
|
---|
5 | using System.Windows.Forms;
|
---|
6 |
|
---|
7 | namespace WeifenLuo.WinFormsUI.Docking
|
---|
8 | {
|
---|
9 | internal static class DrawHelper
|
---|
10 | {
|
---|
11 | public static Point RtlTransform(Control control, Point point)
|
---|
12 | {
|
---|
13 | if (control.RightToLeft != RightToLeft.Yes)
|
---|
14 | return point;
|
---|
15 | else
|
---|
16 | return new Point(control.Right - point.X, point.Y);
|
---|
17 | }
|
---|
18 |
|
---|
19 | public static Rectangle RtlTransform(Control control, Rectangle rectangle)
|
---|
20 | {
|
---|
21 | if (control.RightToLeft != RightToLeft.Yes)
|
---|
22 | return rectangle;
|
---|
23 | else
|
---|
24 | return new Rectangle(control.ClientRectangle.Right - rectangle.Right, rectangle.Y, rectangle.Width, rectangle.Height);
|
---|
25 | }
|
---|
26 |
|
---|
27 | public static GraphicsPath GetRoundedCornerTab(GraphicsPath graphicsPath, Rectangle rect, bool upCorner)
|
---|
28 | {
|
---|
29 | if (graphicsPath == null)
|
---|
30 | graphicsPath = new GraphicsPath();
|
---|
31 | else
|
---|
32 | graphicsPath.Reset();
|
---|
33 |
|
---|
34 | int curveSize = 6;
|
---|
35 | if (upCorner)
|
---|
36 | {
|
---|
37 | graphicsPath.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Top + curveSize / 2);
|
---|
38 | graphicsPath.AddArc(new Rectangle(rect.Left, rect.Top, curveSize, curveSize), 180, 90);
|
---|
39 | graphicsPath.AddLine(rect.Left + curveSize / 2, rect.Top, rect.Right - curveSize / 2, rect.Top);
|
---|
40 | graphicsPath.AddArc(new Rectangle(rect.Right - curveSize, rect.Top, curveSize, curveSize), -90, 90);
|
---|
41 | graphicsPath.AddLine(rect.Right, rect.Top + curveSize / 2, rect.Right, rect.Bottom);
|
---|
42 | }
|
---|
43 | else
|
---|
44 | {
|
---|
45 | graphicsPath.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom - curveSize / 2);
|
---|
46 | graphicsPath.AddArc(new Rectangle(rect.Right - curveSize, rect.Bottom - curveSize, curveSize, curveSize), 0, 90);
|
---|
47 | graphicsPath.AddLine(rect.Right - curveSize / 2, rect.Bottom, rect.Left + curveSize / 2, rect.Bottom);
|
---|
48 | graphicsPath.AddArc(new Rectangle(rect.Left, rect.Bottom - curveSize, curveSize, curveSize), 90, 90);
|
---|
49 | graphicsPath.AddLine(rect.Left, rect.Bottom - curveSize / 2, rect.Left, rect.Top);
|
---|
50 | }
|
---|
51 |
|
---|
52 | return graphicsPath;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public static GraphicsPath CalculateGraphicsPathFromBitmap(Bitmap bitmap)
|
---|
56 | {
|
---|
57 | return CalculateGraphicsPathFromBitmap(bitmap, Color.Empty);
|
---|
58 | }
|
---|
59 |
|
---|
60 | // From http://edu.cnzz.cn/show_3281.html
|
---|
61 | public static GraphicsPath CalculateGraphicsPathFromBitmap(Bitmap bitmap, Color colorTransparent)
|
---|
62 | {
|
---|
63 | GraphicsPath graphicsPath = new GraphicsPath();
|
---|
64 | if (colorTransparent == Color.Empty)
|
---|
65 | colorTransparent = bitmap.GetPixel(0, 0);
|
---|
66 |
|
---|
67 | for(int row = 0; row < bitmap.Height; row ++)
|
---|
68 | {
|
---|
69 | int colOpaquePixel = 0;
|
---|
70 | for(int col = 0; col < bitmap.Width; col ++)
|
---|
71 | {
|
---|
72 | if(bitmap.GetPixel(col, row) != colorTransparent)
|
---|
73 | {
|
---|
74 | colOpaquePixel = col;
|
---|
75 | int colNext = col;
|
---|
76 | for(colNext = colOpaquePixel; colNext < bitmap.Width; colNext ++)
|
---|
77 | if(bitmap.GetPixel(colNext, row) == colorTransparent)
|
---|
78 | break;
|
---|
79 |
|
---|
80 | graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));
|
---|
81 | col = colNext;
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 | return graphicsPath;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|