public override void OnMouseMove(ICoordinate worldPosition, MouseEventArgs e) { if (!Dragging) { return; } DragEndPoint = e.Location; var point = new Point((DragEndPoint.X - DragStartPoint.X), (DragEndPoint.Y - DragStartPoint.Y)); var previewImage = new Bitmap(DragImage.Width, DragImage.Height); Graphics g = Graphics.FromImage(previewImage); g.Clear(MapControl.BackColor); g.DrawImageUnscaled(DragImage, point); g.DrawImageUnscaled(StaticToolsImage, 0, 0); g.Dispose(); g = MapControl.CreateGraphics(); g.DrawImage(previewImage, 0, 0); g.Dispose(); previewImage.Dispose(); }
public virtual void DoDrawing(bool drawTools) { if (!dragging) { return; } Graphics graphics = Graphics.FromImage(drawingBitmap); // use transform from map; this enables directly calling ILayer.OnRender graphics.Transform = Map.MapTransform.Clone(); graphics.Clear(Color.Transparent); graphics.PageUnit = GraphicsUnit.Pixel; graphics.Clear(MapControl.BackColor); graphics.DrawImage(backGroundImage, 0, 0); if (drawTools) { foreach (IMapTool tool in MapControl.Tools) { if (tool.IsActive) { tool.Render(graphics, Map); } } } OnDraw(graphics); Graphics graphicsMap = MapControl.CreateGraphics(); graphicsMap.DrawImage(drawingBitmap, 0, 0); graphicsMap.Dispose(); graphics.Dispose(); }
public override void OnMouseWheel(ICoordinate mouseWorldPosition, MouseEventArgs e) { // zoom map double scale = (-e.Delta / 250.0); double scaleBase = 1 + wheelZoomMagnitude; // fine zoom if alt is pressed if (IsAltPressed) { scale = (-e.Delta / 500.0); } double zoomFactor = scale > 0 ? scaleBase : 1 / scaleBase; Map.Zoom *= zoomFactor; //determine center coordinate in world units double newCenterX = mouseWorldPosition.X - Map.PixelWidth * (e.X - MapControl.Width / 2.0); double newCenterY = mouseWorldPosition.Y - Map.PixelHeight * (MapControl.Height / 2.0 - e.Y); // use current map center if shift is pressed Map.Center = new Coordinate(newCenterX, newCenterY); // draw zoom rectangle (in screen coordinates) Rectangle zoomRectangle = new Rectangle( (int)(e.X * (1 - zoomFactor)), (int)(e.Y * (1 - zoomFactor)), (int)(MapControl.Size.Width * zoomFactor), (int)(MapControl.Size.Height * zoomFactor)); // draw image and clear background in a separate image first to prevent flickering Bitmap previewImage = (Bitmap)Map.Image.Clone(); Graphics g = Graphics.FromImage(previewImage); g.Clear(MapControl.BackColor); g.DrawImage(Map.Image, MapControl.ClientRectangle, zoomRectangle, GraphicsUnit.Pixel); // make tools to draw themself while map is being rendered foreach (IMapTool tool in MapControl.Tools) { if (tool.IsActive) { tool.OnPaint(new PaintEventArgs(g, MapControl.ClientRectangle)); } } g.Dispose(); // now draw preview image on control g = MapControl.CreateGraphics(); g.DrawImage(previewImage, 0, 0); g.Dispose(); previewImage.Dispose(); // call full map rendering (long operation) MapControl.Refresh(); }
public override void OnMouseMove(ICoordinate worldPosition, MouseEventArgs e) { if (!zooming) { return; } endDragPoint = e.Location; // draw image and clear background in a separate image first to prevent flickering Graphics g = Graphics.FromImage(previewImage); g.Clear(MapControl.BackColor); g.DrawImage(Map.Image, 0, 0); GraphicsHelper.DrawSelectionRectangle(g, Color.DeepSkyBlue, startDragPoint, endDragPoint); g.Dispose(); // now draw it on control g = MapControl.CreateGraphics(); g.DrawImage(previewImage, 0, 0); g.Dispose(); }
public override void OnMouseMove(ICoordinate worldPosition, MouseEventArgs e) { if (!Dragging) { if (IsCtrlAndAltPressed) { StartDrag(e.Location); } return; } // in case key events get lost: stop dragging if no longer mouse / keyboard down if (!IsCtrlAndAltPressed && e.Button != MouseButtons.Middle) { StopDrag(); return; } MapControl.Cursor = Cursors.Hand; DragEndPoint = e.Location; var point = new Point((DragEndPoint.X - DragStartPoint.X), (DragEndPoint.Y - DragStartPoint.Y)); using (var previewImage = new Bitmap(DragImage.Width, DragImage.Height)) { using (var g = Graphics.FromImage(previewImage)) { g.Clear(MapControl.BackColor); g.DrawImageUnscaled(DragImage, point); g.DrawImageUnscaled(StaticToolsImage, 0, 0); } using (var g = MapControl.CreateGraphics()) { g.DrawImage(previewImage, 0, 0); } } }
public override void OnMouseWheel(ICoordinate mouseWorldPosition, MouseEventArgs e) { if (Dragging) { return; } // zoom map double scale = (-e.Delta / 250.0); double usedWheelZoomMagnutide = wheelZoomMagnitude; // fine zoom if alt is pressed if (IsAltPressed) { usedWheelZoomMagnutide = wheelZoomMagnitude / 8; } double scaleBase = 1 + usedWheelZoomMagnutide; double zoomFactor = scale > 0 ? scaleBase : 1 / scaleBase; Map.Zoom *= zoomFactor; Rectangle zoomRectangle; if (!IsShiftPressed) { //determine center coordinate in world units double newCenterX = mouseWorldPosition.X - Map.PixelWidth * (e.X - MapControl.Width / 2.0); double newCenterY = mouseWorldPosition.Y - Map.PixelHeight * (MapControl.Height / 2.0 - e.Y); // use current map center if shift is pressed Map.Center = new Coordinate(newCenterX, newCenterY); // draw zoom rectangle (in screen coordinates) zoomRectangle = new Rectangle( (int)(e.X * (1 - zoomFactor)), (int)(e.Y * (1 - zoomFactor)), (int)(MapControl.Size.Width * zoomFactor), (int)(MapControl.Size.Height * zoomFactor)); } else { // draw zoom rectangle (in screen coordinates) zoomRectangle = new Rectangle( (int)(MapControl.Width / 2.0 * (1 - zoomFactor)), (int)(MapControl.Height / 2.0 * (1 - zoomFactor)), (int)(MapControl.Size.Width * zoomFactor), (int)(MapControl.Size.Height * zoomFactor)); } // draw image and clear background in a separate image first to prevent flickering using (var previewImage = (Bitmap)Map.Image.Clone()) { using (var g = Graphics.FromImage(previewImage)) { g.Clear(MapControl.BackColor); g.DrawImage(Map.Image, MapControl.ClientRectangle, zoomRectangle, GraphicsUnit.Pixel); DrawStaticTools(g); // make tools to draw themself while map is being rendered } // now draw preview image on control using (var g = MapControl.CreateGraphics()) { g.DrawImage(previewImage, 0, 0); } } // call full map rendering (long operation) MapControl.Refresh(); }