DarkGDK Classes for Text Draw
=============================
gc/gc_text.h/cpp
===========================================================================
Class dgcText
Original DarkGDK Text Functions
Last Modification 28.05.2009
===========================================================================
COMMAND LIST
//Constructor:
dgcText ();
//Destructor:
~dgcText ();
static void constructor(HINSTANCE hInst);
static void destructor();
static void setErrorHandlerText(LPVOID pErrorHandlerPtr);
static void passCoreDataText(LPVOID pGlobPtr);
//This command will set the typeface of the font you wish to use.
//You can optionally specify a character set value when selecting your font.
//The character set value allows you to use other western non-unicode languages not available through the standard ASCII character set.
//To switch the character set to another language, use an international charset code.
static void setFont(gcString fontName, int charSet=0);
//This command will return a string containing the typeface description of the current text settings.
static gcString getFontName();
//This command will set the point size of any text you are about to output.
//The point size should be an integer value.
//The size of printed text will not change if the font used does not support the size specified.
//Using this command with dbSetTextFont to set a font type that allows multiple sizes such as 'Arial'.
static void setSize(int size);
//This command will return the point size of the current font described by the current text settings.
static int getSize();
//This command will return the width of the provided string using the current text settings.
static int GetTextWidth(gcString str);
//This command will return the height of the provided string using the current text settings.
static int GetTextHeight(gcString str);
static int getTextWidth(gcString str);
static int getTextHeight(gcString str);
//This command will set text style to non-bold and non-italic.
static void setToNormal();
//This command will set the text style to italic.
static void setToItalic();
//This command will set the text style to bold.
static void setToBold();
//This command will set the text style to bold and italic.
static void setToBoldItalic();
//This command will return a code based on the style of the current text settings.
//The return value will be an integer number of zero for normal,
//1 for italic, 2 for bold and 3 for bold italic.
static int getStyle();
static void setColor(int alpha, int red, int green, int blue);
//This command will set the background of the current text settings to the color of the background ink.
static void setOpaque();
//This command will set the background of the text you are about to output as transparent.
static void setTransparent();
static void setToOpaque();
static void setToTransparent();
//This command will return an integer value of one if the current text settings
//is set to using a transparent background, otherwise zero is returned.
static bool isBackgroundTransparent();
//This command will output the provided string using the current text settings at the specified coordinates on the screen.
static void print(int x, int y, gcString str);
//This command will output the provided string using the current text settings at the specified coordinates.
//The text will be centered on the iX coordinate given.
static void printCenter(int x, int y, gcString str);
static void text3D(gcString str);
static void refreshD3DText(int mode);
//This command will produce a string containing the number of spaces specified.
static gcString spaces(int num);
//This command will return a string converting the specified string to lowercase.
static gcString setLower(gcString str);
//This command will return a string converting the specified string to uppercase.
static gcString setUpper(gcString str);
//This command will return the number of characters in the string provided.
//Non-printable control characters and blanks are counted.
static int getLen(gcString str);
//This command will return a string containing the leftmost characters of the string that was provided.
//If the value is greater than the number of characters in the string then the entire string is return.
//If the value is zero then an empty string is returned.
static gcString getLeft(gcString str, int numChar);
//This command will return the rightmost set of characters.
//The value specifies the number of characters to extract from the string provided.
static gcString getRight(gcString str, int numChar);
//This command will extract a character from the string provided.
//The return string will contain a single character extracted from the string specified.
static gcString getChar(gcString str, int pos);
//This command will append the two specified strings together.
static void append(char* str1, char* str2);
//This command will reverse the contents of the specified string.
static void reverse(char* str);
//This command will find the first occurance of the specified character in the string.
static int findFirstChar(char* str, char* chr);
//This command will find the last occurance of the specified character in the string.
static int findLastChar(char* str, char* chr);
//This command will find the first occurance of the substring within the specified source string.
static int findSubString(char* str, char* substr);
//This command will compare the two specified strings and return a value of one if they match,
//and a value of zero if they do not match.
static bool compareCase(char* str1, char* str2);
//This command will return the first string that was seperated by the specified delimiter.
static char* getFirstToken(char* str, char* delim);
//static String getFirstToken(String str, char* delim);
//This command will return the next string that was seperated by the specified delimiter.
static char* getNextToken(char* delim);
//static String getNextToken(char* delim);
//This command will return an integer value that represents the ASCII code for the first character of the provided string.
static int getASCII(gcString str);
//This command will return a 32 character string equivalent to the binary representation of the specified value provided.
static gcString getBin(int value);
//This command will return a character string equivalent to the ASCII character number provided.
//ASCII is a standard way of coding the characters used to construct strings.
static gcString getChr(int value);
//This command will return an eight character string equivalent to the hexadecimal representation of the number provided.
static gcString getHex(int value);
//This command will return a string representation of the value provided.
static gcString intToStr(int value);
//This command will return a string representation of the value provided.
static gcString floatToStr(float value);
//This command will return an integer number of the string provided by converting the string to a numerical form.
static float StrToFloat(gcString str);
static float strToFloat(gcString str);
//static String DoubleToStr(double value);
static LONGLONG strToLONGLONG(gcString str);
//This command will build a checklist and search for all available fonts on the system.
//Use the check list commands found in the System command set to access the checklist.
static void performCheckList();
DarkSDKText.h -> gc_text.h
void ConstructorText (HINSTANCE); | static void constructor(HINSTANCE hInst);
void DestructorText (); | static void destructor();
void SetErrorHandlerText (LPVOID pErrorHandlerPtr); | static void setErrorHandlerText(LPVOID pErrorHandlerPtr);
void PassCoreDataText (LPVOID pGlobPtr); | static void passCoreDataText(LPVOID pGlobPtr);
void dbSetTextFont (char* szTypeface); | static void setFont(String fontName);
void dbSetTextFont (char* szTypeface, int iCharacterSet); | static void setFont(String fontName, int charSet);
char* dbTextFont (); | static String getFontName();
void dbSetTextSize (int iSize); | static void setSize(int size);
int dbTextSize (); | static int getSize();
int dbTextWidth (char* szString); | static int GetTextWidth(String str);
int dbTextHeight (char* szString); | static int GetTextHeight(String str);
int dbGetTextWidth (char* szString); | static int getTextWidth(String str);
int dbGetTextHeight (char* szString); | static int getTextHeight(String str);
void dbSetTextToNormal (); | static void setToNormal();
void dbSetTextToItalic (); | static void setToItalic();
void dbSetTextToBold (); | static void setToBold();
void dbSetTextToBoldItalic (); | static void setToBoldItalic();
int dbTextStyle (); | static int getStyle();
void dbSetTextColor (int iAlpha, int iRed, int iGreen, int iBlue); | static void setColor(int alpha, int red, int green, int blue);
void dbSetTextOpaque (); | static void setOpaque();
void dbSetTextTransparent (); | static void setTransparent();
void dbSetTextToOpaque (); | static void setToOpaque();
void dbSetTextToTransparent(); | static void setToTransparent();
int dbTextBackgroundType (); | static bool isBackgroundTransparent();
void dbText (int iX, int iY, char* szText); | static void print(int x, int y, String str);
void dbCenterText (int iX, int iY, char* szText); | static void printCenter(int x, int y, String str);
void dbText3D (char* szText); | static void text3D(String str);
void RefreshD3DText(int iMode); | static void refreshD3DText(int mode);
void dbAppend (char* dwA, char* dwB); | static void append(char* str1, char* str2);
void dbReverse (char* dwA); | static void reverse(char* str);
char* dbSpaces (int iSpaces); | static String spaces(int num);
char* dbLower (char* szText); | static String setLower(String str);
char* dbUpper (char* szText); | static String setUpper(String str)
int dbLen (char* dwSrcStr); | static int getLen(String str);
char* dbLeft (char* szText, int iValue); | static String getLeft(String str, int numChar);
char* dbRight (char* szText, int iValue); | static String getRight(String str, int numChar);
char* dbMid (char* szText, int iValue); | static String getChar(String str, int pos);
int dbAsc (char* dwSrcStr); | static int getASCII(String str);
char* dbBin (int iValue); | static String getBin(int value);
char* dbChr (int iValue); | static String getChr(int value);
char* dbHex (int iValue); | static String getHex(int value);
char* dbStr (float fValue); | static String floatToStr(float value);
char* dbStr (int iValue); | static String intToStr(int value);
float dbVal (char* dwSrcStr); | static float StrToFloat(String str);
float dbValF (char* dwSrcStr ); | static float strToFloat(String str);
double dbStrDouble(double dValue); | ???
LONGLONG dbValR (char* dwSrcStr); | static String LONGLONGToStr(LONGLONG value);
int dbFindFirstChar(char* dwSource, char* dwChar); | static int findFirstChar(char* str, char* chr);
int dbFindLastChar (char* dwSource, char* dwChar); | static int findLastChar(char* str, char* chr);
int dbFindSubString(char* dwSource, char* dwString); | static int findSubString(char* str, char* substr);
int dbCompareCase (char* dwA, char* dwB); | static bool compareCase(char* str1, char* str2);
char* dbFirstToken (char* dwSource, char* dwDelim); | static char* getFirstToken(char* str, char* delim); ?
char* dbNextToken (char* dwDelim); | static char* getNextToken(char* delim); ?
void dbPerformChecklistForFonts(); | static void performCheckList();
Sample
String strt = Text::intToStr(1234567);
===========================================================================
Class d3dText
Fast Antialiased Direct3D Text
Last Modification 28.05.2009
===========================================================================
COMMAND LIST
//Create "System" Font:
d3dText();
//Create any Font:
d3dText(gcString sFont, int FontSize=12, bool FontBold=TRUE, bool FontItalic=FALSE);
//Destructor:
~d3dText();
//Set Text Color:
void setColor(int a=255, int r=255, int g=255, int b=0);
void setColor(ColorARGB fc);
void setColor(D3DCOLOR clr);
//Set Text Color1,2, Shadow Color:
void setColor(int id, ColorARGB fc);
void setColor(int id, D3DCOLOR clr);
//Set Color2 for Bicolor Text
void setColor2( int a, int r, int g, int b);
//Set Shadow Color:
void setShadowColor(int a=128, int r=0, int g=0, int b=0);
//Get Text Color1,2, Shadow Color:
ColorARGB getColor(int id);
//Get Font Color:
ColorARGB getColor();
D3DCOLOR getColorD3D();
D3DCOLOR getColorD3D(int id);
//Set Text Alpha (Opaque / Transparent)
void setAlpha(int value=255);
//Get Text Alpha
int getAlpha();
//Set Shadow Offset:
void setShadowOffset(int dx=2, int dy=2);
//Set Font:
void setFont(gcString sFont, int FontSize, bool FontBold=TRUE, bool FontItalic=FALSE);
//Set Font Attributes:
void setAttr(int FontSize, bool FontBold=TRUE, bool FontItalic=FALSE);
//Set Font Charset:
void setCharset(int charset);
//Start Text Draw:
void begin();
//Draw ALIGN_LEFT String
int draw(int x, int y, gcString str);
//Draw aligned String
void draw(int x, int y, int align, gcString str);
//Draw Text with Shadow:
void drawTextShadow(int x, int y, int align, gcString str);
//Draw aligned Bicolor String:
void drawTextBicolor(int x, int y, int align, gcString str, float up, float down);
//End Text Draw:
void end(void) {
textSprite->End();
}
//Get Text Heigth:
int getTextHeight(gcString str);
//Get Text Width:
int getTextWidth(gcString str);
SIZE getCharSize(char ch);
//Get Font Name:
char* getFontName();
//Get Font Size:
int getFontSize();
//Get Font Style:
int getFontStyle();
//Draw 1 aligned String only
void Print(int x, int y, int align, gcString str);
//Draw 1 String only (Start Position = xPos, yPos)
void print(gcString str);
//Draw 1 String only (Start Position = xPos, yPos) + NewLine
void println(gcString str);
//New String Position = Screen LT
void home();
//Begin New Line
void newLine();
//Set Absatz:
void setXAbsatz(int dx);
void setYAbsatz(int dy);
//Set Offset:
void setXOffset(int dx);
void setYOffset(int dy);
//Set Start String Position:
void setXPos(int x);
void setYPos(int y);
//Push/Pop String Color:
void pushColor();
void popColor();
//Show/Hide Text:
void show();
void hide();
Samples:
Create Fonts:
d3dText sysfnt= new d3dText ();
d3dText arial = new d3dText ("Arial", 15, TRUE, FALSE);
d3dText arialBold = new d3dText ("Arial Bold", 20, TRUE, FALSE);
or
d3dText sysfnt;
d3dText arial("Arial", 15, TRUE, FALSE);
d3dText arialBold("Arial Bold", 20, TRUE, FALSE);
Delete "new" Font:
delete sysfnt;
Set Font Attributes
Transparent (Opaque (value=255) -> Full Transparent (value=0)):
void setAlpha(int value=255);
arial->setAlpha(); //= arial->setAlpha(255);
arial->setAlpha(127);
arial->setAlpha(40);
Get Current Alpha Value:
int getAlpha();
Color (and Transparent!):
void setColor(int a=255, int r=255, int g=255, int b=0);
void setColor(ColorARGB fc);
void setColor(D3DCOLOR clr);
arial->setColor(255,255,255,0); // = arial->setColor();
arial->setColor(clYellow32); = bmptxt->setColor(0xFFFFFF00);= bmptxt->setColor(D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0x00);
Get Current Color Value:
ColorARGB getColor();
D3DCOLOR getColorD3D();
Font and Font Size:
void setFont(gcString sFont, int FontSize, bool FontBold=TRUE, bool FontItalic=FALSE);
arial->setFont("Arial", 15, TRUE, TRUE); //Set Attributes for Font Arial
Set Attributes for Current Font:
void setAttr(int FontSize, bool FontBold=TRUE, bool FontItalic=FALSE);
//Change Charset:
void setCharset(int charset);
Draw String:
//Draw ALIGN_LEFT String
int draw(int x, int y, gcString str);
//Draw aligned String
void draw(int x, int y, int align, gcString str);
Parameter align =
ALIGN_LEFT (start x)
ALIGN_CENTER (center x)
ALIGN_RIGHT (endx)
ALIGN_CENTERWINDOW (center Screen)
//Draw Text with Shadow:
void drawTextShadow(int x, int y, int align, gcString str);
//Set Shadow Color:
void setShadowColor(int a=128, int r=0, int g=0, int b=0);
//Shadow Offset:
void setShadowOffset(int dx=2, int dy=2);
//Draw Bicolor Text
void drawTextBicolor(int x, int y, int align, gcString str, float up, float down);
//Set Down Alpha & Color:
void setColor2( int a, int r, int g, int b);
//Set Up Alpha & Color:
-> setColor.
Sample:
arial->begin()
arial->draw(l, t, ALIGN_LEFT, " 1-Display");
arial->draw(l, t+yoff, ALIGN_LEFT, " 2-String");
arial->end();
//////////////////////////////////////////////////////////////////
//
// Class Fonts
//
//////////////////////////////////////////////////////////////////
===========================================================================
Class BitmapFont
Class for Codehead's Bitmap Font Generator 1.41
Last Modification 28.05.2009
===========================================================================
Format Font Files bmp/tga + dat
COMMAND LIST
//Create Font From Codehead's Bitmap Font Generator 1.41
BitmapFont(gcString filename, gcString datfilename="");
//Delete Font:
~BitmapFont();
//Draw String:
void draw(gcString str, int x, int y);
//Set Font Color:
void setColor(int red, int green, int blue);
void setColor(D3DCOLOR clr);
//Get Font Color:
D3DCOLOR getColor();
//Get Font Color Component:
int getRed();
int getGreen();
int getBlue();
//Set Font Alpha (Transparent):
void setAlpha(int value);
//Get Font Alpha (Transparent):
int getAlpha();
SAMPLES
Create Font:
BitmapFont(gcString filename, gcString datfilename="");
Sample:
BitmapFont *bmpfnt;
bmpfnt= new BitmapFont("Media/fonts/tahoma30.bmp","Media/fonts/tahoma.dat");
bmpfnt= new BitmapFont("Media/fonts/tahoma30.bmp");
or
BitmapFont bmptxt("Media/fonts/tahoma30.bmp","Media/fonts/tahoma.dat");
BitmapFont bmptxt("Media/fonts/tahoma30.bmp");
Delete "new" Font:
delete bmpfnt;
//Draw String:
int draw(gcString str, int x, int y);
===========================================================================
Class BitmapText
Class for Asphyre Font Tool 1.0
Last Modification 28.05.2009
===========================================================================
Format Font Files png/bmp/tga + xml (txt)
COMMAND LIST
//Create Font was created Asphyre Font Tool 1.0 -> Files - .png (& xml/txt):
BitmapText(gcString filename, gcString datfilename="");
//Delete Font:
~BitmapText();
//Draw String Left to Right:
int draw(gcString str, int x, int y);
//Draw String Right to Left:
int drawRtoL(gcString str, int x, int y);
//Draw String Flip:
int drawFlip(gcString str, int x, int y);
//Draw Scaled String:
int drawEx(gcString str, int x, int y, float scx=0, float scy=0);
//Draw String Vertical Up to Down:
int drawVUD(gcString str, int x, int y);
//Draw Left Rotated String:
int drawRotL(gcString str, int x, int y);
//Draw Right Rotated String:
int drawRotR(gcString str, int x, int y);
//Draw Angle Rotated String:
int drawAngle(gcString str, int x, int y, float angle);
//Return end draw position
//Set Font Color:
void setColor(int red, int green, int blue);
void setColor(D3DCOLOR clr);
//Get Font Color:
D3DCOLOR getColor();
//Get Font Color Component:
int getRed();
int getGreen();
int getBlue();
//Set Font Alpha (Transparent):
void setAlpha(int value);
//Get Font Alpha (Transparent):
int getAlpha();}
//Set Font Width Scale:
void setScaleX(float value=1.0f);
//Get Font Width Scale:
float getScaleX();
//Set Font Height Scale:
void setScaleY(float value=1.0f);
//Get Font Height Scale:
float getScaleY();
//Set String Offset:
void setAbsatz(int value);
//Get String Offset:
int getAbsatz();
//Set Words Offset:
void setWhitespace(int value);
//Get Words Offset:
int getWhitespace();
//Set Chars Offset:
void setKerning(int value);
//Get Chars Offset:
int getKerning();
//Set Vertical String Offset:
void setLinespace(int value);
//Get Vertical String Offset:
int getLinespace();
SAMPLES
Create Font:
BitmapText(gcString filename, gcString datfilename="");
Sample:
BitmapText *bmptxt;
bmptxt= new BitmapText("Media/fonts/ftm_tahoma11.png","Media/fonts/tahoma11.xml");
bmptxt= new BitmapText("Media/fonts/ftm_tahoma11.png");
or
BitmapText bmptxt("Media/fonts/ftm_tahoma11.png","Media/fonts/tahoma11.xml"); //png != xml
BitmapText bmptxt("Media/fonts/ftm_tahoma11.png"); //png == xml/txt
//File Path - from exe-File
//Delete "new" Font:
delete bmptxt;
Set Font Attributes
Set Color:
void setColor(int red, int green, int blue);
void setColor(D3DCOLOR clr);
//Sample:
bmptxt->setColor(255,255,255);
bmptxt->setColor(clYellow32); = bmptxt->setColor(0xFFFFFF00);= bmptxt->setColor(D3DCOLOR_XRGB(0xff, 0xff, 0x00);
//Get Current Font Color:
D3DCOLOR getColor();
int getRed();
int getGreen();
int getBlue();
Set Transparent (Opaque (value=255) -> Full Transparent (value=0)):
void setAlpha(int value);
//Sample:
bmptxt->setAlpha(255);
bmptxt->setAlpha(127);
bmptxt->setAlpha(40);
//Get Current Text Alpha:
int getAlpha();
Set Font Size
For drawEx:
//Set X Scale (Width):
void setScaleX(float value=1.0f);
bmptxt16->setScaleX(1.5f);
//Get Current X Scale Value:
float getScaleX();
//Set Y Scale (Height):
void setScaleY(float value=1.0f);
bmptxt16->setScaleY(1.2f);
//Get Current Y Scale Value:
float getScaleY();
//Return to Begin Font Size:
setScaleX(); и setScaleY();
Set Absatz/WhiteSpace/Kerning
X/Y Begin String Offset:
void setAbsatz(int value);
bmptxt->setAbsatz(20);
//Get Current Absatz Value:
int getAbsatz();
//Set Words Offset:
void setWhitespace(int value);
bmptxt->setWhitespace(30);
//Get Current Words Offset:
int getWhitespace();
//Set Chars Offset:
void setKerning(int value);
bmptxt->setKerning(-2);
//Get Current Chars Offset:
int getKerning();
Draw String
//Draw String from Left to Right
int draw(gcString str, int x, int y);
x, y - Left/Up Start Coords of String
//Draw String from Right to Left
int drawRtoL(gcString str, int x, int y);
//Draw X-Mirrord String
int drawFlip(gcString str, int x, int y);
//Draw Scaled String
int drawEx(gcString str, int x, int y, float scx=0, float scy=0);
If scx=scy=1 then drawEx = draw
If scx=scy=0 (or drawEx(str, x,y);) then scx=setScaleX(); & scy=setScaleY();
//Draw String from Up to Down
int drawVUD(gcString str, int x, int y);
//Draw 90grad-Rotated String from Down to Up
int drawRotL(gcString str, int x, int y);
//Draw 90grad-Rotated String from Up to Down
int drawRotR(gcString str, int x, int y);
//Draw Angle Rotated String:
int drawAngle(gcString str, int x, int y, float angle);
All functios returns End String Coord (x or y)
===========================================================
Old Version (Class CAAText (Fast Antialiased DirectX Text))
http://forum.thegamecreators.com/?m=forum_view&t=145832&b=22
===========================================================
Class Bitmap Text Demo (DarkGDK)
Class Bitmap Text Demo (Pure DirectX)
Magic Particles Demo (Pure DirectX)
===========================================================
DarkGDK Samples + Source Code:
http://rvGames.de/darkgdk/__DarkGDKClasses.rar
Pure DirectX Samples:
http://rvGames.de/darkgdk/__gex0_0_1.rar
===========================================================
Tools:
- Codehead's Bitmap Font Generator CBFG 1.41
http://rvGames.de/darkgdk/CodeheadBitmapFontGenerator.zip
- Asphyre Sphinx FontTool 1.0
http://rvGames.de/darkgdk/AsphyreSphinxFontTool.rar
============================================================