Sprite.Method.02.Render.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. using System.Windows.Forms;
  5. using Microsoft.Drawing;
  6. using Microsoft.Windows.Forms.Layout;
  7. namespace Microsoft.Windows.Forms
  8. {
  9. partial class Sprite
  10. {
  11. //渲染时传递进来的临时变量
  12. private Rectangle m_BackColorRect;
  13. private Rectangle m_BackgroundImageRect;
  14. private Rectangle m_BackgroundImage9Rect;
  15. private Rectangle m_TextImageRect;
  16. private Rectangle m_StringRect;
  17. private Rectangle m_BorderColorRect;
  18. //渲染文本核心方法
  19. private void RenderTextCore(LayoutData layout)
  20. {
  21. layout.DoLayout();//执行布局
  22. this.CurrentTextPreferredRect = layout.OutTextBounds;//保存文本区域矩形
  23. bool needRotate = !(Single.IsNaN(this.m_TextRotateAngle) || this.m_TextRotateAngle % 360f == 0f);//是否需要旋转
  24. Rectangle textRect = needRotate ? RenderEngine.RotateRect(this.m_Graphics, this.CurrentTextPreferredRect, this.m_TextRotateAngle, false) : this.CurrentTextPreferredRect; //新绘图区域(如果旋转则为旋转后的区域)
  25. //绘制阴影或描边
  26. if (this.m_TextShadowShapeStyle != 0)
  27. {
  28. using (new SmoothingModeGraphics(this.m_Graphics, SmoothingMode.AntiAlias))
  29. {
  30. using (GraphicsPath textPath = new GraphicsPath())
  31. {
  32. //添加文本
  33. textPath.AddString(this.m_Text, this.m_Font.FontFamily, (int)this.m_Font.Style, this.m_Graphics.DpiY * this.m_Font.SizeInPoints / 72f, textRect, layout.CurrentStringFormat);
  34. //绘制阴影和阴影描边
  35. if (((this.m_TextShadowShapeStyle & ShadowShapeStyle.Shadow) != 0) || ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfShadow) != 0 && this.m_TextShapeOfShadowWidth > 0f))
  36. {
  37. using (GraphicsPath shadowPath = textPath.Clone() as GraphicsPath)
  38. {
  39. using (Matrix shadowMatrix = new Matrix(1, 0, 0, 1, this.m_TextShadowMatrixOffset.X, this.m_TextShadowMatrixOffset.Y))
  40. {
  41. shadowPath.Transform(shadowMatrix);
  42. }
  43. //绘制阴影
  44. if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.Shadow) != 0)
  45. {
  46. using (Brush shadowBrush = new SolidBrush(this.m_TextShadowColor))
  47. {
  48. this.m_Graphics.FillPath(shadowBrush, shadowPath);
  49. }
  50. }
  51. //阴影描边
  52. if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfShadow) != 0 && this.m_TextShapeOfShadowWidth > 0f)
  53. {
  54. using (Pen shapeOfShadowPen = new Pen(this.m_TextShapeOfShadowColor, this.m_TextShapeOfShadowWidth))
  55. {
  56. this.m_Graphics.DrawPath(shapeOfShadowPen, shadowPath);
  57. }
  58. }
  59. }
  60. }
  61. //绘制文本
  62. using (Brush textBrush = new SolidBrush(this.CurrentForeColor))
  63. {
  64. this.m_Graphics.FillPath(textBrush, textPath);
  65. }
  66. //文本描边
  67. if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfText) != 0 && this.m_TextShapeOfTextWidth > 0f)
  68. {
  69. using (Pen shapeOfTextPen = new Pen(this.m_TextShapeOfTextColor, this.m_TextShapeOfTextWidth))
  70. {
  71. this.m_Graphics.DrawPath(shapeOfTextPen, textPath);
  72. }
  73. }
  74. }
  75. }
  76. }
  77. else
  78. {
  79. using (new TextRenderingHintGraphics(this.m_Graphics, this.m_TextRenderingHint))
  80. {
  81. using (Brush textBrush = new SolidBrush(this.CurrentForeColor))
  82. {
  83. this.m_Graphics.DrawString(this.m_Text, this.m_Font, textBrush, textRect, layout.CurrentStringFormat);
  84. }
  85. }
  86. }
  87. //恢复旋转
  88. if (needRotate)
  89. this.m_Graphics.ResetTransform();
  90. }
  91. //渲染图片核心方法
  92. private void RenderImageCore(LayoutData layout)
  93. {
  94. layout.DoLayout();//执行布局
  95. this.CurrentImagePreferredRect = layout.OutImageBounds;//保存图片区域矩形
  96. bool needRotate = !(float.IsNaN(this.m_ImageRotateAngle) || this.m_ImageRotateAngle % 360f == 0f);//是否需要旋转
  97. Rectangle imageBounds = needRotate ? RenderEngine.RotateRect(this.m_Graphics, this.CurrentImagePreferredRect, this.m_ImageRotateAngle, false) : this.CurrentImagePreferredRect;//新绘图区域(如果旋转则为旋转后的区域)
  98. //开始绘制
  99. if (this.m_State == State.Disabled && this.m_ImageGrayOnDisabled)
  100. {
  101. using (Image grayImg = RenderEngine.GetGrayImage(this.CurrentImage))
  102. {
  103. this.m_Graphics.DrawImage(grayImg, imageBounds);
  104. }
  105. }
  106. else
  107. {
  108. this.m_Graphics.DrawImage(this.CurrentImage, imageBounds);
  109. }
  110. //恢复旋转
  111. if (needRotate)
  112. this.m_Graphics.ResetTransform();
  113. }
  114. /// <summary>
  115. /// 创建区域
  116. /// </summary>
  117. /// <param name="rect">区域位置和大小</param>
  118. /// <returns>区域</returns>
  119. public Region CreateRegion(Rectangle rect)
  120. {
  121. if (this.m_RoundStyle == RoundStyle.None)//直角
  122. {
  123. if ((this.m_RoundCornerStyle & CornerStyle.Horizontal) != 0)
  124. rect.Inflate(2, 0);
  125. else if ((this.m_RoundCornerStyle & CornerStyle.Vertical) != 0)
  126. rect.Inflate(0, 2);
  127. else
  128. return null;
  129. }
  130. else//有圆角
  131. {
  132. if ((this.m_RoundCornerStyle & CornerStyle.Horizontal) != 0)
  133. rect.Inflate(5, 1);
  134. else if ((this.m_RoundCornerStyle & CornerStyle.Vertical) != 0)
  135. rect.Inflate(1, 5);
  136. else
  137. return null;
  138. }
  139. using (GraphicsPath path = RenderEngine.CreateGraphicsPath(rect, this.m_RoundCornerStyle, this.m_RoundStyle, this.m_RoundRadius, false))
  140. {
  141. return new Region(path);
  142. }
  143. }
  144. /// <summary>
  145. /// 渲染背景色
  146. /// </summary>
  147. /// <param name="rect">渲染区域</param>
  148. public void RenderBackColor(Rectangle rect)
  149. {
  150. this.m_BackColorRect = rect;
  151. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackColorRect))
  152. return;
  153. using (Brush brush = RenderEngine.CreateBrush(this.CurrentBackColorBrushRect, this.CurrentBackColor, this.m_BackColorPos1, this.m_BackColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_BackColorBlendStyle))
  154. {
  155. if (float.IsNaN(this.m_RoundRadius) || this.m_RoundRadius <= 0f)
  156. this.m_Graphics.FillRectangle(brush, this.CurrentBackColorPathRect);
  157. else
  158. this.m_Graphics.FillPath(brush, this.CurrentBackColorPath);
  159. }
  160. }
  161. /// <summary>
  162. /// 渲染背景色特效
  163. /// </summary>
  164. public void RenderBackColorAero()
  165. {
  166. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackColorRect))
  167. return;
  168. //绘制模糊效果
  169. if ((this.m_BackColorAeroStyle & AeroStyle.Blur) != 0)
  170. {
  171. Rectangle blurRect = this.CurrentBackColorPathRect;
  172. int blurWidth = 0;
  173. int blurHeight = 0;
  174. switch (this.m_BackColorAlign)
  175. {
  176. case TabAlignment.Top:
  177. blurHeight = (int)(this.CurrentBackColorPathRect.Height * this.m_BackColorAeroPos);
  178. blurRect.Height = blurHeight;
  179. break;
  180. case TabAlignment.Bottom:
  181. blurHeight = (int)(this.CurrentBackColorPathRect.Height * this.m_BackColorAeroPos);
  182. blurRect.Y = blurRect.Bottom - blurHeight;
  183. blurRect.Height = blurHeight;
  184. break;
  185. case TabAlignment.Left:
  186. blurWidth = (int)(this.CurrentBackColorPathRect.Width * this.m_BackColorAeroPos);
  187. blurRect.Width = blurWidth;
  188. break;
  189. case TabAlignment.Right:
  190. blurWidth = (int)(this.CurrentBackColorPathRect.Width * this.m_BackColorAeroPos);
  191. blurRect.X = blurRect.Right - blurWidth;
  192. blurRect.Width = blurWidth;
  193. break;
  194. default://同Top
  195. blurHeight = (int)(this.CurrentBackColorPathRect.Height * this.m_BackColorAeroPos);
  196. blurRect.Height = blurHeight;
  197. break;
  198. }
  199. //绘制
  200. RenderEngine.DrawAeroBlur(this.m_Graphics, blurRect, this.m_BackColorAeroBlurColor);
  201. }
  202. //绘制玻璃效果
  203. if ((this.m_BackColorAeroStyle & AeroStyle.Glass) != 0)
  204. {
  205. Rectangle glassRect = this.CurrentBackColorPathRect;
  206. int blurWidth = 0;
  207. int blurHeight = 0;
  208. switch (this.m_BackColorAlign)
  209. {
  210. case TabAlignment.Top:
  211. blurHeight = (int)(glassRect.Height * this.BackColorAeroPos);
  212. glassRect.Y += blurHeight;//底部
  213. glassRect.Height = (glassRect.Height - blurHeight) * 2;//圆的一半
  214. break;
  215. case TabAlignment.Bottom:
  216. blurHeight = (int)(glassRect.Height * this.BackColorAeroPos);
  217. glassRect.Y -= (glassRect.Height - blurHeight);//顶部
  218. glassRect.Height = (this.CurrentBackColorPathRect.Height - blurHeight) * 2;//圆的一半
  219. break;
  220. case TabAlignment.Left:
  221. blurWidth = (int)(glassRect.Width * this.BackColorAeroPos);
  222. glassRect.X += blurWidth;//右侧
  223. glassRect.Width = (glassRect.Width - blurWidth) * 2;//圆的一半
  224. break;
  225. case TabAlignment.Right:
  226. blurWidth = (int)(glassRect.Width * this.BackColorAeroPos);
  227. glassRect.X -= (glassRect.Width - blurWidth);//左侧
  228. glassRect.Width = (glassRect.Width - blurWidth) * 2;//圆的一般
  229. break;
  230. default://同Top
  231. blurHeight = (int)(glassRect.Height * this.BackColorAeroPos);
  232. glassRect.Y += blurHeight;//底部
  233. glassRect.Height = (glassRect.Height - blurHeight) * 2;//圆的一半
  234. break;
  235. }
  236. //绘制
  237. RenderEngine.DrawAeroGlass(this.m_Graphics, glassRect, this.BackColorAeroGlassCenterColor, this.BackColorAeroGlassSurroundColor);
  238. }
  239. }
  240. /// <summary>
  241. /// 渲染背景图
  242. /// </summary>
  243. /// <param name="rect">渲染区域</param>
  244. public void RenderBackgroundImage(Rectangle rect)
  245. {
  246. this.m_BackgroundImageRect = rect;
  247. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackgroundImageRect) || this.CurrentBackgroundImage == null)
  248. return;
  249. if (this.m_State == State.Disabled && this.m_BackgroundImageGrayOnDisabled)//灰色图片
  250. {
  251. using (Image img = RenderEngine.GetGrayImage(this.CurrentBackgroundImage))
  252. {
  253. RenderEngine.DrawBackgroundImage(this.m_Graphics, img, this.CurrentBackgroundImageRect, this.m_BackgroundImageLayout);
  254. }
  255. }
  256. else//原图
  257. {
  258. RenderEngine.DrawBackgroundImage(this.m_Graphics, this.CurrentBackgroundImage, this.CurrentBackgroundImageRect, this.m_BackgroundImageLayout);
  259. }
  260. }
  261. /// <summary>
  262. /// 渲染九宫格背景图
  263. /// </summary>
  264. /// <param name="rect">渲染区域</param>
  265. public void RenderBackgroundImage9(Rectangle rect)
  266. {
  267. this.m_BackgroundImage9Rect = rect;
  268. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackgroundImage9Rect) || this.CurrentBackgroundImage9 == null)
  269. return;
  270. if (this.m_State == State.Disabled && this.m_BackgroundImage9GrayOnDisabled)//灰色图片
  271. {
  272. using (Image img = RenderEngine.GetGrayImage(this.CurrentBackgroundImage9))
  273. {
  274. RenderEngine.DrawBackgroundImage9(this.m_Graphics, img, this.CurrentBackgroundImage9Rect, this.m_BackgroundImage9Padding.Left, this.m_BackgroundImage9Padding.Top, this.m_BackgroundImage9Padding.Right, this.m_BackgroundImage9Padding.Bottom, this.m_BackgroundImage9Layout);
  275. }
  276. }
  277. else//原图
  278. {
  279. RenderEngine.DrawBackgroundImage9(this.m_Graphics, this.CurrentBackgroundImage9, this.CurrentBackgroundImage9Rect, this.m_BackgroundImage9Padding.Left, this.m_BackgroundImage9Padding.Top, this.m_BackgroundImage9Padding.Right, this.m_BackgroundImage9Padding.Bottom, this.m_BackgroundImage9Layout);
  280. }
  281. }
  282. /// <summary>
  283. /// 渲染文本和图片
  284. /// </summary>
  285. /// <param name="rect">渲染区域</param>
  286. public void RenderTextAndImage(Rectangle rect)
  287. {
  288. this.m_TextImageRect = rect;
  289. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_TextImageRect) || ((this.m_Text == null || this.m_Text.Length <= 0) && this.m_Image == null))
  290. return;
  291. using (LayoutData layout = new LayoutData())
  292. {
  293. layout.Graphics = this.m_Graphics;
  294. layout.ClientRectangle = this.CurrentTextImageClientRect;
  295. layout.Padding = this.m_Padding;
  296. layout.TextImageRelation = this.m_TextImageRelation;
  297. layout.RightToLeft = this.m_RightToLeft;
  298. layout.ImageSize = (this.CurrentImage == null ? Size.Empty : this.m_ImageSize);
  299. layout.ImageAlign = this.m_ImageAlign;
  300. layout.ImageOffset = this.m_ImageOffset;
  301. layout.Text = this.m_Text;
  302. layout.Font = this.m_Font;
  303. layout.TextAlign = this.m_TextAlign;
  304. layout.TextOffset = this.m_TextOffset;
  305. if (this.CurrentImage != null)
  306. this.RenderImageCore(layout);
  307. if (this.Text != null && this.Text.Length > 0)
  308. this.RenderTextCore(layout);
  309. }
  310. }
  311. /// <summary>
  312. /// 渲染文本
  313. /// </summary>
  314. /// <param name="rect">渲染区域</param>
  315. public void RenderText(Rectangle rect)
  316. {
  317. this.m_TextImageRect = rect;
  318. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_TextImageRect) || this.Text == null || this.Text.Length <= 0)
  319. return;
  320. using (LayoutData layout = new LayoutData())
  321. {
  322. layout.Graphics = this.m_Graphics;
  323. layout.ClientRectangle = this.CurrentTextImageClientRect;
  324. layout.Padding = this.m_Padding;
  325. layout.TextImageRelation = this.m_TextImageRelation;
  326. layout.RightToLeft = this.m_RightToLeft;
  327. layout.Text = this.m_Text;
  328. layout.Font = this.m_Font;
  329. layout.TextAlign = this.m_TextAlign;
  330. layout.TextOffset = this.m_TextOffset;
  331. this.RenderTextCore(layout);
  332. }
  333. }
  334. /// <summary>
  335. /// 渲染图片
  336. /// </summary>
  337. /// <param name="rect">渲染区域</param>
  338. public void RenderImage(Rectangle rect)
  339. {
  340. this.m_TextImageRect = rect;
  341. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_TextImageRect) || this.CurrentImage == null)
  342. return;
  343. using (LayoutData layout = new LayoutData())
  344. {
  345. layout.Graphics = this.m_Graphics;
  346. layout.ClientRectangle = this.CurrentTextImageClientRect;
  347. layout.Padding = this.m_Padding;
  348. layout.TextImageRelation = this.m_TextImageRelation;
  349. layout.RightToLeft = this.m_RightToLeft;
  350. layout.ImageSize = (this.CurrentImage == null ? Size.Empty : this.m_ImageSize);
  351. layout.ImageAlign = this.m_ImageAlign;
  352. layout.ImageOffset = this.m_ImageOffset;
  353. this.RenderImageCore(layout);
  354. }
  355. }
  356. /// <summary>
  357. /// 准备渲染字符串路径,返回字符串路径的大小(测量字符串路径大小,画布无限制)
  358. /// </summary>
  359. /// <returns>字符串路径大小</returns>
  360. public Size BeginRenderString()
  361. {
  362. if (this.m_State == State.Hidden || this.Text == null || this.Text.Length <= 0)
  363. return Size.Empty;
  364. Size strSize;
  365. this.m_CurrentStringPathRect = RenderEngine.BeginDrawString(this.m_Graphics, this.Text, this.Font, out strSize);
  366. this.m_CurrentStringSize = strSize;
  367. return this.CurrentStringPathRect.Size;
  368. }
  369. /// <summary>
  370. /// 准备渲染字符串路径,返回字符串路径的大小(测量字符串路径大小,画布有限制)
  371. /// </summary>
  372. /// <param name="rect">测量时,画布限制.与绘制区域无关</param>
  373. /// <returns>字符串路径大小</returns>
  374. public Size BeginRenderString(Rectangle rect)
  375. {
  376. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect) || this.Text == null || this.Text.Length <= 0)
  377. return Size.Empty;
  378. Size strSize;
  379. this.m_CurrentStringPathRect = RenderEngine.BeginDrawString(this.m_Graphics, this.Text, this.Font, rect, out strSize);
  380. this.m_CurrentStringSize = strSize;
  381. return this.CurrentStringPathRect.Size;
  382. }
  383. /// <summary>
  384. /// 正式渲染字符串路径
  385. /// </summary>
  386. /// <param name="rect">渲染区域</param>
  387. public void EndRenderString(Rectangle rect)
  388. {
  389. this.m_StringRect = rect;
  390. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_StringRect) || this.Text == null || this.Text.Length <= 0)
  391. return;
  392. using (Brush brush = new SolidBrush(this.CurrentForeColor))
  393. {
  394. RenderEngine.EndDrawString(this.m_Graphics, this.m_Text, this.m_Font, brush, this.CurrentStringRect, this.m_TextAlign, this.CurrentStringPathRect, this.CurrentStringSize);
  395. }
  396. }
  397. /// <summary>
  398. /// 渲染字符串路径
  399. /// </summary>
  400. /// <param name="rect">渲染区域</param>
  401. public void RenderString(Rectangle rect)
  402. {
  403. this.BeginRenderString(rect);
  404. this.EndRenderString(rect);
  405. }
  406. /// <summary>
  407. /// 渲染边框颜色(RoundStyle圆角样式,BorderStyle确定绘制哪个边,BlendStyle混合方式)
  408. /// </summary>
  409. /// <param name="rect">渲染区域</param>
  410. public void RenderBorder(Rectangle rect)
  411. {
  412. this.m_BorderColorRect = rect;
  413. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BorderColorRect))
  414. return;
  415. //重置剪切区
  416. this.m_Graphics.SetClip(this.m_GraphicsClip, CombineMode.Replace);
  417. //绘制内边框
  418. if (this.m_InnerBorderVisibleStyle != BorderVisibleStyle.None)
  419. {
  420. using (Brush brush = RenderEngine.CreateBrush(this.CurrentInnerBorderBrushRect, this.CurrentInnerBorderColor, this.m_InnerBorderColorPos1, this.m_InnerBorderColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_InnerBorderBlendStyle))
  421. {
  422. using (Pen pen = RenderEngine.CreatePen(brush, 1, this.m_InnerBorderDashStyle, this.m_InnerBorderDashPattern, this.m_InnerBorderDashCap, this.m_InnerBorderDashOffset))
  423. {
  424. RenderEngine.DrawBorder(this.m_Graphics, pen, this.CurrentInnerBorderPathRect, this.m_InnerBorderVisibleStyle, this.m_RoundCornerStyle, this.m_RoundStyle, this.m_RoundRadius, false);
  425. }
  426. }
  427. }
  428. //绘制边框
  429. if (this.m_BorderVisibleStyle != BorderVisibleStyle.None)
  430. {
  431. using (Brush brush = RenderEngine.CreateBrush(this.CurrentBorderBrushRect, this.CurrentBorderColor, this.m_BorderColorPos1, this.m_BorderColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_BorderBlendStyle))
  432. {
  433. using (Pen pen = RenderEngine.CreatePen(brush, 1, this.m_BorderDashStyle, this.m_BorderDashPattern, this.m_BorderDashCap, this.m_BorderDashOffset))
  434. {
  435. RenderEngine.DrawBorder(this.m_Graphics, pen, this.CurrentBorderPathRect, this.m_BorderVisibleStyle, this.m_RoundCornerStyle, this.m_RoundStyle, this.m_RoundRadius, false);
  436. }
  437. }
  438. }
  439. }
  440. /// <summary>
  441. /// 渲染线段
  442. /// </summary>
  443. /// <param name="pt1">起点</param>
  444. /// <param name="pt2">终点</param>
  445. public void RenderLine(Point pt1, Point pt2)
  446. {
  447. if (this.m_State == State.Hidden || pt1 == pt2)
  448. return;
  449. //使用边框颜色
  450. using (Brush brush = RenderEngine.CreateBrush(pt1, pt2, this.CurrentLineColor, this.m_LineBlendStyle))
  451. {
  452. using (Pen pen = RenderEngine.CreatePen(brush, this.m_LineWidth, this.m_LineDashStyle, this.m_LineDashPattern, this.m_LineDashCap, this.m_LineDashOffset))
  453. {
  454. this.m_Graphics.DrawLine(pen, pt1, pt2);
  455. }
  456. }
  457. }
  458. /// <summary>
  459. /// 渲染对号(按比例渲染)
  460. /// </summary>
  461. /// <param name="rect">渲染区域</param>
  462. public void RenderCheck(Rectangle rect)
  463. {
  464. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
  465. return;
  466. this.CurrentTextPreferredRect = rect;
  467. RenderEngine.DrawCheck(this.m_Graphics, this.CurrentTextPreferredRect, this.CurrentForeColor);
  468. }
  469. /// <summary>
  470. /// 渲染叉号(按比例渲染)
  471. /// </summary>
  472. /// <param name="rect">渲染区域</param>
  473. public void RenderCross(Rectangle rect)
  474. {
  475. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
  476. return;
  477. this.CurrentTextPreferredRect = rect;
  478. RenderEngine.DrawCross(this.m_Graphics, this.CurrentTextPreferredRect, this.CurrentForeColor);
  479. }
  480. /// <summary>
  481. /// 渲染省略号(按比例渲染)
  482. /// </summary>
  483. /// <param name="rect">渲染区域</param>
  484. public void RenderEllipsis(Rectangle rect)
  485. {
  486. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
  487. return;
  488. this.CurrentTextPreferredRect = rect;
  489. RenderEngine.DrawEllipsis(this.m_Graphics, this.CurrentTextPreferredRect, this.CurrentForeColor);
  490. }
  491. /// <summary>
  492. /// 渲染箭头(按比例渲染)
  493. /// </summary>
  494. /// <param name="rect">渲染区域</param>
  495. /// <param name="direction">箭头方向</param>
  496. public void RenderArrow(Rectangle rect, ArrowDirection direction)
  497. {
  498. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
  499. return;
  500. this.CurrentTextPreferredRect = rect;
  501. RenderEngine.DrawArrow(this.m_Graphics, this.CurrentTextPreferredRect, this.CurrentForeColor, direction);
  502. }
  503. /// <summary>
  504. /// 渲染箭头(固定大小)
  505. /// </summary>
  506. /// <param name="rect">渲染区域</param>
  507. /// <param name="direction">箭头方向</param>
  508. /// <param name="style">大小样式</param>
  509. public void RenderArrow(Rectangle rect, ArrowDirection direction, SizeStyle style)
  510. {
  511. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
  512. return;
  513. this.CurrentTextPreferredRect = rect;
  514. RenderEngine.DrawArrow(this.m_Graphics, this.CurrentTextPreferredRect, this.CurrentForeColor, direction, style);
  515. }
  516. /// <summary>
  517. /// 渲染Metrol按下边框
  518. /// </summary>
  519. /// <param name="rect">渲染区域</param>
  520. public void RenderMetroPress(Rectangle rect)
  521. {
  522. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
  523. return;
  524. //左侧
  525. if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Left) != 0)
  526. {
  527. rect.X += 2;
  528. rect.Width -= 2;
  529. }
  530. else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Left) != 0)
  531. {
  532. rect.X += 1;
  533. rect.Width -= 1;
  534. }
  535. //上边
  536. if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Top) != 0)
  537. {
  538. rect.Y += 2;
  539. rect.Height -= 2;
  540. }
  541. else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Top) != 0)
  542. {
  543. rect.Y += 1;
  544. rect.Height -= 1;
  545. }
  546. //右边
  547. if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Right) != 0)
  548. {
  549. rect.Width -= 2;
  550. }
  551. else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Right) != 0)
  552. {
  553. rect.Width -= 1;
  554. }
  555. //下边
  556. if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
  557. {
  558. rect.Height -= 2;
  559. }
  560. else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
  561. {
  562. rect.Height -= 1;
  563. }
  564. //设置剪切区
  565. this.m_Graphics.SetClip(rect);
  566. //绘制宽边框
  567. using (GraphicsPath pathBorder = RenderEngine.CreateGraphicsPath(rect),
  568. pathBorderIn = RenderEngine.CreateGraphicsPath(Rectangle.Inflate(rect, -3, -3)))
  569. {
  570. //边框区域
  571. pathBorder.AddPath(pathBorderIn, true);
  572. //绘制
  573. using (Brush brush = new SolidBrush(this.CurrentBorderColor))
  574. {
  575. this.m_Graphics.FillPath(brush, pathBorder);
  576. }
  577. }
  578. }
  579. /// <summary>
  580. /// 绘制Metrol选中边框
  581. /// </summary>
  582. /// <param name="rect">渲染区域</param>
  583. public void RenderMetroCheck(Rectangle rect)
  584. {
  585. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(rect))
  586. return;
  587. //左侧
  588. if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Left) != 0)
  589. {
  590. rect.X += 2;
  591. rect.Width -= 2;
  592. }
  593. else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Left) != 0)
  594. {
  595. rect.X += 1;
  596. rect.Width -= 1;
  597. }
  598. //上边
  599. if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Top) != 0)
  600. {
  601. rect.Y += 2;
  602. rect.Height -= 2;
  603. }
  604. else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Top) != 0)
  605. {
  606. rect.Y += 1;
  607. rect.Height -= 1;
  608. }
  609. //右边
  610. if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Right) != 0)
  611. {
  612. rect.Width -= 2;
  613. }
  614. else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Right) != 0)
  615. {
  616. rect.Width -= 1;
  617. }
  618. //下边
  619. if ((this.m_InnerBorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
  620. {
  621. rect.Height -= 2;
  622. }
  623. else if ((this.m_BorderVisibleStyle & BorderVisibleStyle.Bottom) != 0)
  624. {
  625. rect.Height -= 1;
  626. }
  627. //设置剪切区
  628. this.m_Graphics.SetClip(rect);
  629. //绘制宽边框
  630. using (GraphicsPath pathBorder = RenderEngine.CreateGraphicsPath(rect),
  631. pathBorderIn = RenderEngine.CreateGraphicsPath(Rectangle.Inflate(rect, -3, -3)),
  632. pathTriangle = new GraphicsPath())
  633. {
  634. //边框区域
  635. pathBorder.AddPath(pathBorderIn, true);
  636. //右上角三角区域
  637. Point[] points = new Point[] {
  638. new Point(rect.X + rect.Width - 40, rect.Y),
  639. new Point(rect.X + rect.Width, rect.Y),
  640. new Point(rect.X + rect.Width, rect.Y + 40)
  641. };
  642. pathTriangle.AddPolygon(points);
  643. //绘制
  644. using (Brush brush = new SolidBrush(this.CurrentBackColor))
  645. {
  646. this.m_Graphics.FillPath(brush, pathBorder);
  647. this.m_Graphics.FillPath(brush, pathTriangle);
  648. }
  649. }
  650. //绘制对号
  651. RenderEngine.DrawCheck(this.m_Graphics, new Rectangle(rect.Right - 22, rect.Y + 2, 20, 20), this.CurrentForeColor);
  652. }
  653. /// <summary>
  654. /// 渲染标签样式分组控件背景色
  655. /// </summary>
  656. /// <param name="rect">渲染区域</param>
  657. /// <param name="tabSize">左上角标签大小</param>
  658. /// <param name="tabRound">标签右上角是否发圆角</param>
  659. /// <param name="tabRadius">标签右上角圆角半径</param>
  660. public void RenderBackColorGroupBoxTab(Rectangle rect, Size tabSize, bool tabRound, float tabRadius)
  661. {
  662. this.m_BackColorRect = rect;
  663. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BackColorRect))
  664. return;
  665. using (Brush brush = RenderEngine.CreateBrush(this.CurrentBackColorBrushRect, this.CurrentBackColor, this.m_BackColorPos1, this.m_BackColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_BackColorBlendStyle))
  666. {
  667. //校正背景区域
  668. if (this.m_InnerBorderVisibleStyle != BorderVisibleStyle.None)
  669. tabSize.Width -= 4;
  670. else if (this.m_BorderVisibleStyle != BorderVisibleStyle.None)
  671. tabSize.Width -= 2;
  672. using (GraphicsPath path = RenderEngine.CreateGroupBoxTabGraphicsPath(this.CurrentBackColorPathRect, this.m_RoundStyle, this.m_RoundRadius, tabSize, tabRound, tabRadius, false))
  673. {
  674. this.m_Graphics.SetClip(path, CombineMode.Intersect);
  675. this.m_Graphics.FillPath(brush, path);
  676. }
  677. }
  678. }
  679. /// <summary>
  680. /// 渲染标签样式分组控件边框色
  681. /// </summary>
  682. /// <param name="rect">渲染区域</param>
  683. /// <param name="tabSize">左上角标签大小</param>
  684. /// <param name="tabRound">标签右上角是否发圆角</param>
  685. /// <param name="tabRadius">标签右上角圆角半径</param>
  686. public void RenderBorderColorGroupBoxTab(Rectangle rect, Size tabSize, bool tabRound, float tabRadius)
  687. {
  688. this.m_BorderColorRect = rect;
  689. if (this.m_State == State.Hidden || !RectangleEx.IsVisible(this.m_BorderColorRect))
  690. return;
  691. //重置剪切区
  692. this.m_Graphics.SetClip(this.m_GraphicsClip, CombineMode.Replace);
  693. //绘制内边框
  694. if (this.m_InnerBorderVisibleStyle != BorderVisibleStyle.None)
  695. {
  696. using (Brush brush = RenderEngine.CreateBrush(this.CurrentInnerBorderBrushRect, this.CurrentInnerBorderColor, this.m_InnerBorderColorPos1, this.m_InnerBorderColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_InnerBorderBlendStyle))
  697. {
  698. using (Pen pen = RenderEngine.CreatePen(brush, 1, this.m_InnerBorderDashStyle, this.m_InnerBorderDashPattern, this.m_InnerBorderDashCap, this.m_InnerBorderDashOffset))
  699. {
  700. Size innerBorderTabSize = new Size(tabSize.Width - 3, tabSize.Height);
  701. using (GraphicsPath path = RenderEngine.CreateGroupBoxTabGraphicsPath(this.CurrentInnerBorderPathRect, this.m_RoundStyle, this.m_RoundRadius, innerBorderTabSize, tabRound, tabRadius, false))
  702. {
  703. this.m_Graphics.DrawPath(pen, path);
  704. }
  705. }
  706. }
  707. }
  708. //绘制边框
  709. if (this.m_BorderVisibleStyle != BorderVisibleStyle.None)
  710. {
  711. using (Brush brush = RenderEngine.CreateBrush(this.CurrentBorderBrushRect, this.CurrentBorderColor, this.m_BorderColorPos1, this.m_BorderColorPos2, this.CurrentBackColorReverse, this.CurrentBackColorMode, this.m_BorderBlendStyle))
  712. {
  713. using (Pen pen = RenderEngine.CreatePen(brush, 1, this.m_BorderDashStyle, this.m_BorderDashPattern, this.m_BorderDashCap, this.m_BorderDashOffset))
  714. {
  715. Size borderTabSize = new Size(tabSize.Width - 1, tabSize.Height);
  716. using (GraphicsPath path = RenderEngine.CreateGroupBoxTabGraphicsPath(this.CurrentBorderPathRect, this.m_RoundStyle, this.m_RoundRadius, borderTabSize, tabRound, tabRadius, false))
  717. {
  718. this.m_Graphics.DrawPath(pen, path);
  719. }
  720. }
  721. }
  722. }
  723. }
  724. }
  725. }