Exemplo n.º 1
0
 void IMouseBehaviour.OnMouseDown(object sender, MouseEventArgs e)
 {
     isDragging = true;
     Viewport viewport = camera.Viewport;
     Vector3 pObjCenter3 = Vector3.Project(RenderableObject.AbsolutePosition, viewport.X, viewport.Y, viewport.Width, viewport.Height,
                                          viewport.MinZ, viewport.MaxZ, camera.WorldViewProjection);
     pOffset = e.Location - new Vector2(pObjCenter3.X, pObjCenter3.Y);
 }
Exemplo n.º 2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            Ray ray = GetRay(Camera, e);
            //

            //if (!result)
            //    return;
            if (rObject != null && rObject.HasBehaviour(typeof(MouseDraggingBehaviour).Name))
            {
                rObject.ProcessMouseEvent(MouseEventType.MouseMove, e);
                return;
            }
            bool result = Game.CurrentRenderer.Scene.CheckIntersection(ray, out rObject);
            if (result)
                rObject.ProcessMouseEvent(MouseEventType.MouseMove, e);
        }
Exemplo n.º 3
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            Contract.Requires(Camera != null);
            base.OnMouseDown(e);
            Ray ray = GetRay(Camera, e);
            LogEvent.UserInterface.Log(ray.ToString());

            bool result = Game.CurrentRenderer.Scene.CheckIntersection(ray, out rObject);

            if (!result)
            {
                LogEvent.UserInterface.Log("Intersection failed)");
            }
            else
            {
                LogEvent.UserInterface.Log("Intersected [" + rObject.Name + "]");
                rObject.ProcessMouseEvent(MouseEventType.MouseDown, e);
            }
        }
Exemplo n.º 4
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (OwnerGrid.SnapToGrid)
            {
                targetControl.Position = SelectionRectangle.SnapPositionToGrid(targetControl.Position,
                    OwnerGrid.GridSpacing);
                targetControl.Size = SelectionRectangle.SnapSizeToGrid(targetControl.Size, OwnerGrid.GridSpacing);
            }

            base.OnMouseUp(e);
            UpdatePositionDependantParameters();

            OdysseyUI.CurrentHud.CaptureControl = null;
            drag = false;
            IsVisible = true;
        }
