AdvMatrixObject.Draw.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. using System.Windows.Forms;
  5. using FastReport.Table;
  6. using FastReport.Utils;
  7. namespace FastReport.AdvMatrix
  8. {
  9. public partial class AdvMatrixObject
  10. {
  11. #region Private Methods
  12. private void DrawHeaderArea(FRPaintEventArgs e)
  13. {
  14. TableCell c = this[Data.Rows.Size, Data.Columns.Size];
  15. Pen p = e.Cache.GetPen(Color.Black, 1 * e.ScaleX, DashStyle.Dash);
  16. e.Graphics.DrawRectangle(p, (c.AbsLeft - 1) * e.ScaleX, AbsTop * e.ScaleY, 2 * e.ScaleX, Height * e.ScaleY);
  17. e.Graphics.DrawRectangle(p, AbsLeft * e.ScaleX, (c.AbsTop - 1) * e.ScaleY, Width * e.ScaleY, 2 * e.ScaleY);
  18. }
  19. private void DrawGroups(FRPaintEventArgs e, MatrixHeader header)
  20. {
  21. Pen groupPen = e.Cache.GetPen(Color.Orange, 3 * e.ScaleX, DashStyle.Solid);
  22. Pen topNPen = e.Cache.GetPen(Color.Red, 3 * e.ScaleX, DashStyle.Solid);
  23. foreach (HeaderDescriptor d in header.Descriptor.AllItems)
  24. {
  25. TableCell c = d.TemplateCell;
  26. if (c != null && d.IsGroup)
  27. {
  28. Pen p = d.TopN.Count != 0 && d.TopNItemsPresent() ? topNPen : groupPen;
  29. if (d.IsColumn)
  30. {
  31. e.Graphics.DrawLines(p, new PointF[] {
  32. new PointF(c.AbsLeft * e.ScaleX, (c.AbsTop + 6) * e.ScaleY), new PointF(c.AbsLeft * e.ScaleX, c.AbsTop * e.ScaleY),
  33. new PointF(c.AbsRight * e.ScaleX, c.AbsTop * e.ScaleY), new PointF(c.AbsRight * e.ScaleX, (c.AbsTop + 6) * e.ScaleY)
  34. });
  35. }
  36. else
  37. {
  38. e.Graphics.DrawLines(p, new PointF[] {
  39. new PointF((c.AbsLeft + 6) * e.ScaleX, c.AbsBottom * e.ScaleY), new PointF(c.AbsLeft * e.ScaleX, c.AbsBottom * e.ScaleY),
  40. new PointF(c.AbsLeft * e.ScaleX, c.AbsTop * e.ScaleY), new PointF((c.AbsLeft + 6) * e.ScaleX, c.AbsTop * e.ScaleY)
  41. });
  42. }
  43. }
  44. }
  45. }
  46. private void DrawTopNMarks(FRPaintEventArgs e, MatrixHeader header)
  47. {
  48. foreach (HeaderDescriptor d in header.Descriptor.AllItems)
  49. {
  50. TableCell c = d.TemplateCell;
  51. if (c != null && d.IsTopNItem)
  52. {
  53. e.Graphics.DrawImage(Report.Designer.GetImage(99), (int)((c.AbsRight - 14) * e.ScaleX), (int)((c.AbsTop + 2) * e.ScaleY), 16 * e.ScaleX, 16 * e.ScaleY);
  54. }
  55. }
  56. }
  57. private void DrawFrame(FRPaintEventArgs e, ComponentBase c, Color color)
  58. {
  59. Pen p = e.Cache.GetPen(color, 3 * e.ScaleX, DashStyle.Solid);
  60. e.Graphics.DrawRectangle(p, c.AbsLeft * e.ScaleX, c.AbsTop * e.ScaleY, c.Width * e.ScaleX, c.Height * e.ScaleY);
  61. }
  62. private void DrawDragIndicator(FRPaintEventArgs e)
  63. {
  64. dragInfo.TargetCell.DrawDragAcceptFrame(e, Color.Red);
  65. if (dragInfo.Indicator.Width > 0 || dragInfo.Indicator.Height > 0)
  66. {
  67. IGraphics g = e.Graphics;
  68. int left = (int)Math.Round((dragInfo.Indicator.Left + AbsLeft) * e.ScaleX);
  69. int top = (int)Math.Round((dragInfo.Indicator.Top + AbsTop) * e.ScaleY);
  70. int right = (int)Math.Round(dragInfo.Indicator.Width * e.ScaleX) + left;
  71. int bottom = (int)Math.Round(dragInfo.Indicator.Height * e.ScaleY) + top;
  72. Pen p = e.Cache.GetPen(Color.Red, 1 * e.ScaleX, DashStyle.Dot);
  73. g.DrawLine(p, left, top, right, bottom);
  74. p = Pens.Red;
  75. Brush b = Brushes.Red;
  76. int n = (int)(5 * e.ScaleX);
  77. if (dragInfo.Indicator.Width == 0)
  78. {
  79. Point[] poly = new Point[] {
  80. new Point(left, top),
  81. new Point(left - n, top - n),
  82. new Point(left + n, top - n),
  83. new Point(left, top) };
  84. g.FillPolygon(b, poly);
  85. g.DrawPolygon(p, poly);
  86. poly = new Point[] {
  87. new Point(left, bottom),
  88. new Point(left - n, bottom + n),
  89. new Point(left + n, bottom + n),
  90. new Point(left, bottom) };
  91. g.FillPolygon(b, poly);
  92. g.DrawPolygon(p, poly);
  93. }
  94. else
  95. {
  96. Point[] poly = new Point[] {
  97. new Point(left, top),
  98. new Point(left - n, top - n),
  99. new Point(left - n, top + n),
  100. new Point(left, top) };
  101. g.FillPolygon(b, poly);
  102. g.DrawPolygon(p, poly);
  103. poly = new Point[] {
  104. new Point(right, top),
  105. new Point(right + n, top - n),
  106. new Point(right + n, top + n),
  107. new Point(right, top) };
  108. g.FillPolygon(b, poly);
  109. g.DrawPolygon(p, poly);
  110. }
  111. }
  112. }
  113. private void HighlightButtonLinkedItems(FRPaintEventArgs e)
  114. {
  115. if (Report.Designer.SelectedObjects.Count == 1)
  116. {
  117. MatrixCollapseButton btn = Report.Designer.SelectedObjects[0] as MatrixCollapseButton;
  118. if (btn != null && btn.Cell != null)
  119. {
  120. HeaderDescriptor descr = btn.Cell.GetHeaderDescriptor();
  121. if (descr != null)
  122. {
  123. foreach (HeaderDescriptor d in descr.Root.AllItems)
  124. {
  125. if (d.VisibleToggledBy == btn.Name)
  126. DrawFrame(e, d.TemplateCell, Color.FromArgb(80, Color.Red));
  127. }
  128. }
  129. }
  130. }
  131. }
  132. private void HighlightLinkedButton(FRPaintEventArgs e, TableCell cell)
  133. {
  134. HeaderDescriptor descr = cell.GetHeaderDescriptor();
  135. if (descr != null)
  136. {
  137. MatrixCollapseButton btn = Report.FindObject(descr.VisibleToggledBy) as MatrixCollapseButton;
  138. if (btn != null)
  139. DrawFrame(e, btn, Color.FromArgb(80, Color.Red));
  140. }
  141. }
  142. private void HighlightTopNItems(FRPaintEventArgs e, TableCell cell)
  143. {
  144. HeaderDescriptor descr = cell.GetHeaderDescriptor();
  145. if (descr != null && descr.TopN.Count > 0 && descr.TopNItemsPresent())
  146. {
  147. Color c = Color.FromArgb(80, Color.Red);
  148. DrawFrame(e, descr.TopN.Total.Descriptor.TemplateCell, c);
  149. DrawFrame(e, descr.TopN.Others.Descriptor.TemplateCell, c);
  150. DrawFrame(e, descr.TopN.OthersTotal.Descriptor.TemplateCell, c);
  151. }
  152. }
  153. #endregion
  154. #region Public Methods
  155. /// <inheritdoc/>
  156. public override void Draw(FRPaintEventArgs e)
  157. {
  158. if (IsDesigning && !Report.Designer.IsPreviewPageDesigner)
  159. UpdateDescriptors();
  160. base.Draw(e);
  161. if (!IsDesigning || (IsDesigning && Report.Designer.IsPreviewPageDesigner))
  162. return;
  163. if (Data.Columns.Descriptor.IsEmpty() && Data.Rows.Descriptor.IsEmpty())
  164. {
  165. TextRenderer.DrawText(e.Graphics.Graphics, Res.Get("ComponentsMisc,AdvMatrix,NewItems"),
  166. e.Cache.GetFont(DrawUtils.DefaultFont.FontFamily, 8 * e.ScaleX * 96 / DrawUtils.ScreenDpi, FontStyle.Regular),
  167. new Rectangle((int)(AbsLeft * e.ScaleX), (int)(AbsTop * e.ScaleY), (int)(Width * e.ScaleX), (int)(Height * e.ScaleY)), Color.Black,
  168. TextFormatFlags.WordBreak | TextFormatFlags.NoPrefix |
  169. TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter |
  170. TextFormatFlags.PreserveGraphicsTranslateTransform);
  171. }
  172. else
  173. {
  174. if (IsSelected)
  175. {
  176. DrawHeaderArea(e);
  177. DrawGroups(e, Data.Columns);
  178. DrawGroups(e, Data.Rows);
  179. DrawTopNMarks(e, Data.Columns);
  180. DrawTopNMarks(e, Data.Rows);
  181. }
  182. HighlightButtonLinkedItems(e);
  183. if (dragInfo.SelectedCell != null)
  184. {
  185. DrawFrame(e, dragInfo.SelectedCell, Color.Black);
  186. HighlightTopNItems(e, dragInfo.SelectedCell);
  187. HighlightLinkedButton(e, dragInfo.SelectedCell);
  188. }
  189. }
  190. if (dragInfo.TargetCell != null)
  191. DrawDragIndicator(e);
  192. }
  193. #endregion
  194. }
  195. }