I have the following code:
public void draw(Context2d context) {
context.beginPath();
context.rect(x, y, width, height);
context.fill();
context.closePath();
context.stroke();
}
I would like to add a mouse event for when the mouse moves over the rectangle. What's the best way to do this? I was able to do it if I in the mouse move event for the canvas and with an if statement I checked to see if the mouse moved within the coordinates of the rectangle.
canvas.addMouseMoveHandler(new MouseMoveHandler() {
public void onMouseMove(MouseMoveEvent event) {
mouseX = event.getRelativeX(canvas.getElement());
mouseY = event.getRelativeY(canvas.getElement());
if(insideRectangle(mouseX, mouseY)) {
// fire mouse event for rectangle
}
}
});
However, I am worry about working with a bunch of objects and speed doing it this way. Is there a way to add a mouseMoveHandler directly to the rectangle?
Thanks,
Matt
--You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/ZcJTa9KelVEJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment