KineticJS icon indicating copy to clipboard operation
KineticJS copied to clipboard

Click event in Kinetic.text not triggered

Open v1r opened this issue 14 years ago • 7 comments

Hi,

I don't know if someone had experienced this behaviour.
Try to click in the middle of "T" letter in this example : http://jsfiddle.net/v1r00z/tDTfr/

Some times the click event not being triggered.

PS : click right in the middle of the vertical green line of the "T" letter. or any other letter!

I'm using Chrome/ubuntu.

Update :

Weird! The problem does not occur in win7

v1r avatar Oct 22 '12 20:10 v1r

Weird! The problem does not occur in win7/chrome

v1r avatar Oct 22 '12 20:10 v1r

I see two reasons for this problem.

1# The canvas is offset by 1px because of the border (almost all exampled on html5canvastutorials have this problem) 2# The font is anti-aliasing causing the buffer layer to be a different colour at the edges - This is very hard to fix, I've ben looking in to it before, but found no solution. While the is no shape behind the color is correct but the opacity is not 1.0, but when there is something behind the color will be a mix of the to shapes colorkey...


There is also another problem for me with this (obviously not showing in Chrome): all texts (maybe even all shapes?) will have a solid fill in the buffer layer even when not set in the config. This is probably caused when white-/blacklisting members of the attars before the shape is drawn on the buffer. This is probably not very hard to solve, but I haven't had time to look into it. Maybe Eric can take a look?

davonium avatar Oct 22 '12 20:10 davonium

@v1r: the reason you're not seeing this in win might be what i described at the end. I have one temporary workaround to make the first problems more visible: Include the setting "image: true" in the config of the simpleText, then after the node is created add (to a new line): simpleText.imageBuffer = true

like in this version: http://jsfiddle.net/davonium/tDTfr/1/

davonium avatar Oct 22 '12 21:10 davonium

@davonium hmm i understand.

v1r avatar Oct 22 '12 21:10 v1r

I'm getting a similar problem with the behaviour also. I can get it to alert, inside the onclick without the imageBuffer statements. The problem is when I try to use txt.setText within onclick function, it can't see the txt object. i'm using kinetic-v4.0.3

ginhanlabs avatar Oct 27 '12 06:10 ginhanlabs

Interesting thread! Thoughts:

  1. okay, the buffer canvas. Every shape is assigned a unique color code for the purpose of really fast hit detection. When shapes are antialiased around the edges of a shape, the alpha component of the RGBA color is not equal to 1, and therefore is ignored by the hit detection algorithm. I don't personally see this as a bug, because this case only occurs within a fraction of a pixel around the edges of a shape.

  2. canvas border used in Html5CanvasTutorials.com - very interesting! This whole time, I had no idea that border sizes were offsetting the hit detection. Will definitely look into this.

ericdrowell avatar Oct 27 '12 17:10 ericdrowell

This isn't really an issue any more - The Kinetic.Text hit graph now renders a rectangle in place of the text to make the hit detection easier. Also, the Kinetic tutorials have removed the one pixel border so there shouldn't be an issue there anymore.

Also, since KineticJS is building the canvas elements dynamically, we shouldn't be modifying the styles of those elements.

ericdrowell avatar Feb 15 '13 01:02 ericdrowell