Beispiel #1
0
            public Brush GetSolidBrush(WinDrawingContext theHDC, Color aColor)
            {
                int   i;
                Brush result = null;

                // See if it's already in the cache
                for (i = 0; (i < BRUSH_CACHE_SIZE) && mCache[i].mBrush != null; i++)
                {
                    if (mCache[i].mBrush != null && (mCache[i].mBrushColor == aColor))
                    {
                        // Found an existing brush
                        result = mCache[i].mBrush;
                        theHDC.currentBrush = result;
                        break;
                    }
                }

                if (result == null)
                {
                    // We didn't find it in the set of existing brushes, so create a
                    // new brush
                    result = new SolidBrush(aColor);
                    theHDC.currentBrush = result;



                    // If there's an empty slot in the cache, then just add it there
                    if (i >= BRUSH_CACHE_SIZE)
                    {
                        // Nope. The cache is full so we need to replace the oldest entry
                        // in the cache

                        i = mIndexOldest;
                        if (++mIndexOldest >= BRUSH_CACHE_SIZE)
                        {
                            mIndexOldest = 2;
                        }
                    }

                    // Add the new entry
                    mCache[i].mBrush      = result;
                    mCache[i].mBrushColor = aColor;
                }
                return(result);
            }
Beispiel #2
0
			public Brush GetSolidBrush(WinDrawingContext theHDC, Color aColor)
			{
				int     i;
        Brush result = null;
   
				// See if it's already in the cache
				for (i = 0; (i < BRUSH_CACHE_SIZE) && mCache[i].mBrush != null; i++) 
				{
					if (mCache[i].mBrush != null && (mCache[i].mBrushColor == aColor)) 
					{
						// Found an existing brush
						result = mCache[i].mBrush;
						theHDC.currentBrush = result;
						break;
					}
				}
 
				if (result == null) 
				{
					// We didn't find it in the set of existing brushes, so create a
					// new brush
          result = new SolidBrush(aColor);
          theHDC.currentBrush = result;
 
					
 
					// If there's an empty slot in the cache, then just add it there
					if (i >= BRUSH_CACHE_SIZE) 
					{
						// Nope. The cache is full so we need to replace the oldest entry
						// in the cache
						
						i = mIndexOldest;
						if (++mIndexOldest >= BRUSH_CACHE_SIZE) 
						{
							mIndexOldest = 2;
						}
					}
 
					// Add the new entry
					mCache[i].mBrush = result;
					mCache[i].mBrushColor = aColor;
				}
				return result;
			}