/// <summary> /// Constructs a new object that represents the current state of the given /// cell in the specified view. /// </summary> /// <param name="view">Graph view that contains the state.</param> /// <param name="cell">Cell that this state represents.</param> /// <param name="style">Array of key, value pairs that constitute the style.</param> public mxCellState(mxGraphView view, Object cell, Dictionary <string, Object> style) { View = view; Cell = cell; Style = style; }
/// <summary> /// Constructs a new object that represents the current state of the given /// cell in the specified view. /// </summary> /// <param name="view">Graph view that contains the state.</param> /// <param name="cell">Cell that this state represents.</param> /// <param name="style">Array of key, value pairs that constitute the style.</param> public mxCellState(mxGraphView view, Object cell, Dictionary<string, Object> style) { View = view; Cell = cell; Style = style; }
/// <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; // Creates virtual parent state for validation mxCellState state = view.CreateState(new mxCell()); // 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.ValidateBounds(state, cells[i]); } for (int i = 0; i < cells.Length; i++) { view.ValidatePoints(state, 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); }