Beispiel #1
0
/**
 * Creates an image with a gray gradient.
 */
Image* ScreenImageSwiper::createBackgroundGradient()
{
	// Create gradient bitmap.
	int *gradientBitmap = new int[16 * 16];
	for (int i = 0; i < 16; ++i)
	{
		for (int j = 0; j<16; ++j)
		{
			int color = 0xFF - (i * 0xFF / 16);
			gradientBitmap[i*16 + j] = color | (color << 8) | (color << 16);
		}
	}

	// Create image with gradient.
	MAHandle imageHandle = maCreatePlaceholder();
	maCreateImageRaw(imageHandle, gradientBitmap, EXTENT(16, 16), 0);
	delete gradientBitmap;

	// Create image widget.
	Image* imageWidget = new Image();
	imageWidget->setImage(imageHandle);
	imageWidget->setPosition(0, 0);
	imageWidget->setSize(
		MAW_CONSTANT_FILL_AVAILABLE_SPACE,
		MAW_CONSTANT_FILL_AVAILABLE_SPACE);

	// Tell image to stretch.
	imageWidget->setProperty("scaleMode", "scaleXY");

	return imageWidget;
}
Beispiel #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);
	}
Beispiel #3
0
	void testImageRawData() {
		const unsigned int NUMCOLORS = sizeof(sColors)/sizeof(int);

		unsigned int colors2[NUMCOLORS];

		MAHandle testImg = maCreatePlaceholder();

		printf("imageRawData\n");

		int res = maCreateImageRaw(testImg, sColors, EXTENT(NUMCOLORS,1), 1);
		assert("maCreateImageRaw", res == RES_OK);

		MAExtent e1 = maGetImageSize(testImg);

		assert("maGetImageSize", e1 == EXTENT(NUMCOLORS,1));

		MARect rect = {0, 0, NUMCOLORS, 1};

		maGetImageData(testImg, colors2, &rect, NUMCOLORS);

		assert("image: createRaw then getData",
			(memcmp(sColors, colors2, sizeof(sColors)) == 0)
		);
	}