Beispiel #1
0
static Texture* addTexture(MAHandle image, GLuint handle) {
	int imageWidth = EXTENT_X(maGetImageSize(image));
	int imageHeight = EXTENT_Y(maGetImageSize(image));

	textures[numTextures].glTexture = handle;
	textures[numTextures].maTexture = image;
	textures[numTextures].imageWidth = imageWidth;
	textures[numTextures].imageHeight = imageHeight;
	textures[numTextures].textureWidth = nextPowerOf2(1, imageWidth);
	textures[numTextures].textureHeight = nextPowerOf2(1, imageHeight);
	textures[numTextures].textureWidthInv = 0x10000/textures[numTextures].textureWidth;
	textures[numTextures].textureHeightInv = 0x10000/textures[numTextures].textureHeight;

	// cache texture coordinates (for the most common case, drawImage).
	textures[numTextures].textureCoords[0] = 0;
	textures[numTextures].textureCoords[1] = 0;
	textures[numTextures].textureCoords[2] = imageWidth;
	textures[numTextures].textureCoords[3] = 0;
	textures[numTextures].textureCoords[4] = imageWidth;
	textures[numTextures].textureCoords[5] = imageHeight;
	textures[numTextures].textureCoords[6] = 0;
	textures[numTextures].textureCoords[7] = imageHeight;

	numTextures++;

	//printf("Added texture. Num textures: %d\n", numTextures);

	return &textures[numTextures-1];
}
Beispiel #2
0
ArrowLayer::ArrowLayer(): MapLayer()
{
	MAExtent imageSize = maGetImageSize(ARROW_ANIMATION);

	int height = EXTENT_Y(imageSize);
	int width = EXTENT_X(imageSize);

	animation = new MAUI::Image(0, 0, width, height, NULL, true, true, ARROW_ANIMATION);

	animState = ARROW_ANIMATION;
}
Beispiel #3
0
int MAMain() {
	int x=0, y=0, dx=1, dy=1;
	int scrW, scrH;
	int srcW, srcH;
	{
		int srcSize = maGetImageSize(SIMG);
		srcW = EXTENT_X(srcSize);
		srcH = EXTENT_Y(srcSize);
	}
	maCreateDrawableImage(TIMG, srcW,srcH);
	maSetDrawTarget(TIMG);

	maSetColor(0);	//black
	maFillRect(0,0, srcW,srcH);
	maDrawImage(SIMG, 0,0);
	maSetColor(0xff0000);	//red
	maLine(0,0, srcW,srcH);
	maLine(srcW,0, 0,srcH);

	maSetDrawTarget(HANDLE_SCREEN);
	{
		int scrSize = maGetScrSize();
		scrW = EXTENT_X(scrSize);
		scrH = EXTENT_Y(scrSize);
	}
	while(1) {
		//int then = maGetMilliSecondCount();

		maSetColor(0);	//black
		maFillRect(0,0, scrW,scrH);

		maDrawImage(TIMG, x, y);
		if((dx > 0 && x + srcW > scrW) || (dx < 0 && x < 0)) {
			dx = -dx;
		}
		if((dy > 0 && y + srcH > scrH) || (dy < 0 && y < 0)) {
			dy = -dy;
		}
		x += dx;
		y += dy;
		maUpdateScreen();
		/*{
		int now = maGetMilliSecondCount();
		int time_padding = 10 - (now - then);
		if(time_padding > 0)
		maSleep(time_padding);
		}*/
	}
}
NewMenuScreen::NewMenuScreen(Feed *feed) : mHttp(this), screenType(screenType) {
	lprintfln("NewMenuScreen::Memory Heap %d, Free Heap %d", heapTotalMemory(), heapFreeMemory());
	this->feed = feed;

	int itemCount = sizeof(menuItems)/sizeof(item);

	c=0;
	versionChecked=0;
	next = NULL;
	first = 1;

	mainLayout = new Layout(0, 0, scrWidth, scrHeight, NULL, 1, 2);

	MAExtent imgSize = maGetImageSize(RES_IMAGE);
	int imgHeight = EXTENT_Y(imgSize);

	ListBox *listBox = new ListBox(0, 0, scrWidth, scrHeight, mainLayout, ListBox::LBO_VERTICAL, ListBox::LBA_LINEAR, true);
	listBox->setSkin(Util::getSkinBack());
	/*listBox->setSkin(Util::getSkinHeader());*/
	/*listBox->setDrawBackground(false);*/


	/*Layout *header = new Layout(0,0,scrWidth, imgHeight, NULL, 1, 1);
	header->setSkin(Util::getSkinHeader());*/

	ListBox *header = new ListBox(0, 0, scrWidth, imgHeight, NULL, ListBox::LBO_VERTICAL, ListBox::LBA_LINEAR, true);
	header->setSkin(Util::getSkinHeader());

	Image *image = new Image(0, 0, scrWidth,  imgHeight, NULL, true, true, RES_IMAGE);
	header->add(image);

	listBox->add(header);

	label = new Label(0,0,scrWidth,36,NULL,"",0,Util::getDefaultSelected());
	label->setMultiLine(true);
	label->setAutoSizeY();
	label->setMultiLine(true);
	label->setDrawBackground(false);
	listBox->add(label);

	menu = new GCMenu(menuItems, itemCount, 0, 0, scrWidth, listBox->getHeight() - imgHeight, false, false, listBox);

	setMain(mainLayout);

	origMenu = this;
}
Beispiel #5
0
	void testDrawableImages() {
		const unsigned int colors[] = {
			0xff000000,
			0xff0000ff,
			0xff00ff00,
			0xff00ffff,
			0xffff0000,
			0xffff00ff,
			0xffffff00,
			0xffffffff,
		};

		const unsigned int NUMCOLORS = sizeof(colors)/sizeof(int);

		unsigned int colors2[NUMCOLORS];

		MAHandle testImg = maCreatePlaceholder();

		printf("testing resources\n");

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

		MAExtent e1 = maGetImageSize(testImg);

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

		maSetDrawTarget(testImg);

		for(unsigned int i = 0; i < NUMCOLORS; i++) {
			maSetColor(colors[i]);
			maPlot(i, 0);
		}

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

		maSetDrawTarget(0);

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

		assert(
				"testing drawable image res",
				(memcmp(colors, colors2, sizeof(colors)) == 0)
		);
	}
