Rect Font::calculateRectOfIndex(int index, const char *str, const Rect& bound) const { int line = calculateLine(index, str, bound); int lineBreak = 0; if(line>0) lineBreak = getLineBreak(line-1, str, bound); MAPoint2d cursor = {0, 0}; cursor.y+=line*mCharset->lineHeight; MAExtent lineRect = getStringDimensions(&str[lineBreak], index-lineBreak); cursor.x+=EXTENT_X(lineRect); MAExtent charRect = getStringDimensions(&str[index], 1); return Rect(cursor.x, cursor.y, EXTENT_X(charRect), mCharset->lineHeight); }
void CFont::printProportional(float widthRatio, float heightRatio, float width, float height, float r, float g, float b, const String &string) { Tuple4i viewport; if (!string.getLength()) return; glGetIntegerv(GL_VIEWPORT, viewport); Tuple2i dimensions = getStringDimensions(string); float xPosition = (viewport.z - dimensions.x*width)*widthRatio, yPosition = (viewport.w - dimensions.y*height)*heightRatio; print(xPosition, yPosition, width, height, r, g, b, string); }