void PaintOutBox(IPen pen, Topic topic, RenderArgs e, int round) { Rectangle rect = topic.Bounds; rect.Inflate(OutBoxSpace, OutBoxSpace); //GraphicsPath gp = PaintHelper.GetRoundRectangle(rect, round); //e.Graphics.DrawPath(pen, gp); e.Graphics.DrawRoundRectangle(pen, rect, round); }
public void PaintTopics(IEnumerable <Topic> topics, RenderArgs e) { if (topics.IsNullOrEmpty()) { return; } foreach (var topic in topics) { var pt = topic.Location; e.Graphics.TranslateTransform(pt.X, pt.Y); _PaintNode(topic, e); e.Graphics.TranslateTransform(-pt.X, -pt.Y); } }
void PaintNodeShadow(Topic topic, RenderArgs e, int round) { if (ShadowSize > 0) { Shape shaper = Shape.GetShaper(topic.Style.Shape, round); Rectangle rect = topic.Bounds; rect.Offset(ShadowSize, ShadowSize); //GraphicsPath gpShadow = shaper.GetShape(new Rectangle(rect.Left + ShadowSize, rect.Top + ShadowSize, rect.Width, rect.Height), 0); //PT.GetRoundRectangle(new Rectangle(rect.Left + ShadowSize, rect.Top + ShadowSize, rect.Width, rect.Height), round); //args.Graphics.FillPath(BrushNodeShadow, gpShadow); Color color; if (e.Mode == RenderMode.UserInface) { if (topic.Style.BackColor.IsEmpty) { color = PaintHelper.GetDarkColor(topic.MindMap.NodeBackColor, 0.5); } else { color = PaintHelper.GetDarkColor(topic.Style.BackColor, 0.5); } //e.Graphics.FillPath(new SolidBrush(Color.FromArgb(150, color)), gpShadow); shaper.Fill(e.Graphics, e.Graphics.SolidBrush(Color.FromArgb(150, color)), rect); } else // for print { if (topic.Style.BackColor.IsEmpty) { color = PaintHelper.GetDarkColor(topic.MindMap.NodeBackColor); } else { color = PaintHelper.GetDarkColor(topic.Style.BackColor); } //e.Graphics.FillPath(new SolidBrush(color), gpShadow); shaper.Fill(e.Graphics, e.Graphics.SolidBrush(color), rect); } shaper.Dispose(); } }
void PaintLinkLines(Topic topic, RenderArgs e) { // links foreach (Link link in topic.Links) { if (link.Visible) { PaintLinkLine(link, e); } } if (!topic.Children.IsEmpty && !topic.Folded) { foreach (Topic subTopic in topic.Children) { PaintLinkLines(subTopic, e); } } }
public void Paint(MindMap map, RenderArgs args) { if (map == null) { throw new ArgumentNullException(); } ResetObjects(args.Graphics, map); //PaintBackground(map, args); if (map.Root != null) { Liner = LayoutManage.GetLiner(map.LayoutType); //GenerateFoldingButtonImage(map); PaintNode(map.Root, args); PaintLinkLines(map.Root, args); } }
/*public override void ExportImage(string filename, string typeMime) * { * ChartsExportEngine engine = ChartsExportEngine.GetEngine(typeMime); * if (engine == null) * { * this.ShowMessage("The format is not supported", MessageBoxIcon.Error); * } * else * { * engine.Export(this, filename); * } * }*/ public Image GenerateImage(RenderMode renderMode, bool transparentBackground) { Bitmap bmp = new Bitmap(OriginalContentSize.Width, OriginalContentSize.Height); using (Graphics grf = Graphics.FromImage(bmp)) { PaintHelper.SetHighQualityRender(grf); if (!transparentBackground) { grf.Clear(ChartBackColor); } if (Render != null && Map != null) { RenderArgs args = new RenderArgs(renderMode, grf, this, ChartBox.DefaultChartFont); Render.Paint(Map, args); } grf.Dispose(); } return(bmp); }
// 坐标已经转换, 原点为Topic.Left/Top void PaintNodeBackground(Topic topic, RenderArgs e) { var grf = e.Graphics; var rect = new Rectangle(Point.Empty, topic.Bounds.Size); bool hover = false; bool select = false; bool active = false; if (e.Mode == RenderMode.UserInface && e.View != null) { hover = e.View.HoverObject != null && e.View.HoverObject.Topic == topic && !e.View.HoverObject.IsFoldingButton; select = topic.Selected; active = topic == e.View.SelectedTopic; } Shape shaper = Shape.GetShaper(topic.Style.Shape, topic.Style.RoundRadius); // draw shadow //if (ShadowSize != 0)// && hover) // PaintNodeShadow(topic, e, round); // draw background Color backColor = topic.Style.BackColor; if (backColor.IsEmpty) { backColor = e.Chart.NodeBackColor; } var ft = FillType.GetFillType(topic.Style.FillType); IBrush brushBack = ft.CreateBrush(e.Graphics, backColor, rect); //IBrush brushBack; //if (!topic.Style.BackColor.IsEmpty) //{ // brushBack = e.Graphics.SolidBrush(topic.Style.BackColor); //} //else //{ // brushBack = topic.IsRoot ? BrushRootNodeBack : BrushNodeBack; //} shaper.Fill(e.Graphics, brushBack, rect); // draw border if (hover) { shaper.DrawBorder(e.Graphics, PenNodeBorderHover, rect); } else { if (topic.Style.BorderColor.IsEmpty) { shaper.DrawBorder(e.Graphics, PenNodeBorder, rect); } else { shaper.DrawBorder(e.Graphics, e.Graphics.Pen(topic.Style.BorderColor, PenNodeBorder.Width), rect); } } if (active || select) { //Pen pen = active ? PenNodeBorderActive : PenNodeBorderSelect; //Rectangle rectOut = rect; //rectOut.Inflate(OutBoxSpace, OutBoxSpace); //shaper.DrawOutBox(e.Graphics, pen, rect, OutBoxSpace); DrawSelectRectangle(e.Graphics, e.Chart.SelectColor, rect); } shaper.Dispose(); }
// 坐标已经转换, 原点为 Topic.Left/Top void _PaintNode(Topic topic, RenderArgs e) { var style = topic.Style; var font = style.Font != null?e.Graphics.Font(style.Font) : e.Font; // draw background PaintNodeBackground(topic, e); // calculate paint bounds var rect = new Rectangle(Point.Empty, topic.Bounds.Size); // 修改参照原点 rect = rect.Inflate(style.Padding); // widgets foreach (var widget in topic.Widgets) { //if (!widget.Visible) // continue; widget.Paint(e); if (widget.Selectable && widget.Selected) { DrawSelectRectangle(e.Graphics, e.Chart.SelectColor, widget.Bounds); } } // draw text if (!string.IsNullOrEmpty(topic.Text)) { var rectText = topic.TextBounds; //rectText.Offset(topic.Left, topic.Top); // 原点已经在调用时转换 IBrush brushFore = style.ForeColor.IsEmpty ? BrushNodeFore : (e.Graphics.SolidBrush(style.ForeColor)); var sf = PaintHelper.SFCenter; if (e.Mode == RenderMode.Print && !topic.CustomWidth.HasValue) { sf.FormatFlags |= StringFormatFlags.NoWrap; sf.Trimming = StringTrimming.None; } switch (topic.TextAlignment) { case HorizontalAlignment.Left: sf.Alignment = StringAlignment.Near; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; break; } var font2 = font; if (!string.IsNullOrEmpty(topic.Hyperlink)) { font2 = e.Graphics.Font(font, font.Style | FontStyle.Underline); } e.Graphics.DrawString(topic.Text, font2, brushFore, rectText, sf); } // draw remark icon if (e.ShowRemarkIcon && topic.HaveRemark) { var iconRemark = Properties.Resources.note_small; var rectRemark = topic.RemarkIconBounds; e.Graphics.DrawImage(iconRemark, rectRemark, 0, 0, iconRemark.Width, iconRemark.Height); } }
void PaintNode(Topic topic, RenderArgs e) { if (topic.Bounds.IsEmpty) { return; } var rect = topic.Bounds; if (topic.Lines.Count > 0) { if (Liner is BezierLine) { ((BezierLine)Liner).IsRoot = topic.IsRoot; } else if (Liner is HandPaintLine) { ((HandPaintLine)Liner).IsRoot = topic.IsRoot; } LineAnchor sla = LineAnchor.None; LineAnchor ela = e.ShowLineArrowCap ? LineAnchor.Arrow : LineAnchor.None; foreach (var line in topic.Lines) { if (line.Target == null) { continue; } var rectFrom = line.BeginRectangle; var rectTo = line.EndRectangle;// line.Target.Bounds; //if (e.Layouter != null) // e.Layouter.AdjustLineRect(line, topic, ref rectFrom, ref rectTo); var linePen = PenLine; if (!line.Target.Style.LineColor.IsEmpty) { linePen = GetLinePen(e.Graphics, e.Chart.LineWidth, line.Target.Style.LineColor); } Liner.DrawLine(e.Graphics, linePen, topic.Style.Shape, line.Target.Style.Shape, rectFrom, rectTo, line.BeginSide, line.EndSide, sla, ela); } } PaintTopic(topic, e); // draw children if (!topic.Children.IsEmpty) { if (!topic.Folded) { foreach (Topic subTopic in topic.Children) { PaintNode(subTopic, e); } } if (!topic.IsRoot) { bool hover = e.Mode == RenderMode.UserInface && e.View != null && !e.View.HoverObject.IsEmpty && e.View.HoverObject.IsFoldingButton && e.View.HoverObject.Topic == topic; PaintFoldingButton(topic, e, topic.Folded, hover); } } }
public void Draw(PaintEventArgs e) { //System.Diagnostics.Debug.WriteLine("Draw"); if (Bounds.IsEmpty || Topics.IsNullOrEmpty() || OwnerView == null) { return; } //e.Graphics.DrawRectangle(Pens.Blue, Bounds.X, Bounds.Y, Bounds.Width - 1, Bounds.Height - 1); if (ObjectImage == null) { ObjectImage = new Bitmap(Bounds.Width, Bounds.Height); using (Graphics grfImg = Graphics.FromImage(ObjectImage)) { if (!Topics.IsNullOrEmpty()) { PaintHelper.SetHighQualityRender(grfImg); //grfImg.DrawRectangle(Pens.Red, 0, 0, Bounds.Width - 1, Bounds.Height - 1); //grfImg.TranslateTransform( Bounds.X - StartBounds.X, Bounds.Y - StartBounds.Y); grfImg.TranslateTransform(-LogicLocation.X + Padding, -LogicLocation.Y + Padding); var args = new RenderArgs(RenderMode.UserInface, grfImg, OwnerView, ChartBox.DefaultChartFont); OwnerView.Render.PaintTopics(Topics, args); } } PaintHelper.TransparentImage(ObjectImage, 0.75f); } e.Graphics.DrawImage(ObjectImage, Bounds, 0, 0, ObjectImage.Width, ObjectImage.Height, GraphicsUnit.Pixel); if (SubTitle != null || SubTitleIcon != null) { var rectSubTitle = new Rectangle(Bounds.X + Padding, Bounds.Bottom - SubTitleSize.Height, Bounds.Width - Padding * 2, SubTitleSize.Height); if (SubTitleIcon != null) { var rectIcon = new Rectangle(rectSubTitle.X, rectSubTitle.Y + (rectSubTitle.Height - 16) / 2, 16, 16); if (!CanDragDrop) { e.Graphics.DrawImageUnscaled(Properties.Resources.stop, rectIcon); } else { e.Graphics.DrawImageUnscaled(SubTitleIcon, rectIcon); } } if (!string.IsNullOrEmpty(SubTitle)) { var rectText = new Rectangle(rectSubTitle.X + 18, rectSubTitle.Y, SubTitleSize.Width, rectSubTitle.Height); rectText.Inflate(0, -1); e.Graphics.FillRectangle(new SolidBrush(UITheme.Default.Colors.MediumLight), rectText); rectText.Inflate(-2, 0); //using (var p = PaintHelper.GetRoundRectangle(rectText, 2)) //{ // e.Graphics.FillPath(new SolidBrush(UITheme.Default.Colors.MediumLight), p); // rectText.Inflate(-2, 0); //} var sf = PaintHelper.SFLeft; sf.FormatFlags |= StringFormatFlags.NoWrap; sf.Trimming |= StringTrimming.None; e.Graphics.DrawString(SubTitle, SystemFonts.MenuFont, new SolidBrush(UITheme.Default.Colors.ControlText), rectText, sf); } } else { if (!CanDragDrop) { Image icon = Properties.Resources.stop; e.Graphics.DrawImage(icon, new Rectangle(Bounds.Left + (Bounds.Width - icon.Width) / 2, Bounds.Top + (Bounds.Height - icon.Height) / 2, icon.Width, icon.Height), 0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel); } } //e.Graphics.DrawRectangle(Pens.Red, Bounds.Left, Bounds.Top, Bounds.Width - 1, Bounds.Height - 1); }
// 坐标已经转换, 原点为Topic.Left/Top void PaintNodeBackground(Topic topic, RenderArgs e) { var grf = e.Graphics; var rect = new Rectangle(Point.Empty, topic.Bounds.Size); bool hover = false; bool select = false; bool active = false; if (e.Mode == RenderMode.UserInface && e.View != null) { hover = e.View.HoverObject != null && e.View.HoverObject.Topic == topic && !e.View.HoverObject.IsFoldingButton; select = topic.Selected; active = topic == e.View.SelectedTopic; } Shape shaper = Shape.GetShaper(topic.Style.Shape, topic.Style.RoundRadius); // draw border Rectangle rectBoundary = Rectangle.Union(rect, topic.TextBounds); rectBoundary.Inflate(2, 2); if (hover) { shaper.DrawBorder(e.Graphics, PenNodeBorderHover, rectBoundary); } //else //{ // if (topic.Style.BorderColor.IsEmpty) // shaper.DrawBorder(e.Graphics, PenNodeBorder, rectBoundary); // else // shaper.DrawBorder(e.Graphics, e.Graphics.Pen(topic.Style.BorderColor, PenNodeBorder.Width), rectBoundary); //} if (active || select) { DrawSelectRectangle(e.Graphics, e.Chart.SelectColor, rectBoundary); } // draw background Color backColor = topic.Style.BackColor; if (backColor.IsEmpty) { backColor = e.Chart.NodeBackColor; } if (topic.Type == TopicType.Hazard) { IBrush brushBack = e.Graphics.SolidBrush(backColor); shaper.Fill(e.Graphics, brushBack, rect); // Draw pattern IGraphics graphics = e.Graphics; IGraphicsState savedState = graphics.Save(); graphics.SetClip(rect); IBrush blackBrush = graphics.SolidBrush(Color.Black); Rectangle patternRect = new Rectangle(new Point(rect.X, rect.Y - rect.Height), new Size(15, 2 * rect.Height)); graphics.TranslateTransform(rect.Width - 30, 0); graphics.RotateTransform(135); graphics.FillRectangle(blackBrush, patternRect); int i = 0, rectH = rect.Height + 30; while (i <= rectH) { graphics.TranslateTransform(30, 0); graphics.FillRectangle(blackBrush, patternRect); i += 30; } graphics.Restore(savedState); } else if (topic.Type != TopicType.None) { Color midColor = topic.Type == TopicType.TopEvent ? Color.Orange : Color.White; IBrush brushBack = e.Graphics.LinearGradientBrush(rect, backColor, midColor, backColor); shaper.Fill(e.Graphics, brushBack, rect); } else { var ft = FillType.GetFillType(topic.Style.FillType); IBrush brushBack = ft.CreateBrush(e.Graphics, backColor, rect); shaper.Fill(e.Graphics, brushBack, rect); } shaper.DrawBorder(e.Graphics, e.Graphics.Pen(Color.Black), rect); shaper.Dispose(); }