File:  [Local Repository] / DewFind / word.cpp
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed Mar 2 17:51:54 2011 UTC (13 years, 2 months ago) by nick
Branches: MAIN, INITIAL
CVS tags: r_0, HEAD
Initial import

#include "StdAfx.h"
#include "resource.h"
#include "word.h"

//#32
//*************************************
//Programmed by: Brendan Lynch
//Email:    	 dewgames@gmail.com
//Website:	     www.dewgames.com
//*************************************


//**************************************************************************************************
//
//-------------------------------------PUBLIC-------------------------------------------------------
//
//**************************************************************************************************

Word::Word()
{
	Reset();
};

void Word::Reset()
{
	limit_ = MAXLETTERS;
	color_ = 0; //Black
};
void Word::SetLimit(int lim)
{
 //Used so that it will only print upto the limit.
 //Makes sure it doesnt go over the max
	if (lim <= MAXLETTERS)		
	   limit_ = lim;
}

void Word::Write(CString writeme,int x,int y,CDC *xDC)
{
	Display(true,writeme,x,y,xDC);
};

void Word::Write(char writeme,int x,int y,CDC *xDC)
{
	ShowChar(xDC,x,y,writeme);
};

void Word::SetColor(int color)
{
	color_ = color;
}
void Word::WriteBackwards(bool IsVert, CString writeme, int x, int y, CDC *xDC)
{
	CString backwards;

	int len,tmpy;	
	char tChar;

	len = writeme.GetLength();
	tmpy = len-1;

	backwards = "";
	for(tmpy;tmpy>=0;tmpy--)
	{
		tChar = writeme.GetAt(tmpy);
		backwards = backwards + tChar;
	};

	if (IsVert == true)
	{
		WriteVert(backwards,x,y,xDC);
	}
	else
	{
		Write(backwards,x,y,xDC);
	};
};


void Word::Write(int number,int x,int y,int zeros, CDC *xDC)
{
	//Converts the number to a string
	//Adds 0's base on what number zeros is equal to
    //Then uses the write string function
	CString str;
	bool done=false;
	CString strx("");

	if ((number > 9999999)&&(zeros == 8))
	{
		str.Format("%i",number);
		done = true;
	}
	if ((number > 999999)&&(zeros == 7))
	{
		str.Format("%i",number);
		done = true;
	}
	if ((number > 99999)&&(zeros == 6))
	{
		str.Format("%i",number);
		done = true;
	}
	if ((number > 9999)&&(zeros == 5))
	{
		str.Format("%i",number);
		done = true;
	}
	if ((number > 999)&&(zeros == 4))
	{
	  str.Format("%i",number);
	  done = true;
	}
	if (done==false)
	{
	if ((number < 10000000)&&(zeros > 7))
		strx = strx + "0";
	if ((number < 1000000)&&(zeros > 6))
		strx = strx + "0";
	if ((number < 100000)&&(zeros > 5))
		strx = strx + "0";
	if ((number < 10000)&&(zeros > 4))
		strx = strx + "0";
    if ((number < 1000)&&(zeros > 3))
	  strx = strx + "0";
	if ((number < 100)&&(zeros > 2))
		strx = strx + "0";
	if (number < 10)
		strx = strx + "0";

	str.Format("%i",number);
	str = strx + str;
	}



	Write(str,x,y,xDC);
}


void Word::WriteVert(CString writeme,int x,int y,CDC *xDC)
{
	Display(false,writeme,x,y,xDC);
}

//******************************************************************************************************
//
//-------------------------------------PRIVATE-------------------------------------------------------
//
//******************************************************************************************************

void Word::Display(bool horz,CString writeme,int x,int y,CDC *xDC)
{
    //This function writes the string to the screen. 
	//Will not write the string if its bigger than the max
	//If horz = true then it writes it horiztal otherwise it
	//writes it vertically
	int len,i;
    char tmp[MAXLETTERS];
	writeme.MakeUpper();
	len = writeme.GetLength();
	if (len > limit_)
	{ len = limit_; };
	if (len <= MAXLETTERS)
	{
	strcpy(tmp,writeme);
	 for (i=0;i<len;i++)
	 {
	 ShowChar(xDC,x,y,tmp[i]);
	 if (horz == true)
	   x = x + 19;
	 else
	   y = y + 30;

	 };	
	};
}

void Word::ShowChar(CDC *dc, int picX, int picY, char Let)
{	
   //Prints the Letter to the screen
   CBitmap bitmap;
   
   switch(color_)
   {
   case 0 : bitmap.LoadBitmap(LETBLACK); break;
   case 1 : bitmap.LoadBitmap(LETRED);   break;
   case 2 : bitmap.LoadBitmap(LETGREEN);  break;
   default: bitmap.LoadBitmap(LETBLACK); break;
   };


   CDC dcComp;
   dcComp.CreateCompatibleDC(dc);
   dcComp.SelectObject(&bitmap);
   BITMAP bmInfo;
   bitmap.GetObject(sizeof(bmInfo),&bmInfo);
   int width,height,srcx,srcy;
   width = 19;//with of the letter
   height = 30;//height of the letter
   srcx = 1; //Starting Value
   if ((Let == ' ')||((Let < 'N')&&(Let >= 'A')))
   {
    srcy = 1;
	if ((Let > 'A')||(Let == ' '))
		srcx = srcx + (20 * GetNum(Let));
   }
   else if ((Let == '-')||((Let <= 'Z')&&(Let >= 'N')))
   {
	   srcy = 37;
	   if ((Let > 'N')||(Let == '-'))
		   srcx = srcx + (20 * GetNum(Let));
   }
   else if ((Let == '=')||(Let == '.')||(Let == '?')||(Let == '!')||(Let <= '9')&&(Let >= '0'))
   {
	   srcy = 73;
	   if (Let != '0')
		   srcx = srcx + (20 * GetNum(Let));
   }
   else if ((Let == '[')||(Let == '+')||(Let == '/'))
   {
	   srcy = 109;
	   if (Let != '[')
		   srcx = srcx + (20 * GetNum(Let));
   }
   else
   {
	   srcy = 1;
	   Let = ' ';
	   srcx = srcx + (20 * GetNum(Let));
   }
   dc->BitBlt(picX,picY,width,height,&dcComp,srcx,srcy,SRCCOPY);
}

int Word::GetNum(char Let)
{
  //Used with ShowChar gets a number of the character it is to print
	int ans;
  switch(Let)
  {
  case 'O' :
  case '1' :
  case 'B' : ans = 1; break;
  case '2' :
  case 'P' :
  case 'C' : ans = 2; break;
  case '3' :
  case 'Q' :
  case 'D' : ans = 3; break;
  case '4' :
  case 'R' :
  case 'E' : ans = 4; break;
  case '5' :
  case 'S' :
  case 'F' : ans = 5; break;
  case '6' :
  case 'T' :
  case 'G' : 
  case '/' : ans = 6; break;
  case '7' :
  case 'U' :
  case 'H' : ans = 7; break;
  case '8' :
  case 'V' :
  case 'I' : ans = 8; break;
  case '9' :
  case 'W' :
  case 'J' : ans = 9; break;
  case '!' :
  case 'X' :
  case 'K' : ans = 10; break;
  case '?' :
  case 'Y' :
  case 'L' : ans = 11; break;
  case '.' :
  case 'Z' :
  case 'M' : ans = 12; break;
  default  : ans = 13; break;
  }
  return(ans);
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>