/// <summary> /// Creates an image for the given arguments. /// </summary> public static Image CreateImage(mxGraph graph, Object[] cells, double scale, Color?background, bool antiAlias, mxRectangle clip, mxGdiCanvas graphicsCanvas) { mxImageCanvas canvas = (mxImageCanvas)DrawCells(graph, cells, scale, clip, new ImageCanvasFactory(graphicsCanvas, background, antiAlias)); return(canvas.Destroy()); }
/// <summary> /// Returns true if the given object equals this rectangle. /// </summary> /// <returns>Returns true if obj is equal.</returns> new public Boolean Equals(Object obj) { if (obj is mxRectangle) { mxRectangle rect = (mxRectangle)obj; return(rect.X == X && rect.Y == Y && rect.Width == Width && rect.Height == height); } return(false); }
/// <summary> /// Adds the given rectangle to this rectangle. /// </summary> public void Add(mxRectangle rect) { if (rect != null) { double minX = Math.Min(x, rect.x); double minY = Math.Min(y, rect.y); double maxX = Math.Max(x + width, rect.x + rect.width); double maxY = Math.Max(y + height, rect.y + rect.height); x = minX; y = minY; width = maxX - minX; height = maxY - minY; } }
/// <summary> /// Draws the given cells using a Graphics2D canvas and returns the buffered image /// that represents the cells. /// </summary> public static mxICanvas DrawCells(mxGraph graph, Object[] cells, double scale, mxRectangle clip, CanvasFactory factory) { mxICanvas canvas = null; if (cells == null) { cells = new Object[] { graph.Model.Root }; } if (cells != null) { // Gets the current state of the view mxGraphView view = graph.View; Dictionary <Object, mxCellState> states = view.States; double oldScale = view.Scale; // Keeps the existing translation as the cells might // be aligned to the grid in a different way in a graph // that has a translation other than zero bool eventsEnabled = view.IsEventsEnabled; // Disables firing of scale events so that there is no // repaint or update of the original graph view.IsEventsEnabled = false; try { // TODO: Factor-out into mxTemporaryCellStates class view.States = new Dictionary <Object, mxCellState>(); view.Scale = scale; // Validates the vertices and edges without adding them to // the model so that the original cells are not modified for (int i = 0; i < cells.Length; i++) { view.ValidateCellState(view.ValidateCell(cells[i])); } if (clip == null) { clip = graph.GetPaintBounds(cells); } if (clip != null && clip.Width > 0 && clip.Height > 0) { Rectangle rect = clip.GetRectangle(); canvas = factory.CreateCanvas(rect.Width + 1, rect.Height + 1); if (canvas != null) { double previousScale = canvas.Scale; Point previousTranslate = canvas.Translate; try { canvas.Translate = new Point(-rect.X, -rect.Y); canvas.Scale = view.Scale; for (int i = 0; i < cells.Length; i++) { graph.DrawCell(canvas, cells[i]); } } finally { canvas.Scale = previousScale; canvas.Translate = previousTranslate; } } } } finally { view.Scale = oldScale; view.States = states; view.IsEventsEnabled = eventsEnabled; } } return(canvas); }
/// <summary> /// Creates an image for the given arguments. /// </summary> public static Image CreateImage(mxGraph graph, Object[] cells, double scale, Color?background, bool antiAlias, mxRectangle clip) { return(CreateImage(graph, cells, scale, background, antiAlias, clip, new mxGdiCanvas())); }
/// <summary> /// Constructs a copy of the given rectangle. /// </summary> /// <param name="rect">Rectangle to construct a copy of.</param> public mxRectangle(mxRectangle rect) : this(rect.X, rect.Y, rect.Width, rect.Height) { }