Ejemplo n.º 1
0
        // This sets the view to be centered at x,y

        /*private void ScrollTo(float x, float y)
         * {
         *      // Scroll now
         *      renderer2d.PositionView(x, y);
         *      this.OnViewChanged();
         *
         *      // Redraw
         *      General.MainWindow.RedrawDisplay();
         *
         *      // Determine new unprojected mouse coordinates
         *      mousemappos = renderer2d.DisplayToMap(mousepos);
         *      General.MainWindow.UpdateCoordinates(mousemappos);
         * }*/

        // This zooms
        private void ZoomBy(float deltaz)
        {
            Vector2D zoompos;

            // This will be the new zoom scale
            float newscale = renderer2d.Scale * deltaz;

            // Limit scale
            if (newscale > SCALE_MAX)
            {
                newscale = SCALE_MAX;
            }
            if (newscale < SCALE_MIN)
            {
                newscale = SCALE_MIN;
            }

            // Get the dimensions of the display
            Vector2D clientsize = new Vector2D(General.Map.Graphics.RenderTarget.ClientSize.Width,
                                               General.Map.Graphics.RenderTarget.ClientSize.Height);

            // When mouse is inside display
            if (mouseinside)
            {
                // Zoom into or from mouse position
                zoompos = (mousepos / clientsize) - new Vector2D(0.5f, 0.5f);
            }
            else
            {
                // Zoom into or from center
                zoompos = new Vector2D(0f, 0f);
            }

            // Calculate view position difference
            Vector2D diff   = ((clientsize / newscale) - (clientsize / renderer2d.Scale)) * zoompos;
            Vector2D offset = ClampViewOffset(renderer2d.OffsetX - diff.x, renderer2d.OffsetY + diff.y);             //mxd

            // Zoom now
            renderer2d.PositionView(offset.x, offset.y);
            renderer2d.ScaleView(newscale);
            this.OnViewChanged();

            //mxd. Change grid size?
            MatchGridSizeToDisplayScale();

            // Redraw
            General.MainWindow.RedrawDisplay();

            // Give a new mousemove event to update coordinates
            if (mouseinside)
            {
                OnMouseMove(new MouseEventArgs(mousebuttons, 0, (int)mousepos.x, (int)mousepos.y, 0));
            }
        }