cTextWriter.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
- #include "stdafx.h"
- #include "cTextWriter.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- cTextWriter::cTextWriter()
- {
- }
- cTextWriter::~cTextWriter()
- {
- }
- //绘制文字到屏幕
- int cTextWriter::WriteText(LPDIRECTDRAWSURFACE7 pSurface, char *lpszText, int iX, int iY, bool bFixed)
- {
- int pos;
- int nextx;
- RECT rcRect;
- nextx = iX;
- while (*lpszText != ' ')
- {
- if (*lpszText != ' ')
- {
- //step1:找出该字符在对应位图中的数值位置
- if (*lpszText >= 48 &&
- *lpszText <= 57)
- {
- //数字:0的ASCII码值是48
- pos = (int) *lpszText - 48;
- }
- else
- //字母:-55=-65(A)+10(位图中前十个子位图被数字占有了)
- pos = (int) *lpszText - 55;
- //'@'在位图中第37个字符的位置
- if (*lpszText == '@')
- pos = 36;
- //'-'在位图中第38个字符的位置
- if (*lpszText == '-')
- pos = 37;
- //','在位图中第39个字符的位置
- if (*lpszText == ',')
- pos = 38;
- //句号和冒号都用一个dot子位图构成,它在位图的最后位置
- if (*lpszText == '.' || *lpszText == ':')
- pos = 39;
- //step2:提取该字符在对应位图中的空间位置
- rcRect.left = AA[pos].start;
- rcRect.right = AA[pos].end;
- rcRect.top = 0;
- rcRect.bottom = 15;
- //如果是冒号字符,则它要由两个dot字符堆叠而成;m_iAlphabet是三张位图的标志
- if(*lpszText == ':')
- {
- m_surfLetters.Draw(pSurface, nextx, iY, AA[pos].start, 0, AA[pos].end-AA[pos].start, m_iAlphabet == 1 ? 15 : m_iAlphabet == 2 ? 22 : 8);
- m_surfLetters.Draw(pSurface, nextx+1, iY, AA[pos].start, 4, AA[pos].end-AA[pos].start, m_iAlphabet == 1 ? 7 : m_iAlphabet == 2 ? 11 : 4);
- if(bFixed)
- nextx-=4;
- else
- nextx++;
- }
- else
- {
- m_surfLetters.Draw(pSurface, nextx, iY, AA[pos].start, 0, AA[pos].end-AA[pos].start, m_iAlphabet == 1 ? 15 : m_iAlphabet == 2 ? 22 : 8);
- }
-
- if(bFixed == true)
- nextx+=8;
- else
- nextx += (AA[pos].end - AA[pos].start) + 1;
- }
- else
- {
- //空格
- switch(m_iAlphabet)
- {
- case 1:
- nextx += 14;
- break;
- case 2:
- nextx += 10;
- break;
- case 3:
- nextx += 4;
- break;
- }
- }
- lpszText++;
- }
- return nextx;
- }
- //载入位图曲面
- void cTextWriter::Create(int iAlphabet)
- {
- m_iAlphabet = iAlphabet;
- switch(iAlphabet)
- {
- //大号位图
- case 1:
- m_surfLetters.Create(621, 15);
- m_surfLetters.LoadBitmap(GetMainApp()->m_hInst, IDB_DIGITAL_BIG);
- AA = (struct Alphabet*) &DA[0];
- break;
- //小号位图
- case 3:
- m_surfLetters.Create(311, 8);
- m_surfLetters.LoadBitmap(GetMainApp()->m_hInst, IDB_DIGITAL_SMALL);
- AA = (struct Alphabet*) &SDA[0];
- break;
- //黄色前景位图
- case 2:
- m_surfLetters.Create(500, 22);
- m_surfLetters.LoadBitmap(GetMainApp()->m_hInst, IDB_VERDANA);
- AA = (struct Alphabet*) &VA[0];
- break;
- }
- }
- //删除位图曲面
- void cTextWriter::Destroy()
- {
- m_surfLetters.Destroy();
- }