Beispiel #6
0
	void testGetImageData() {
		printf("testing maGetImageData\n");

		const unsigned int NUMCOLORS = sizeof(sColors)/sizeof(int);
		unsigned int colors2[NUMCOLORS];
		MAExtent e1 = maGetImageSize(ARGB_PNG);

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

		MARect rect = {0, 0, NUMCOLORS, 1};
		maGetImageData(ARGB_PNG, colors2, &rect, NUMCOLORS);

		assert("image: getData from PNG",
			(memcmp(sColors, colors2, sizeof(sColors)) == 0)
		);
		maDrawImage(ARGB_PNG, 0, 0);
		maUpdateScreen();
		//FREEZE;
	}
Beispiel #7
0
	void setupImageButton(
			NativeUI::ImageButton* imageButton,
			NativeUI::ButtonListener* btnListener,
			MAHandle normalImage,
			MAHandle pressedImage )
	{
		if ( NULL == imageButton)
		{
			return;
		}
		imageButton->wrapContentHorizontally();
		imageButton->wrapContentVertically();
		imageButton->setBackgroundImage(normalImage);
		imageButton->setPressedImage(pressedImage);
		imageButton->addButtonListener(btnListener);

		// Set initial image button size.
		MAExtent imageButtonSize = maGetImageSize(normalImage);
		imageButton->setWidth(EXTENT_X(imageButtonSize));
		imageButton->setHeight(EXTENT_Y(imageButtonSize));
	}
