//----- public void pickRect(int x, int y) { //save current selected rectangle //to avoid double save of undo int lastPick = -1; if (selectedIndex >= 0) { lastPick = selectedIndex; } unpick(); //undo any selection //see if one is being selected for (int i = 0; i < drawings.Count; i++) { VisRectangle v = (VisRectangle)drawings[i]; if (v.contains(x, y)) //did click inside a rectangle { selectedIndex = i; //save it rectSelected = true; if (selectedIndex != lastPick) //but don't save twice { caretakr.rememberPosition(v); } v.setSelected(true); //turn on handles repaint(); //and redraw } } }
//----- public void drag(int x, int y) { if (rectSelected) { VisRectangle v = (VisRectangle)drawings[selectedIndex]; if (v.contains(x, y)) { v.move(x, y); repaint(); } } }