예제 #1
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     if (EditMode == EEditMode.Pan)
     {
         dragging = true;
         dragStartPoint = e.Location;
     }
     else if (EditMode == EEditMode.Transform)
     {
         Point p = e.Location;
         Rectangle r = (CurrentItem.GetCompByType(typeof(Transform)) as Transform).GetOrthoBox();
         Rectangle camR = camera.RectangleToScreen(r);
         transType = TransHelper.CheckTransformRect(camR, p);
         if (transType != ETransformType.None)
         {
             dragStartPoint = p;
             dragging = true;
         }
         else
         {
             EditMode = EEditMode.Idle;
         }
     }
 }
예제 #2
0
        public static Rectangle GetTransformRect(Rectangle r, ETransformType errt)
        {
            switch (errt)
            {
                case ETransformType.TopLeft:
                    return new Rectangle(r.X - 4, r.Y - 4, 8, 8);
                case ETransformType.TopRight:
                    return new Rectangle(r.X + r.Width - 4, r.Y - 4, 8, 8);
                case ETransformType.BottomLeft:
                    return new Rectangle(r.X - 4, r.Y + r.Height - 4, 8, 8);
                case ETransformType.BottomRight:
                    return new Rectangle(r.X + r.Width - 4, r.Y + r.Height - 4, 8, 8);

                case ETransformType.Top:
                    if (r.Width < 8)
                        return new Rectangle();
                    else
                        return new Rectangle(r.X + 4, r.Y - 1, r.Width - 8, 3);
                case ETransformType.Bottom:
                    if (r.Width < 8)
                        return new Rectangle();
                    else
                        return new Rectangle(r.X + 4, r.Y + r.Height - 1, r.Width - 8, 3);
                case ETransformType.Left:
                    if (r.Height < 8)
                        return new Rectangle();
                    else
                        return new Rectangle(r.X - 1, r.Y + 4, 3, r.Height - 8);
                case ETransformType.Right:
                    if (r.Height < 8)
                        return new Rectangle();
                    else
                        return new Rectangle(r.X + r.Width - 1, r.Y + 4, 3, r.Height - 8);
                case ETransformType.Middle:
                    if (r.Height < 8 || r.Width < 8)
                        return new Rectangle();
                    else
                        return new Rectangle(r.X + 4, r.Y + 4, r.Width - 8, r.Height - 8);
                case ETransformType.Center:
                    // TODO
                    return new Rectangle();
            }
            return new Rectangle();
        }
예제 #3
0
 public Transform(FAssetArchive Ar)
 {
     SourceText    = new FText(Ar);
     TransformType = Ar.Read <ETransformType>();
 }
예제 #4
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     if (EditMode == EEditMode.Pan)
     {
         dragging = true;
         dragStartPoint = e.Location;
     }
     else if (EditMode == EEditMode.TransformTexture)
     {
         Point p = e.Location;
         Rectangle r = animTexture.GetAABB();
         Rectangle camR = camera.RectangleToScreen(r);
         transType = TransHelper.CheckTransformRect(camR, p);
         if (transType != ETransformType.None)
         {
             dragStartPoint = p;
             dragging = true;
         }
         else
         {
             EditMode = EEditMode.Idle;
         }
     }
     else if (EditMode == EEditMode.TransformBody)
     {
         Point p = e.Location;
         Rectangle r = physicsBody.GetAABB();
         Rectangle camR = camera.RectangleToScreen(r);
         transType = TransHelper.CheckTransformRect(camR, p);
         if (transType != ETransformType.None)
         {
             dragStartPoint = p;
             dragging = true;
         }
         else
         {
             EditMode = EEditMode.Idle;
         }
     }
 }
예제 #5
0
 internal Transform(PackageReader reader)
 {
     SourceText    = new FText(reader);
     TransformType = (ETransformType)reader.ReadByte();
 }