Beispiel #8
0
	void WidgetSkin::setUnselectedImage(MAHandle image) {
		this->unselectedImage = image;
		if(!unselectedImage) return;
		MAExtent imgSize = maGetImageSize(image);

		unselectedImageWidth = EXTENT_X(imgSize);
		unselectedImageHeight = EXTENT_Y(imgSize);

		if(selectedImage) {
			if(unselectedImageHeight!=selectedImageHeight ||
				unselectedImageWidth!=selectedImageWidth) {
				unselectedImageWidth = 0;
				unselectedImageHeight = 0;
				unselectedImage = 0;
				maPanic(0, "Not the same dimension on WidgetSkin unselectedImage as selectedImage");
			}
		} else {
			imageWidth = unselectedImageWidth;
			imageHeight = unselectedImageHeight;
		}

		rebuildRects();
	}
Beispiel #9
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)
		);
	}
Beispiel #10
0
bool BarcodeScanner::uploadHandle(MAHandle image)
{
	if(mImageScanner == NULL)
		maPanic(0, "No Image Scanner");

	if(mImgData != NULL)
		maPanic(0, "Image already uploaded!");

	int imgSize = maGetImageSize(image);

	int imgW = EXTENT_X(imgSize);
	int imgH = EXTENT_Y(imgSize);

	int imgDataSize = imgW * imgH;
	int* imgData = (int*) malloc(imgDataSize * 4);

	MARect imgRect = {0, 0, imgW, imgH};

	maGetImageData(image, imgData, &imgRect, imgW);

	mImgData = (unsigned char*) malloc(imgDataSize);

	return upload(imgData, imgW, imgH);
}
Beispiel #11
0
/**
 * Entry point of the program. The MAMain function
 * needs to be declared as extern "C".
 */
extern "C" int MAMain()
{
	MAEvent event;

	int imgSize = maGetImageSize(RES_BARCODE_IMAGE);

	int imgW = EXTENT_X(imgSize);
	int imgH = EXTENT_Y(imgSize);

	int imgDataSize = imgW * imgH;
	int* imgData = (int*) malloc(imgDataSize * 4);

	MARect imgRect;
	imgRect.left = 0;
	imgRect.top = 0;
	imgRect.width = imgW;
	imgRect.height = imgH;

	maGetImageData(RES_BARCODE_IMAGE, imgData, &imgRect, imgW);

	unsigned char* fixedImg = (unsigned char*) malloc(imgDataSize);

	printf("Converting image\n");

	createLuminosity(imgData, fixedImg, imgDataSize);

	printf("Scanning for barcodes\n");

	// create a reader
	zbar::ImageScanner scanner = zbar::zbar_image_scanner_create();

	// configure the reader
	zbar::zbar_image_scanner_set_config(scanner, zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);

	// wrap image data
	zbar::zbar_image_t *image = zbar::zbar_image_create();
	zbar::zbar_image_set_format(image, 0x30303859);// "Y800" = 0x30303859

	zbar::zbar_image_set_size(image, imgW, imgH);

	zbar::zbar_image_set_data(image, fixedImg, imgW * imgH, NULL);//zbar_image_free_data);

	// scan the image for barcodes
	zbar_scan_image(scanner, image);

	// extract results
	bool result = false;
	const zbar::zbar_symbol_t *symbol = zbar_image_first_symbol(image);
	for(; symbol; symbol = zbar_symbol_next(symbol)) {
		// do something useful with results
		zbar::zbar_symbol_type_t typ = zbar_symbol_get_type(symbol);
		const char *data = zbar_symbol_get_data(symbol);
		printf("decoded %s symbol \"%s\"\n",
			   zbar_get_symbol_name(typ), data);
		result = true;
	}

	// clean up
	zbar_image_destroy(image);

	if(!result)
		printf("No symbols found.\n");

	printf("Press zero, back or touch screen to exit\n");

	while (TRUE)
	{
		maWait(0);
		maGetEvent(&event);

		if (EVENT_TYPE_CLOSE == event.type)
		{
			// Exit while loop.
			break;
		}
		else if (EVENT_TYPE_KEY_PRESSED == event.type)
		{
			if (MAK_BACK == event.key || MAK_0 == event.key)
			{
				// Exit while loop.
				break;
			}
		}
		else if (EVENT_TYPE_POINTER_PRESSED == event.type)
		{
			break;
		}
	}

	return 0;
}
Beispiel #12
0
/*
 * Create the UI for the image swiper screen.
 */
