예제 #1
0
        protected override bool ProcessKeyMessage(ref Message m)
        {
            if (EventProcessKeyMessage != null)
            {
                EventProcessKeyMessage(ref m);
            }
            else if (Enabled && m.Msg == 0x100)
            {
                if (CurrentViewport.ProcessKeys((Keys)m.WParam, Control.ModifierKeys))
                {
                    return(true);
                }
            }

            return(base.ProcessKeyMessage(ref m));
        }
예제 #2
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            switch (e.Button)
            {
            case Forms.MouseButtons.Left:
                _mouseDown = false;
                if (_draggingViewports)
                {
                    _draggingViewports = false;
                    int range = 8;
                    for (int i = 0; i < _viewports.Count; i++)
                    {
                        GLViewport v = _viewports[i];
                        if (v.Region.Width < range || v.Region.Height < range)
                        {
                            v.OnInvalidate -= Invalidate;
                            RemoveViewport(i--);
                        }
                    }
                }
                else
                {
                    CurrentViewport.HandleLeftMouseUp(e);
                }
                break;

            case Forms.MouseButtons.Right:
                CurrentViewport._grabbing = false;
                break;

            case Forms.MouseButtons.Middle:
                CurrentViewport._scrolling = false;
                break;

            default:
                base.OnMouseUp(e);
                return;
            }

            Invalidate();
            base.OnMouseUp(e);
        }
예제 #3
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            ModelPanelViewport highlighted = HighlightedViewport;

            if (CurrentViewport != highlighted)
            {
                CurrentViewport        = highlighted;
                CurrentViewport._lastX = e.X - CurrentViewport.Region.X;
                CurrentViewport._lastY = e.Y - CurrentViewport.Region.Y;
            }

            switch (e.Button)
            {
            case Forms.MouseButtons.Left:
                _mouseDown = true;
                if (_dragging.Count > 0 && _viewports.Count > 1)
                {
                    _draggingViewports = true;
                }
                else
                {
                    CurrentViewport.HandleLeftMouseDown(e);
                }
                break;

            case Forms.MouseButtons.Right:
                CurrentViewport._grabbing = true;
                break;

            case Forms.MouseButtons.Middle:
                CurrentViewport._scrolling = true;
                break;
            }

            base.OnMouseDown(e);
        }
예제 #4
0
        public void SetCamWithBox(Vector3 min, Vector3 max)
        {
            GLCamera cam = CurrentViewport.Camera;

            //Get the position of the midpoint of the bounding box plane closer to the camera
            Vector3 frontMidPt = new Vector3((max._x + min._x) / 2.0f, (max._y + min._y) / 2.0f, max._z);
            float   tan = (float)Math.Tan(cam.VerticalFieldOfView / 2.0f * Maths._deg2radf), distX = 0, distY = 0;

            //The tangent value would only be 0 if the FOV was 0,
            //meaning nothing would be visible anyway
            if (tan != 0)
            {
                //Calculate lengths
                Vector3 extents     = max - min;
                Vector3 halfExtents = extents / 2.0f;
                if (halfExtents._y != 0.0f)
                {
                    float ratio = halfExtents._x / halfExtents._y;
                    distY = halfExtents._y / tan; //The camera's distance from the model's midpoint in respect to Y
                    distX = distY * ratio;
                }
                else if (halfExtents._x != 0.0f)
                {
                    float ratio = halfExtents._y / halfExtents._x;
                    distX = halfExtents._x / tan; //The camera's distance from the model's midpoint in respect to Y
                    distY = distX * ratio;
                }
            }

            cam.Reset();

            cam.Translate(frontMidPt._x, frontMidPt._y, Maths.Max(distX, distY, max._z) + 2.0f);
            if (CurrentViewport.GetProjectionType() == ViewportProjection.Orthographic)
            {
                cam.Zoom(Maths.Max(distX, distY, max._z) / (Maths.Max(Size.Height, Size.Width) * 0.01f));
            }

            Invalidate();
        }
예제 #5
0
 public void ResetCamera()
 {
     CurrentViewport.ResetCamera();
     Invalidate();
 }
