I am working on plug-in for eclipse CDT editor, which is an overlay that can highlight certain parts of code. I have access to opened CEditor (and its IDocument), and from it also to StyledText. I also have a character offset of parts i want to highlight.
Currently i have PaintListener over editor and i am able to draw over(I make transparent image onto which i paint highlighting, then set it as text background, i.e. styledText.setBackgroundImage(newImage);
). From styledText i am also able to get information about text height and text vertical position (scrolling included) i.e. i am able to highlight line of code, but i want to highlight only part of that line.
gc.fillRectangle(OFFSETX1, styledText.getLinePixel(LINE), OFFSETX2, tyledText.getLineHeight());
How can i get X in pixels(OFFSETX1,OFFSETX2) from character offset ??(Is it possible to get it from StyledText ? ). I have been searching StyledText API for hours, but couldn't find it. Thank you.
Use StyledText.getLocationAtOffset
Returns the x, y location of the upper left corner of the character bounding box at the specified offset in the text. The point is relative to the upper left corner of the widget client area.
Point loc = styledText.getLocationAtOffset(character offset);