In memory of Ben “bushing” Byer, who passed away on Monday, February 8th, 2016.

Difference between revisions of "User:PaceMaker"

From WiiBrew
Jump to navigation Jump to search
Line 9: Line 9:
  
 
==Code Snippets==
 
==Code Snippets==
 +
 +
* Here's a simple Screen Font class for LibWiiSprite.
 +
 +
=BibScreenFont.h=
 +
<source lang="cpp">
 +
/*
 +
BibScreenFont.h
 +
 +
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 ( http://sourceforge.net/projects/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.
 +
*/
 +
 +
 +
#ifndef _BIBSCREENFONT_H_
 +
#define _BIBSCREENFONT_H_
 +
 +
class BibScreenFont
 +
{
 +
private:
 +
wsp::Sprite AlphabetBitmap;
 +
int nXLetterWidth;
 +
int nYLetterHeight;
 +
const unsigned char * nCharWidths; // Array of [128]
 +
int nCharsPerLine;
 +
 +
public:
 +
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);
 +
};
 +
#endif
 +
</source>
 +
 +
=BibScreenFont.cpp=
 +
<source lang="cpp">
 +
/*
 +
 +
BibScreenFont.cpp
 +
 +
*/
 +
 +
#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.SetFrame(cChar);
 +
AlphabetBitmap.SetTransparency (nTransparency);
 +
AlphabetBitmap.Draw();
 +
 +
// Every time we blit a letter we need to move to the right
 +
// for the start of the next blit
 +
nXScreenLoc += nCharWidths [cChar];
 +
}
 +
 +
}
 +
 +
</source>

Revision as of 18:32, 5 September 2008

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.

BibScreenFont.h

/*
	BibScreenFont.h

	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 ( http://sourceforge.net/projects/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.
*/


#ifndef _BIBSCREENFONT_H_
#define _BIBSCREENFONT_H_

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

public:
	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);
};
#endif

BibScreenFont.cpp

/*

	BibScreenFont.cpp

*/

#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.SetFrame(cChar);
		AlphabetBitmap.SetTransparency (nTransparency);
		AlphabetBitmap.Draw();

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

}