public override void executePress(Point p, Drawing d) { //grab frontmost shape at point, copy it, then perform normal move command on copy s = d.getFrontmostContainer(p); d.copy(s); base.executePress(p,d); }
public override void executeClick(Point p, Drawing d) { //if current point is contained by a shape if (d.getFrontmostContainer(p) != null) { //set shape's color equal to drawing object's color d.getFrontmostContainer(p).MyColor = d.MyColor; } }
public override void executePress(Point p, Drawing d) { lastX = p.X; lastY = p.Y; do { s = d.getFrontmostContainer(p); doTwice++; }while(doTwice < 2); //System.Windows.Forms.MessageBox.Show(d.getFrontmostContainer(p).ToString()); }
public override void executeDrag(Point p, Drawing d) { //as long as point is contained in a shape onscreen... if (s != null) { s.move(p.X-lastX,p.Y-lastY); lastX = p.X; lastY = p.Y; } return; }
//copy constructor public Drawing(Drawing d) { InitializeComponent(); ClientSize = d.ClientSize; myImage = d.myImage; myShapes = new ArrayList(); //copy each shape in list foreach (Shape s in d.myShapes) { myShape = new Rect(0,0,1,1,Color.Black); //is s a rectangle...? if (myShape.GetType() == s.GetType()) myShape = new Rect((Rect)s); else { //is it an oval...? myShape = new Oval(0,0,1,1,Color.Black); if (myShape.GetType() == s.GetType()) myShape = new Oval((Oval)s); else { //is it a line...? myShape = new Segment(0,0,1,1,Color.Black,1); if (myShape.GetType() == s.GetType()) myShape = new Segment((Segment)s); else { //is it a triangle...? Point p1 = new Point(); Point p2 = new Point(); Point p3 = new Point(); myShape = new Triangle(p1,p2,p3,Color.Black); if (myShape.GetType() == s.GetType()) myShape = new Triangle((Triangle)s); } } } myShape.MyColor = s.MyColor; myShape.MyCenter = s.MyCenter; myShapes.Add(myShape); } myShape = d.myShape; offGraphics = d.offGraphics; visGraphics = d.visGraphics; offBitmap = d.offBitmap; offGraphics = Graphics.FromImage(offBitmap); myColor = d.myColor; }
//on mouse move public override void executeDrag(Point p, Drawing d) { d.clear(); //if point of click was to the left of current point... if (lastX < p.X) { d.MyShape = new Segment(lastX,lastY,p.X-lastX,p.Y-lastY,d.MyColor,5); } //if point of click was to the right of current point... else if (p.X < lastX) { d.MyShape = new Segment(p.X, p.Y, lastX-p.X,lastY-p.Y,d.MyColor,5); } }
//on mouse down public abstract void executePress(Point p, Drawing d);
//on mouse move public abstract void executeDrag(Point p, Drawing d);
//on mouse up public abstract void executeClick(Point p, Drawing d);
//on mouse down public override void executePress(Point p, Drawing d) { //identify original point of mouse down lastX = p.X; lastY = p.Y; }
//on mouse up public override void executeClick(Point p, Drawing d) { d.addShape(d.MyShape); d.MyShape = null; }
public override void executePress(Point p, Drawing d) { }
public override void executeDrag(Point p, Drawing d) { }
public override void executeClick(Point p, Drawing d) { //if current point is contained in a shape if(d.getFrontmostContainer(p)!=null)d.delete(d.getFrontmostContainer(p)); return; }
public override void executeClick(Point p, Drawing d) { s = null; }