EDIT:
Fixed faulty logic in formulas (result of LSL's odd orientation)
=====================
a handy method for finding where your button edges are in your texture (assuming a rectangular button shape aligned to the image axis)
get the x,y of the pixel in the top-left (TL) of your button, and the bottom-right (BR) along with the images overall x,y dimensions (IMG)
//-- this part can be pre calculated, you only ned TL and BR at the end.
TL.x /= IMG.x;
TL.y = 1.0 - (TL.y / IMG.y); //-- ** see note below
BR.x /= IMG.x
BR.y = 1.0 - (BR.y / IMG.y); //-- ** see note below
uCheckButton( vector vPosTouch ){
if (TL.x < vPosTouch.x && vPosTouch.x < BR.x){
if (TL.y < vPosTouch.y && vPosTouch.y < BR.y){
//-- button touched
}
}
}
round buttons can be done by picking the pixel in the center(BC), and one on the lower right edge(BE).
//-- this part can be pre calculated you only need BC and vFltBE at the end
BC.x /= IMG.x;
BC.y = 1.0 - (BC.y / IMG.y); //-- ** see note below
BE.x /= IMG.x;
BE.y = 1.0 - (BE.y / IMG.y); //-- ** see note below
vFltBE = llVecDist( BC, BE );
uCheckRoundButton( vector vPosTouch ){
if (llVecDist( vPosTouch, BC ) < vFltBE){
//-- button touched
}
}
llDetectedTouchUV is probably preferred in most cases, but if the texture is stretched on the prim face with 1.0 repeats in both directions, and no offsets, or rotation, then ST will produce the same results.
if your button is another shape, you can use
http://wiki.secondlife.com/wiki/IsPointInPolygon2D with a list of x,y pixel points from each vertex of the button converted to percentages and placed in a list.
**NOTE:
most image editors count pixels from the top-left corner, LSL reports percentages from the bottom-left corner, so we have to flip the y position reported by the image editor with 1.0 - (calculated percentage) to get the correct range (in case you were wondering