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


C++ TextWidth函数代码示例

本文整理汇总了C++中TextWidth函数的典型用法代码示例。如果您正苦于以下问题:C++ TextWidth函数的具体用法?C++ TextWidth怎么用?C++ TextWidth使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ItemWidth

		intptr_t ItemWidth(const T &Item)
		{
			switch(Item.Type)
			{
			case DI_TEXT:
				return TextWidth(Item);

			case DI_CHECKBOX:
			case DI_RADIOBUTTON:
			case DI_BUTTON:
				return TextWidth(Item) + 4;

			case DI_EDIT:
			case DI_FIXEDIT:
			case DI_COMBOBOX:
			case DI_LISTBOX:
			case DI_PSWEDIT:
				{
					intptr_t Width = Item.X2 - Item.X1 + 1;
					// стрелка history занимает дополнительное место, но раньше она рисовалась поверх рамки???
					if (Item.Flags & DIF_HISTORY)
						Width++;
					return Width;
				}
				break;

			default:
				break;
			}
			return 0;
		}
开发者ID:brucewu16899,项目名称:cmder-1,代码行数:31,代码来源:DlgBuilder.hpp

示例2: TextWidth

//Create a string of text that will fit in the width provided by SetArea.  SetArea
//must be called before this, or an error will occur.
void ShortenenedText::CreateFittedText(std::string text)
{
	fulltext_.CreateTextureFromText(text);

	int textwidth = TextWidth(text);

	std::string showtext;
	if (textwidth > maxtextwidth_)
	{
		double proportiontoshow = static_cast<double>(maxtextwidth_) / static_cast<double>(textwidth);
		showtext = text.substr(0, static_cast<int>(text.length() * proportiontoshow));
		if (showtext.length() >= 3)
		{
			showtext = showtext.substr(0, showtext.length() - 3);
			showtext = showtext + "...";
		}

		CreateTextureFromText(showtext);
		isshortened_ = true;
	}
	else
	{
		showtext = text;
		CreateTextureFromText(showtext);		
	}

	SDL_Rect currentmousearea = mousefunction_->GetMouseArea();
	mousefunction_->SetMouseArea(SDL_Rect{ currentmousearea.x, currentmousearea.y, TextWidth(showtext), TextHeight() });
}
开发者ID:KGrJacobson,项目名称:Captioning,代码行数:31,代码来源:ShortenedText.cpp

示例3: while

unsigned short Font::FitText( const char *str, unsigned short width,
                              bool word ) const {
  int lastspace = 0, pos = 0;
  string line;

  do {
    if ( (str[pos] == ' ') || (str[pos] == '\n') || (str[pos] == '\0') ) {
      if ( TextWidth( line.c_str() ) > width ) {
        // go back to last space
        line.erase( lastspace );
        pos = lastspace;

        if ( lastspace != 0 && word ) return pos + 1;
        else {
          // add single characters until we hit the wall
          do {
            line += str[pos++];
          } while ( TextWidth( line.c_str() ) <= width );
          return pos - 1;
        }
      }

      if ( (str[pos] == '\n') || (str[pos] == '\0') ) return pos + 1;
      lastspace = pos;
      line += str[pos];
    }

    else line += str[pos];

  } while ( str[pos++] != '\0' );

  return pos;
}
开发者ID:drodin,项目名称:Crimson,代码行数:33,代码来源:font.cpp

示例4: fitwidth

// adjust the font to fit within a width
void fitwidth(int width, int adj, char *s, FW * f) {
	f->tw = TextWidth(s, f->fontsize);
	while (f->tw > width) {
		f->fontsize -= adj;
		f->tw = TextWidth(s, f->fontsize);
	}
}
开发者ID:chengjianwen,项目名称:openvg,代码行数:8,代码来源:shapedemo.c

示例5: TextHeight

