//----- 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 unpick() { if (rectSelected && (selectedIndex >= 0) && (selectedIndex < drawings.Count)) { VisRectangle vis = (VisRectangle)drawings[selectedIndex]; vis.setSelected(false); selectedIndex = -1; rectSelected = false; canvas.Refresh(); } }