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.
how to obtain caret pixel position of a editbox element?
Moderators: CEGUI MVP, CEGUI Team
- 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?
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?!
HTH
CE.
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?!
HTH
CE.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: how to obtain caret pixel position of a editbox element?
thanks CE,i think i understood your idea,and i wrote a function by following it.currently it works very well.
-
- Just popping in
- Posts: 4
- Joined: Fri Apr 23, 2010 17:45
Who is online
Users browsing this forum: No registered users and 31 guests