Beispiel #1
0
        /// <summary>
        /// Is called when the mouse-wheel is moved.
        /// </summary>
        public override void OnMouseWheel(Plot.MouseEventArgs e)
        {
            double factor = Math.Pow(1.2, Math.Sign(e.Delta));

            if (factor != 1)
            {
                double x = Model.x0 + (1 - factor) * e.X * (Model.x1 - Model.x0) / Bounds.Width;
                double y = Model.y0 + (1 - factor) * (Bounds.Height - e.Y) * (Model.y1 - Model.y0) / Bounds.Height;
                if (!(Model.x.fix && Model.y.fix))
                {
                    if (Model.x.fix)
                    {
                        Model.SetRange(Model.x0, Model.x1, y, y + factor * (Model.y1 - Model.y0), Bounds);
                    }
                    else if (Model.y.fix)
                    {
                        Model.SetRange(x, x + factor * (Model.x1 - Model.x0), Model.y0, Model.y1, Bounds);
                    }
                    else
                    {
                        Model.SetRange(x, x + factor * (Model.x1 - Model.x0), y, y + factor * (Model.y1 - Model.y0), Bounds);
                    }
                }
            }
        }
Beispiel #2
0
 void ZoomCursor(Plot.MouseEventArgs e)
 {
     if (Parent != null && e.Button == MouseButtons.Left)
     {
         zoomIn = ((e.ModifierKeys & (Keys.Shift | Keys.Control)) == Keys.None);
         if (zoomIn)
         {
             Parent.Cursor = SpecialCursors.EnlargeCursor;
         }
         else
         {
             Parent.Cursor = SpecialCursors.ShrinkCursor;
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// Is called when a mouse-button is released.
 /// </summary>
 public override void OnMouseUp(Plot.MouseEventArgs e)
 {
     if (sx != -1 && sy != -1 && sw != 0 && sh != 0)
     {
         Zoom(zoomIn, new Rectangle(sx, sy, sw, sh));
     }
     sx = sy = -1; sw = sh = 0;
     if (Parent != null)
     {
         if (PaintThread.DrawDone)
         {
             Parent.Cursor = Cursors.Cross;
         }
         else
         {
             Parent.Cursor = Cursors.WaitCursor;
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Is called when the mouse moves over the control.
        /// </summary>
        /// <param name="e"></param>
        public override void OnMouseMove(Plot.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (Parent != null)
                {
                    Parent.Cursor = Cursors.SizeAll;
                }
                if (sx != -1)
                {
                    MovePlot(e.X - sx, e.Y - sy);
                }
                sx = e.X;
                sy = e.Y;
            }
            else if (Parent != null && (e.Button == MouseButtons.Left) && !(Model.x.fix && Model.y.fix))
            {
                ZoomCursor(e);

                Graphics g = Parent.CreateGraphics();

                Region clip;

                if (sx == -1 || sy == -1)
                {
                    sx = e.X; sy = e.Y; sw = sh = 0;
                    if (Model.x.fix)
                    {
                        sx = Bounds.X; sw = Bounds.Width;
                    }
                    if (Model.y.fix)
                    {
                        sy = Bounds.Y; sh = Bounds.Height;
                    }
                }

                int dw, dh;

                dw = e.X - sx - sw;
                dh = e.Y - sy - sh;

                if (Model.x.fix)
                {
                    dw = 0;
                }
                if (Model.y.fix)
                {
                    dh = 0;
                }

                int x = Math.Min(sx, sx + sw); int y = Math.Min(sy, sy + sh);
                int w = Math.Abs(sw); int h = Math.Abs(sh);
                clip = new Region(new Rectangle(x, y, w + 1, 1));
                clip.Union(new Rectangle(x, y, 1, h + 1));
                clip.Union(new Rectangle(x + w, y, 1, h + 1));
                clip.Union(new Rectangle(x, y + h, w + 1, 1));

                sw += dw;
                sh += dh;

                x = Math.Min(sx, sx + sw); y = Math.Min(sy, sy + sh);
                w = Math.Abs(sw); h = Math.Abs(sh);
                clip.Union(new Rectangle(x, y, w + 1, 1));
                clip.Union(new Rectangle(x, y, 1, h + 1));
                clip.Union(new Rectangle(x + w, y, 1, h + 1));
                clip.Union(new Rectangle(x, y + h, w + 1, 1));

                g.SetClip(clip, CombineMode.Intersect);
                g.FillRectangle(white, sx, sy, w + 1, h + 1);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                Draw(g, new Rectangle(0, 0, Parent.Bounds.Width, Parent.Bounds.Height));
            }

            ZoomCursor(e);
            double mx = WorldCoordinateX(e.X);
            double my = WorldCoordinateY(e.Y);
            double mz = 0;

            if (Model != null)
            {
                int i = 0;
                while (i < Model.Count && !(Model[i] is Function2DItem))
                {
                    i++;
                }
                if (i < Model.Count)
                {
                    try {
                        mz = ((Function2DItem)Model[i]).f(mx, my);
                    } catch { }
                }
            }
            FireNotifyCursor(mx, my, mz);
        }
Beispiel #5
0
 /// <summary>
 /// Is called when a mouse button is pressed.
 /// </summary>
 /// <param name="e"></param>
 public override void OnMouseDown(Plot.MouseEventArgs e)
 {
     button = e.Button;
     ZoomCursor(e);
 }