how to obtain caret pixel position of a editbox element?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Cloudage
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Thu May 28, 2009 11:37

how to obtain caret pixel position of a editbox element?

Postby Cloudage » Fri May 29, 2009 03:43

i want to pop up a window at where user is currently typing,like visual studio`s intelsence,or the ime window on ms windows,so i need the caret`s screen position.is there any helpful api or some trick for these things?

thanks.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: how to obtain caret pixel position of a editbox element?

Postby CrazyEddie » Fri May 29, 2009 08:48

Hi,

I think it's possible, but something of an ordeal to get the carat pixel location; there is no simple API unfortunately. Basically the method is something like this:

1 ) Get the carat text index via MultiLineEditbox::getCaratIndex
2 ) Get the line number where the carat index falls via MultiLineEditbox::getLineNumberFromIndex.
3 ) Your intermediate 'y' co-ordinate is the line number from 2 multiplied by the Font height.
4 ) Get the formatted line information collection (LineList which is a std::vector of MultiLineEditbox::LineInfo structs) via MultiLineEditbox::getFormattedLines.
5 ) Access the LineList collection to obtain the LineInfo with details of the line number determined in step 2.
6 ) From this LineInfo obtain the text substring from LineInfo::d_startIdx with a length of caratIndex - LineInfo::d_startIdx.
7 ) to get the intermediate 'x' co-ordinate use Font::getTextExtent to obtain the pixel extent of the string from step 6.
8 ) Use MultiLineEditbox::getTextRenderArea and offset the intermediate 'x' and 'y' by the location of this Rect.

This gives you your carat pixel location as offset from the top-left corner of the editbox window. For screen positions, you just have to add the pixel position of the window (there are converters, you just get the screen position Rect via Window::getUnclippedPixelRect). Simple, eh?! :lol:

HTH

CE.

Cloudage
Not too shy to talk
Not too shy to talk
Posts: 27
Joined: Thu May 28, 2009 11:37

Re: how to obtain caret pixel position of a editbox element?

Postby Cloudage » Fri May 29, 2009 15:14

thanks CE,i think i understood your idea,and i wrote a function by following it.currently it works very well.

sky_answer
Just popping in
Just popping in
Posts: 4
Joined: Fri Apr 23, 2010 17:45

Re: how to obtain caret pixel position of a editbox element?

Postby sky_answer » Sat Apr 24, 2010 05:21

Thank you


Return to “Help”

Who is online

Users browsing this forum: No registered users and 34 guests