Thursday, November 29, 2012

Re: Canvas drawn objects mouse events

I don't want to discourage you from trying your own implementation but you 
might want to take a look at Lienzo and see if it works for what you need. It's 100% built on GWT and lighting fast. It should do all the things you will need and likely more. It's released under Apache.

Explorer:


Download:


Best regards,

Alfredo


On Thu, Nov 29, 2012 at 1:29 PM, Matt Fair <matt.fair@gmail.com> wrote:

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.



--
Alfredo Quiroga-Villamil

AOL/Yahoo/Gmail/MSN IM:  lawwton


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
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