示例#1
0
文件: cbuttons.cpp 项目: DaniM/lyngo
//------------------------------------------------------------------------
bool CCheckBox::sizeToFit ()
{
	if (title == 0)
		return false;
	IFontPainter* painter = font ? font->getFontPainter () : 0;
	if (painter)
	{
		CRect fitSize (getViewSize ());
		if (getDrawBackground ())
		{
			fitSize.setWidth (getDrawBackground ()->getWidth ());
			fitSize.setHeight (getDrawBackground ()->getHeight () / 6);
		}
		else
		{
			fitSize.setWidth (fitSize.getHeight ());
		}
		fitSize.right += kCheckBoxTitleMargin;
		fitSize.right += painter->getStringWidth (0, title, true);
		setViewSize (fitSize);
		setMouseableArea (fitSize);
		return true;
	}
	return false;
}
示例#2
0
文件: ctextlabel.cpp 项目: EQ4/vstgui
//------------------------------------------------------------------------
void CTextLabel::calculateTruncatedText ()
{
	truncatedText = "";
	if (textRotation != 0.) // currently truncation is only supported when not rotated
		return;
	std::string _truncatedText;
	if (!(textTruncateMode == kTruncateNone || text.getByteCount () == 0 || fontID == 0 || fontID->getPlatformFont () == 0 || fontID->getPlatformFont ()->getPainter () == 0))
	{
		IFontPainter* painter = fontID->getPlatformFont ()->getPainter ();
		CCoord width = painter->getStringWidth (0, text.getPlatformString (), true);
		width += textInset.x * 2;
		if (width > getWidth ())
		{
			if (textTruncateMode == kTruncateTail)
			{
				_truncatedText = text;
				_truncatedText += "..";
				while (width > getWidth () && _truncatedText.size () > 2)
				{
					UTF8CharacterIterator it (_truncatedText);
					it.end ();
					for (int32_t i = 0; i < 3; i++, --it)
					{
						if (it == it.front ())
						{
							break;
						}
					}
					_truncatedText.erase (_truncatedText.size () - (2 + it.getByteLength ()), it.getByteLength ());
					width = painter->getStringWidth (0, CString (_truncatedText.c_str ()).getPlatformString (), true);
					width += textInset.x * 2;
				}
			}
			else if (textTruncateMode == kTruncateHead)
			{
				_truncatedText = "..";
				_truncatedText += text;
				while (width > getWidth () && _truncatedText.size () > 2)
				{
					UTF8CharacterIterator it (_truncatedText);
					for (int32_t i = 0; i < 2; i++, ++it)
					{
						if (it == it.back ())
						{
							break;
						}
					}
					_truncatedText.erase (2, it.getByteLength ());
					width = painter->getStringWidth (0, CString (_truncatedText.c_str ()).getPlatformString (), true);
					width += textInset.x * 2;
				}
			}
		}
	}
	if (truncatedText != _truncatedText)
	{
		truncatedText = _truncatedText.c_str ();
		changed (kMsgTruncatedTextChanged);
	}
}
示例#3
0
//------------------------------------------------------------------------
void CDrawContext::drawString (IPlatformString* string, const CRect& _rect, const CHoriTxtAlign hAlign, bool antialias)
{
	if (!string || currentState.font == 0)
		return;
	IFontPainter* painter = currentState.font->getFontPainter ();
	if (painter == 0)
		return;
	
	CRect rect (_rect);
	
	double capHeight = -1;
	IPlatformFont* platformFont = currentState.font->getPlatformFont ();
	if (platformFont)
		capHeight = platformFont->getCapHeight ();
	
	if (capHeight > 0.)
		rect.bottom -= (rect.getHeight () / 2. - capHeight / 2.);
	else
		rect.bottom -= (rect.getHeight () / 2. - currentState.font->getSize () / 2.) + 1.;
	if (hAlign != kLeftText)
	{
		CCoord stringWidth = painter->getStringWidth (this, string, antialias);
		if (hAlign == kRightText)
			rect.left = rect.right - stringWidth;
		else
			rect.left = rect.left + (rect.getWidth () / 2.) - (stringWidth / 2.);
	}

	painter->drawString (this, string, CPoint (rect.left, rect.bottom), antialias);
}
示例#4
0
//------------------------------------------------------------------------
void CDrawContext::drawString (IPlatformString* string, const CPoint& point, bool antialias)
{
	if (string == 0 || currentState.font == 0)
		return;
	
	IFontPainter* painter = currentState.font->getFontPainter ();
	if (painter)
		painter->drawString (this, string, point, antialias);
}
示例#5
0
//------------------------------------------------------------------------
void CTextLabel::calculateTruncatedText ()
{
	std::string tmp (truncatedText);
	truncatedText.clear ();
	if (!(textTruncateMode == kTruncateNone || text == 0 || text[0] == 0 || fontID == 0 || fontID->getPlatformFont () == 0 || fontID->getPlatformFont ()->getPainter () == 0))
	{
		IFontPainter* painter = fontID->getPlatformFont ()->getPainter ();
		CCoord width = painter->getStringWidth (0, text, true);
		width += textInset.x * 2;
		if (width > getWidth ())
		{
			if (textTruncateMode == kTruncateTail)
			{
				truncatedText = text;
				truncatedText += "..";
				while (width > getWidth () && truncatedText.size () > 2)
				{
					UTF8CharacterIterator it (truncatedText);
					it.end ();
					for (int32_t i = 0; i < 3; i++, --it)
					{
						if (it == it.front ())
						{
							break;
						}
					}
					truncatedText.erase (truncatedText.size () - (2 + it.getByteLength ()), it.getByteLength ());
					width = painter->getStringWidth (0, truncatedText.c_str (), true);
					width += textInset.x * 2;
				}
			}
			else if (textTruncateMode == kTruncateHead)
			{
				truncatedText = "..";
				truncatedText += text;
				while (width > getWidth () && truncatedText.size () > 2)
				{
					UTF8CharacterIterator it (truncatedText);
					for (int32_t i = 0; i < 2; i++, ++it)
					{
						if (it == it.back ())
						{
							break;
						}
					}
					truncatedText.erase (2, it.getByteLength ());
					width = painter->getStringWidth (0, truncatedText.c_str (), true);
					width += textInset.x * 2;
				}
			}
		}
	}
	if (tmp != truncatedText)
		changed (kMsgTruncatedTextChanged);
}
示例#6
0
//-----------------------------------------------------------------------------
void CDrawContext::drawString (UTF8StringPtr string, const CPoint& point, bool antialias)
{
	if (string == 0 || currentState.font == 0)
		return;

	IFontPainter* painter = currentState.font->getFontPainter ();
	if (painter)
	{
		painter->drawString (this, getDrawString (string), point, antialias);
		clearDrawString ();
	}
}
示例#7
0
//------------------------------------------------------------------------
CCoord CDrawContext::getStringWidth (IPlatformString* string)
{
	CCoord result = -1;
	if (currentState.font == 0 || string == 0)
		return result;
	
	IFontPainter* painter = currentState.font->getFontPainter ();
	if (painter)
	{
		result = painter->getStringWidth (this, string, true);
	}
	
	return result;
}
示例#8
0
//-----------------------------------------------------------------------------
CCoord CDrawContext::getStringWidth (UTF8StringPtr string)
{
	CCoord result = -1;
	if (currentState.font == 0 || string == 0)
		return result;

	IFontPainter* painter = currentState.font->getFontPainter ();
	if (painter)
	{
		result = painter->getStringWidth (this, getDrawString (string), true);
		clearDrawString ();
	}

	return result;
}
示例#9
0
文件: cbuttons.cpp 项目: DaniM/lyngo
//------------------------------------------------------------------------
bool CTextButton::sizeToFit ()
{
	if (title.empty ())
		return false;
	IFontPainter* painter = font ? font->getFontPainter () : 0;
	if (painter)
	{
		CRect fitSize (getViewSize ());
		fitSize.right = fitSize.left + (roundRadius + 1.) * 4.;
		fitSize.right += painter->getStringWidth (0, title.c_str (), true);
		setViewSize (fitSize);
		setMouseableArea (fitSize);
		return true;
	}
	return false;
}
示例#10
0
//-----------------------------------------------------------------------------
void CDrawContext::drawString (UTF8StringPtr _string, const CRect& _rect, const CHoriTxtAlign hAlign, bool antialias)
{
	if (!_string || currentState.font == 0)
		return;
	IFontPainter* painter = currentState.font->getFontPainter ();
	if (painter == 0)
		return;
	
	const CString& string = getDrawString (_string);
	CRect rect (_rect);

	double capHeight = -1;
	IPlatformFont* platformFont = currentState.font->getPlatformFont ();
	if (platformFont)
		capHeight = platformFont->getCapHeight ();
	
	if (capHeight > 0.)
		rect.bottom -= (rect.height ()/2 - capHeight / 2);
	else
		rect.bottom -= (rect.height ()/2 - currentState.font->getSize () / 2) + 1;
	if (hAlign != kLeftText)
	{
		CCoord stringWidth = painter->getStringWidth (this, string, antialias);
		if (hAlign == kRightText)
			rect.left = rect.right - stringWidth;
		else
			rect.left = (CCoord)(rect.left + (rect.getWidth () / 2.f) - (stringWidth / 2.f));
	}
	CRect oldClip;
	getClipRect (oldClip);
	CRect newClip (_rect);
	newClip.bound (oldClip);
	setClipRect (newClip);
	painter->drawString (this, string, CPoint (rect.left, rect.bottom), antialias);
	setClipRect (oldClip);
	clearDrawString ();
}