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


C++ u16string::at方法代码示例

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


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

示例1: CreateRenderCharacters

void RenderString::CreateRenderCharacters(const std::u16string& newString) {
	if (!newString.empty() && mFont) {
		int advanceAccum = 0; // the accumulated horizontal advance for the current line
		int kerningAccum = 0; // the accumulated kerning offset for the current line
		int lineOffset = 0; // the vertical offset of the current line
		int lineHeight = mFont->GetLineHeight(); // retrieve and store the new line offset
		
		if (!mString.empty() && !mRenderChars.empty()) { // if we already have characters entered...
			if (mString.back() == u'\n') { // if the last character entered was a new line...
				lineOffset = mRenderChars.back().mLineHeight + lineHeight; // adjust the line offset for following characters
			}
			else {
				// laod the states of the accumulators from the previous characters entered
				advanceAccum = mRenderChars.back().mAdvanceAccum;
				kerningAccum = mRenderChars.back().mKerningAccum;
				lineOffset = mRenderChars.back().mLineHeight;
				
				kerningAccum += mFont->GetKerning(mString.back(), newString.front()); // adjust the kerning offset for the new character
			}
		}
		
		for (unsigned int i = 0u; i < newString.size(); ++i) {
			char16_t codePoint = newString.at(i);
			
			if (codePoint == u'\n') { // if the current character is a new line...
				advanceAccum = 0; // reset the horizontal advance
				kerningAccum = 0; // reset the kerning offset
				lineOffset += lineHeight; // increment the vertical offset by the new line height
				continue; // go to the next character
			}
			
			try {
				const FontBase::Glyph& glyph = mFont->GetGlyph(codePoint); // get the glyph object for the current character
				Shape shape = glyph.mBaseShape; // get the glyph shape from the glyph object
				float height = 0.0f; // the height of the glyph shape used for positional offsetting
				
				{
					const std::vector<glm::vec2>& bbox = shape.GetLocalBoundingBox(); // get the bounding box of the glyph
					if (!bbox.empty()) { // if the bounding box is valid...
						height = bbox.at(2).y - bbox.at(0).y; // calculate the height of the glyph shape
					}
				}
				
				shape.SetPosition(glm::vec2((advanceAccum + kerningAccum) + glyph.mBearing.x,
						((mFont->GetBearingMax().y - glyph.mBearing.y) - mFont->GetBearingMax().y) + lineOffset)); // position the glyph shape
				
				{ // update the local bounding box
					// get the bounding box of the newly added character
					std::vector<glm::vec2> bbox = shape.GetGlobalBoundingBox();
					
					if (bbox.size() > 3) { // if the bounding box is valid...
						mTopLeft.x = std::min(bbox.at(0).x, mTopLeft.x);
						mTopLeft.y = std::min(bbox.at(0).y, mTopLeft.y);
						
						mBottomRight.x = std::max(bbox.at(2).x, mBottomRight.x);
						mBottomRight.y = std::max(bbox.at(2).y, mBottomRight.y);
					}
				}
				
				advanceAccum += glyph.mAdvance; // increment the horizontal advance accumulator by the current glyph's advance metric
				if (i != newString.size() - 1) { // if this is not the final character in the string...
					kerningAccum += mFont->GetKerning(codePoint, newString.at(i + 1)); // increment the kerning offset by the kerning value of this and the next character
				}
				
				mRenderChars.push_back({std::move(shape), advanceAccum, kerningAccum, lineOffset,
						mTopLeft, mBottomRight});
			} catch(std::exception& e) {
				std::cout << "unknown codepoint: " << codePoint << std::endl;
			}
		}
		
		// update the full sized (not yet scaled) local bounding box
		glm::vec2 dimensions = mBottomRight - mTopLeft;
		mLocalBoundingBoxFull.clear();
		mLocalBoundingBoxFull.emplace_back(0.0f, 0.0f);
		mLocalBoundingBoxFull.emplace_back(dimensions.x, 0.0f);
		mLocalBoundingBoxFull.emplace_back(dimensions.x, dimensions.y);
		mLocalBoundingBoxFull.emplace_back(0.0f, dimensions.y);
	}
}
开发者ID:dakodun,项目名称:uair,代码行数:80,代码来源:renderstring.cpp


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