Esempio n. 1
0
Counter::Counter(
	const Font& font,
	float textSize,
	GUISizeUnit sizeUnit,
	unsigned int maxDigits,
	unsigned int decimals,
	char fillChar)
	: m_dotChar(font, '.')
	, m_subChar(font, ',')
	, m_NPart(font, maxDigits - decimals, fillChar)
	, m_FPart(font, decimals, '0')
	, m_hasFPart(decimals > 0)
	, m_decPow(pow(10, decimals))
{
	float aspectRatio = m_NPart.GetAspectRatio()
		+ (m_hasFPart ? m_FPart.GetAspectRatio() : 0.0f)
		+ font.GetAspectRatio(',')
		+ font.GetAspectRatio('.');

	LayoutProperties layoutProperties;
	layoutProperties.m_desiredSize = Vec2f(aspectRatio * textSize, textSize);
	layoutProperties.m_desiredSizeUnit = sizeUnit;
	layoutProperties.m_aspectRatio = aspectRatio;
	SetLayoutProperties(layoutProperties);

	SetNumber(0);
}
Esempio n. 2
0
DigitField::DigitField(const Font& font, unsigned int maxDigits, char fillChar)
{
	maxDigits = maxDigits == 0 ? 1 : maxDigits;

	m_number.resize(maxDigits);

	std::string digits("0123456789");
	digits.push_back(fillChar);

	float maxDigitAspectRatio = 0.0f;

	for (size_t i = 0; i < maxDigits; ++i)
	{
		std::vector<std::shared_ptr<StaticChar>> digitLookup;

		for (char digit : digits)
		{
			assert(font.HasGlyph(digit));
			digitLookup.push_back(std::make_shared<StaticChar>(font, digit));
			maxDigitAspectRatio =
				std::max(maxDigitAspectRatio, font.GetAspectRatio(digit));
		}

		m_digitLookups.push_back(digitLookup);
	}

	m_aspectRatio = maxDigits * maxDigitAspectRatio;

	SetNumber(0);
}