On Fri, 2008-10-17 at 15:53 -0400, Jeremy Moles wrote:
> On Tue, 2008-10-14 at 21:25 +0800, yang zhiyuan wrote:
> > Hi:
> >     I have solved the problem how to get one char's position inside a
> > osgText::Text;
> >     The purpose is to move cursor when input text.
> >     
> >     Here is my code:
> >    updateCursorPos(const std::string& string, int position)
> > {
> >   osg::Vec3 cursor_position = m_inputText->getPosition();
> >   //get the font resolution
> >    osgText::FontResolution fr;
> >     fr.first = FONT_RES_X;
> >     fr.second = FONT_RES_Y;
> >     
> >     //m_inputText is the osg::Text from which you want to get the last
> > char's position
> >      const osgText::Font* font = m_inputText->getFont();
> >      osgText::Font* font1 = const_cast<osgText::Font*>(font);
> >     //get total size of input parameter string
> >    //string is the the std::string inside the m_inputText
> >     unsigned int size = string.size();
> >     osgText::Font::Glyph* glyph = font1->getGlyph(fr,size-1);
> >     osgText::Font::GlyphTexture* glyphTexture = glyph->getTexture();
> >    
> >     const osgText::Text::GlyphQuads * glyph_quads =
> > m_inputText->getGlyphQuads( glyphTexture );
> >     if( glyph_quads )
> >     {
> >         int coord_size = glyph_quads->getTransformedCoords(0).size();
> >         int input_text_size = string.size();     // # chars on line.
> >         if( position > 0 )
> >         {
> >             // Get position of character under cursor
> >             // There are 4 coords per character, BottomLeft, TopLeft,
> >             //   BottomRight, TopRight. We want the BottomRight.
> >             osg::Vec3 glyph_pos =
> > glyph_quads->getTransformedCoords(0)[ position * 4 - 2 ];
> >             cursor_position[0] = glyph_pos[0];  // Use only the X
> > position
> >         }
> >     }
> >  
> > }
> 
> I'm going to try and adapt this to osgWidget::Input. Right now I use a
> much different method for calculating the cursor position of my Input
> object (which doesn't work), so perhaps this will help. I will, of
> course, post more info soon. :)

So, it turns out this didn't work for me either--but I did finally,
FINALLY come up with a solution. :) It'll be in osgWidget::Input soon,
so hopefully I'll have it all ready before the next OSG release.

One problem I'm encountering is that Input text must be positioned using
the baseline, but that it's impossible (as far as I can see?) to find
the largest glyph descent to properly allocate the height of an Input
widget. Not sure if anyone has any advice to work around this...
    
My current solution to this isn't BAD (you can call Input::setYOffset or
Input::calculateBestYOffsetForString("...")), but if anyone has any
other ideas I'd welcome them. :)

(P.S. The descent of a font glyph is the distance between the
bottom-most point and the baseline for characters such as "y", "q",
etc...)

> On a different note--are you writing your own widget library?
> 
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to