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


C++ TextLayout::box方法代码示例

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


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

示例1: _render

void BitmapTextComponentManager::_render(EntityRef entity, float interp, const OrthographicCamera& camera) {
	if ( !entity.isEnabled() )
		return;

	BitmapTextComponent* comp = get(entity);
	if(comp && comp->isEnabled()
	&& comp->font() && comp->font()->get() && comp->font()->get()->isValid()) {
		BitmapFontSP font = comp->font()->get();

		Matrix4 wt = lerp(interp,
						  comp->_entity()->prevWorldTransform.matrix(),
						  comp->_entity()->worldTransform.matrix());

		// FIXME: Find a way to get rid of this - we should not upload stuff here.
		if(!comp->texture()) {
			comp->_setTexture(_spriteRenderer->createTexture(font->image()));
			_spriteRenderer->renderer()->uploadPendingTextures();
		}
		TextureSP tex = comp->texture()->_get();

		int width = (comp->size()(0) > 0)? comp->size()(0): 999999;
		TextLayout layout = font->layoutText(comp->text(), width);
		unsigned index = _spriteRenderer->indexCount();
		for(unsigned i = 0; i < layout.nGlyphs(); ++i) {
			unsigned cp = layout.glyph(i).codepoint;
			Vector2 pos = layout.glyph(i).pos;
			const BitmapFont::Glyph& glyph = font->glyph(cp);

			Vector2 size = glyph.size;

			pos(0) += glyph.offset(0);
			pos(1) += font->height() - size(1) - glyph.offset(1)
			        + layout.box().sizes()(1);
			pos -= layout.box().sizes().cwiseProduct(comp->anchor());
			Box2 coords(pos, pos + size);

			_spriteRenderer->addSprite(wt, coords, comp->color(), glyph.region);
		}
		unsigned count = _spriteRenderer->indexCount() - index;

		if(count) {
			_states.texture      = tex;

			const ShaderParameter* params = _spriteRenderer->addShaderParameters(
			            _spriteRenderer->shader(), camera.transform(), 0, Vector4i(1, 1, 65536, 65536));

			float depth = 1.f - normalize(wt(2, 3), camera.viewBox().min()(2),
			                                        camera.viewBox().max()(2));
			_renderPass->addDrawCall(_states, params, depth, index, count);
		}
	}

	EntityRef child = entity.firstChild();
	while(child.isValid()) {
		render(child, interp, camera);
		child = child.nextSibling();
	}
}
开发者ID:DrWindu,项目名称:lair,代码行数:58,代码来源:bitmap_text_component.cpp


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