/*--------------------------------------------------------------------------*/
void PegChart::RecalcLayout(BOOL bRedraw /*=TRUE*/)
{
    mChartRegion = mClient;
    
    if(mwExStyle & CS_DRAWXTICS)
    {
        mChartRegion.wBottom -= mwMajorTicSize;
    }

    if(mwExStyle & CS_DRAWYTICS)
    {
        mChartRegion.wLeft += mwMajorTicSize;

		if(mwExStyle & CS_DUALYTICS)
		{
			mChartRegion.wRight -= mwMajorTicSize;
		}
    }

    if (mwExStyle & CS_DRAWYLABELS)
    {
		SIGNED iSkipHeight = TextHeight(lsTEST, mpFont);
		iSkipHeight++;
		iSkipHeight >>= 1;
		mChartRegion.wTop += iSkipHeight;

		if(!(mwExStyle & CS_DRAWXLABELS))
		{
			mChartRegion.wBottom -= iSkipHeight;
		}
        
        if(mwYLabelWidth == 0)
		{
			PEGCHAR cBuffer[20];
			_ltoa(mlMinY, cBuffer, 10);
			SIGNED iMinWidth = TextWidth(cBuffer, mpFont);
			//_ltoa(mlMinY,cBuffer,10);
			_ltoa(mlMaxY, cBuffer, 10);
			SIGNED iMaxWidth = TextWidth(cBuffer, mpFont);
			/*_ltoa(mlMinY,cBuffer,10);*/
			/*_ltoa(mlMaxY,cBuffer,10);*/
			mChartRegion.wLeft += 
                iMinWidth > iMaxWidth ? iMinWidth : iMaxWidth;
            mChartRegion.wLeft += 2;

            if(mwExStyle & CS_DUALYLABELS)
            {
                mChartRegion.wRight -= 
                    iMinWidth > iMaxWidth ? iMinWidth : iMaxWidth;
                mChartRegion.wRight -= 2;
            }
		}
		else
		{
			mChartRegion.wLeft += mwYLabelWidth;
		}
    }
开发者ID:garyqinyu,项目名称:abv,代码行数:58,代码来源:pchart.cpp

示例6: GetLineStart

/*--------------------------------------------------------------------------*/
void PegTextBox::DrawTextLine(SIGNED iLine, PegPoint Put, BOOL bFill)
{
    SIGNED iLineLength;
    PegRect FillRect;
    PEGCHAR *pGet = GetLineStart(iLine, &iLineLength);
    PegColor Color(muColors[PCI_NTEXT], muColors[PCI_NORMAL], CF_FILL);

    CheckBufLen(iLineLength);

    if (iLine == miMarkLine)
    {
        Color.Set(muColors[PCI_STEXT], muColors[PCI_SELECTED], CF_FILL);
        bFill = TRUE;
    }
    if (bFill)
    {
        FillRect.Set(mClient.wLeft + TB_WHITESPACE, Put.y, mClient.wRight - TB_WHITESPACE,
            Put.y + miLineHeight - 1);
        Rectangle(FillRect, Color, 0);
    }

    if (!pGet)
    {
        return;
    }

    Color.uFlags = CF_NONE;

    if (iLineLength > 0)
    {
        strncpy(mpBuf, pGet, iLineLength);
        mpBuf[iLineLength] = '\0';

        switch(Style() & TJ_MASK)
        {
        case TJ_RIGHT:
            iLineLength = TextWidth(mpBuf, mpFont);
            Put.x = mClient.wRight - iLineLength - TB_WHITESPACE;
            break;

        case TJ_CENTER:
            iLineLength = TextWidth(mpBuf, mpFont);
            Put.x = (mClient.Width() - iLineLength) / 2;
            Put.x += mClient.wLeft;
            break;

        case TJ_LEFT:
        default:
            break;
        }
        DrawText(Put, mpBuf, Color, mpFont, -1);
    }
}
开发者ID:garyqinyu,项目名称:abv,代码行数:54,代码来源:ptextbox.cpp

示例7: SetMarginType

void SvnBlameEditor::Initialize()
{
    // Initialize some styles
    SetMarginType (0, wxSTC_MARGIN_TEXT  );
    SetMarginType (1, wxSTC_MARGIN_NUMBER);
    SetMarginWidth(1, 4 + 5*TextWidth(wxSTC_STYLE_LINENUMBER, wxT("9")));
    SetMarginWidth(2, 0);
    SetMarginWidth(3, 0);
    SetMarginWidth(4, 0);
    SetTabWidth(4);
    
    // Define some colors to use
    StyleSetBackground(MARGIN_STYLE_START + 1,  DrawingUtils::LightColour(wxT("GREEN"),      7.0));
    StyleSetBackground(MARGIN_STYLE_START + 2,  DrawingUtils::LightColour(wxT("BLUE"),       7.0));
    StyleSetBackground(MARGIN_STYLE_START + 3,  DrawingUtils::LightColour(wxT("ORANGE"),     7.0));
    StyleSetBackground(MARGIN_STYLE_START + 4,  DrawingUtils::LightColour(wxT("YELLOW"),     7.0));
    StyleSetBackground(MARGIN_STYLE_START + 5,  DrawingUtils::LightColour(wxT("PURPLE"),     7.0));
    StyleSetBackground(MARGIN_STYLE_START + 6,  DrawingUtils::LightColour(wxT("RED"),        7.0));
    StyleSetBackground(MARGIN_STYLE_START + 7,  DrawingUtils::LightColour(wxT("BROWN"),      7.0));
    StyleSetBackground(MARGIN_STYLE_START + 8,  DrawingUtils::LightColour(wxT("LIGHT GREY"), 7.0));
    StyleSetBackground(MARGIN_STYLE_START + 9,  DrawingUtils::LightColour(wxT("SIENNA"),     7.0));

    StyleSetBackground(MARGIN_STYLE_START + 10, wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
    StyleSetForeground(MARGIN_STYLE_START + 10, wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
}
开发者ID:292388900,项目名称:codelite,代码行数:25,代码来源:svnblameeditor.cpp

示例8: PegButton

/*--------------------------------------------------------------------------*/
PegRadioButton::PegRadioButton(SIGNED iLeft, SIGNED iTop,
     const PEGCHAR *Text, WORD wId, WORD wStyle) :
     PegButton(wId, wStyle),
     PegTextThing(Text, wStyle & TT_COPY, PEG_RBUTTON_FONT)
{
    Type(TYPE_RADIOBUTTON);

    SetSignals(SIGMASK(PSF_DOT_ON));

    mReal.wLeft = iLeft;
    mReal.wTop = iTop;

    SIGNED iHeight = TextHeight(lsTEST, mpFont);
    if (gbRadioOnBitmap.wHeight > iHeight)
    {
        iHeight = gbRadioOnBitmap.wHeight;
    }
    iHeight += 4;

    if (Text)
    {
        mReal.wRight = mReal.wLeft + TextWidth(Text, mpFont) + 2;
        mReal.wRight += gbRadioOnBitmap.wWidth + RBUTTON_SPACING;
        mReal.wBottom = mReal.wTop + iHeight;
    }
    else
    {
        mReal.wRight = mReal.wLeft + 3;
        mReal.wBottom = mReal.wTop + iHeight;
    }
    mClient = mReal;
}
开发者ID:garyqinyu,项目名称:abv,代码行数:33,代码来源:pbutton.cpp

示例9: ShowAllKeys

static void ShowAllKeys(int index, int change)
{
	int x1, x2, y1, y2;
	
	x1 = CenterX((TextCharWidth('a') * 10)) / 2;
	x2 = x1 * 3;
	
	y1 = (SCREEN_HEIGHT / 2) - (TextHeight() * 10);
	y2 = (SCREEN_HEIGHT / 2) - (TextHeight() * 2);
	
	DisplayKeys(x1, x2, y1, "Player One", &gPlayer1Data, index, change);
	DisplayKeys(x1, x2, y2, "Player Two", &gPlayer2Data, index - 6, change - 6);
	
	y2 += TextHeight() * 8;
	
	TextStringAt(x1, y2, "Map");
	
	if (change == 12)
		DisplayMenuItem(x2, y2, SELECTKEY, index == 12);
	else
		DisplayMenuItem(x2, y2, SDL_GetKeyName(gOptions.mapKey), index == 12);
	
#define DONE	"Done"
	
	y2 += TextHeight () * 2;
	
	DisplayMenuItem(CenterX(TextWidth(DONE)), y2, DONE, index == 13);
}
开发者ID:insin,项目名称:cdogs-wii,代码行数:28,代码来源:mainmenu.c

示例10: ClearAll

/* TextEditor::loadEntry
 * Reads the contents of [entry] into the text area, returns false
 * if the given entry is invalid
 *******************************************************************/
bool TextEditor::loadEntry(ArchiveEntry* entry)
{
	// Clear current text
	ClearAll();

	// Check that the entry exists
	if (!entry)
	{
		Global::error = "Invalid archive entry given";
		return false;
	}

	// Check that the entry has any data, if not do nothing
	if (entry->getSize() == 0 || !entry->getData())
		return true;

	// Get character entry data
	//string text = wxString::From8BitData((const char*)entry->getData(), entry->getSize());
	string text = wxString::FromUTF8((const char*)entry->getData(), entry->getSize());
	// If opening as UTF8 failed for some reason, try again as 8-bit data
	if (text.length() == 0)
		text = wxString::From8BitData((const char*)entry->getData(), entry->getSize());

	// Load text into editor
	SetText(text);

	// Update line numbers margin width
	string numlines = S_FMT("0%d", GetNumberOfLines());
	SetMarginWidth(0, TextWidth(wxSTC_STYLE_LINENUMBER, numlines));

	return true;
}
开发者ID:macressler,项目名称:SLADE,代码行数:36,代码来源:TextEditor.cpp

示例11: SetMarginWidth

void IWnd_stc::UpdateMarginLineNumWidth(bool flag)
{
	BitFlags &flags(param.flags);

	if(!flags.get(FLAG_LINENUM))
	{
		if(m_nLineNumWidth==0)
		{
			return;
		}
		m_nLineNumWidth=0;
		SetMarginWidth(StcManager::LINE_NR_ID,0);
	}
	else
	{

		int _nWidth=3+(int)::log10(double(GetLineCount()));
		if(_nWidth<4) _nWidth=4;
		if(_nWidth>7) _nWidth=7;

		if(_nWidth==m_nLineNumWidth && !flag)
		{
			return;
		}
		m_nLineNumWidth=_nWidth;

		static const char* text="999999999999999";
		int wd=TextWidth (wxSTC_STYLE_LINENUMBER, wxString(text,m_nLineNumWidth));
		SetMarginWidth(StcManager::LINE_NR_ID,wd);
	}

}
开发者ID:xuanya4202,项目名称:ew_base,代码行数:32,代码来源:iwnd_stc.cpp

示例12: strlen

/////////////////////////////////////////////////////////////
//
// DrawString
//
void
nsPluginInstance::DrawString(const unsigned char* text, 
                             short width, 
                             short height, 
                             short centerX, 
                             Rect drawRect)
{
	short length, textHeight, textWidth;
 
	if(text == NULL)
		return;
	
	length = strlen((char*)text);
	TextFont(1);
	TextFace(bold);
	TextMode(srcCopy);
	TextSize(12);
	
	FontInfo fontInfo;
	GetFontInfo(&fontInfo);

	textHeight = fontInfo.ascent + fontInfo.descent + fontInfo.leading;
	textWidth = TextWidth(text, 0, length);
		
	if (width > textWidth && height > textHeight)
	{
		MoveTo(centerX - (textWidth >> 1), height >> 1);
		DrawText(text, 0, length);
	}		
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:33,代码来源:plugin.cpp

示例13: strlen

/*
mVerticalPix - is height relative to bottom of the control.
*/
char* MarqueeView::draw_one_line( char* mtext, int mVerticalPix )
{
	int strLength = strlen(mtext);
	char* pos = strchr(mtext, '\n');
	int len = (pos-mtext);
	
	int length = get_num_chars_fit( mtext, right_margin-left_margin );		
	if ((pos>0) && (len<length))
		length = len;
//	printf("MarqueeView::draw_one_line width=%d num_chars=%d nl=%d\n", (right_margin-left_margin),
//					 length, pos);

	char tmp = mtext[length];
	mtext[length] = 0;

	if (style & CENTER_HORIZONTAL)
	{
		VGfloat font_width = TextWidth( mtext, *font, text_size );
		int space = (width-(font_width))/2;		
		Text(left+space, bottom+mVerticalPix, mtext, *font, text_size );
	} else {
		Text(left_margin, bottom+mVerticalPix, mtext, *font, text_size );
	}
	mtext[length] = tmp;	
	
	if (length==strLength)
		return NULL;			// Done drawing string.
	return &(mtext[length]);
}
开发者ID:stenniswood,项目名称:bk_code,代码行数:32,代码来源:marquee.cpp

示例14: do_redisplay

/* Here is where all redrawing will take place for your program. 
 * When the window needs to be redrawn, this function will be called.
 * When your program starts up for the first time, this function will 
 * be called and you should draw anything you need to draw in here.
 */
void do_redisplay(MyProgram *me, int width, int height) 
{
  int i;
  char *str = "My Cool Program";

  if (me->in_color_mode)
   {
     do_colorstuff();
     return;
   }

  SetBgColor(me->draw_widget, WHITE);
  ClearDrawArea();       /* start with a clean slate */

  SetColor(BLACK);
  SetBgColor(me->draw_widget, GREEN);
  DrawText(str, (width-TextWidth(me->draw_font, str))/2, height/2); 

  SetBgColor(me->draw_widget, WHITE);
  SetColor(me->col1);
  for(i=0; i < width; i+=5)
     DrawLine(0,i, i,height);

  SetColor(me->col2);
  for(i=0; i < width; i+=5)
     DrawLine(width,i, width-i,height);
}
开发者ID:dervish77,项目名称:adgf,代码行数:32,代码来源:main.c

示例15: ShowPlayerControls

static void ShowPlayerControls(int x, struct PlayerData *data)
{
	char s[256];
	int y;

	y = SCREEN_HEIGHT - (SCREEN_HEIGHT / 6);

	if (data->controls == JOYSTICK_ONE)
		TextStringAt(x, y, "(joystick one)");
	else if (data->controls == JOYSTICK_TWO)
		TextStringAt(x, y, "(joystick two)");
	else {
		sprintf(s, "(%s, %s, %s, %s, %s and %s)",
			SDL_GetKeyName(data->keys[0]),
			SDL_GetKeyName(data->keys[1]),
			SDL_GetKeyName(data->keys[2]),
			SDL_GetKeyName(data->keys[3]),
			SDL_GetKeyName(data->keys[4]),
			SDL_GetKeyName(data->keys[5]));
		if (TextWidth(s) < 125)
			TextStringAt(x, y, s);
		else {
			sprintf(s, "(%s, %s, %s,",
				SDL_GetKeyName(data->keys[0]),
				SDL_GetKeyName(data->keys[1]),
				SDL_GetKeyName(data->keys[2]));
			TextStringAt(x, y - 10, s);
			sprintf(s, "%s, %s and %s)",
				SDL_GetKeyName(data->keys[3]),
				SDL_GetKeyName(data->keys[4]),
				SDL_GetKeyName(data->keys[5]));
			TextStringAt(x, y, s);
		}
	}
}
开发者ID:devmabbott,项目名称:cdogs-sdl,代码行数:35,代码来源:prep.c


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