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); }
void MAUI::ImageDrawable::draw(int left, int top, int width, int height) { Gfx_drawImage(mImage, left, top); }