I
Ian Stanley
hi,
back again and revisiting an old problem from months ago(still stuck)
I need a way to test what type of shape is selected and set further
behaviour accordingly. eg if rectangle selected, then change its color to
red, circle blue etc.
The main problem is that once the shapes are rotated or scaled the usual
rules(from what I can gather) do not apply. The general path takes over. I
have looked at the path iterator but am not sure how to use it.
The only shapes I am interested in are: rectangle, triangle, line, square or
circle.
has anyone a suggestion how to test if a mouse click occurs over one of
these which determines what type of shape is selected. If the click is over
a number of shapes then the last one is tested - I have started to try and
test using the bounds somehow- dicovered is too tricky(below)
Thanking you in advance
Ian
public Shape hitTest(int x, int y)
{
for (int i = 0; i < v.size(); i++){
Shape s = (Shape)v.elementAt(i);
if (s.contains(x,y) ){
int wid = s.getBounds().width;
int hei = s.getBounds().height;
... ... ...
return s;
}
}
return null;
}
back again and revisiting an old problem from months ago(still stuck)
I need a way to test what type of shape is selected and set further
behaviour accordingly. eg if rectangle selected, then change its color to
red, circle blue etc.
The main problem is that once the shapes are rotated or scaled the usual
rules(from what I can gather) do not apply. The general path takes over. I
have looked at the path iterator but am not sure how to use it.
The only shapes I am interested in are: rectangle, triangle, line, square or
circle.
has anyone a suggestion how to test if a mouse click occurs over one of
these which determines what type of shape is selected. If the click is over
a number of shapes then the last one is tested - I have started to try and
test using the bounds somehow- dicovered is too tricky(below)
Thanking you in advance
Ian
public Shape hitTest(int x, int y)
{
for (int i = 0; i < v.size(); i++){
Shape s = (Shape)v.elementAt(i);
if (s.contains(x,y) ){
int wid = s.getBounds().width;
int hei = s.getBounds().height;
... ... ...
return s;
}
}
return null;
}