Exemplo n.º 5
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (!drag) return;

            const int minimumSize = 10;

            Vector2 prevPosition = targetControl.Position;
            Vector2 newPosition;
            Size prevSize = targetControl.Size;
            Size newSize;
            Vector2 currentPosition = e.Location;
            Vector2 delta = currentPosition - dragStartPosition;

            switch (previousIntersection)
            {
                case IntersectionLocation.None:
                    break;

                case IntersectionLocation.Inner:
                    targetControl.Position += delta;
                    Position += delta;
                    break;

                case IntersectionLocation.CornerNW:
                    height = (int)((initialPosition.Y - currentPosition.Y + initialSize.Height));
                    width = (int)(initialPosition.X - currentPosition.X + initialSize.Width);

                    newSize = new Size(width, height);
                    newPosition = new Vector2(currentPosition.X, currentPosition.Y);

                    if (newSize.Width <= minimumSize || currentPosition.X >= initialPosition.X + initialSize.Width - minimumSize)
                    {
                        newSize.Width = minimumSize;
                        newPosition.X = initialPosition.X + initialSize.Width - minimumSize;
                    }

                    if (newSize.Height <= minimumSize || currentPosition.Y >= initialPosition.Y + initialSize.Height - minimumSize)
                    {
                        newSize.Height = minimumSize;
                        newPosition.Y = initialPosition.Y + initialSize.Height - minimumSize;
                    }

                    targetControl.Position = newPosition;
                    targetControl.Size = newSize;

                    break;

                    case IntersectionLocation.Top:
                    height = (int)((initialPosition.Y - currentPosition.Y + initialSize.Height));

                    newSize = new Size(prevSize.Width, height);
                    newPosition = new Vector2(prevPosition.X, currentPosition.Y);

                    if (newSize.Height <= minimumSize || currentPosition.Y >= initialPosition.Y + initialSize.Height - minimumSize)
                    {
                        newSize.Height = minimumSize;
                        newPosition.Y = initialPosition.Y + initialSize.Height - minimumSize;
                    }

                    targetControl.Position = newPosition;
                    targetControl.Size = newSize;

                    //System.Diagnostics.Debug.WriteLine("{1}) H:{0} Y:{2} P:{3}", newSize.Height, t++, targetControl.Position.Y, targetControl.Position.Y + targetControl.Size.Height);
                    break;

                case IntersectionLocation.Bottom:
                    height = (int) (currentPosition.Y - initialPosition.Y);
                    newSize = new Size(prevSize.Width, height);

                    if (newSize.Height <= minimumSize || currentPosition.Y <= initialPosition.Y + minimumSize)
                    {
                        newSize.Height = minimumSize;
                    }
                    targetControl.Size = newSize;
                    break;

                case IntersectionLocation.CornerNE:
                    height = (int)((initialPosition.Y - currentPosition.Y + initialSize.Height));
                    width = (int)(currentPosition.X - initialPosition.X);

                    newSize = new Size(width, height);
                    newPosition = new Vector2(prevPosition.X, currentPosition.Y);

                    if (newSize.Height <= minimumSize || currentPosition.Y >= initialPosition.Y + initialSize.Height - minimumSize)
                    {
                        newSize.Height = minimumSize;
                        newPosition.Y = initialPosition.Y + initialSize.Height - minimumSize;
                    }

                    if (newSize.Width <= minimumSize || currentPosition.X <= initialPosition.X + minimumSize)
                        newSize.Width = minimumSize;

                    targetControl.Position = newPosition;
                    targetControl.Size = newSize;
                    break;

                case IntersectionLocation.Right:
                    width = (int)(currentPosition.X - initialPosition.X);
                    newSize = new Size(width, prevSize.Height);

                    if (newSize.Width <= minimumSize || currentPosition.X <= initialPosition.X + minimumSize)
                        newSize.Width = minimumSize;

                    targetControl.Size = newSize;
                    //width = targetControl.ClientSize.Width;
                    break;

                case IntersectionLocation.CornerSE:
                    width = (int)(currentPosition.X - initialPosition.X);
                    height = (int) (currentPosition.Y - initialPosition.Y);
                    newSize = new Size(width, height);

                    if (newSize.Height <= minimumSize || currentPosition.Y <= initialPosition.Y + minimumSize)
                    {
                        newSize.Height = minimumSize;
                    }
                    if (newSize.Width <= minimumSize || currentPosition.X <= initialPosition.X + minimumSize)
                        newSize.Width = minimumSize;

                    targetControl.Size = newSize;

                    break;

                case IntersectionLocation.CornerSW:
                    width = (int)(initialPosition.X - currentPosition.X  +initialSize.Width);
                    height = (int) (currentPosition.Y - initialPosition.Y);
                    newSize = new Size(width, height);

                    newPosition = new Vector2(currentPosition.X, prevPosition.Y);
                    if (newSize.Width <= minimumSize || currentPosition.X >= initialPosition.X + initialSize.Width - minimumSize)
                    {
                        newSize.Width = minimumSize;
                        newPosition.X = initialPosition.X + initialSize.Width - minimumSize;
                    }
                    if (newSize.Height <= minimumSize || currentPosition.Y <= initialPosition.Y + minimumSize)
                    {
                        newSize.Height = minimumSize;
                    }

                    targetControl.Position = newPosition;
                    targetControl.Size = newSize;
                    break;

                case IntersectionLocation.Left:
                    width = (int)(initialPosition.X - currentPosition.X  +initialSize.Width);
                    newSize = new Size(width, prevSize.Height);
                    newPosition = new Vector2(currentPosition.X, prevPosition.Y);

                    if (newSize.Width <= minimumSize || currentPosition.X >= initialPosition.X + initialSize.Width - minimumSize)
                    {
                        newSize.Width = minimumSize;
                        newPosition.X = initialPosition.X + initialSize.Width - minimumSize;
                    }

                    targetControl.Position = newPosition;
                    targetControl.Size = newSize;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
            {
                dragStartPosition = currentPosition;
            }
        }
