Page 1 of 1

font/text size/pos-calc utils

Posted: Sun Mar 04, 2007 5:06 am
by ghoulsblade
Hi all !

some util methods in the ogre font class for calculating infos about how the text would look if rendered without actually creating a TextAreaOverlay would be nice, ideally something like

Code: Select all

void getTextSize(const String& text,Real& cx,Real &cy); 
// (e.g. centered text, buttons that automatically scale to their label )

void getCharBounds(const String& text,const int iCharIndex,Rectangle& bounds); 
// (e.g. for custom selection effects, custom blinking caret) 

int getCharAtPos(const String& text,const Real x,const Real y); 
// (e.g. clicking to place the caret) 
and maybe a Visitor design pattern in the font class for capsuling the drawing/iteration over text.
the code for that is currently deep inside in TextAreaOverlayElement::updatePositionGeometry() and would have to be copied to be used for custom widgets or stuff like text billboards inside the scene (with depthcheck and depthwrite, not overlay).

i think all the viewport and resolution calc can be done afterwards, the font doesn't need to bother about that.

its all nothing thats desperately needed, but might be nice to have =)

edit : even stuff like charwidth,charheight could be calculated outside these basic functions by simply multiplicating the result, maybe convenience variants with viewport and fontsize params.

edit 2: meanwhile i think a smart iterator would be better than a visitor, it would remember the current position while "drawing" text or whatever, and provide info about the current char (widht,height, texcoords,isnewline,iswhitespace,...), it would probably be a derived class of one of the Ogre::UTFString:: iterators....
maybe i'll implement that thing soon if you guys don't find the time, any comments/ideas/... are welcome =)

Posted: Fri Apr 06, 2007 9:41 pm
by ghoulsblade
as promised, here's a header full of font utils :
http://zwischenwelt.org/trac/lugre/brow ... nthelper.h

even with support for autowrapping.

example usage can be found here :
http://zwischenwelt.org/trac/lugre/brow ... verlay.cpp
http://zwischenwelt.org/trac/lugre/brow ... tOverlay.h

(click "Download in other formats:* Plain Text" at the bottom of the page to avoid copying with linenumbers)

hope this helps, greets =)

EDIT : update urls to new location

Posted: Tue Jun 19, 2007 8:12 am
by mdc
Thanks for this Ghoulsblade... your code has been helpful to me in implementing my own Gui system.

Posted: Tue Jun 19, 2007 3:24 pm
by ghoulsblade
you're welcome, i'm glad someone found it useful =)

Posted: Mon Jul 02, 2007 1:14 am
by ghoulsblade
i just made a wiki page for it and added it to the "HOWTO's and Code Snippets" page so it doesn't get lost :
http://www.ogre3d.org/wiki/index.php/OgreFontHelper

Re: font/text size/pos-calc utils

Posted: Tue Mar 16, 2010 6:49 pm
by NeilBright
Hi Ghoulsblade,

What is the mymax function in the utils as it won't build without it?

Regards,
Neil.

Delayed response from me. :)