void ScreenImageSwiper::createUI()
{
	// Create the main layout for this screen.
	mMainLayout = new VerticalLayout();

	// Set the screne title.
	setTitle(TXT_SCREEN_TITLE);

	if (WidgetManager::isAndroid())
	{
		// Set screen icon for Android.
		setIcon(RES_TAB_ICON_IMAGE_SWIPER_ANDROID);
	}
	else
	{
		// Create the navigation bar for iOS.
		mTitleWidget = new NavigationBar();

		// Set the navigation's bar title.
		mTitleWidget->setTitle(TXT_SCREEN_TITLE);

		// Remove the navigation's bar back button.
		mTitleWidget->setBackButtonTitle("");

		// Add the navigation bar to the main layout of the screen.
		mMainLayout->addChild(mTitleWidget);

		// Set screen icon for iOS.
		setIcon(RES_TAB_ICON_IMAGE_SWIPER);
	}

	// Get the screen size.
	getScreenSize();

	// Create a RelativeLayout as container for images.
	mImagesLayout = new RelativeLayout();

	// Set the layout's background color.
	mImagesLayout->setBackgroundColor(SCREEN_BG_COLOR);

	// Create a background gradient and add it to the images Layout
	mImagesLayout->addChild(createBackgroundGradient());

	// Loads the needed image according to the screen resolution.
	loadImages(mScreenWidth);

	// Get the image size.
	MAExtent size = maGetImageSize(mImages[DEFAULT_IMAGE_INDEX]->getHandle());

	// Compute the needed width and height for images.
	int imageWidth = mScreenWidth - (mScreenWidth / 3) - mScreenWidth / 6;
	int imageHeight = imageWidth * EXTENT_Y(size) / EXTENT_X(size);

	setupImages(imageWidth, imageHeight);

	//Creates a label layout to display image names and sets it's properties
	mLabelLayout = new Label();
	mLabelLayout->setSize(MAW_CONSTANT_FILL_AVAILABLE_SPACE, mScreenHeight / 10);
	mLabelLayout->setBackgroundColor(LABEL_BG_COLOR);
	mLabelLayout->setText(mImages[DEFAULT_IMAGE_INDEX]->getName());
	mLabelLayout->setFontColor(FONT_COLOR);
	mLabelLayout->centerTextHorizontally();
	mLabelLayout->centerTextVertically();

	// Adds the created layouts as childrens of the main one.
	mMainLayout->addChild(mImagesLayout);
	mMainLayout->addChild(mLabelLayout);

	// Sets the main layout as the main widget for the current screen.
	setMainWidget(mMainLayout);
}
Beispiel #13
0
	void AnimatedImage::setResource(MAHandle res) {
		mResource = res;
		if(res == 0) return;
		mResSize = maGetImageSize(res);
	}
