本文整理汇总了C++中LLWString::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ LLWString::c_str方法的具体用法?C++ LLWString::c_str怎么用?C++ LLWString::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LLWString
的用法示例。
在下文中一共展示了LLWString::c_str方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addLabel
void LLHUDNameTag::addLabel(const std::string& label_utf8)
{
LLWString wstr = utf8string_to_wstring(label_utf8);
if (!wstr.empty())
{
LLWString seps(utf8str_to_wstring("\r\n"));
LLWString empty;
typedef boost::tokenizer<boost::char_separator<llwchar>, LLWString::const_iterator, LLWString > tokenizer;
boost::char_separator<llwchar> sep(seps.c_str(), empty.c_str(), boost::keep_empty_tokens);
tokenizer tokens(wstr, sep);
tokenizer::iterator iter = tokens.begin();
while (iter != tokens.end())
{
U32 line_length = 0;
do
{
S32 segment_length = mFontp->maxDrawableChars(iter->substr(line_length).c_str(),
HUD_TEXT_MAX_WIDTH, wstr.length(), LLFontGL::WORD_BOUNDARY_IF_POSSIBLE);
LLHUDTextSegment segment(iter->substr(line_length, segment_length), LLFontGL::NORMAL, mColor, mFontp);
mLabelSegments.push_back(segment);
line_length += segment_length;
}
while (line_length != iter->size());
++iter;
}
}
}
示例2: addQueuedLines
void LLConsole::addQueuedLines()
{
for (line_queue_t::iterator iter = mLineQueue.begin();
iter != mLineQueue.end(); ++iter)
{
LineInfo& line_info = *iter;
LLWString wline = line_info.wline;
//F32 size = line_info.size;
LLColor4 color = line_info.color;
if (!wline.empty() && mFont != NULL)
{
// Wrap lines that are longer than the view is wide.
S32 offset = 0;
while( offset < (S32)wline.length() )
{
S32 skip_chars; // skip '\n'
// Figure out if a word-wrapped line fits here.
LLWString::size_type line_end = wline.find_first_of(llwchar('\n'), offset);
if (line_end != LLWString::npos)
{
skip_chars = 1; // skip '\n'
}
else
{
line_end = wline.size();
skip_chars = 0;
}
U32 drawable = mFont->maxDrawableChars(wline.c_str()+offset, (F32)mRect.getWidth(), line_end-offset, TRUE);
if (drawable != 0)
{
LLFixedBuffer::addLine(wline.substr(offset, drawable));
mAddTimes[mAddTimes.size()-1] = line_info.add_time;
}
else
{
// force a blank line
LLFixedBuffer::addLine(" ");
}
mColors.push_back(color);
offset += (drawable + skip_chars);
}
}
}
mLineQueue.clear();
}
示例3: getNotifyTipRect
// static
LLRect LLNotifyBox::getNotifyTipRect(const std::string &utf8message)
{
LLWString message = utf8str_to_wstring(utf8message);
S32 message_len = message.length();
const S32 NOTIFY_WIDTH = gSavedSettings.getS32("NotifyBoxWidth");
// Make room for the icon area.
const S32 text_area_width = NOTIFY_WIDTH - HPAD * 4 - 32;
const llwchar* wchars = message.c_str();
const llwchar* start = wchars;
const llwchar* end;
S32 total_drawn = 0;
bool done = false;
S32 line_count;
for (line_count = 2; !done; ++line_count)
{
for (end = start; *end != 0 && *end != '\n'; end++);
if (*end == 0)
{
end = wchars + message_len;
done = true;
}
for (S32 remaining = end - start; remaining;)
{
S32 drawn = sFont->maxDrawableChars(start, (F32)text_area_width, remaining, LLFontGL::WORD_BOUNDARY_IF_POSSIBLE);
if (0 == drawn)
{
drawn = 1; // Draw at least one character, even if it doesn't all fit. (avoids an infinite loop)
}
total_drawn += drawn;
start += drawn;
remaining -= drawn;
if (total_drawn < message_len)
{
if (wchars[ total_drawn ] != '\n')
{
// wrap because line was too long
line_count++;
}
}
else
{
done = true;
}
}
total_drawn++; // for '\n'
start = ++end;
}
const S32 MIN_NOTIFY_HEIGHT = 72;
const S32 MAX_NOTIFY_HEIGHT = 600;
S32 notify_height = llceil((F32) (line_count+1) * sFont->getLineHeight());
if (gOverlayBar)
{
notify_height += gOverlayBar->getBoundingRect().mTop;
}
else
{
// *FIX: this is derived from the padding caused by the
// rounded rects, shouldn't be a const here.
notify_height += 10;
}
notify_height += VPAD;
notify_height = llclamp(notify_height, MIN_NOTIFY_HEIGHT, MAX_NOTIFY_HEIGHT);
const S32 RIGHT = gNotifyBoxView->getRect().getWidth();
const S32 LEFT = RIGHT - NOTIFY_WIDTH;
// Make sure it goes slightly offscreen
return LLRect(LEFT, notify_height-1, RIGHT, -1);
}
示例4:
F32 LLFontGL::getWidthF32(const std::string& utf8text, const S32 begin_offset, const S32 max_chars ) const
{
LLWString wtext = utf8str_to_wstring(utf8text);
return getWidthF32(wtext.c_str(), begin_offset, max_chars);
}
示例5: render
S32 LLFontGL::render(const LLWString &wstr,
const S32 begin_offset,
const F32 x, const F32 y,
const LLColor4 &color,
const HAlign halign, const VAlign valign,
U8 style,
const S32 max_chars, S32 max_pixels,
F32* right_x,
BOOL use_embedded,
BOOL use_ellipses) const
{
if(!sDisplayFont) //do not display texts
{
return wstr.length() ;
}
if (wstr.empty())
{
return 0;
}
gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
S32 scaled_max_pixels = max_pixels == S32_MAX ? S32_MAX : llceil((F32)max_pixels * sScaleX);
// Strip off any style bits that are already accounted for by the font.
style = style & (~getFontDesc().getStyle());
F32 drop_shadow_strength = 0.f;
if (style & (DROP_SHADOW | DROP_SHADOW_SOFT))
{
F32 luminance;
color.calcHSL(NULL, NULL, &luminance);
drop_shadow_strength = clamp_rescale(luminance, 0.35f, 0.6f, 0.f, 1.f);
if (luminance < 0.35f)
{
style = style & ~(DROP_SHADOW | DROP_SHADOW_SOFT);
}
}
gGL.pushMatrix();
glLoadIdentity();
gGL.translatef(floorf(sCurOrigin.mX*sScaleX), floorf(sCurOrigin.mY*sScaleY), sCurOrigin.mZ);
// this code snaps the text origin to a pixel grid to start with
F32 pixel_offset_x = llround((F32)sCurOrigin.mX) - (sCurOrigin.mX);
F32 pixel_offset_y = llround((F32)sCurOrigin.mY) - (sCurOrigin.mY);
gGL.translatef(-pixel_offset_x, -pixel_offset_y, 0.f);
LLFastTimer t(LLFastTimer::FTM_RENDER_FONTS);
gGL.color4fv( color.mV );
S32 chars_drawn = 0;
S32 i;
S32 length;
if (-1 == max_chars)
{
length = (S32)wstr.length() - begin_offset;
}
else
{
length = llmin((S32)wstr.length() - begin_offset, max_chars );
}
F32 cur_x, cur_y, cur_render_x, cur_render_y;
// Not guaranteed to be set correctly
gGL.setSceneBlendType(LLRender::BT_ALPHA);
cur_x = ((F32)x * sScaleX);
cur_y = ((F32)y * sScaleY);
// Offset y by vertical alignment.
switch (valign)
{
case TOP:
cur_y -= mAscender;
break;
case BOTTOM:
cur_y += mDescender;
break;
case VCENTER:
cur_y -= ((mAscender - mDescender)/2.f);
break;
case BASELINE:
// Baseline, do nothing.
break;
default:
break;
}
switch (halign)
{
case LEFT:
break;
case RIGHT:
cur_x -= llmin(scaled_max_pixels, llround(getWidthF32(wstr.c_str(), 0, length) * sScaleX));
break;
//.........这里部分代码省略.........
示例6: findSegments
// Walk through a string, applying the rules specified by the keyword token list and
// create a list of color segments.
void LLKeywords::findSegments(std::vector<LLTextSegment *>* seg_list, const LLWString& wtext, const LLColor4 &defaultColor)
{
std::for_each(seg_list->begin(), seg_list->end(), DeletePointer());
seg_list->clear();
if( wtext.empty() )
{
return;
}
S32 text_len = wtext.size();
seg_list->push_back( new LLTextSegment( LLColor3(defaultColor), 0, text_len ) );
const llwchar* base = wtext.c_str();
const llwchar* cur = base;
const llwchar* line = NULL;
while( *cur )
{
if( *cur == '\n' || cur == base )
{
if( *cur == '\n' )
{
cur++;
if( !*cur || *cur == '\n' )
{
continue;
}
}
// Start of a new line
line = cur;
// Skip white space
while( *cur && isspace(*cur) && (*cur != '\n') )
{
cur++;
}
if( !*cur || *cur == '\n' )
{
continue;
}
// cur is now at the first non-whitespace character of a new line
// Line start tokens
{
BOOL line_done = FALSE;
for (token_list_t::iterator iter = mLineTokenList.begin();
iter != mLineTokenList.end(); ++iter)
{
LLKeywordToken* cur_token = *iter;
if( cur_token->isHead( cur ) )
{
S32 seg_start = cur - base;
while( *cur && *cur != '\n' )
{
// skip the rest of the line
cur++;
}
S32 seg_end = cur - base;
LLTextSegment* text_segment = new LLTextSegment( cur_token->getColor(), seg_start, seg_end );
text_segment->setToken( cur_token );
insertSegment( seg_list, text_segment, text_len, defaultColor);
line_done = TRUE; // to break out of second loop.
break;
}
}
if( line_done )
{
continue;
}
}
}
// Skip white space
while( *cur && isspace(*cur) && (*cur != '\n') )
{
cur++;
}
while( *cur && *cur != '\n' )
{
// Check against delimiters
{
S32 seg_start = 0;
LLKeywordToken* cur_delimiter = NULL;
for (token_list_t::iterator iter = mDelimiterTokenList.begin();
iter != mDelimiterTokenList.end(); ++iter)
{
LLKeywordToken* delimiter = *iter;
if( delimiter->isHead( cur ) )
{
cur_delimiter = delimiter;
break;
//.........这里部分代码省略.........
示例7: draw
//.........这里部分代码省略.........
center_x++;
}
// fade out overlay images on disabled buttons
LLColor4 overlay_color = mImageOverlayColor;
if (!getEnabled())
{
overlay_color.mV[VALPHA] = 0.5f;
}
switch(mImageOverlayAlignment)
{
case LLFontGL::LEFT:
text_left += overlay_width + 1;
text_width -= overlay_width + 1;
text_middle += (overlay_width+1)/4;
mImageOverlay->draw(
mLeftHPad,
center_y - (overlay_height / 2),
overlay_width,
overlay_height,
overlay_color);
break;
case LLFontGL::HCENTER:
mImageOverlay->draw(
center_x - (overlay_width / 2),
center_y - (overlay_height / 2),
overlay_width,
overlay_height,
overlay_color);
break;
case LLFontGL::RIGHT:
text_right -= overlay_width + 1;
text_width -= overlay_width + 1;
text_middle += (overlay_width+1)/4;
mImageOverlay->draw(
getRect().getWidth() - mRightHPad - overlay_width,
center_y - (overlay_height / 2),
overlay_width,
overlay_height,
overlay_color);
break;
default:
// draw nothing
break;
}
}
// Draw label
if( !label.empty() )
{
LLWStringUtil::trim(label);
S32 x;
switch( mHAlign )
{
case LLFontGL::RIGHT:
x = text_right;
break;
case LLFontGL::HCENTER:
{
S32 actual_width = mGLFont->getWidth(label.c_str());
x = llmax(text_middle, text_left + actual_width/2);
}
break;
case LLFontGL::LEFT:
default:
x = text_left;
break;
}
S32 y_offset = 2 + (getRect().getHeight() - 20)/2;
if (pressed)
{
y_offset--;
x++;
}
mGLFont->render(label, 0,
(F32)x,
(F32)(LLBUTTON_V_PAD + y_offset),
label_color,
mHAlign, LLFontGL::BOTTOM,
LLFontGL::NORMAL,
mDropShadowedText ? LLFontGL::DROP_SHADOW_SOFT : LLFontGL::NO_SHADOW,
U32_MAX, text_width,
NULL, FALSE, FALSE);
}
if (sDebugRects
|| (LLView::sEditingUI && this == LLView::sEditingUIView))
{
drawDebugRect();
}
// reset hover status for next frame
mNeedsHighlight = FALSE;
}
示例8: render
S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, const LLColor4 &color, HAlign halign, VAlign valign, U8 style,
ShadowType shadow, S32 max_chars, S32 max_pixels, F32* right_x, BOOL use_embedded, BOOL use_ellipses) const
{
LLFastTimer _(FTM_RENDER_FONTS);
if(!sDisplayFont) //do not display texts
{
return wstr.length() ;
}
if (wstr.empty() || !max_pixels)
{
return 0;
}
if (max_chars == -1)
max_chars = S32_MAX;
const S32 max_index = llmin(llmax(max_chars, begin_offset + max_chars), S32(wstr.length()));
if (max_index <= 0 || begin_offset >= max_index || max_pixels <= 0)
return 0;
gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
S32 scaled_max_pixels = max_pixels == S32_MAX ? S32_MAX : llceil((F32)max_pixels * sScaleX);
// Strip off any style bits that are already accounted for by the font.
style = style & (~getFontDesc().getStyle());
F32 drop_shadow_strength = 0.f;
if (shadow != NO_SHADOW)
{
F32 luminance;
color.calcHSL(NULL, NULL, &luminance);
drop_shadow_strength = clamp_rescale(luminance, 0.35f, 0.6f, 0.f, 1.f);
if (luminance < 0.35f)
{
shadow = NO_SHADOW;
}
}
gGL.pushUIMatrix();
gGL.loadUIIdentity();
LLVector2 origin(floorf(sCurOrigin.mX*sScaleX), floorf(sCurOrigin.mY*sScaleY));
// Depth translation, so that floating text appears 'in-world'
// and is correctly occluded.
gGL.translatef(0.f,0.f,sCurDepth);
S32 chars_drawn = 0;
S32 i;
S32 length = max_index - begin_offset;
F32 cur_x, cur_y, cur_render_x, cur_render_y;
// Not guaranteed to be set correctly
gGL.setSceneBlendType(LLRender::BT_ALPHA);
cur_x = ((F32)x * sScaleX) + origin.mV[VX];
cur_y = ((F32)y * sScaleY) + origin.mV[VY];
// Offset y by vertical alignment.
// use unscaled font metrics here
switch (valign)
{
case TOP:
cur_y -= llceil(mFontFreetype->getAscenderHeight());
break;
case BOTTOM:
cur_y += llceil(mFontFreetype->getDescenderHeight());
break;
case VCENTER:
cur_y -= llceil((llceil(mFontFreetype->getAscenderHeight()) - llceil(mFontFreetype->getDescenderHeight())) / 2.f);
break;
case BASELINE:
// Baseline, do nothing.
break;
default:
break;
}
switch (halign)
{
case LEFT:
break;
case RIGHT:
cur_x -= llmin(scaled_max_pixels, ll_round(getWidthF32(wstr.c_str(), begin_offset, length) * sScaleX));
break;
case HCENTER:
cur_x -= llmin(scaled_max_pixels, ll_round(getWidthF32(wstr.c_str(), begin_offset, length) * sScaleX)) / 2;
break;
default:
break;
}
cur_render_y = cur_y;
cur_render_x = cur_x;
//.........这里部分代码省略.........
示例9: render
S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, const LLColor4 &color, HAlign halign, VAlign valign, U8 style,
ShadowType shadow, S32 max_chars, S32 max_pixels, F32* right_x, BOOL use_ellipses) const
{
LLFastTimer _(FTM_RENDER_FONTS);
if(!sDisplayFont) //do not display texts
{
return wstr.length() ;
}
if (wstr.empty())
{
return 0;
}
gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
S32 scaled_max_pixels = max_pixels == S32_MAX ? S32_MAX : llceil((F32)max_pixels * sScaleX);
// determine which style flags need to be added programmatically by stripping off the
// style bits that are drawn by the underlying Freetype font
U8 style_to_add = (style | mFontDescriptor.getStyle()) & ~mFontFreetype->getStyle();
F32 drop_shadow_strength = 0.f;
if (shadow != NO_SHADOW)
{
F32 luminance;
color.calcHSL(NULL, NULL, &luminance);
drop_shadow_strength = clamp_rescale(luminance, 0.35f, 0.6f, 0.f, 1.f);
if (luminance < 0.35f)
{
shadow = NO_SHADOW;
}
}
gGL.pushUIMatrix();
gGL.loadUIIdentity();
//gGL.translateUI(floorf(sCurOrigin.mX*sScaleX), floorf(sCurOrigin.mY*sScaleY), sCurOrigin.mZ);
// this code snaps the text origin to a pixel grid to start with
//F32 pixel_offset_x = llround((F32)sCurOrigin.mX) - (sCurOrigin.mX);
//F32 pixel_offset_y = llround((F32)sCurOrigin.mY) - (sCurOrigin.mY);
//gGL.translateUI(-pixel_offset_x, -pixel_offset_y, 0.f);
LLVector2 origin(floorf(sCurOrigin.mX*sScaleX), floorf(sCurOrigin.mY*sScaleY));
// snap the text origin to a pixel grid to start with
origin.mV[VX] -= llround((F32)sCurOrigin.mX) - (sCurOrigin.mX);
origin.mV[VY] -= llround((F32)sCurOrigin.mY) - (sCurOrigin.mY);
S32 chars_drawn = 0;
S32 i;
S32 length;
if (-1 == max_chars)
{
length = (S32)wstr.length() - begin_offset;
}
else
{
length = llmin((S32)wstr.length() - begin_offset, max_chars );
}
F32 cur_x, cur_y, cur_render_x, cur_render_y;
// Not guaranteed to be set correctly
gGL.setSceneBlendType(LLRender::BT_ALPHA);
cur_x = ((F32)x * sScaleX) + origin.mV[VX];
cur_y = ((F32)y * sScaleY) + origin.mV[VY];
// Offset y by vertical alignment.
switch (valign)
{
case TOP:
cur_y -= mFontFreetype->getAscenderHeight();
break;
case BOTTOM:
cur_y += mFontFreetype->getDescenderHeight();
break;
case VCENTER:
cur_y -= (mFontFreetype->getAscenderHeight() - mFontFreetype->getDescenderHeight()) / 2.f;
break;
case BASELINE:
// Baseline, do nothing.
break;
default:
break;
}
switch (halign)
{
case LEFT:
break;
case RIGHT:
cur_x -= llmin(scaled_max_pixels, llround(getWidthF32(wstr.c_str(), begin_offset, length) * sScaleX));
break;
case HCENTER:
//.........这里部分代码省略.........
示例10: render
//.........这里部分代码省略.........
mImageGLp->bind(0);
// Not guaranteed to be set correctly
gGL.setSceneBlendType(LLRender::BT_ALPHA);
cur_x = ((F32)x * sScaleX);
cur_y = ((F32)y * sScaleY);
// Offset y by vertical alignment.
switch (valign)
{
case TOP:
cur_y -= mAscender;
break;
case BOTTOM:
cur_y += mDescender;
break;
case VCENTER:
cur_y -= ((mAscender - mDescender)/2.f);
break;
case BASELINE:
// Baseline, do nothing.
break;
default:
break;
}
switch (halign)
{
case LEFT:
break;
case RIGHT:
cur_x -= llmin(scaled_max_pixels, llround(getWidthF32(wstr.c_str(), 0, length) * sScaleX));
break;
case HCENTER:
cur_x -= llmin(scaled_max_pixels, llround(getWidthF32(wstr.c_str(), 0, length) * sScaleX)) / 2;
break;
default:
break;
}
// Round properly.
//cur_render_y = (F32)llfloor(cur_y/sScaleY + 0.5f)*sScaleY;
//cur_render_x = (F32)llfloor(cur_x/sScaleX + 0.5f)*sScaleX;
cur_render_y = cur_y;
cur_render_x = cur_x;
F32 start_x = cur_x;
F32 inv_width = 1.f / mImageGLp->getWidth();
F32 inv_height = 1.f / mImageGLp->getHeight();
const S32 LAST_CHARACTER = LLFont::LAST_CHAR_FULL;
BOOL draw_ellipses = FALSE;
if (use_ellipses && halign == LEFT)
{
// check for too long of a string
if (getWidthF32(wstr.c_str(), 0, max_chars) * sScaleX > scaled_max_pixels)
{
// use four dots for ellipsis width to generate padding
const LLWString dots(utf8str_to_wstring(std::string("....")));
scaled_max_pixels = llmax(0, scaled_max_pixels - llround(getWidthF32(dots.c_str())));