Пример #1
0
float
ETextEditable::_StringWidth(const EFont &font, const char *str) const
{
	if(fTypingHidden == 0x01 || str == NULL || *str == 0) return 0;
	if(fTypingHidden == 0x00) return font.StringWidth(str);

	EString aStr;
	aStr.Append(*((char*)&fTypingHidden), e_utf8_strlen(str));
	return font.StringWidth(aStr);
}
Пример #2
0
float*
ETextEditable::_CharWidths(const EFont &font, const char *str, eint32 *count) const
{
	if(fTypingHidden == 0x01 || str == NULL || *str == 0) return NULL;
	if(fTypingHidden == 0x00) return font.CharWidths(str, count);

	EString aStr;
	aStr.Append(*((char*)&fTypingHidden), e_utf8_strlen(str));
	return font.CharWidths(aStr.String(), count);
}
Пример #3
0
void
ETextEditable::_DrawString(const char *str, EPoint location)
{
	if(fTypingHidden == 0x01 || str == NULL || *str == 0) return;

	if(fTypingHidden == 0x00)
	{
		DrawString(str, location);
	}
	else
	{
		EString aStr;
		aStr.Append(*((char*)&fTypingHidden), e_utf8_strlen(str));
		DrawString(aStr.String(), location);
	}
}
Пример #4
0
bool
ETextEditable::GetCharLocation(eint32 pos, float *x, float *y, EFont *tFont)
{
	if(!x) return false;

	ERect rect = Frame().OffsetToSelf(E_ORIGIN);
	rect.left += fMargins.left;
	rect.top += fMargins.top;
	rect.right -= fMargins.right;
	rect.bottom -= fMargins.bottom;

	rect.InsetBy(2, 2);

	if(!rect.IsValid()) return false;

	EFont font;
	e_font_height fontHeight;

	if(tFont) font = *tFont;
	else GetFont(&font);
	font.GetHeight(&fontHeight);
	float sHeight = fontHeight.ascent + fontHeight.descent;
	float strWidth = (fCount <= 0 ? 0.f : max_c(0.f, _StringWidth(font, fText)));
	float fontSpacing = (float)ceil((double)font.Spacing() * font.Size());

	if(fAlignment == E_ALIGN_RIGHT) *x = rect.right - strWidth;
	else if(fAlignment == E_ALIGN_CENTER) *x = rect.Center().x - strWidth / 2.f;
	else *x = rect.left; /* E_ALIGN_LEFT */
	if(y) *y = (rect.Center().y - sHeight/ 2.f + fontHeight.ascent + 1);

	if(strWidth <= rect.Width() || !IsEnabled() ||
	   !(IsEditable() || (IsSelectable() && IsSelected())) ||
	   fPosition < 0 || fPosition > fCount)
	{
		locationOffset = 0;
	}
	else
	{
		float xx = *x + locationOffset;

		if(fPosition > 0 && fPosition < fCount)
		{
			const char *p = e_utf8_at((const char*)fText, fPosition, NULL);
			if(p != NULL)
			{
				EString str;
				str.Append(fText, (eint32)(p - (const char*)fText));
				xx += _StringWidth(font, str.String()) + fontSpacing;
			}
		}
		else if(fPosition == fCount)
		{
			xx += strWidth + fontSpacing;
		}

		if(xx < rect.left)
			locationOffset += (rect.left - xx);
		else if(xx > rect.right)
			locationOffset += (rect.right - xx);
	}

	*x += locationOffset;

	if(pos > 0 && pos < fCount)
	{
		const char *p = e_utf8_at((const char*)fText, pos, NULL);
		if(p != NULL)
		{
			EString str;
			str.Append(fText, (eint32)(p - (const char*)fText));
			*x += _StringWidth(font, str.String()) + fontSpacing;
		}
	}
	else if(pos < 0 || pos >= fCount)
	{
		*x += strWidth + fontSpacing;
	}

	return true;
}