Joined 11 April 2007

I'd be interested in your ScreenFont class. --Beardface 15:02, 5 September 2008 (UTC)

Wii Stuff by me

Code Snippets

  • Here's a simple Screen Font class for LibWiiSprite.



	This class was designed around two ideas.
	1.  It uses LibWiiSprite for screen drawing details and assumes the 
		correct header file <wiisprite.h> is in place as well as the library.
	2.  It was designed to work with output of F2IBuilder ( ).

	F2IBuilder can output two files, a PNG and a Metrics file.
	This class expects the two files to be run through raw2c.exe (from DevKitPro)
	and included(.h) and compiled(.c) into the project.
	The png data should be loaded into a wsp Image class via LoadImage.
	The metrics data should be passed directly as the nCharWidths parameter to Initialize.
	Initialize() should be called first and only once.
	DisplayText() should be called to display text for the current frame.


class BibScreenFont
	wsp::Sprite AlphabetBitmap;
	int nXLetterWidth;
	int nYLetterHeight;
	const unsigned char * nCharWidths;	// Array of [128]
	int nCharsPerLine;

	void Initialize (wsp::Image * pImage, int nXLetterWidth, int nYLetterHeight, 
					const unsigned char * nCharWidths);
	void DisplayText (int nXScreenLoc, int nYScreenLoc, const char * szText, int nTransparency = 0xFF);





#include <wiisprite.h>
#include "BibScreenFont.h"

void BibScreenFont::Initialize (wsp::Image * pImage, int innXLetterWidth, int innYLetterHeight, 
								const unsigned char * innCharWidths)
	nXLetterWidth = innXLetterWidth;
	nYLetterHeight = innYLetterHeight;
	nCharWidths = innCharWidths;
	AlphabetBitmap.SetImage (pImage, nXLetterWidth, nYLetterHeight);

	Transparency has a range from 0x00 (invisible) to 0xFF (fully visible)
void BibScreenFont::DisplayText (int nXScreenLoc, int nYScreenLoc, const char * szText, int nTransparency)
char cChar;
int i;

	// Loop for every character.
	for (i = 0; szText [i]; i++)
		cChar = szText [i];
		if (cChar >= 128)
			cChar &= 0xEF;

		// Render each letter.
		AlphabetBitmap.SetPosition(nXScreenLoc, nYScreenLoc);
		AlphabetBitmap.SetTransparency (nTransparency);

		// Every time we blit a letter we need to move to the right 
		// for the start of the next blit
		nXScreenLoc += nCharWidths [cChar];