예제 #6
0
        protected override void OnKeyUp(KeyEventArgs e)
        {
            base.OnKeyUp(e);

            CurrentViewport.HandleKeyUp(e);
        }
예제 #7
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            //Reset the cursor to default first, then override it later
            //Parent control mouse move functions are called after this one
            if (!_mouseDown && !CurrentViewport._grabbing && !CurrentViewport._scrolling && Cursor != Cursors.Default)
            {
                Invalidate();
                Cursor = Cursors.Default;
            }

            if (!Enabled)
            {
                return;
            }

            base.OnMouseMove(e);

            int x = e.X.Clamp(0, Width),
                y = Height - e.Y.Clamp(0, Height);

            if (_draggingViewports)
            {
                float
                    yP = (float)y / Height,
                    xP = (float)x / Width;

                foreach (var t in _dragging)
                {
                    //TODO: don't allow the user to drag over another viewport
                    //bool cont = false;
                    bool  isX = ((int)t.Value & 1) == 0;
                    float p   = isX ? xP : yP;
                    //foreach (ModelPanelViewport v in _viewports)
                    //{
                    //    foreach (var t2 in _dragging)
                    //        if (t2.Key == v)
                    //            cont = true;
                    //    if (cont)
                    //    {
                    //        cont = false;
                    //        continue;
                    //    }
                    //    float ep = v.Percentages[(int)t.Value];
                    //    if (ep > p)
                    //    {
                    //        cont = true;
                    //        break;
                    //    }
                    //}
                    //if (cont)
                    //    continue;
                    t.Key.SetPercentageIndex((int)t.Value, p);
                }

                Invalidate();
            }
            else if (_viewports.Count > 1)
            {
                _dragging.Clear();
                int  range = 8;
                bool xd = false, yd = false;

                Func <DragFlags, Rectangle, bool> inRange = (flag, region) =>
                {
                    switch (flag)
                    {
                    case DragFlags.xMin:
                        return(xd = Math.Abs(x - region.X) <= range && x > range);

                    case DragFlags.xMax:
                        int xT = region.X + region.Width;
                        return(xd = Math.Abs(x - xT) <= range && Math.Abs(Width - xT) > range);

                    case DragFlags.yMin:
                        return(yd = Math.Abs(y - region.Y) <= range && y > range);

                    case DragFlags.yMax:
                        int yT = region.Y + region.Height;
                        return(yd = Math.Abs(y - yT) <= range && Math.Abs(Height - yT) > range);
                    }
                    return(false);
                };
                Action <ModelPanelViewport, DragFlags> add = (w, flag) =>
                {
                    _dragging.Add(new KeyValuePair <ModelPanelViewport, DragFlags>(w, flag));
                };

                //TODO: allow the user to drag only the viewports that share a line,
                //but make sure they can't break up the line (viewports must take up all of the screen)
                //At the moment, you can only drag a whole line on the screen
                foreach (ModelPanelViewport w in _viewports)
                {
                    //if (y > w.Region.Y - range && y < w.Region.Y + w.Region.Height + range)
                    if (inRange(DragFlags.xMin, w.Region))
                    {
                        add(w, DragFlags.xMin);
                    }
                    else if (inRange(DragFlags.xMax, w.Region))
                    {
                        add(w, DragFlags.xMax);
                    }
                    //if (x > w.Region.X - range && x < w.Region.X + w.Region.Width + range)
                    if (inRange(DragFlags.yMin, w.Region))
                    {
                        add(w, DragFlags.yMin);
                    }
                    else if (inRange(DragFlags.yMax, w.Region))
                    {
                        add(w, DragFlags.yMax);
                    }
                }

                if (xd && yd)
                {
                    Cursor = Cursors.SizeAll;
                }
                else if (xd)
                {
                    Cursor = Cursors.SizeWE;
                }
                else if (yd)
                {
                    Cursor = Cursors.SizeNS;
                }
                else
                {
                    CurrentViewport.HandleMouseMove(_ctx, e);
                }
            }
            else
            {
                CurrentViewport.HandleMouseMove(_ctx, e);
            }
        }