Answered by:
How to track the mouse movement on the child elements inside a grid

Question
-
I am trying to create a words search game where I have dynamically generated a puzzle board of different sizes (10 by 10, 15 by 15 etc).
On the puzzle board, it is a currently a grid such as 10X10 small buttons inside, each button with a letter on it. When user presses on a button and moves the mouse/finger, I would like to detect those little buttons that are covered by the finger/mouse movement.
What event should I use? I have tried to add PointerPressedEvent, PointerMovedEvent, PointerReleasedEvent on the button, but the PointerPressedEvent and PointerMovedEvent are all fired on the same button which received the Pressed initially. On the PointerMovedEvent, I can get the current pointer position relative to the big grid, but I don't know how to convert the current position to the actual button that's underneath it.
Let me know if you have any ideas.
Friday, March 13, 2015 12:14 AM
Answers
-
Thanks James for your quick response.
Since I have set TabIndex on each button, when the PointerPressedEvent is received on a button, I know it's the correct button that the mouse is pressed on. After that I have moved the mouse away and with mouse still pressed, PointerMovedEvent is received on the same button. I expect to be on a different button since I have moved the mouse away.
This is currently not a problem for me any more. I figured out how to calculate the Grid row and column for the underlying button based on the current position (relative to the big outside Grid) and the Grid heigh and width.
PointerPoint^ pp = e->GetCurrentPoint(BoardGrid);
m_currentRow = (pp->Position.Y * RowCount) / m_boardHeight;
m_currentColumn = (pp->Position.X * ColumnCount) / m_boardWidth;
Thanks,
Jiying
- Proposed as answer by Jamles HezModerator Wednesday, March 25, 2015 12:24 PM
- Marked as answer by Jamles HezModerator Thursday, March 26, 2015 2:06 AM
Friday, March 13, 2015 4:25 AM
All replies
-
Hi Jiying Ren,
but the PointerPressedEvent and PointerMovedEvent are all fired on the same button which received the Pressed initially
-> Is that means the first button react correctly but when click or move the second button, the event still fires on the first button? If yes, could you share a demo with us for a better analysis?
but I don't know how to convert the current position to the actual button that's underneath it.
-> Probably you have to calculate if there is any button existing on the current position, I don't think there is any existing event or solution that can help you resolve it.
--James
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Friday, March 13, 2015 2:17 AMModerator -
Thanks James for your quick response.
Since I have set TabIndex on each button, when the PointerPressedEvent is received on a button, I know it's the correct button that the mouse is pressed on. After that I have moved the mouse away and with mouse still pressed, PointerMovedEvent is received on the same button. I expect to be on a different button since I have moved the mouse away.
This is currently not a problem for me any more. I figured out how to calculate the Grid row and column for the underlying button based on the current position (relative to the big outside Grid) and the Grid heigh and width.
PointerPoint^ pp = e->GetCurrentPoint(BoardGrid);
m_currentRow = (pp->Position.Y * RowCount) / m_boardHeight;
m_currentColumn = (pp->Position.X * ColumnCount) / m_boardWidth;
Thanks,
Jiying
- Proposed as answer by Jamles HezModerator Wednesday, March 25, 2015 12:24 PM
- Marked as answer by Jamles HezModerator Thursday, March 26, 2015 2:06 AM
Friday, March 13, 2015 4:25 AM -
Hi Jiying,
That means your question is solved?
--James
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Tuesday, March 17, 2015 9:15 AMModerator