Beispiel #14
0
	void ImageGenerators::linearGradient(
		MAHandle image, 
		Point start, 
		Point end, 
		int startColor,
		int endColor, 
		ImageGenerators::AlphaMode alphaMode)
	{
		MAExtent size = maGetImageSize(image);
		int imgWidth = EXTENT_X(size);
		int imgHeight = EXTENT_Y(size);

		int gradVecX;
		int gradVecY;
		int gradOrthoVecX;
		int gradOrthoVecY;

		gradVecX = end.x - start.x;
		gradVecY = end.y - start.y;
		gradOrthoVecX = gradVecY;
		gradOrthoVecY = -gradVecX;

		int startAlpha =	(startColor&0xff000000)>>24;
		int startRed =		(startColor&0x00ff0000)>>16;
		int startGreen =	(startColor&0x0000ff00)>>8;
		int startBlue =		(startColor&0x000000ff);

		int endAlpha =		(endColor&0xff000000)>>24;
		int endRed =		(endColor&0x00ff0000)>>16;
		int endGreen =		(endColor&0x0000ff00)>>8;
		int endBlue =		(endColor&0x000000ff);

		int *tempSurface = new int[imgWidth*imgHeight];

		if(!tempSurface) {
			maPanic(0, "ImageGenerators::linearGradient, NO MEMORY!");
		}

		int *dst = tempSurface;

		MAHandle lastDrawTarget = maSetDrawTarget(image);

		int sqrLen = gradOrthoVecX*gradOrthoVecX + gradOrthoVecY*gradOrthoVecY;
		double sqrtLen = (sqrt((double)sqrLen));
		double sqrtLenRecip = 1.0/sqrtLen;
		//lprintfln("imgWidth: %d, imgHeight: %d\n", imgWidth, imgHeight);
		for(int j = 0; j < imgHeight; j++) {
			for(int i = 0; i < imgWidth; i++) {

				int u = (((i - start.x)*gradOrthoVecX + 
					(j - start.y)*gradOrthoVecY)<<16) / sqrLen;

				int projectedPointX = ((u*gradOrthoVecX)>>16);
				int projectedPointY = ((u*gradOrthoVecY)>>16);

				//lprintfln("we come here! %d\n", i + j*imgWidth);

				double distToStart = 
					(sqrt((double)
						(((start.x+projectedPointX)-i)*((start.x+projectedPointX)-i) +
						((start.y+projectedPointY)-j)*((start.y+projectedPointY)-j))
						));

				double distToEnd = (sqrt((double)
					(((end.x+projectedPointX)-i)*((end.x+projectedPointX)-i) +
					((end.y+projectedPointY)-j)*((end.y+projectedPointY)-j))
					)); 
				//double distToStart = 0.0;
				//double distToEnd = 0.0;

				//	double distToEnd = sqrtLen - distToStart;

				if(distToEnd >= sqrtLen) {
					*dst++  = startColor;
				} 
				else if(distToStart >= sqrtLen) {
					*dst++ = endColor;
				} 
				else {
					int r = (int)(((distToStart*(double)endRed) 
						+ (distToEnd*(double)startRed))*sqrtLenRecip);
					int g = (int)(((distToStart*(double)endGreen) 
						+ (distToEnd*(double)startGreen))*sqrtLenRecip);
					int b = (int)(((distToStart*(double)endBlue) 
						+ (distToEnd*(double)startBlue))*sqrtLenRecip);
					int a = (int)(((distToStart*(double)endAlpha) 
						+ (distToEnd*(double)startAlpha))*sqrtLenRecip);
					if(r<0)		r = 0;
					if(r>255)	r = 255;
					if(g<0)		g = 0;
					if(g>255)	g = 255;
					if(b<0)		b = 0;
					if(b>255)	b = 255;
					if(a<0)		a = 0;
					if(a>255)	a = 255;

					*dst++ = (a<<24)|(r<<16)|(g<<8)|(b);
				}
			} 
		}

		if(alphaMode == AM_WRITEALPHA) {
			MAPoint2d dstPoint = {0, 0};
			MARect srcRect = {0, 0, imgWidth, imgHeight};
			maDrawRGB(&dstPoint, tempSurface, &srcRect, imgWidth);
			maSetDrawTarget(lastDrawTarget);
		} 
		else if(alphaMode == AM_USEALPHA) {
			// TODO: Implement missing code.
		} 
		else if(alphaMode == AM_NOALPHA) {
			// TODO: Implement missing code.
		}

		delete []tempSurface;
	}
