Exemplo n.º 1
0
void logString(void* aVisualString) {
	if (!doLogString) {
		initCocoaBundle();
	}
	VisualString* aString = reinterpret_cast<VisualString*>(aVisualString);
	CFStringRef aCFStringRef = aString->getCharactersPointer();
	doLogString(aCFStringRef);
}
OSStatus VisualTextureContainer::initWithURL(VisualString& anURL) {

	this->releaseTextureData();
	if (this->pixelBuffer != NULL) {
		free(this->pixelBuffer);
		this->pixelBuffer = NULL;
	}

	OSStatus osStatus = noErr;
	
	CFURLRef imageURL = CFURLCreateWithString(kCFAllocatorDefault, anURL.getCharactersPointer(), NULL);
	CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imageURL, NULL);
	CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
	this->imageWidth = CGImageGetWidth(imageRef);
	this->imageHeight = CGImageGetHeight(imageRef);
	VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
	this->useRectExtension = theVisualGraphics->canUseTextureRectExtension();
	if (this->useRectExtension == false) {
		this->textureWidth = theVisualGraphics->power2Ceiling(this->imageWidth);
		this->textureHeight = theVisualGraphics->power2Ceiling(this->imageHeight);
	} else {
		this->textureWidth = this->imageWidth;
		this->textureHeight = this->imageHeight;
	}
	CGContextRef context = theVisualGraphics->createBitmapContext(this->textureWidth, this->textureHeight);

	CGContextTranslateCTM(context, 0.0, (float)this->textureHeight + (float)(this->textureHeight - this->imageHeight));
	CGContextScaleCTM(context, 1.0, -1.0);

	CGRect rect = CGRectMake(0, (this->textureHeight - this->imageHeight), this->imageWidth, this->imageHeight);
	CGContextDrawImage(context, rect, imageRef);

	this->pixelBuffer = static_cast<UInt32*>(CGBitmapContextGetData(context));

	this->textureName = theVisualGraphics->getNextFreeTextureName();
	this->textureIsSet = true;
	VisualTextureContainer::textureRefCountMap[this->textureName] = 1;
	theVisualGraphics->copyARGBBitmapDataToTexture(this->textureName, this->textureWidth, this->textureHeight, this->useRectExtension, this->pixelFormat, this->dataType, const_cast<const UInt32**>(&(this->pixelBuffer)));

	CGContextRelease(context);
	if (this->pixelBuffer) {
		free(this->pixelBuffer);
		this->pixelBuffer = NULL;
	}
	CGImageRelease(imageRef);

	if (this->useRectExtension == false) {
		this->textureLogicalWidth = (double)this->imageWidth / (double)this->textureWidth;
		this->textureLogicalHeight = (double)this->imageHeight / (double)this->textureHeight;
	} else {
		this->textureLogicalWidth = (double)this->textureWidth;
		this->textureLogicalHeight = (double)this->textureHeight;
	}

	return osStatus;

}
Exemplo n.º 3
0
bool getDimensionsOfCocoaStringBitmap(void* aVisualString, void* aVisualStringStyle, uint32* imageWidth, uint32* imageHeight, uint16 maxPixelWidth, uint16 maxPixelHeight, char* alignment) {
	
	bool success = true;
	
	if (!doGetDimensionsOfStringBitmap) {
		initCocoaBundle();
	}
	
	VisualString* aString = reinterpret_cast<VisualString*>(aVisualString);
	VisualStringStyle* aStringStyle = reinterpret_cast<VisualStringStyle*>(aVisualStringStyle);
	const CFStringRef aCFStringRef = aString->getCharactersPointer();
	success = doGetDimensionsOfStringBitmap(aCFStringRef, imageWidth, imageHeight, aStringStyle->fontNameStr, &(aStringStyle->fontSize), aStringStyle->fontColor.red, aStringStyle->fontColor.green, aStringStyle->fontColor.blue, maxPixelWidth, maxPixelHeight, alignment);
	
    if (!success) {
        writeLog("ERR: getDimensionsOfCocoaStringBitmap");
        return false;
    }
	
	return success;
}
Exemplo n.º 4
0
OSStatus getCocoaStringBitmapData(void* aVisualString, UInt32 bitmapWidth, UInt32 bitmapHeight, char* fontNameStr, float fontSize, float red, float green, float blue, char* alignment, UInt32** bitmapData) {

    OSStatus err = noErr;
	
	if (!doGetStringBitmapData) {
		initCocoaBundle();
	}
    
	VisualString* aString = reinterpret_cast<VisualString*>(aVisualString);
	CFStringRef aCFStringRef = aString->getCharactersPointer();
    err = doGetStringBitmapData(aCFStringRef, bitmapWidth, bitmapHeight, fontNameStr, fontSize, red, green, blue, alignment, bitmapData);
	
    if (err != noErr) {
		char logStr[64];
		sprintf(logStr, "ERR: getCocoaStringBitmapData: %ld", err);
        writeLog(logStr);
        return 1001;
    }
	
	return err;
}
Exemplo n.º 5
0
OSStatus getDimensionsOfCocoaStringBitmap(void* aVisualString, UInt32* imageWidth, UInt32* imageHeight, char* fontNameStr, float* fontSize, float red, float green, float blue, UInt16 maxPixelWidth, UInt16 maxPixelHeight, char* alignment) {

    OSStatus err = noErr;
	
	if (!doGetDimensionsOfStringBitmap) {
		initCocoaBundle();
	}

	VisualString* aString = reinterpret_cast<VisualString*>(aVisualString);
	const CFStringRef aCFStringRef = aString->getCharactersPointer();
    err = doGetDimensionsOfStringBitmap(aCFStringRef, imageWidth, imageHeight, fontNameStr, fontSize, red, green, blue, maxPixelWidth, maxPixelHeight, alignment);
	
    if (err != noErr) {
		char logStr[64];
		sprintf(logStr, "ERR: getDimensionsOfCocoaStringBitmap: %ld", err);
        writeLog(logStr);
        return 1;
    } else {
        return 0;
    }
	
	return err;
}
OSStatus VisualTextureContainer::initWithString(const VisualString& stringValue, VisualStringStyle& stringStyle) {
	
	this->releaseTextureData();
	if (this->pixelBuffer != NULL) {
		free(this->pixelBuffer);
		this->pixelBuffer = NULL;
	}

    OSStatus status = noErr;

	VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
	UInt16 maxPixelWidth = theVisualGraphics->getCanvasPixelWidth();
	UInt16 maxPixelHeight = theVisualGraphics->getCanvasPixelHeight();
	
	this->textureName = theVisualGraphics->getNextFreeTextureName();
	this->textureIsSet = true;
	VisualTextureContainer::textureRefCountMap[this->textureName] = 1;
	this->useRectExtension = theVisualGraphics->canUseTextureRectExtension();

#if TARGET_OS_MAC
	char alignmentStr[32];	
	switch (stringStyle.horizontalAlignment) {
		case (kLeftAligned):
			strcpy(alignmentStr, "left");
			break;
		case(kCenterAligned):
			strcpy(alignmentStr, "center");
			break;
		case(kRightAligned):
			strcpy(alignmentStr, "right");
			break;
		default:
			break;
	}
	
	status = getDimensionsOfCocoaStringBitmap((void*)&stringValue, &(this->imageWidth), &(this->imageHeight), const_cast<char*>(stringStyle.fontNameStr), &(stringStyle.fontSize), stringStyle.fontColor.r, stringStyle.fontColor.g, stringStyle.fontColor.b, maxPixelWidth, maxPixelHeight, alignmentStr);
	
	if (this->useRectExtension == false) {
		this->textureWidth = theVisualGraphics->power2Ceiling(this->imageWidth);
		this->textureHeight = theVisualGraphics->power2Ceiling(this->imageHeight);
	} else {
		this->textureWidth = this->imageWidth;
		this->textureHeight = this->imageHeight;
	}
	
	this->pixelBuffer = (UInt32*)calloc(this->textureWidth * this->textureHeight, sizeof(UInt32));

	status = getCocoaStringBitmapData((void*)&stringValue, this->textureWidth, this->textureHeight, const_cast<char*>(stringStyle.fontNameStr), stringStyle.fontSize, stringStyle.fontColor.r, stringStyle.fontColor.g, stringStyle.fontColor.b, alignmentStr, &(this->pixelBuffer));
	
	theVisualGraphics->copyARGBBitmapDataToTexture(this->textureName, this->textureWidth, this->textureHeight, this->useRectExtension, this->pixelFormat, this->dataType, const_cast<const UInt32**>(&(this->pixelBuffer)));

#endif

#if TARGET_OS_WIN

	wchar_t* stringValueRef = (wchar_t*)stringValue.getCharactersPointer();
	UInt8 red = (UInt8)(stringStyle.fontColor.r * 255.0f);
	UInt8 green = (UInt8)(stringStyle.fontColor.g * 255.0f);
	UInt8 blue = (UInt8)(stringStyle.fontColor.b * 255.0f);
	
	status = theVisualGraphics->makeTextureOfStringWin(stringValueRef, stringValue.getNumberOfCharacters(), this->textureName, this->textureWidth, this->textureHeight, this->imageWidth, this->imageHeight, stringStyle.fontNameStr, (UInt16)stringStyle.fontSize, red, green, blue, stringStyle.horizontalAlignment, maxPixelWidth, maxPixelHeight);

#endif

	if (this->useRectExtension == false) {
		this->textureLogicalWidth = (double)this->imageWidth / (double)this->textureWidth;
		this->textureLogicalHeight = (double)this->imageHeight / (double)this->textureHeight;
	} else {
		this->textureLogicalWidth = (double)this->textureWidth;
		this->textureLogicalHeight = (double)this->textureHeight;
	}

	return status;
}