Ja do wyswietlania tekstu zrobilem sobie taką klase:
#ifndef CRAYON_LABEL_H
#define CRAYON_LABEL_H
//=============================================================================
class C_LABEL : public C_DDOBJECT
{
public:
C_LABEL();
~C_LABEL();
void Init(char path1[255],char path2[255],DWORD posx=0,DWORD posy=0,DWORD ck=0);
void Blt();
DWORD GetWidth() { return Width; }
DWORD GetHeight() { return Height; }
string Caption;
DWORD PosX;
DWORD PosY;
BOOL Visible;
private:
void Restore();
LPDIRECTDRAWSURFACE4 lpDDS4Bitmap;
DWORD Width;
DWORD Height;
DWORD ColorKey;
DWORD Widths[256];
char PathBitmap[255];
char PathWidths[255];
};
//=============================================================================
C_LABEL::C_LABEL()
{
lpDDS4Bitmap = NULL;
PosX = 0;
PosY = 0;
Visible = FALSE;
Width = 0;
Height = 0;
ColorKey = 0;
ZeroMemory(PathBitmap,255);
ZeroMemory(PathWidths,255);
}
//=============================================================================
C_LABEL::~C_LABEL()
{
if(lpDDS4Bitmap!=NULL)
{
lpDDS4Bitmap->Release();
lpDDS4Bitmap = NULL;
}
PosX = 0;
PosY = 0;
Visible = FALSE;
Width = 0;
Height = 0;
ColorKey = 0;
ZeroMemory(PathBitmap,255);
ZeroMemory(PathWidths,255);
}
//=============================================================================
void C_LABEL::Init(char path1[],char path2[],DWORD posx,DWORD posy,DWORD ck)
{
PosX = posx;
PosY = posy;
ColorKey = ck;
strcpy(PathBitmap,path1);
strcpy(PathWidths,path2);
FILE *file=fopen(PathWidths,"r");
for(int i=0;i<256;i++) Widths[i] = fgetc(file);
fclose(file);
int lgh = strlen(path1);
if(path1[lgh-3]=='c'&&path1[lgh-2]=='r'&&path1[lgh-1]=='a')
lpDDS4Bitmap = DDLoadCrayon(lpDD4,path1);
else
if(path1[lgh-3]=='b'&&path1[lgh-2]=='m'&&path1[lgh-1]=='p')
lpDDS4Bitmap = DDLoadBitmap(lpDD4,path1);
else
Log("C_LABEL::Init() - nieprawidlowy typ pliku");
if(lpDDS4Bitmap!=NULL)
{
Visible=TRUE;
DDSURFACEDESC2 ddsd;
ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
ddsd.dwSize = sizeof(DDSURFACEDESC2);
lpDDS4Bitmap->GetSurfaceDesc(&ddsd);
Width = ddsd.dwWidth/16;
Height = ddsd.dwHeight/16;
if(ColorKey!=0xFFFFFFFF)
{
DDCOLORKEY ddck;
ddck.dwColorSpaceHighValue = ck;
ddck.dwColorSpaceLowValue = ck;
err = lpDDS4Bitmap->SetColorKey(DDCKEY_SRCBLT,&ddck);
LogErr(err,"C_LABEL::Init() - SetColorKey()");
}
}
}
//=============================================================================
void C_LABEL::Blt()
{
if(Visible&&lpDD4->TestCooperativeLevel()==DD_OK)
{
LPC_SCREEN Screen;
Screen = C_SCREEN::GetPointer();
DWORD diff = 0;
for(int i=0;i<Caption.size();i++)
{
DWORD x = ((unsigned char)Caption[i]%16)*Width;
DWORD y = ((unsigned char)Caption[i]/16 - (((unsigned char)Caption[i]/16==0)?1:0) )*Height;
RECT rect = {x, y, x+Width, y+Height};
if(ColorKey==0xFFFFFFFF)
{
err = Screen->lpDDS4Back->BltFast(PosX+diff,PosY,lpDDS4Bitmap,&rect,
DDBLTFAST_WAIT| DDBLTFAST_NOCOLORKEY);
}else
{
err = Screen->lpDDS4Back->BltFast(PosX+diff,PosY,lpDDS4Bitmap,&rect,
DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY);
}
diff += Widths[(unsigned char)Caption[i]];
if(err==DDERR_SURFACELOST) Restore();
if(err!=DD_OK && err!=DDERR_SURFACELOST)
LogErr(err,"C_LABEL::Blt() - BltFast()");
}
}
}
//=============================================================================
void C_LABEL::Restore()
{
if(lpDD4->TestCooperativeLevel()==DD_OK&&lpDDS4Bitmap->IsLost()==DDERR_SURFACELOST)
{
lpDDS4Bitmap->Restore();
Init(PathBitmap,PathWidths,PosX,PosY,ColorKey);
}
}
//=============================================================================
#endif
//Czcionki bitmapowe robie za pomocą Bitmap Font Builder'a