Beispiel #15
0
/*
 * Create the UI for the image swiper screen.
 */
void ScreenImageSwiper::createUI()
{
	// Create the main layout for this screen.
	mMainLayout = new VerticalLayout();

	// Set the screen title.
	setTitle(TXT_SCREEN_TITLE);

	// Get the screen size.
	getScreenSize();

	if (getPlatform() == ANDROID)
	{
		// Set screen icon for Android.
		setIcon(RES_TAB_ICON_IMAGE_SWIPER_ANDROID);

		// Create ads banner.
		if ( mScreenWidth > 50 )
		{
			if ( mScreenWidth > 60 )
			{
				mAdsBanner = new Ads::Banner(ADS_PUBLISHER_ID, Ads::BANNER_SIZE_LEADERBOARD);
			}
			else
			{
				mAdsBanner = new Ads::Banner(ADS_PUBLISHER_ID, Ads::BANNER_SIZE_IAB);
			}
		}
		else
		{
			mAdsBanner = new Ads::Banner(ADS_PUBLISHER_ID);
		}
	}
	else if(getPlatform() == IOS)
	{
		// Create the navigation bar for iOS.
		mTitleWidget = new NavigationBar();

		// Set the navigation's bar title.
		mTitleWidget->setTitle(TXT_SCREEN_TITLE);

		// Remove the navigation's bar back button.
		mTitleWidget->setBackButtonTitle("");

		mTitleWidget->fillSpaceHorizontally();

		// Add the navigation bar to the main layout of the screen.
		mMainLayout->addChild(mTitleWidget);

		// Set screen icon for iOS.
		setIcon(RES_TAB_ICON_IMAGE_SWIPER);

		// Create ads banner.
		mAdsBanner = new Ads::Banner(ADS_PUBLISHER_ID);
	}

	mAdsBanner->requestContent(true);

	// Add banner to layout.
	mMainLayout->addBanner(mAdsBanner);

	// Create a RelativeLayout as container for images.
	mImagesLayout = new RelativeLayout();

	// Set the layout's background color.
	mImagesLayout->setBackgroundColor(SCREEN_BG_COLOR);

	// Create a background gradient and add it to the images Layout
	mImagesLayout->addChild(createBackgroundGradient());

	// Loads the needed image according to the screen resolution.
	loadImages(mScreenWidth);

	// Get the image size.
	MAExtent size = maGetImageSize(mImages[DEFAULT_IMAGE_INDEX]->getHandle());

	// Compute the needed width and height for images.
	int imageWidth = mScreenWidth - (mScreenWidth / 3) - mScreenWidth / 6;
	int imageHeight = imageWidth * EXTENT_Y(size) / EXTENT_X(size);

	setupImages(imageWidth, imageHeight);

	//Creates a label layout to display image names and sets it's properties
	mLabelLayout = new Label();
	mLabelLayout->setSize(MAW_CONSTANT_FILL_AVAILABLE_SPACE, mScreenHeight / 10);
	mLabelLayout->setBackgroundColor(LABEL_BG_COLOR);
	mLabelLayout->setText(mImages[DEFAULT_IMAGE_INDEX]->getName());
	mLabelLayout->setFontColor(FONT_COLOR);
	mLabelLayout->setTextHorizontalAlignment(MAW_ALIGNMENT_CENTER);
	mLabelLayout->setTextVerticalAlignment(MAW_ALIGNMENT_CENTER);

	// Adds the created layouts as childrens of the main one.
	mMainLayout->addChild(mImagesLayout);
	mMainLayout->addChild(mLabelLayout);

	// Sets the main layout as the main widget for the current screen.
	setMainWidget(mMainLayout);
}