Annotation of DewFind/word.cpp, revision 1.1
1.1 ! nick 1: #include "StdAfx.h"
! 2: #include "resource.h"
! 3: #include "word.h"
! 4:
! 5: //#32
! 6: //*************************************
! 7: //Programmed by: Brendan Lynch
! 8: //Email: dewgames@gmail.com
! 9: //Website: www.dewgames.com
! 10: //*************************************
! 11:
! 12:
! 13: //**************************************************************************************************
! 14: //
! 15: //-------------------------------------PUBLIC-------------------------------------------------------
! 16: //
! 17: //**************************************************************************************************
! 18:
! 19: Word::Word()
! 20: {
! 21: Reset();
! 22: };
! 23:
! 24: void Word::Reset()
! 25: {
! 26: limit_ = MAXLETTERS;
! 27: color_ = 0; //Black
! 28: };
! 29: void Word::SetLimit(int lim)
! 30: {
! 31: //Used so that it will only print upto the limit.
! 32: //Makes sure it doesnt go over the max
! 33: if (lim <= MAXLETTERS)
! 34: limit_ = lim;
! 35: }
! 36:
! 37: void Word::Write(CString writeme,int x,int y,CDC *xDC)
! 38: {
! 39: Display(true,writeme,x,y,xDC);
! 40: };
! 41:
! 42: void Word::Write(char writeme,int x,int y,CDC *xDC)
! 43: {
! 44: ShowChar(xDC,x,y,writeme);
! 45: };
! 46:
! 47: void Word::SetColor(int color)
! 48: {
! 49: color_ = color;
! 50: }
! 51: void Word::WriteBackwards(bool IsVert, CString writeme, int x, int y, CDC *xDC)
! 52: {
! 53: CString backwards;
! 54:
! 55: int len,tmpy;
! 56: char tChar;
! 57:
! 58: len = writeme.GetLength();
! 59: tmpy = len-1;
! 60:
! 61: backwards = "";
! 62: for(tmpy;tmpy>=0;tmpy--)
! 63: {
! 64: tChar = writeme.GetAt(tmpy);
! 65: backwards = backwards + tChar;
! 66: };
! 67:
! 68: if (IsVert == true)
! 69: {
! 70: WriteVert(backwards,x,y,xDC);
! 71: }
! 72: else
! 73: {
! 74: Write(backwards,x,y,xDC);
! 75: };
! 76: };
! 77:
! 78:
! 79: void Word::Write(int number,int x,int y,int zeros, CDC *xDC)
! 80: {
! 81: //Converts the number to a string
! 82: //Adds 0's base on what number zeros is equal to
! 83: //Then uses the write string function
! 84: CString str;
! 85: bool done=false;
! 86: CString strx("");
! 87:
! 88: if ((number > 9999999)&&(zeros == 8))
! 89: {
! 90: str.Format("%i",number);
! 91: done = true;
! 92: }
! 93: if ((number > 999999)&&(zeros == 7))
! 94: {
! 95: str.Format("%i",number);
! 96: done = true;
! 97: }
! 98: if ((number > 99999)&&(zeros == 6))
! 99: {
! 100: str.Format("%i",number);
! 101: done = true;
! 102: }
! 103: if ((number > 9999)&&(zeros == 5))
! 104: {
! 105: str.Format("%i",number);
! 106: done = true;
! 107: }
! 108: if ((number > 999)&&(zeros == 4))
! 109: {
! 110: str.Format("%i",number);
! 111: done = true;
! 112: }
! 113: if (done==false)
! 114: {
! 115: if ((number < 10000000)&&(zeros > 7))
! 116: strx = strx + "0";
! 117: if ((number < 1000000)&&(zeros > 6))
! 118: strx = strx + "0";
! 119: if ((number < 100000)&&(zeros > 5))
! 120: strx = strx + "0";
! 121: if ((number < 10000)&&(zeros > 4))
! 122: strx = strx + "0";
! 123: if ((number < 1000)&&(zeros > 3))
! 124: strx = strx + "0";
! 125: if ((number < 100)&&(zeros > 2))
! 126: strx = strx + "0";
! 127: if (number < 10)
! 128: strx = strx + "0";
! 129:
! 130: str.Format("%i",number);
! 131: str = strx + str;
! 132: }
! 133:
! 134:
! 135:
! 136: Write(str,x,y,xDC);
! 137: }
! 138:
! 139:
! 140: void Word::WriteVert(CString writeme,int x,int y,CDC *xDC)
! 141: {
! 142: Display(false,writeme,x,y,xDC);
! 143: }
! 144:
! 145: //******************************************************************************************************
! 146: //
! 147: //-------------------------------------PRIVATE-------------------------------------------------------
! 148: //
! 149: //******************************************************************************************************
! 150:
! 151: void Word::Display(bool horz,CString writeme,int x,int y,CDC *xDC)
! 152: {
! 153: //This function writes the string to the screen.
! 154: //Will not write the string if its bigger than the max
! 155: //If horz = true then it writes it horiztal otherwise it
! 156: //writes it vertically
! 157: int len,i;
! 158: char tmp[MAXLETTERS];
! 159: writeme.MakeUpper();
! 160: len = writeme.GetLength();
! 161: if (len > limit_)
! 162: { len = limit_; };
! 163: if (len <= MAXLETTERS)
! 164: {
! 165: strcpy(tmp,writeme);
! 166: for (i=0;i<len;i++)
! 167: {
! 168: ShowChar(xDC,x,y,tmp[i]);
! 169: if (horz == true)
! 170: x = x + 19;
! 171: else
! 172: y = y + 30;
! 173:
! 174: };
! 175: };
! 176: }
! 177:
! 178: void Word::ShowChar(CDC *dc, int picX, int picY, char Let)
! 179: {
! 180: //Prints the Letter to the screen
! 181: CBitmap bitmap;
! 182:
! 183: switch(color_)
! 184: {
! 185: case 0 : bitmap.LoadBitmap(LETBLACK); break;
! 186: case 1 : bitmap.LoadBitmap(LETRED); break;
! 187: case 2 : bitmap.LoadBitmap(LETGREEN); break;
! 188: default: bitmap.LoadBitmap(LETBLACK); break;
! 189: };
! 190:
! 191:
! 192: CDC dcComp;
! 193: dcComp.CreateCompatibleDC(dc);
! 194: dcComp.SelectObject(&bitmap);
! 195: BITMAP bmInfo;
! 196: bitmap.GetObject(sizeof(bmInfo),&bmInfo);
! 197: int width,height,srcx,srcy;
! 198: width = 19;//with of the letter
! 199: height = 30;//height of the letter
! 200: srcx = 1; //Starting Value
! 201: if ((Let == ' ')||((Let < 'N')&&(Let >= 'A')))
! 202: {
! 203: srcy = 1;
! 204: if ((Let > 'A')||(Let == ' '))
! 205: srcx = srcx + (20 * GetNum(Let));
! 206: }
! 207: else if ((Let == '-')||((Let <= 'Z')&&(Let >= 'N')))
! 208: {
! 209: srcy = 37;
! 210: if ((Let > 'N')||(Let == '-'))
! 211: srcx = srcx + (20 * GetNum(Let));
! 212: }
! 213: else if ((Let == '=')||(Let == '.')||(Let == '?')||(Let == '!')||(Let <= '9')&&(Let >= '0'))
! 214: {
! 215: srcy = 73;
! 216: if (Let != '0')
! 217: srcx = srcx + (20 * GetNum(Let));
! 218: }
! 219: else if ((Let == '[')||(Let == '+')||(Let == '/'))
! 220: {
! 221: srcy = 109;
! 222: if (Let != '[')
! 223: srcx = srcx + (20 * GetNum(Let));
! 224: }
! 225: else
! 226: {
! 227: srcy = 1;
! 228: Let = ' ';
! 229: srcx = srcx + (20 * GetNum(Let));
! 230: }
! 231: dc->BitBlt(picX,picY,width,height,&dcComp,srcx,srcy,SRCCOPY);
! 232: }
! 233:
! 234: int Word::GetNum(char Let)
! 235: {
! 236: //Used with ShowChar gets a number of the character it is to print
! 237: int ans;
! 238: switch(Let)
! 239: {
! 240: case 'O' :
! 241: case '1' :
! 242: case 'B' : ans = 1; break;
! 243: case '2' :
! 244: case 'P' :
! 245: case 'C' : ans = 2; break;
! 246: case '3' :
! 247: case 'Q' :
! 248: case 'D' : ans = 3; break;
! 249: case '4' :
! 250: case 'R' :
! 251: case 'E' : ans = 4; break;
! 252: case '5' :
! 253: case 'S' :
! 254: case 'F' : ans = 5; break;
! 255: case '6' :
! 256: case 'T' :
! 257: case 'G' :
! 258: case '/' : ans = 6; break;
! 259: case '7' :
! 260: case 'U' :
! 261: case 'H' : ans = 7; break;
! 262: case '8' :
! 263: case 'V' :
! 264: case 'I' : ans = 8; break;
! 265: case '9' :
! 266: case 'W' :
! 267: case 'J' : ans = 9; break;
! 268: case '!' :
! 269: case 'X' :
! 270: case 'K' : ans = 10; break;
! 271: case '?' :
! 272: case 'Y' :
! 273: case 'L' : ans = 11; break;
! 274: case '.' :
! 275: case 'Z' :
! 276: case 'M' : ans = 12; break;
! 277: default : ans = 13; break;
! 278: }
! 279: return(ans);
! 280: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>