On 20-feb-2007, at 22:29, Mads Lindstrøm wrote:

> Hi All
>
> Arthur van Leeuwen wrote:
>> On 18-feb-2007, at 18:23, Mads Lindstrøm 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  
>> 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),  
> (0,1),
> (0,2), (1,2), and (2,2) respectively.

Yes, and it gets this from the mouse position you pass to the function.
 From 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  
> position
> on the canvas (on which the characters are drawn) - I should have  
> been a
> bit more precise there. I get this position by capturing mouse events
> by:
>
>    set textCtrl [ on mouse := ... ]

Yes. The canvas contains the textCtrl, and the textCtrl draws the  
string.
Therefore it can perform the mapping back to character coordinate from
mouse position. From that you can map back to position in string  
yourself.

Maybe I am just completely misunderstanding what you want to do.

Doei, Arthur.

-- 

   /\    / |       [EMAIL PROTECTED]       | Work like you don't need  
the money
/__\  /  | A friend is someone with whom | Love like you have never  
been hurt
/    \/__ | you can dare to be yourself   | Dance like there's nobody  
watching




-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
wxhaskell-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to