From: Mads <mad...@ya...> - 2007-02-18 17:22:24
|
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? /Mads Lindstrøm |
From: Arie M. <ar...@cs...> - 2007-02-18 18:16:19
|
If you can somehow convert a mouse-hover action into a mouse-press action, the following would be a solution: 1. save carret position 2. propagate event (text-control will move the carret) 3. obtain carret position as character index 4. restore carret position There are some wxHaskell functions that deal with events, but I'm not sure whether or not they provide the required functionality. Greetings, Arie ----- Original Message ----- From: "Mads Lindstrøm" <mad...@ya...> To: <wxh...@li...> Sent: Sunday, February 18, 2007 6:23 PM Subject: [wxhaskell-users] From mouse position to character index (textCtrl) 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? /Mads Lindstrøm ------------------------------------------------------------------------- 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 wxh...@li... https://lists.sourceforge.net/lists/listinfo/wxhaskell-users |
From: Arthur v. L. <art...@cs...> - 2007-02-19 08:02:35
|
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 of the character in character increments. textCtrlPositionToXY is in WXCore. One tip: try searching the wxWidgets docs first when trying to figure out how to do stuff. For me it tends to lead me to the result quicker =20= than perusing just the wxHaskell docs. With regards, Arthur van Leeuwen. --=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 |
From: Mads <mad...@ya...> - 2007-02-20 21:28:27
|
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. 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 := ... ] > > One tip: try searching the wxWidgets docs first when trying to figure > out how to do stuff. For me it tends to lead me to the result quicker > than > perusing just the wxHaskell docs. Good point. > > With regards, Arthur van Leeuwen. > Kind regards, Mads Lindstrøm |
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 |