Page 1 of 1

how to obtain caret pixel position of a editbox element?

Posted: Fri May 29, 2009 03:43
by Cloudage
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.

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

Posted: Fri May 29, 2009 08:48
by CrazyEddie
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.

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

Posted: Fri May 29, 2009 15:14
by Cloudage
thanks CE,i think i understood your idea,and i wrote a function by following it.currently it works very well.

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

Posted: Sat Apr 24, 2010 05:21
by sky_answer
Thank you