public override void RenderElement(IRenderable renderable, Graphics graphics, Render render) { Solid solid = renderable as Solid; GraphicsPath path = solid.GetPath(); if (path == null) { return; } //Fill the solid RenderSolid(solid, graphics, render); //Set clipping for this shape Region current = null; //Add local clipping if (solid.Clip) { Region region = new Region(path); current = graphics.Clip; graphics.SetClip(region, CombineMode.Intersect); } if (!render.Summary) { //Render image if (solid.Image != null) { IFormsRenderer renderer = render.GetRenderer(solid.Image); renderer.RenderElement(solid.Image, graphics, render); } //Render label if (solid.Label != null) { LabelRender renderer = render.GetRenderer(solid.Label) as LabelRender; if (solid.Label.Wrap) { renderer.RenderElement(solid.Label, graphics, render, solid.InternalRectangle); } else { renderer.RenderElement(solid.Label, graphics, render); } } } //Restore clipping if (solid.Clip) { graphics.Clip = current; } //Call the base implementation of render to draw border if (solid.DrawBorder) { base.RenderElement(renderable, graphics, render); } }
//fill the marker background public override void RenderElement(IRenderable element, Graphics graphics, Render render) { MarkerBase markerBase = element as MarkerBase; graphics.SmoothingMode = markerBase.SmoothingMode; if (markerBase.DrawBackground) { SolidBrush brush; brush = new SolidBrush(render.AdjustColor(markerBase.BackColor, 0, markerBase.Opacity)); graphics.FillPath(brush, markerBase.GetPath()); } base.RenderElement(element, graphics, render); //Draw any images and annotations if (markerBase.Image != null) { IFormsRenderer renderer = render.GetRenderer(markerBase.Image); renderer.RenderElement(markerBase.Image, graphics, render); } if (markerBase.Label != null) { IFormsRenderer renderer = render.GetRenderer(markerBase.Image); renderer.RenderElement(markerBase.Label, graphics, render); } }
public override void RenderElement(IRenderable element, Graphics graphics, Render render) { Port port = element as Port; if (port.GetPath() == null) { return; } //Translate by offset graphics.TranslateTransform(port.Offset.X, port.Offset.Y); //Fill and draw the port RenderPort(port, graphics, render); //Render image if (port.Image != null) { IFormsRenderer renderer = render.GetRenderer(port.Image); renderer.RenderElement(port.Image, graphics, render); } //Render label if (port.Label != null) { IFormsRenderer renderer = render.GetRenderer(port.Label); renderer.RenderElement(port.Label, graphics, render); } graphics.TranslateTransform(-port.Offset.X, -port.Offset.Y); }
//Implement a base rendering of an element selection public override void RenderAction(IRenderable element, Graphics graphics, ControlRender render) { Table table = element as Table; if (render.ActionStyle == ActionStyle.Default) { RenderTable(table, graphics, render); //Render the ports if (table.Ports != null) { foreach (Port port in table.Ports.Values) { if (port.Visible) { graphics.TranslateTransform(-port.Bounds.X + port.Bounds.X, -port.Bounds.Y + port.Bounds.Y); port.SuspendValidation(); IFormsRenderer renderer = render.GetRenderer(port); renderer.RenderElement(port, graphics, render); port.ResumeValidation(); graphics.TranslateTransform(port.Bounds.X - port.Bounds.X, port.Bounds.Y - port.Bounds.Y); } } } } else { base.RenderAction(element, graphics, render); } }
public override void RenderAction(IRenderable element, Graphics graphics, ControlRender render) { ComplexShape complex = element as ComplexShape; base.RenderAction(element, graphics, render); Region current = null; //Set up clipping if required if (complex.Clip) { Region region = new Region(complex.GetPath()); current = graphics.Clip; graphics.SetClip(region, CombineMode.Intersect); } //Render the children if (complex.Children != null) { foreach (Solid solid in complex.RenderList) { graphics.TranslateTransform(solid.Bounds.X, solid.Bounds.Y); IFormsRenderer renderer = render.GetRenderer(solid); renderer.RenderAction(solid, graphics, render); graphics.TranslateTransform(-solid.Bounds.X, -solid.Bounds.Y); } } if (complex.Clip) { graphics.Clip = current; } }
private void RenderTableRows(Table table, Graphics graphics, Render render, TableRows rows, ref float iHeight) { foreach (TableRow tableRow in rows) { IFormsRenderer renderer = render.GetRenderer(tableRow); renderer.RenderElement(tableRow, graphics, render); iHeight += table.RowHeight; } }
public virtual void AddRenderer(Type type, IFormsRenderer render) { if (type == null) { throw new ArgumentNullException("type"); } if (render == null) { throw new ArgumentNullException("render"); } _renderers.Add(type, render); }
public override void RenderElement(IRenderable element, Graphics graphics, Render render) { //Render this shape base.RenderElement(element, graphics, render); Shape shape = element as Shape; //Undo the rotate transform if (shape.Rotation != 0) { //Get the local center PointF center = new PointF(shape.Bounds.Width / 2, shape.Bounds.Height / 2); Matrix matrix = graphics.Transform; matrix.RotateAt(-shape.Rotation, center); graphics.Transform = matrix; } //Render the ports if (shape.Ports != null && !render.Summary) { foreach (Port port in shape.Ports.Values) { if (port.Visible) { graphics.TranslateTransform(-shape.Bounds.X + port.Bounds.X, -shape.Bounds.Y + port.Bounds.Y); graphics.RotateTransform(port.Rotation); port.SuspendValidation(); IFormsRenderer renderer = render.GetRenderer(port); renderer.RenderElement(port, graphics, render); port.ResumeValidation(); graphics.RotateTransform(-port.Rotation); graphics.TranslateTransform(shape.Bounds.X - port.Bounds.X, shape.Bounds.Y - port.Bounds.Y); } } } //Redo the rotate transform if (shape.Rotation != 0) { //Get the local center PointF center = new PointF(shape.Bounds.Width / 2, shape.Bounds.Height / 2); Matrix matrix = graphics.Transform; matrix.RotateAt(shape.Rotation, center); graphics.Transform = matrix; } }
public override void RenderElement(IRenderable element, Graphics graphics, Render render) { Connector connector = element as Connector; base.RenderElement(element, graphics, render); //Render Image if (connector.Image != null || connector.Label != null) { //Determine central point //If even number of points, then position half way on segment PointF center = connector.Center; graphics.TranslateTransform(center.X, center.Y); if (connector.Image != null) { IFormsRenderer renderer = render.GetRenderer(connector.Image); renderer.RenderElement(connector.Image, graphics, render); } if (connector.Label != null) { IFormsRenderer renderer = render.GetRenderer(connector.Label); renderer.RenderElement(connector.Label, graphics, render); } graphics.TranslateTransform(-center.X, -center.Y); } //Draw test squares for points // if (Selected) // { // graphics.TranslateTransform(-Rectangle.X,-Rectangle.Y); // Pen newPen = new Pen(Color.Red,1); // // Font font = new Font("Arial",8); // SolidBrush brush = new SolidBrush(Color.Blue); // int offset = 0; // // foreach (PointF point in Points) // { // offset+=20; // graphics.DrawRectangle(newPen,point.X-2,point.Y-2,4,4); // graphics.DrawString(point.ToString(),font,brush,10,offset); // // } // graphics.TranslateTransform(Rectangle.X,Rectangle.Y); // } }
public virtual IFormsRenderer GetRenderer(IRenderable element) { if (element.Renderer == null) { //Lookup renderer for type IFormsRenderer render = null; if (!_renderers.TryGetValue(element.GetType(), out render)) { throw new RenderException(string.Format("A renderer was not found for type {0}.", element.GetType().FullName)); } element.Renderer = render; } return(element.Renderer as IFormsRenderer); }
//Renders a graphics marker protected virtual void RenderMarkerAction(MarkerBase marker, PointF markerPoint, PointF referencePoint, Graphics graphics, ControlRender render) { if (marker == null) { return; } //Save the graphics state Matrix gstate = graphics.Transform; //Apply the marker transform and render the marker graphics.Transform = Link.GetMarkerTransform(marker, markerPoint, referencePoint, graphics.Transform); IFormsRenderer renderer = render.GetRenderer(marker); renderer.RenderAction(marker, graphics, render); //Restore the graphics state graphics.Transform = gstate; }
private void RenderTableGroups(Table table, Graphics graphics, Render render, TableGroups groups, ref float iHeight) { foreach (TableGroup tableGroup in groups) { IFormsRenderer renderer = render.GetRenderer(tableGroup); renderer.RenderElement(tableGroup, graphics, render); iHeight += table.GroupHeight; //Render groups and rows recursively if (tableGroup.Groups.Count > 0 && tableGroup.Expanded) { RenderTableGroups(table, graphics, render, tableGroup.Groups, ref iHeight); } if (tableGroup.Rows.Count > 0 && tableGroup.Expanded) { RenderTableRows(table, graphics, render, tableGroup.Rows, ref iHeight); } } }
public override void RenderLayer(Graphics graphics, Layer layer, ElementList elementRenderList, RectangleF renderRectangle) { base.RenderLayer(graphics, layer, elementRenderList, renderRectangle); //Render selections if (DrawSelections) { foreach (Element element in elementRenderList) { if (element is ISelectable && element.Visible) { ISelectable selectable = (ISelectable)element; if (element.Layer == layer && selectable.Selected && selectable.DrawSelected && element.Bounds.IntersectsWith(renderRectangle)) { PointF transform; //Calculate the transform if (element is ITransformable) { ITransformable transformable = (ITransformable)element; transform = new PointF(transformable.TransformRectangle.X, transformable.TransformRectangle.Y); } else { transform = new PointF(element.Bounds.X, element.Bounds.Y); } //Apply and render graphics.TranslateTransform(transform.X, transform.Y); graphics.SmoothingMode = element.SmoothingMode; IFormsRenderer renderer = GetRenderer(element); renderer.RenderSelection(element, graphics, this); graphics.TranslateTransform(-transform.X, -transform.Y); } } } } }
public override void RenderLayer(Graphics graphics, Layer layer, ElementList elementRenderList, RectangleF renderRectangle) { if (elementRenderList == null) { throw new ArgumentNullException("elementRenderList"); } //Draw each element by checking if it is renderable and calling the render method foreach (Element element in elementRenderList) { if (element.Layer == layer && element.Visible && element.Bounds.IntersectsWith(renderRectangle)) { //Draw shapes GraphicsState graphicsState = graphics.Save(); Matrix matrix = graphics.Transform; matrix.Translate(element.Bounds.X, element.Bounds.Y); //Set up rotation and other transforms if (element is ITransformable) { ITransformable rotatable = (ITransformable)element; PointF center = new PointF(element.Bounds.Width / 2, element.Bounds.Height / 2); matrix.RotateAt(rotatable.Rotation, center); } //Apply transform, mode, and render element graphics.Transform = matrix; graphics.SmoothingMode = element.SmoothingMode; //Get the renderer for this type and render IFormsRenderer renderer = GetRenderer(element); renderer.RenderElement(element, graphics, this); graphics.Restore(graphicsState); } } }
public override void RenderElement(IRenderable element, Graphics graphics, Render render) { Table table = element as Table; RenderTable(table, graphics, render); RenderExpand(table, graphics, render); //Render the ports if (table.Ports != null) { foreach (Port port in table.Ports.Values) { graphics.TranslateTransform(-table.Bounds.X + port.Bounds.X, -table.Bounds.Y + port.Bounds.Y); port.SuspendValidation(); IFormsRenderer renderer = render.GetRenderer(port); renderer.RenderElement(port, graphics, render); port.ResumeValidation(); graphics.TranslateTransform(table.Bounds.X - port.Bounds.X, table.Bounds.Y - port.Bounds.Y); } } }
//Renders a graphics marker protected virtual void RenderSegment(ComplexLine line, Segment segment, PointF targetPoint, PointF referencePoint, Graphics graphics, Render render) { if (segment.Label == null && segment.Image == null) { return; } //Get midpoint of segment PointF midPoint = new PointF(targetPoint.X + ((referencePoint.X - targetPoint.X) / 2), targetPoint.Y + ((referencePoint.Y - targetPoint.Y) / 2)); //Save the graphics state Matrix gstate = graphics.Transform; //Apply the rotation transform around the centre graphics.Transform = line.GetSegmentTransform(midPoint, referencePoint, graphics.Transform); //Offset and draw image if (segment.Image != null) { graphics.TranslateTransform(0, -segment.Image.Bitmap.Height / 2); IFormsRenderer renderer = render.GetRenderer(segment.Image); renderer.RenderElement(segment.Image, graphics, render); graphics.TranslateTransform(0, segment.Image.Bitmap.Height / 2); } //Draw annotation if (segment.Label != null) { IFormsRenderer renderer = render.GetRenderer(segment.Label); renderer.RenderElement(segment.Label, graphics, render); } //Restore the graphics state graphics.Transform = gstate; }
protected virtual void RenderDecorations(Graphics graphics, Rectangle renderRectangle, Paging paging) { GraphicsState state = graphics.Save(); graphics.SmoothingMode = SmoothingMode.AntiAlias; //Undo any clipping if (paging.Enabled) { graphics.ResetClip(); } //Draw any action paths if (Actions != null) { foreach (Element element in Actions) { if (element.Visible) { GraphicsState graphicsState = graphics.Save(); Matrix matrix = graphics.Transform; PointF translate = element.Bounds.Location; //Translate to the required position matrix.Translate(translate.X, translate.Y); //Set up rotation if (element is ITransformable) { ITransformable rotatable = (ITransformable)element; PointF center = new PointF(element.Bounds.Width / 2, element.Bounds.Height / 2); matrix.RotateAt(rotatable.Rotation, center); } //Apply transform graphics.Transform = matrix; IFormsRenderer renderer = GetRenderer(element); renderer.RenderAction(element, graphics, this); //Restore graphics state graphics.Restore(graphicsState); } } } //Draw any highlights if (Highlights != null) { foreach (Element element in Highlights) { GraphicsState graphicsState = graphics.Save(); Matrix matrix = graphics.Transform; PointF translate = element.Bounds.Location; //Translate to the required position matrix.Translate(translate.X, translate.Y); //Set up rotation if (element is ITransformable) { ITransformable rotatable = (ITransformable)element; PointF center = new PointF(element.Bounds.Width / 2, element.Bounds.Height / 2); matrix.RotateAt(rotatable.Rotation, center); } //Apply transform graphics.Transform = matrix; IFormsRenderer renderer = GetRenderer(element); renderer.RenderHighlight(element, graphics, this); //Restore graphics state graphics.Restore(graphicsState); } } //Draw any decorations if (DecorationPath != null) { graphics.FillPath(Singleton.Instance.HighlightBrush, DecorationPath); graphics.DrawPath(Singleton.Instance.HighlightPen, DecorationPath); } //Reset transformation for non scaled transformations and translate for feedback and selection rectangle graphics.ResetTransform(); graphics.TranslateTransform(-renderRectangle.X, -renderRectangle.Y); graphics.TranslateTransform(paging.WorkspaceOffset.X, paging.WorkspaceOffset.Y); //Offset for page border (if paged). //Draw the vector if required if (Vectors != null) { SmoothingMode mode = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.None; foreach (RectangleF vector in Vectors) { if (vector.Width != 0 || vector.Height != 0) { PointF start = new PointF(vector.Left, vector.Top); PointF end = new PointF(vector.Right, vector.Bottom); graphics.DrawLine(Singleton.Instance.VectorPen, start, end); } } graphics.SmoothingMode = mode; } //Undo paged transform graphics.TranslateTransform(-paging.WorkspaceOffset.X, -paging.WorkspaceOffset.Y); //Offset for page border (if paged). //Draw any feedback if required if (Feedback != null && !FeedbackLocation.IsEmpty) { graphics.SmoothingMode = SmoothingMode.None; Pen pen = new Pen(Color.Black); SolidBrush brush = new SolidBrush(Color.FromArgb(224, SystemColors.Info)); SolidBrush textBrush = new SolidBrush(SystemColors.InfoText); SizeF size = graphics.MeasureString(Feedback, Singleton.Instance.DefaultFont); SizeF padding = new SizeF(2 * ZoomFactor, 1 * ZoomFactor); RectangleF rectangle = new RectangleF(0, 0, size.Width, size.Height); rectangle.Inflate(padding); graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; graphics.TranslateTransform(FeedbackLocation.X, FeedbackLocation.Y); graphics.FillRectangle(brush, rectangle); graphics.DrawRectangle(pen, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); graphics.DrawString(Feedback, Singleton.Instance.DefaultFont, textBrush, 1 * ZoomFactor, 1 * ZoomFactor); graphics.TranslateTransform(-FeedbackLocation.X, -FeedbackLocation.Y); } //Draw the selection rectangle if required if (!SelectionRectangle.IsEmpty && !SelectionRectangle.IsEmpty) { graphics.SmoothingMode = SmoothingMode.None; graphics.FillRectangle(Singleton.Instance.SelectionFillBrush, SelectionRectangle); graphics.DrawRectangle(Singleton.Instance.SelectionPen, SelectionRectangle); } graphics.Restore(state); }
public override void RenderAction(IRenderable element, Graphics graphics, ControlRender render) { Link link = element as Link; if (link.Points == null || link.Points.Count < 2) { return; } PointF startLocation = (PointF)link.Points[0]; PointF startReference = (PointF)link.Points[1]; PointF endLocation = (PointF)link.Points[link.Points.Count - 1]; PointF endReference = (PointF)link.Points[link.Points.Count - 2]; startLocation = Geometry.OffsetPoint(startLocation, link.Bounds.Location); startReference = Geometry.OffsetPoint(startReference, link.Bounds.Location); endLocation = Geometry.OffsetPoint(endLocation, link.Bounds.Location); endReference = Geometry.OffsetPoint(endReference, link.Bounds.Location); //Save the current region Region current = graphics.Clip; //Mask out the start marker if (link.Start.Marker != null) { Region region = new Region(link.Start.Marker.GetPath()); region.Transform(Link.GetMarkerTransform(link.Start.Marker, startLocation, startReference, new Matrix())); graphics.SetClip(region, CombineMode.Exclude); } //Mask out the end marker if (link.End.Marker != null) { Region region = new Region(link.End.Marker.GetPath()); region.Transform(Link.GetMarkerTransform(link.End.Marker, endLocation, endReference, new Matrix())); graphics.SetClip(region, CombineMode.Exclude); } //Render element action base.RenderAction(element, graphics, render); //Render markers if (link.Start.Marker != null || link.End.Marker != null) { graphics.Clip = current; if (link.Start.Marker != null) { RenderMarkerAction(link.Start.Marker, startLocation, startReference, graphics, render); } if (link.End.Marker != null) { RenderMarkerAction(link.End.Marker, endLocation, endReference, graphics, render); } } //Render any ports if (link.Ports != null) { foreach (Port port in link.Ports.Values) { if (port.Visible) { graphics.TranslateTransform(-link.Bounds.X + port.Bounds.X, -link.Bounds.Y + port.Bounds.Y); port.SuspendValidation(); IFormsRenderer renderer = render.GetRenderer(port); renderer.RenderElement(port, graphics, render); port.ResumeValidation(); graphics.TranslateTransform(link.Bounds.X - port.Bounds.X, link.Bounds.Y - port.Bounds.Y); } } } }
private void RenderTable(Table table, Graphics graphics, Render render) { GraphicsPath path = table.GetPath(); if (path == null) { return; } //Draw background Color backColor = render.AdjustColor(table.BackColor, 0, table.Opacity); Color gradientColor = render.AdjustColor(table.GradientColor, 0, table.Opacity); SolidBrush brush = new SolidBrush(backColor); graphics.FillPath(brush, path); Region current = graphics.Clip; Region region = new Region(path); graphics.SetClip(region, CombineMode.Intersect); //Draw Heading RectangleF headingRect = new RectangleF(0, 0, table.Width, table.HeadingHeight); LinearGradientBrush gradient = new LinearGradientBrush(headingRect, gradientColor, backColor, LinearGradientMode.Horizontal); graphics.FillRectangle(gradient, headingRect); //Draw Heading text brush.Color = render.AdjustColor(table.Forecolor, 1, table.Opacity); graphics.DrawString(table.Heading, Singleton.Instance.GetFont(table.FontName, table.FontSize, FontStyle.Bold), brush, 8, 5); graphics.DrawString(table.SubHeading, Singleton.Instance.GetFont(table.FontName, table.FontSize - 1, FontStyle.Regular), brush, 8, 20); if (table.Expanded) { float iHeight = table.HeadingHeight; //Draw the top level rows (if any) if (table.Rows.Count > 0) { brush.Color = table.GradientColor; graphics.FillRectangle(brush, 0, iHeight, table.Indent, 1); iHeight += 1; RenderTableRows(table, graphics, render, table.Rows, ref iHeight); } if (table.Groups.Count > 0) { foreach (TableGroup tableGroup in table.Groups) { iHeight += 1; IFormsRenderer renderer = render.GetRenderer(tableGroup); renderer.RenderElement(tableGroup, graphics, render); iHeight += table.RowHeight; if (tableGroup.Groups.Count > 0 && tableGroup.Expanded) { RenderTableGroups(table, graphics, render, tableGroup.Groups, ref iHeight); } if (tableGroup.Rows.Count > 0 && tableGroup.Expanded) { RenderTableRows(table, graphics, render, tableGroup.Rows, ref iHeight); } } } //Render highlight (if any) if (table.DrawSelectedItem && table.SelectedItem != null && render is ControlRender) { IFormsRenderer renderer = render.GetRenderer(table.SelectedItem); renderer.RenderSelection(table.SelectedItem, graphics, render as ControlRender); } } graphics.Clip = current; //Draw outline Pen pen; if (table.CustomPen == null) { pen = new Pen(table.BorderColor, table.BorderWidth); pen.DashStyle = table.BorderStyle; //Check if winforms renderer and adjust color as required pen.Color = render.AdjustColor(table.BorderColor, table.BorderWidth, table.Opacity); } else { pen = table.CustomPen; } graphics.DrawPath(pen, path); }