예제 #1
0
Font* BAMFontManager::GetFont(ieWord FirstChar,
			  ieWord LastChar,
			  unsigned short /*ptSize*/,
			  FontStyle /*style*/, Palette* pal)
{
	AnimationFactory* af = bamImp->GetAnimationFactory("dummy"); // FIXME: how does this get released?
	unsigned int i = 0, glyphIndexOffset = 0, limit = 0, Count = 0, glyphCount = 0;
	unsigned int CyclesCount = af->GetCycleCount();

	// Numeric fonts have all frames in single cycle
	if (CyclesCount > 1) {
		Count = CyclesCount;
		glyphCount = (LastChar - FirstChar + 1);
		if (Count < glyphCount){
			LastChar = LastChar - (glyphCount - Count);
			glyphCount = Count;
		}
		i = (FirstChar) ? FirstChar - 1 : FirstChar;
		limit = (FirstChar) ? LastChar - 1 : LastChar;
		glyphIndexOffset = i;
	} else { //numeric font
		Count = af->GetFrameCount();
		glyphCount = Count;
		if (FirstChar+Count != (unsigned int) LastChar+1) {
			Log(ERROR, "BAMFontManager", "inconsistent font %s: FirstChar=%d LastChar=%d Count=%d",
				str->filename, FirstChar, LastChar, Count);
			return NULL;
		}
		limit = glyphCount - 1;
	}

	Sprite2D** glyphs = (Sprite2D**)malloc( glyphCount * sizeof(Sprite2D*) );

	for (; i <= limit; i++) {
		if (CyclesCount > 1) {
			glyphs[i - glyphIndexOffset] = af->GetFrame(0, i);

			// Hack to work around original data where some status icons have inverted x and y positions (ie level up icon)
			// isStateFont is set in Open() and simply compares the first 6 characters of the file with "STATES"
			if (isStateFont) {
				// since initials and state icons should all be the same size/position we can just take the position of the first one
				glyphs[i - glyphIndexOffset]->YPos = glyphs[0]->YPos;
			}
		} else {
			glyphs[i - glyphIndexOffset] = af->GetFrameWithoutCycle(i);
			glyphs[i - glyphIndexOffset]->YPos = 13 - glyphs[i - glyphIndexOffset]->Height;
		}
	}

	// assume all sprites have same palette
	Palette* palette = glyphs[0]->GetPalette();
	Font* fnt = new Font(glyphs, FirstChar, LastChar, palette);
	palette->Release();
	if (pal) {
		fnt->SetPalette(pal);
	}
	return fnt;
}
예제 #2
0
파일: GameData.cpp 프로젝트: BehoIder/gemrb
// Return single BAM frame as a sprite. Use if you want one frame only,
// otherwise it's not efficient
Sprite2D* GameData::GetBAMSprite(const ieResRef ResRef, int cycle, int frame, bool silent)
{
	Sprite2D *tspr;
	AnimationFactory* af = ( AnimationFactory* )
		GetFactoryResource( ResRef, IE_BAM_CLASS_ID, IE_NORMAL, silent );
	if (!af) return 0;
	if (cycle == -1)
		tspr = af->GetFrameWithoutCycle( (unsigned short) frame );
	else
		tspr = af->GetFrame( (unsigned short) frame, (unsigned char) cycle );
	return tspr;
}