Example #1
0
	void Text::display() {
		auto tp = _position;

		auto font = _batcher->getFont();

		auto fontHeight = font->getFontHeight();
		auto start = font->getFontStart();
		auto length = font->getFontLength();

		auto glyphs = font->getFontGlyphs();
		if(!_used) {
			_index = _batcher->addString();
		}

		for(int i = 0; _text[i] != 0; i++) {
			char c = _text[i];
			if(_text[i] == '\n') {
				tp.y += fontHeight * _scaling.y;
				tp.x = _position.x;
			} else {
				// Check for correct glyph
				auto gi = c - start;
				if(gi < 0 || gi >= length)
					gi = length;
				glm::vec4 destRect(tp, glyphs[gi].size * _scaling);
				//Add the character to the font batcher
				_batcher->add(destRect, glyphs[gi].uvRect, _depth, _tint, _index);
				tp.x += glyphs[gi].size.x * _scaling.x;
			}
		}
	}
Example #2
0
LRESULT UILabel::onEvent(UINT msg, WPARAM wp, LPARAM lp, UINT flag, Point pt)
{
    switch (msg)
    {
    case WM_SETTEXT:
        setFontText((LPCTSTR)lp);
        invalidate();
        return getFontLength();
    case WM_GETTEXT:
        ASSERT(lp);
        *(CString*)(lp) = getFontText();
        return getFontLength();
    case WM_GETTEXTLENGTH:
        return getFontLength();
    }

    return UIControl::onEvent(msg, wp, lp, flag, pt);
}