当前位置: 首页>>代码示例>>C++>>正文


C++ TextBox::GetLetterHeight方法代码示例

本文整理汇总了C++中TextBox::GetLetterHeight方法的典型用法代码示例。如果您正苦于以下问题:C++ TextBox::GetLetterHeight方法的具体用法?C++ TextBox::GetLetterHeight怎么用?C++ TextBox::GetLetterHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextBox的用法示例。


在下文中一共展示了TextBox::GetLetterHeight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Render

/***********************************
Text_Manager Render

brief: renders the string stored in the text box using the parameters of the text box
Author: Jamie Gault
***********************************/
void Text_Manager::Render( TextBox &textbox )
{
	r = 1.0f;
	if( m_initialized )
	{
		float x0 = textbox.GetPosX() + textbox.GetBGOffset(0,0);
		float x1 = textbox.GetPosX() + textbox.GetBoxWidth()+ textbox.GetBGOffset(1,0);
		float y0 = textbox.GetPosY() + textbox.GetBGOffset(0,1);
		float y1 = textbox.GetPosY() + textbox.GetBoxHeight()+ textbox.GetBGOffset(1,1);

		//if there is a background
		if( textbox.GetBackGround() )
		{
			glBindTexture(GL_TEXTURE_2D, textbox.GetBackGround());
			glBegin(GL_QUADS);
				glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
				glTexCoord2f(0,0);
				glVertex2f(x0,y0);

				glTexCoord2f(0,1);
				glVertex2f(x0,y1);

				glTexCoord2f(1,1);
				glVertex2f(x1,y1);

				glTexCoord2f(1,0);
				glVertex2f(x1,y0 );
			glEnd();
		}

		// Bind text texture
		glBindTexture(GL_TEXTURE_2D, m_textureID);

		glColor4f(textbox.GetColourComp(0), textbox.GetColourComp(1), textbox.GetColourComp(2), textbox.GetColourComp(3));

		//break the words up into a vector of strings
		std::istringstream stream(textbox.GetString());
		std::vector<std::string> word_vec ( (std::istream_iterator<std::string>(stream)), std::istream_iterator<std::string>());

		std::vector<std::string>::iterator word_it = word_vec.begin();

		glBegin(GL_QUADS);

		//while not at the end of the string
		float heightiter = 0.0f;
		float widthiter = 0.0f;
		while( heightiter <  textbox.GetBoxHeight() && word_it != word_vec.end())
		{
			float wordlength = 0.0f;
			float prevletlen;
			widthiter = GetLetterSpace(*(*word_it).begin()) - firstletteroffset;

			//iterate through each letter, spacing based on letter width
			for(std::string::iterator let_it = (*word_it).begin();
							let_it != (*word_it).end() ; ++let_it )
			{
				prevletlen = GetLetterSpace(*let_it); //space between previous letter
				wordlength += DATA("LETTER_WID_SCALE")*textbox.GetLetterWidth()*(1.0f - (prevletlen+GetLetterSpace(*let_it)));
			}
			wordlength += DATA("LETTER_WID_SCALE")*textbox.GetLetterWidth()*(1.0f);

			//while each word has not been processed
			while( word_it != word_vec.end() &&
				 widthiter + wordlength < textbox.GetBoxWidth())
			{
				widthiter += GetLetterSpace(*(*word_it).begin()) - firstletteroffset;
				//iterate through each letter, spacing based on letter width
				for(std::string::iterator let_it = (*word_it).begin();
								let_it != (*word_it).end() ; ++let_it)
				{
					prevletlen = GetLetterSpace(*let_it); //space between previous letter
					RenderLetter( textbox.GetPosX() + widthiter,
								textbox.GetPosY() + heightiter,
								textbox.GetLetterWidth(), textbox.GetLetterHeight(), *let_it);
					widthiter += DATA("LETTER_WID_SCALE")*textbox.GetLetterWidth()*(1.0f - (prevletlen+GetLetterSpace(*let_it)));
				}
				//widthiter += DATA("LETTER_WID_SCALE")*textbox.GetLetterWidth()*(1.0f);
				widthiter += textbox.GetGap(); // add for a space

				wordlength = 0.0f;

				++word_it;

				if( word_it != word_vec.end() )
				{
					wordlength += GetLetterSpace(*(*word_it).begin()) - firstletteroffset;

					//calculate the length of the next word
					for(std::string::iterator let_it = (*word_it).begin();
									let_it != (*word_it).end() ;  ++let_it)
					{
						prevletlen = GetLetterSpace(*let_it); //space between previous letter
						wordlength += DATA("LETTER_WID_SCALE")*textbox.GetLetterWidth()*
										( 1.0f - (prevletlen + GetLetterSpace(*let_it)));
//.........这里部分代码省略.........
开发者ID:fraktalVision,项目名称:Busted-Its_Up_To_You,代码行数:101,代码来源:TextManager.cpp


注:本文中的TextBox::GetLetterHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。