font/text size/pos-calc utils

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
ghoulsblade
Halfling
Posts: 86
Joined: Sun Mar 05, 2006 2:55 pm
Location: Germany
x 2

font/text size/pos-calc utils

Post 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 =)
User avatar
ghoulsblade
Halfling
Posts: 86
Joined: Sun Mar 05, 2006 2:55 pm
Location: Germany
x 2

Post 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
Last edited by ghoulsblade on Wed Oct 31, 2007 2:20 am, edited 1 time in total.
mdc
Kobold
Posts: 28
Joined: Wed Mar 22, 2006 5:18 pm

Post by mdc »

Thanks for this Ghoulsblade... your code has been helpful to me in implementing my own Gui system.
User avatar
ghoulsblade
Halfling
Posts: 86
Joined: Sun Mar 05, 2006 2:55 pm
Location: Germany
x 2

Post by ghoulsblade »

you're welcome, i'm glad someone found it useful =)
User avatar
ghoulsblade
Halfling
Posts: 86
Joined: Sun Mar 05, 2006 2:55 pm
Location: Germany
x 2

Post 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
NeilBright
Gnoblar
Posts: 11
Joined: Wed Feb 24, 2010 1:55 pm

Re: font/text size/pos-calc utils

Post 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. :)
Post Reply