示例#1
0
void
precalculateTileInfo (const TileDescription& tileDesc,
		      int minX, int maxX,
		      int minY, int maxY,
		      int *&numXTiles, int *&numYTiles,
		      int &numXLevels, int &numYLevels)
{
    numXLevels = calculateNumXLevels(tileDesc, minX, maxX, minY, maxY);
    numYLevels = calculateNumYLevels(tileDesc, minX, maxX, minY, maxY);
    
    numXTiles = new int[numXLevels];
    numYTiles = new int[numYLevels];

    calculateNumTiles (numXTiles,
		       numXLevels,
		       minX, maxX,
		       tileDesc.xSize,
		       tileDesc.roundingMode);

    calculateNumTiles (numYTiles,
		       numYLevels,
		       minY, maxY,
		       tileDesc.ySize,
		       tileDesc.roundingMode);
}
示例#2
0
	void WidgetSkin::draw(int x, int y, int width, int height, eType type) {
		MAHandle cached = 0;

		// Calculate numTiles needed to be drawn, if they are many, we need to cache, otherwise draw directly...
		int numTiles = calculateNumTiles(width, height);
		if(!useCache || numTiles<100) {
			drawDirect(x, y, width, height, type);
			return;
		}

		CacheKey newKey = CacheKey(this, width, height, type);
		cached =  getFromCache(newKey);

		// If we didn't find a cached widgetskin, let's generate one and save it in the cache.
		if(!cached) {
			// set malloc handler to null so that we can catch if we're out of heap and write directly to the screen then.
			#ifndef MOSYNC_NATIVE
			malloc_handler mh = set_malloc_handler(NULL);
			#endif
			int *data = new int[width*height];
			if(!data) {
				drawDirect(x, y, width, height, type);
				return;
			}
			#ifndef MOSYNC_NATIVE
			set_malloc_handler(mh);
			#endif
			drawToData(data, 0, 0, width, height, type);
			CacheElement cacheElem;

			flushCacheUntilNewImageFits(width*height);

			cacheElem.image = maCreatePlaceholder();
			if(maCreateImageRaw(cacheElem.image,data,EXTENT(width,height),1)!=RES_OK) {
				maPanic(1, "Could not create raw image");
			}

			delete data;
			cacheElem.lastUsed = maGetMilliSecondCount();
			cached = cacheElem.image;
			addToCache(newKey, cacheElem);
		}

		// Draw the cached widgetskin.
		Gfx_drawImage(cached, x, y);
	}