コード例 #1
0
        //-----
        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
                }
            }
        }
コード例 #2
0
 //-----
 public void reDraw(Graphics g)
 {
     for (int i = 0; i < drawings.Count; i++)
     {
         VisRectangle v = (VisRectangle)drawings[i];
         v.draw(g);
     }
 }
コード例 #3
0
 //------
 public Memento(VisRectangle vrect)
 {
     visRect = vrect;
     rect    = visRect.rects;
     x       = rect.x;
     y       = rect.y;
     w       = rect.w;
     h       = rect.h;
 }
コード例 #4
0
 //-----
 public void unpick()
 {
     if (rectSelected && (selectedIndex >= 0) && (selectedIndex < drawings.Count))
     {
         VisRectangle vis = (VisRectangle)drawings[selectedIndex];
         vis.setSelected(false);
         selectedIndex = -1;
         rectSelected  = false;
         canvas.Refresh();
     }
 }
コード例 #5
0
 //-----
 public void drag(int x, int y)
 {
     if (rectSelected)
     {
         VisRectangle v = (VisRectangle)drawings[selectedIndex];
         if (v.contains(x, y))
         {
             v.move(x, y);
             repaint();
         }
     }
 }
コード例 #6
0
 //-----
 public void createRect(int x, int y)
 {
     unpick();                     //make sure no rectangle is selected
     if (startRect)                //if rect button is depressed
     {
         int count = drawings.Count;
         caretakr.Add(count);                     //Save previous drawing list size
         VisRectangle v = new VisRectangle(x, y); //create a rectangle
         drawings.Add(v);                         //add new element to list
         startRect = false;                       //done with this rectangle
         rect.setSelected(false);                 //unclick button
         canvas.Refresh();
     }
     else
     {
         pickRect(x, y);                   //if not pressed look for rect to select
     }
 }
コード例 #7
0
 public void rememberPosition(VisRectangle vr)
 {
     mem = new Memento(vr);
     undoList.Add(mem);
 }