Exemplo n.º 6
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            IsVisible = false;

            OdysseyUI.CurrentHud.CaptureControl = this;
            //if (previousIntersection != IntersectionLocation.None)
            //{
                drag = true;
                dragStartPosition = e.Location;
            initialSize = targetControl.Size;
            initialPosition = targetControl.Position;
            //width = initialSize.Width;
            //height = initialSize.Height;

            //}
        }
Exemplo n.º 7
0
 static Ray GetRay(ICamera camera, MouseEventArgs e)
 {
     Vector2 p = e.Location;
     Matrix mWVP = camera.WorldViewProjection;
     Viewport viewport = camera.Viewport;
     Vector3 vNear = Vector3.Unproject(new Vector3(p, 0), viewport.X, viewport.Y,
         viewport.Width, viewport.Height, viewport.MinZ, viewport.MaxZ, mWVP);
     Vector3 vFar = Vector3.Unproject(new Vector3(p, 1), viewport.X, viewport.Y,
         viewport.Width, viewport.Height, viewport.MinZ, viewport.MaxZ, mWVP);
     return new Ray(vNear, vFar - vNear);
 }
Exemplo n.º 8
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            Ray ray = GetRay(Camera, e);
            IRenderable rObject;
            bool result = Game.CurrentRenderer.Scene.CheckIntersection(ray, out rObject);

            if (!result)
                return;
            rObject.ProcessMouseEvent(MouseEventType.MouseUp, e);
        }
Exemplo n.º 9
0
 protected override void OnMouseLeave(MouseEventArgs e)
 {
     base.OnMouseLeave(e);
     if (OdysseyUI.CurrentHud.ClickedControl == null)
     {
         dropDownButton.IsHighlighted = false;
     }
 }
Exemplo n.º 10
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     base.OnMouseDown(e);
     if (!droppedDown)
     {
         OnDropDown(EventArgs.Empty);
         dropDownButton.IsSelected = true;
     }
     else
     {
         dropDownButton.IsSelected = false;
         OnDropDownClosed(EventArgs.Empty);
     }
 }
Exemplo n.º 11
0
        void IMouseBehaviour.OnMouseMove(object sender, MouseEventArgs e)
        {
            if (!isDragging)
                return;

            Viewport viewport = camera.Viewport;

            Vector2 pNewPosition2 = new Vector2(e.Location.X, e.Location.Y) - pOffset;
            Vector3 pNear = Vector3.Unproject(new Vector3(pNewPosition2.X, pNewPosition2.Y, 0), viewport.X, viewport.Y, viewport.Width, viewport.Height, viewport.MinZ, viewport.MaxZ,
                              camera.WorldViewProjection);
            Vector3 pFar = Vector3.Unproject(new Vector3(pNewPosition2.X, pNewPosition2.Y, 1), viewport.X, viewport.Y, viewport.Width, viewport.Height, viewport.MinZ, viewport.MaxZ,
                              camera.WorldViewProjection);
            Ray r = new Ray(pNear, pFar - pNear);
            //Ray r = new Ray(pNear, camera.ViewVector);
            Plane p = new Plane(RenderableObject.AbsolutePosition, Vector3.UnitY);

            float distance;
            bool result2 = Ray.Intersects(r, p, out distance);
            Vector3 pIntersection = r.Position + distance * Vector3.Normalize(r.Direction);

            if (result2)
                ((TransformNode)(RenderableObject.ParentNode.Parent)).Position = new Vector3(pIntersection.X, RenderableObject.AbsolutePosition.Y, pIntersection.Z);
        }
Exemplo n.º 12
0
 void IMouseBehaviour.OnMouseClick(object sender, MouseEventArgs e)
 {
     return;
 }
Exemplo n.º 13
0
 void IMouseBehaviour.OnMouseUp(object sender, MouseEventArgs e)
 {
     isDragging = false;
 }