本文整理汇总了C++中FontPtr类的典型用法代码示例。如果您正苦于以下问题:C++ FontPtr类的具体用法?C++ FontPtr怎么用?C++ FontPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FontPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetTextBoxHeight
unsigned TextBox::GetTextBoxHeight() const
{
FontPtr pFont = Renderer::GetInstance().GetFont(mTextSize);
float height = pFont->GetHeight();
pFont->SetBackToOrigHeight();
return Round(height * mNumTextLines) + 16;
}
示例2: iss
FontManager::FontPtr FontManager::Load(const std::string& locator){
std::string file;
int size;
std::string::size_type plast = locator.find_last_not_of(";");
std::string::size_type pfirst = locator.find_first_of(";");
std::string tmp;
if((plast == std::string::npos) || (pfirst == std::string::npos)){
file = locator;
size = DEFAULT_FONT_SIZE;
}else{
file = locator.substr(0, plast - 2);
tmp = locator.substr(pfirst + 1);
std::istringstream iss(tmp);
iss >> size;
}
file = "content/fonts/" + file;
FontPtr font = FontPtr(new sf::Font());
if( !font->LoadFromFile(file, size))
return FontPtr();
return font;
}
示例3: translate
//! [font_translate]
void FontTranslator::translate(ScriptCompiler* compiler, const AbstractNodePtr& node)
{
ObjectAbstractNode* obj = static_cast<ObjectAbstractNode*>(node.get());
// Must have a name - unless we are in legacy mode. Then the class is the name.
if (obj->name.empty() && obj->cls == "font")
{
compiler->addError(ScriptCompiler::CE_OBJECTNAMEEXPECTED, obj->file, obj->line,
"font must be given a name");
return;
}
String& name = obj->cls == "font" ? obj->name : obj->cls;
FontPtr font = FontManager::getSingleton().create(name, compiler->getResourceGroup());
font->_notifyOrigin(obj->file);
for (auto& c : obj->children)
{
if (c->type == ANT_PROPERTY)
{
parseAttribute(compiler, font, static_cast<PropertyAbstractNode*>(c.get()));
}
}
}
示例4:
float
Menu::get_width() const
{
/* The width of the menu has to be more than the width of the text
with the most characters */
float menu_width = 0;
for(unsigned int i = 0; i < items.size(); ++i)
{
FontPtr font = Resources::Resources::normal_font;
if(items[i]->kind == MN_LABEL)
font = Resources::big_font;
float w = font->get_text_width(items[i]->text) +
Resources::big_font->get_text_width(items[i]->input) + 16;
if(items[i]->kind == MN_TOGGLE)
w += 32;
if (items[i]->kind == MN_STRINGSELECT)
w += font->get_text_width(items[i]->list[items[i]->selected]) + 32;
if(w > menu_width)
menu_width = w;
}
return menu_width + 24;
}
示例5:
ObjectPtr<Object> Font::restoreObject(SaveGame *state) {
const char *fname = state->readCharString();
FontPtr font = g_resourceloader->getFont(fname);
delete[] fname;
ObjectPtr<Object> ptr = font.object();
return ptr;
}
示例6: CalcTextWidth
void TextBox::CalcTextWidth()
{
// analyze the text length
FontPtr pFont = Renderer::GetInstance().GetFont(mTextSize);
unsigned width = mSize.x;
float textWidth;
mMultiLineText = pFont->InsertLineFeed((const char*)mTextw.c_str(), mTextw.size() * 2, width, &textWidth, &mNumTextLines);
mTextWidth = (unsigned)Round(textWidth);
pFont->SetBackToOrigHeight();
mUIObject->SetText(mMultiLineText.c_str());
}
示例7: fontPlug
IECore::ConstObjectPtr Text::computeSource( const Context *context ) const
{
std::string fontFileName = fontPlug()->getValue();
std::string text = textPlug()->getValue();
if( !text.size() || !fontFileName.size() )
{
return outPlug()->objectPlug()->defaultValue();
}
FontPtr font = Detail::fontCache()->get( fontFileName );
return font->mesh( text );
}
示例8: GetRawImage
WONButtonPtr WinSkin::CalcCheckButton(const char *theBitmapName, WONButton *orig)
{
WONButtonPtr aCheckbox = new WONButton;
aCheckbox->SetPushOffsets(0,0);
aCheckbox->SetHasCheck(true);
aCheckbox->SetScaleImage(false);
RawImagePtr aButtonMasterImage = GetRawImage("Buttons",theBitmapName);
int aNumPictures = GetIntParam("Buttons","EnhancedMode")?5:4;
if(aButtonMasterImage.get()==NULL)
return orig;
int aWidth = aButtonMasterImage->GetWidth()/aNumPictures;
aCheckbox->SetTextPadding(aWidth + 4,2,2,2);
int aColor = GetColor("Buttons","NormalColour");
FontPtr aFont = GetFont("Buttons","NormalFont");
if(aFont.get()==NULL)
aFont = mWindow->GetWindowManager()->GetNamedFont("MSButton");
if(aColor==-1)
aColor = 0;
CropImageFilterPtr aCrop = new CropImageFilter;
aCrop->SetSize(aWidth,aButtonMasterImage->GetHeight());
for(int i=0; i<4; i++)
{
aCrop->SetPos(i*aWidth,0);
RawImagePtr aRawImage = aCrop->Filter(aButtonMasterImage);
NativeImagePtr aNativeImage = aRawImage->GetNative(mWindow->GetDisplayContext());
bool checked = i&1?true:false;
int anIndex = i>=2?2:0;
aCheckbox->SetButtonState(anIndex,aNativeImage,aColor,aFont,checked);
if(anIndex==0)
{
RawImagePtr aRawImage2 = (RawImage*)aRawImage->Duplicate().get();
TintImageFilterPtr aTint = new TintImageFilter(100,100,150);
aTint->Filter(aRawImage);
aNativeImage = aRawImage->GetNative(mWindow->GetDisplayContext());
aCheckbox->SetButtonState(3,aNativeImage,aColor,aFont,checked);
aTint = new TintImageFilter(100,150,100);
aTint->Filter(aRawImage2);
aNativeImage = aRawImage2->GetNative(mWindow->GetDisplayContext());
aCheckbox->SetButtonState(1,aNativeImage,aColor,aFont,checked);
}
}
return aCheckbox;
}
示例9:
void CategorizedList::Category::layoutChildren()
{
FontPtr font = parent.GetFont();
float pos = font ? font->getLineSpacing() : 0.f;
std::vector<window_ptr>::iterator i = children.begin();
std::vector<window_ptr>::iterator end = children.end();
while(i != end)
{
window_ptr child = *i;
child->setPosition(point(area.m_left, area.m_top + pos));
pos += child->getArea().getHeight();
++i;
}
}
示例10: runtime_error
FontPtr FontManager::load(std::string path)
{
if(isLoaded(path))
{
throw runtime_error("Font '" + path + "' already loaded");
}
FontPtr New = make_shared<Font>();
if(!New->loadFromFile(path))
{
throw runtime_error("Cannot load font " + path);
}
return New;
}
示例11: while
void MarkupBase::render(const Rect& finalRect, const Rect& finalClip)
{
size_t len = m_text.length();
std::vector<PTextLine>::const_iterator i = m_textlines.begin();
std::vector<PTextLine>::const_iterator end = m_textlines.end();
while(i != end)
{
const TextLine* line = (*i).get();
size_t offset = line->start;
Rect rl(line->area);
std::vector<PText>::const_iterator c = line->children.begin();
std::vector<PText>::const_iterator stop = line->children.end();
while(c != stop)
{
const Text* chunk = (*c).get();
if(chunk->len > 0 && chunk->len <= len)
{
FontPtr f = chunk->font;
Color col = chunk->selected ? chunk->selcol : chunk->col;
std::string buf = m_text.substr(chunk->start + offset, chunk->len);
Rect rc(chunk->area);
rc.offset(rl.getPosition());
rc.offset(finalRect.getPosition());
f->drawText(buf, rc, 1.0f, finalClip, LeftAligned, col, 1.f, 1.f);
}
++c;
}
++i;
}
Renderer& r = m_system.getRenderer();
std::vector<PImg>::const_iterator cimg = m_images.begin();
std::vector<PImg>::const_iterator cimgend = m_images.end();
while(cimg != cimgend)
{
const Img* img = (*cimg).get();
Rect rc(img->area);
rc.offset(finalRect.getPosition());
if (img->img)
{
r.draw(*img->img, rc, 1.f, finalClip, m_backColor, Stretch, Stretch);
}
++cimg;
}
}
示例12: while
std::vector<std::unique_ptr<InfoBoxLine> >
InfoBoxLine::split(const std::string& text, float width)
{
std::vector<std::unique_ptr<InfoBoxLine> > lines;
std::string::size_type i = 0;
std::string::size_type l;
char format_char = '#';
while(i < text.size()) {
// take care of empty lines - represent them as blank lines of normal text
if (text[i] == '\n') {
lines.emplace_back(new InfoBoxLine('\t', ""));
i++;
continue;
}
// extract the format_char
format_char = text[i];
i++;
if (i >= text.size()) break;
// extract one line
l = text.find("\n", i);
if (l == std::string::npos) l=text.size();
std::string s = text.substr(i, l-i);
i = l+1;
// if we are dealing with an image, just store the line
if (format_char == '!') {
lines.emplace_back(new InfoBoxLine(format_char, s));
continue;
}
// append wrapped parts of line into list
std::string overflow;
do {
FontPtr font = get_font_by_format_char(format_char);
std::string s2 = s;
if (font) s2 = font->wrap_to_width(s2, width, &overflow);
lines.emplace_back(new InfoBoxLine(format_char, s2));
s = overflow;
} while (s.length() > 0);
}
return lines;
}
示例13: parseScript
//---------------------------------------------------------------------
void FontManager::parseScript(DataStreamPtr& stream, const String& groupName)
{
String line;
FontPtr pFont;
while( !stream->eof() )
{
line = stream->getLine();
// Ignore blanks & comments
if( !line.length() || line.substr( 0, 2 ) == "//" )
{
continue;
}
else
{
if (pFont.isNull())
{
// No current font
// So first valid data should be font name
if (StringUtil::startsWith(line, "font "))
{
// chop off the 'particle_system ' needed by new compilers
line = line.substr(5);
}
pFont = create(line, groupName);
pFont->_notifyOrigin(stream->getName());
// Skip to and over next {
stream->skipLine("{");
}
else
{
// Already in font
if (line == "}")
{
// Finished
pFont.setNull();
// NB font isn't loaded until required
}
else
{
parseAttribute(line, pFont);
}
}
}
}
}
示例14: Sprite
TextSprite::TextSprite(MaterialPtr material, const std::string &text, FontPtr font, PropertiesPtr properties)
: Sprite(), _text(text), _font(font)
{
// Create geometry
createGeometry();
// Add atlas texture to the material
material->setTexture(bRenderer::DEFAULT_SHADER_UNIFORM_CHARACTER_MAP(), font->getAtlas());
setMaterial(material);
setProperties(properties);
}
示例15: calculateTextPixelSize
void OgreText::calculateTextPixelSize(DisplayString text, FontPtr mpFont, Real mCharHeight, Real& width, Real& height)
{
Real vpWidth, vpHeight;
vpWidth = (Real) (OverlayManager::getSingleton().getViewportWidth());
vpHeight = (Real) (OverlayManager::getSingleton().getViewportHeight());
//ROS_ERROR("[viewport] w: %f h: %f",vpWidth,vpHeight);
Real mViewportAspectCoef = vpHeight/vpWidth;
height = mCharHeight;
width = 0;
Real len = 0.0f;
for(DisplayString::iterator i = text.begin();i!=text.end();++i)
{
Font::CodePoint character = OGRE_DEREF_DISPLAYSTRING_ITERATOR(i);
if (character == UNICODE_CR
|| character == UNICODE_NEL
|| character == UNICODE_LF)
{
height += mCharHeight;
if(len > width)
width = len;
len = 0;
}
else if (character == UNICODE_SPACE) // space
{
len += mpFont->getGlyphAspectRatio(UNICODE_ZERO) * mCharHeight;// * 2.0 * mViewportAspectCoef;
}
else
{
len += mpFont->getGlyphAspectRatio(character) * mCharHeight;// * 2.0 * mViewportAspectCoef;
}
}
if(len > width)
width = len;
}