private static IDisposable DrawBackSolid(RectangleF drawRect, Color color1, Graphics g, IDisposable memento) { // Cannot draw a zero length rectangle if ((drawRect.Width > 0) && (drawRect.Height > 0)) { bool generate = true; MementoBackSolid cache; // Access a cache instance and decide if cache resources need generating if ((memento == null) || !(memento is MementoBackSolid)) { if (memento != null) { memento.Dispose(); } cache = new MementoBackSolid(drawRect, color1); memento = cache; } else { cache = (MementoBackSolid)memento; generate = !cache.UseCachedValues(drawRect, color1); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); cache.solidBrush = new SolidBrush(color1); } if (cache.solidBrush != null) { g.FillRectangle(cache.solidBrush, drawRect); } } return(memento); }
private static IDisposable DrawBackSolid(RectangleF drawRect, Color color1, Graphics g, IDisposable memento) { // Cannot draw a zero length rectangle if ((drawRect.Width > 0) && (drawRect.Height > 0)) { bool generate = true; MementoBackSolid cache; // Access a cache instance and decide if cache resources need generating if ((memento == null) || !(memento is MementoBackSolid)) { if (memento != null) memento.Dispose(); cache = new MementoBackSolid(drawRect, color1); memento = cache; } else { cache = (MementoBackSolid)memento; generate = !cache.UseCachedValues(drawRect, color1); } // Do we need to generate the contents of the cache? if (generate) { // Dispose of existing values cache.Dispose(); cache.solidBrush = new SolidBrush(color1); } if (cache.solidBrush != null) g.FillRectangle(cache.solidBrush, drawRect); } return memento; }