예제 #6
0
        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if (!dragging) return;
            if (Action == EAction.FreeCamera)
            {
                Vector2 screenDelta = new Vector2(Mouse.X - dragStartPoint.X, Mouse.Y - dragStartPoint.Y);
                Vector2 worldDelta = ModuleSharer.SceneMgr.Camera.VectorToWorld(screenDelta);
                Camera c = SceneManager.Camera;
                c.SetAbsFocus(new Vector2(c.Focus.X - worldDelta.X, c.Focus.Y - worldDelta.Y));
                dragStartPoint = new Point(Mouse.X, Mouse.Y);
            }
            else if (Action == EAction.Create)
            {
                Vector2 camDelta = new Vector2(Mouse.X - dragStartPoint.X, Mouse.Y - dragStartPoint.Y);
                Vector2 worldDelta = ModuleSharer.SceneMgr.Camera.VectorToScreen(camDelta);
                if (SelectedItem == null && worldDelta.X != 0 && worldDelta.Y != 0)
                {
                    // Create an instance
                    Item item = new Item(penTexturePath);
                    if (item == null)
                    {
                        Console.WriteLine("错误:Item创建失败");
                        return;
                    }

                    // Set an unique name
                    NameHelper.RestartNameInc(0);
                    String name = "";
                    bool occupied = true;
                    List<Item> allItems = SceneManager.GetAllItems();
                    while(occupied)
                    {
                        name = NameHelper.GetNextName("Item");
                        occupied = false;
                        foreach (Item i in allItems)
                        {
                            if (i.Name == name)
                                occupied = true;
                        }
                    }
                    item.Name = name;

                    // Resize to drag rectangle
                    item.Size = new Vector2(worldDelta.X, worldDelta.Y);
                    // Set initial position
                    Vector2 camDragPoint =
                        new Vector2(dragStartPoint.X, dragStartPoint.Y);
                    Vector2 worldDragPoint =  ModuleSharer.SceneMgr.Camera.PositionToWorld(camDragPoint);
                    Vector2 worldCreatePoint = new Vector2(worldDragPoint.X + item.Size.X / 2, worldDragPoint.Y + item.Size.Y / 2);

                    item.Position = worldCreatePoint;
                    // Add to scene
                    SceneManager.AddItem(SelectedGroup, item);

                    // Change to Transform tool immediately
                    action = EAction.Transform;
                    transType = ETransformType.BottomRight;
                    dragStartPoint = new Point(Mouse.X, Mouse.Y);
                    // Set current item to transform it
                    List<Item> il = new List<Item>();
                    il.Add(item);
                    SetSelectedItem(il);

                }
            }
            else if (Action == EAction.Select || Action == EAction.Delete)
            {
                Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle(
                    (int)dragStartPoint.X, (int)dragStartPoint.Y, (int)(Mouse.X - dragStartPoint.X), (int)(Mouse.Y - dragStartPoint.Y));

                SetDrag(true, rect);
            }
            else if (Action == EAction.Transform && SelectedItem != null)
            {
                Vector2 screenDelta = new Vector2(Mouse.X - dragStartPoint.X, Mouse.Y - dragStartPoint.Y);
                Vector2 worldDelta = ModuleSharer.SceneMgr.Camera.VectorToWorld(screenDelta) ;
                SelectedItem.Transform(transType, worldDelta);
                dragStartPoint = new Point(Mouse.X, Mouse.Y);
            }
        }
예제 #7
0
 protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
 {
     if (Action == EAction.FreeCamera || Action == EAction.Select || Action == EAction.Delete || Action == EAction.Create)
     {
         dragging = true;
         dragStartPoint = new Point(Mouse.X, Mouse.Y);
         // setSelectedItem(null);
     }
     else if (Action == EAction.Transform && SelectedItem != null)
     {
         Rectangle worldAABB = SelectedItem.GetAABB();
         Rectangle camAABB = ModuleSharer.SceneMgr.Camera.RectangleToScreen(worldAABB);
         Point p = new Point(Mouse.X, Mouse.Y);
         transType = TransHelper.CheckTransformRect(camAABB, new System.Drawing.Point(p.X, p.Y));
         if (transType != ETransformType.None)
         {
             dragStartPoint = p;
             dragging = true;
         }
         else
         {
             action = EAction.Select;
         }
     }
 }
예제 #8
0
        public static void Transform(ETransformType ett, Vector2 pDelta, Transform trans)
        {
            switch (ett)
            {
                case ETransformType.TopLeft:
                    trans.Size = new Vector2((float)Math.Max(trans.Size.X - pDelta.X, 1.0f), (float)Math.Max(trans.Size.Y - pDelta.Y, 1.0f));
                    // Keep the position of the Bottom Right corner
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2f, trans.Position.Y + pDelta.Y / 2f);
                    break;
                case ETransformType.TopRight:
                    trans.Size = new Vector2((float)Math.Max(trans.Size.X + pDelta.X, 1.0f), (float)Math.Max(trans.Size.Y - pDelta.Y, 1));
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2f, trans.Position.Y + pDelta.Y / 2);
                    break;
                case ETransformType.BottomLeft:
                    trans.Size = new Vector2((float)Math.Max(trans.Size.X - pDelta.X, 1.0f), (float)Math.Max(trans.Size.Y + pDelta.Y, 1.0f));
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2f, trans.Position.Y + pDelta.Y / 2f);
                    break;
                case ETransformType.BottomRight:
                    trans.Size = new Vector2((float)Math.Max(trans.Size.X + pDelta.X, 1f), (float)Math.Max(trans.Size.Y + pDelta.Y, 1f));
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2f, trans.Position.Y + pDelta.Y / 2f);
                    break;

                case ETransformType.Top:
                    trans.Size = new Vector2(trans.Size.X, trans.Size.Y - pDelta.Y);
                    trans.Position = new Vector2(trans.Position.X, trans.Position.Y + pDelta.Y / 2);
                    break;
                case ETransformType.Bottom:
                    trans.Size = new Vector2(trans.Size.X, trans.Size.Y + pDelta.Y);
                    trans.Position = new Vector2(trans.Position.X, trans.Position.Y + pDelta.Y / 2);
                    break;
                case ETransformType.Left:
                    trans.Size = new Vector2(trans.Size.X - pDelta.X, trans.Size.Y);
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2, trans.Position.Y);
                    break;
                case ETransformType.Right:
                    trans.Size = new Vector2(trans.Size.X + pDelta.X, trans.Size.Y);
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2, trans.Position.Y);
                    break;

                case ETransformType.Middle:
                    trans.Position = new Vector2(trans.Position.X + pDelta.X, trans.Position.Y + pDelta.Y);
                    break;
            }
        }