private void Canvas_MouseMove(object sender, MouseEventArgs e) { //Point s = new Point(200, 200); Point s; if (isMouseDown) { //X = X - mouseLastLocation.X + e.X; //Y = Y - mouseLastLocation.Y + e.Y; /* * // Calcualte the Canvas's new location * Point newLocation = new Point(RealLocation.X - mouseLastLocation.X + e.X, * RealLocation.Y - mouseLastLocation.Y + e.Y); * * Size halfCanvas = new Size((int)((float)Canvas.Width / 2.0f), * (int)((float)Canvas.Height / 2.0f)); * * Point canvasLocation = Point.Empty; * * if(IsLeft()) * { * newLocation.X = Funcs.Clamp(newLocation.X, 0, Zoom.paperSize.Width - Canvas.Width); * canvasLocation.X = newLocation.X; * } * else if(IsCenter()) * { * newLocation.X = Funcs.Clamp(newLocation.X, halfCanvas.Width, Zoom.paperSize.Width - halfCanvas.Width); * canvasLocation.X = newLocation.X - halfCanvas.Width; * } * else if(IsRight()) * { * newLocation.X = Funcs.Clamp(newLocation.X, Canvas.Width, Zoom.paperSize.Width); * canvasLocation.X = newLocation.X - Canvas.Width; * } * * if (IsUp()) * { * newLocation.Y = Funcs.Clamp(newLocation.Y, 0, Zoom.paperSize.Height - Canvas.Height); * canvasLocation.Y = newLocation.Y; * } * else if (IsMiddle()) * { * newLocation.Y = Funcs.Clamp(newLocation.Y, halfCanvas.Height, Zoom.paperSize.Height - halfCanvas.Height); * canvasLocation.Y = newLocation.Y - halfCanvas.Height; * } * else if (IsDown()) * { * newLocation.Y = Funcs.Clamp(newLocation.Y, Canvas.Height, Zoom.paperSize.Height); * canvasLocation.Y = newLocation.Y - Canvas.Height; * } * * * RealLocation = newLocation; * * Canvas.Location = Zoom.Calculate(canvasLocation); * Canvas.Update(); * */ // Calcualte the Canvas's new location Point p = new Point(Holder.Location.X - mouseLastLocation.X + e.X, Holder.Location.Y - mouseLastLocation.Y + e.Y); // Ignore snapping and alignment if control is pressed if (Control.ModifierKeys != Keys.Control && e.Button != MouseButtons.Right) { // A Basic snapping Algorithm foreach (DocumentObject obj in Objects.objectList) { if (obj == this || !obj.Visible) { continue; } s = obj.Holder.Location; if (p.X >= s.X - 10 && p.X < s.X + 10) { p.X = s.X; } if (p.Y >= s.Y - 10 && p.Y < s.Y + 10) { p.Y = s.Y; } } } // Always clamp Position to inside the document p.X = Funcs.Clamp(p.X, 0, Zoom.paperSize.Width - Holder.Width); p.Y = Funcs.Clamp(p.Y, 0, Zoom.paperSize.Height - Holder.Height); Holder.Location = p; Holder.Update(); RecalculateRealPosition(); // Update position labels on the main form LivePreview.mainForm.UpdateObjectPosition(); } }