/// <summary> /// Keeps the text view data in sync with this surface. /// </summary> protected virtual void ResetArea() { RenderRects = new Rectangle[area.Width * area.Height]; RenderCells = new Cell[area.Width * area.Height]; int index = 0; for (int y = 0; y < area.Height; y++) { for (int x = 0; x < area.Width; x++) { RenderRects[index] = font.GetRenderRect(x, y); RenderCells[index] = cells[(y + area.Top) * width + (x + area.Left)]; index++; } } // TODO: Optimization by calculating AbsArea and seeing if it's diff from current, if so, don't create new RenderRects AbsoluteArea = new Rectangle(0, 0, area.Width * font.Size.X, area.Height * font.Size.Y); if (LastRenderResult.Bounds.Size != AbsoluteArea.Size) { LastRenderResult.Dispose(); LastRenderResult = new RenderTarget2D(Global.GraphicsDevice, AbsoluteArea.Width, AbsoluteArea.Height, false, Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); } }
/// <summary> /// Calculates which cells to draw based on <see cref="BasicSurface.RenderArea"/>. /// </summary> public override void SetRenderCells() { if (!initDone) { return; } RenderRects = new Rectangle[area.Width * area.Height]; for (int l = 0; l < LayerCount; l++) { ResetAreaLayer(layers[l]); } int index = 0; for (int y = 0; y < area.Height; y++) { for (int x = 0; x < area.Width; x++) { RenderRects[index] = Font.GetRenderRect(x, y); index++; } } // TODO: Optimization by calculating AbsArea and seeing if it's diff from current, if so, don't create new RenderRects AbsoluteArea = new Rectangle(0, 0, area.Width * Font.Size.X, area.Height * Font.Size.Y); if (LastRenderResult.Bounds.Size != AbsoluteArea.Size) { LastRenderResult.Dispose(); LastRenderResult = new RenderTarget2D(Global.GraphicsDevice, AbsoluteArea.Width, AbsoluteArea.Height, false, Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); } }
/// <summary> /// Calculates which cells to draw based on <see cref="SurfaceView.RenderArea"/>. /// </summary> public virtual void SetRenderCells() { if (data == null) { return; } if (viewArea.Left + viewArea.Width > data.Width || viewArea.Top + viewArea.Height > data.Height) { throw new ArgumentOutOfRangeException("RenderArea", "Area is out of range of the surface"); } renderArea = new Rectangle(0, 0, viewArea.Width, viewArea.Height); renderRects = new Rectangle[viewArea.Width * viewArea.Height]; cells = new Cell[viewArea.Width * viewArea.Height]; int index = 0; for (int y = 0; y < viewArea.Height; y++) { for (int x = 0; x < viewArea.Width; x++) { renderRects[index] = font.GetRenderRect(x, y); RenderCells[index] = data[(y + viewArea.Top) * data.Width + (x + viewArea.Left)]; index++; } } cells = RenderCells; AbsoluteArea = new Rectangle(0, 0, viewArea.Width * font.Size.X, viewArea.Height * font.Size.Y); if (LastRenderResult.Bounds.Width != AbsoluteArea.Width || LastRenderResult.Bounds.Height != AbsoluteArea.Height) { LastRenderResult.Dispose(); LastRenderResult = new RenderTarget2D(Global.GraphicsDevice, AbsoluteArea.Width, AbsoluteArea.Height, false, Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); } }