From: Arthur v. L. <art...@cs...> - 2007-02-21 09:26:47
|
On 20-feb-2007, at 22:29, Mads Lindstr=F8m wrote: > Hi All > > Arthur van Leeuwen wrote: >> On 18-feb-2007, at 18:23, Mads Lindstr=F8m wrote: >> >>> Hi all >>> >>> I have created a text-control and I want to know which character the >>> mouse is hovering over. Getting the mouse position is easy enough. >>> However converting the mouse position to a character index (into the >>> text-control's text) seems very difficult. >>> >>> Anybody knows how to go from mouse position to character index? >> >> First, you need to get a hold of the TextCtrl. Then on that >> you can use textCtrlPositionToXY to get the x- and y- coordinate =20 >> of the >> character in character increments. textCtrlPositionToXY is in WXCore. > > textCtrlPositionToXY get the character position. That is, in the text: > > ab > c > def > > a, b, c, d, e, and f will have character positions (0,0), (1,0), =20 > (0,1), > (0,2), (1,2), and (2,2) respectively. Yes, and it gets this from the mouse position you pass to the function. =46rom these coordinates you can generate the position in the string "ab\nc\ndef", e.g. Is this not what you want? > When I wrote the mouse position, I was referring to the bitmap =20 > position > on the canvas (on which the characters are drawn) - I should have =20 > been a > bit more precise there. I get this position by capturing mouse events > by: > > set textCtrl [ on mouse :=3D ... ] Yes. The canvas contains the textCtrl, and the textCtrl draws the =20 string. Therefore it can perform the mapping back to character coordinate from mouse position. =46rom that you can map back to position in string =20 yourself. Maybe I am just completely misunderstanding what you want to do. Doei, Arthur. --=20 /\ / | art...@cs... | Work like you don't need =20= the money /__\ / | A friend is someone with whom | Love like you have never =20 been hurt / \/__ | you can dare to be yourself | Dance like there's nobody =20= watching |