Example #1
0
        public ManipulateResult TryManipulate(IEntityState _state, Point location, System.Windows.Forms.MouseButtons button, System.Windows.Forms.Keys modifiers)
        {
            State state = _state as State;

            if (state == null)
            {
                return(null);
            }

            ManipulateResult result  = new ManipulateResult();
            ManipulateParams mparams = new ManipulateParams();

            result.Params = mparams;

            if (button == System.Windows.Forms.MouseButtons.Right)
            {
                result.Target          = state;
                mparams.AbsoluteDrag   = true;
                mparams.AbsoluteOffset = new PointF(location.X - state.Location.X, location.Y - state.Location.Y);
            }
            else
            {
                if (!MathUtil.IsPointInPoint(location, state.Location, 4))
                {
                    return(null);
                }

                result.Target        = state;
                mparams.AbsoluteDrag = false;
            }

            return(result);
        }
Example #2
0
        public ManipulateResult TryManipulate(IEntityState _state, Point location, System.Windows.Forms.MouseButtons button, System.Windows.Forms.Keys modifiers)
        {
            State state = _state as State;

            if (state == null)
            {
                return(null);
            }

            ManipulateResult result  = new ManipulateResult();
            ManipulateParams mparams = new ManipulateParams();

            result.Params = mparams;

            if (button == System.Windows.Forms.MouseButtons.Right)
            {
                result.Target          = state;
                mparams.AbsoluteDrag   = true;
                mparams.AbsoluteOffset = new PointF(location.X - state.Bounds.X, location.Y - state.Bounds.Y);
            }
            else
            {
                mparams.CornerGrabbed = state.HandleAtLocation(location);

                if (mparams.CornerGrabbed == -1)
                {
                    return(null);
                }

                result.Target        = state;
                mparams.AbsoluteDrag = false;
            }

            return(result);
        }
Example #3
0
            public void Move(PointF target, ManipulateParams mparams)
            {
                var x1 = Bounds.X;
                var x2 = Bounds.X + Bounds.Width;
                var y1 = Bounds.Y;
                var y2 = Bounds.Y + Bounds.Height;

                if (!mparams.AbsoluteDrag)
                {
                    switch (mparams.CornerGrabbed)
                    {
                    case 0:
                        x1 = target.X;
                        y1 = target.Y;
                        break;

                    case 1:
                        x2 = target.X;
                        y1 = target.Y;
                        break;

                    case 2:
                        x2 = target.X;
                        y2 = target.Y;
                        break;

                    case 3:
                        x1 = target.X;
                        y2 = target.Y;
                        break;
                    }
                }
                else
                {
                    target = new PointF(
                        target.X - mparams.AbsoluteOffset.X,
                        target.Y - mparams.AbsoluteOffset.Y);

                    x1 = target.X;
                    y1 = target.Y;
                }

                Bounds.X = x1;
                Bounds.Y = y1;
                if (!mparams.AbsoluteDrag)
                {
                    Bounds.Width  = x2 - x1;
                    Bounds.Height = y2 - y1;

                    if (mparams.KeepAspectRatio)
                    {
                        Bounds.Size = MathUtil.fitToSize(TexWidth, TexHeight, Bounds.Width, Bounds.Height);
                    }
                }
            }
Example #4
0
            public void Move(PointF target, ManipulateParams mparams)
            {
                var x1 = Location.X;
                var x2 = Location.X + Program.ActiveProject.Width * Scale;
                var y1 = Location.Y;
                var y2 = Location.Y + Program.ActiveProject.Height * Scale;

                RectangleF Bounds = new RectangleF(Location, new SizeF(Program.ActiveProject.Width * Scale, Program.ActiveProject.Height * Scale));

                if (!mparams.AbsoluteDrag)
                {
                    switch (mparams.CornerGrabbed)
                    {
                    case 0:
                        x1 = target.X;
                        y1 = target.Y;
                        break;

                    case 1:
                        x2 = target.X;
                        y1 = target.Y;
                        break;

                    case 2:
                        x2 = target.X;
                        y2 = target.Y;
                        break;

                    case 3:
                        x1 = target.X;
                        y2 = target.Y;
                        break;
                    }
                }
                else
                {
                    target = new PointF(
                        target.X - mparams.AbsoluteOffset.X,
                        target.Y - mparams.AbsoluteOffset.Y);

                    x1 = target.X;
                    y1 = target.Y;
                }

                Location.X = x1;
                Location.Y = y1;

                if (!mparams.AbsoluteDrag)
                {
                    Bounds.Width  = x2 - x1;
                    Bounds.Height = y2 - y1;
                }

                Scale = Math.Min(Bounds.Width / Program.ActiveProject.Width, Bounds.Height / Program.ActiveProject.Height);
            }
Example #5
0
 public void Move(PointF target, ManipulateParams mparams)
 {
     if (mparams.AbsoluteDrag)
     {
         Location = new PointF(target.X - mparams.AbsoluteOffset.X, target.Y - mparams.AbsoluteOffset.Y);
     }
     else
     {
         Location = target;
     }
 }
Example #6
0
 public void Move(PointF target, ManipulateParams mparams)
 {
     if (mparams.AbsoluteDrag)
     {
         Location = new PointF(target.X - mparams.AbsoluteOffset.X, target.Y - mparams.AbsoluteOffset.Y);
     }
     else
     {
         Location = target;
     }
 }
Example #7
0
 public void Move(PointF target, ManipulateParams mparams)
 {
     if (mparams.AbsoluteDrag)
     {
         Handle1 = new PointF(target.X - mparams.Handle1Offset.X, target.Y - mparams.Handle1Offset.Y);
         Handle2 = new PointF(target.X - mparams.Handle2Offset.X, target.Y - mparams.Handle2Offset.Y);
     }
     else
     {
         if (mparams.HandleGrabbed == 0)
             Handle1 = target;
         else
             Handle2 = target;
     }
 }
Example #8
0
        public ManipulateResult TryManipulate(IEntityState _state, Point location, System.Windows.Forms.MouseButtons button, System.Windows.Forms.Keys modifiers)
        {
            State state = _state as State;

            if (state == null)
            {
                return(null);
            }

            ManipulateResult result  = new ManipulateResult();
            ManipulateParams mparams = new ManipulateParams();

            result.Params = mparams;

            mparams.AbsoluteOffset = new List <PointF>();

            if (button == System.Windows.Forms.MouseButtons.Right)
            {
                result.Target        = state;
                mparams.AbsoluteDrag = true;

                for (int i = 0; i < state.Points.Count; i++)
                {
                    mparams.AbsoluteOffset.Add(new PointF(location.X - state.Points[i].X, location.Y - state.Points[i].Y));
                }
            }
            else
            {
                for (int i = 0; i < state.Points.Count; i++)
                {
                    if (MathUtil.IsPointInPoint(location, state.Points[i], 4))
                    {
                        result.Target      = state.Points[i];
                        mparams.PointIndex = i;
                    }
                }

                if (result.Target == null)
                {
                    return(null);
                }

                result.Target        = state;
                mparams.AbsoluteDrag = false;
            }

            return(result);
        }
Example #9
0
 public void Move(PointF target, ManipulateParams mparams)
 {
     if(mparams.AbsoluteDrag)
     {
         for (int i = 0; i < Points.Count; i++)
         {
             Points[i] = new PointF(
                 target.X - mparams.AbsoluteOffset[i].X,
                 target.Y - mparams.AbsoluteOffset[i].Y);
         }
     }
     else
     {
         Points[mparams.PointIndex] = target;
     }
 }
Example #10
0
 public void Move(PointF target, ManipulateParams mparams)
 {
     if (mparams.AbsoluteDrag)
     {
         for (int i = 0; i < Points.Count; i++)
         {
             Points[i] = new PointF(
                 target.X - mparams.AbsoluteOffset[i].X,
                 target.Y - mparams.AbsoluteOffset[i].Y);
         }
     }
     else
     {
         Points[mparams.PointIndex] = target;
     }
 }
Example #11
0
            public void Move(PointF target, ManipulateParams mparams)
            {
                var x1 = Bounds.X;
                var x2 = Bounds.X + Bounds.Width;
                var y1 = Bounds.Y;
                var y2 = Bounds.Y + Bounds.Height;

                if (!mparams.AbsoluteDrag)
                {
                    switch (mparams.CornerGrabbed)
                    {
                        case 0:
                            x1 = target.X;
                            y1 = target.Y;
                            break;
                        case 1:
                            x2 = target.X;
                            y1 = target.Y;
                            break;
                        case 2:
                            x2 = target.X;
                            y2 = target.Y;
                            break;
                        case 3:
                            x1 = target.X;
                            y2 = target.Y;
                            break;
                    }
                }
                else
                {
                    target = new PointF(
                               target.X - mparams.AbsoluteOffset.X,
                               target.Y - mparams.AbsoluteOffset.Y);

                    x1 = target.X;
                    y1 = target.Y;
                }

                Bounds.X = x1;
                Bounds.Y = y1;
                if (!mparams.AbsoluteDrag)
                {
                    Bounds.Width = x2 - x1;
                    Bounds.Height = y2 - y1;
                }
            }
Example #12
0
 public void Move(PointF target, ManipulateParams mparams)
 {
     if (mparams.AbsoluteDrag)
     {
         Handle1 = new PointF(target.X - mparams.Handle1Offset.X, target.Y - mparams.Handle1Offset.Y);
         Handle2 = new PointF(target.X - mparams.Handle2Offset.X, target.Y - mparams.Handle2Offset.Y);
     }
     else
     {
         if (mparams.HandleGrabbed == 0)
         {
             Handle1 = target;
         }
         else
         {
             Handle2 = target;
         }
     }
 }
Example #13
0
        public ManipulateResult TryManipulate(IEntityState _state, Point location, System.Windows.Forms.MouseButtons button, System.Windows.Forms.Keys modifiers, bool fromEditor)
        {
            State state = _state as State;

            if (state == null)
            {
                return(null);
            }

            ManipulateResult result  = new ManipulateResult();
            ManipulateParams mparams = new ManipulateParams();

            result.Params = mparams;

            if (fromEditor)
            {
                mparams.DisableIK = true;
            }

            if (button == MouseButtons.Right)
            {
                result.Target          = state.Root;
                mparams.AbsoluteDrag   = true;
                mparams.AbsoluteOffset = new PointF(location.X - state.Root.Location.X, location.Y - state.Root.Location.Y);
            }
            else
            {
                Joint.State target = state.Root.JointAtLocation(location);

                if (target == null)
                {
                    return(null);
                }

                result.Target        = target;
                mparams.AbsoluteDrag = false;
            }

            return(result);
        }
Example #14
0
        public ManipulateResult TryManipulate(IEntityState _state, Point location, MouseButtons button, Keys modifiers)
        {
            State state = _state as State;

            if (state == null)
            {
                return(null);
            }

            ManipulateResult result  = new ManipulateResult();
            ManipulateParams mparams = new ManipulateParams();

            result.Params = mparams;

            if (modifiers == Keys.Shift)
            {
                mparams.PivotDrag = true;
            }
            else if (modifiers == Keys.Alt)
            {
                mparams.DisableIK = true;
            }

            if (button == MouseButtons.Right)
            {
                result.Target          = state.Root;
                mparams.AbsoluteDrag   = true;
                mparams.AbsoluteOffset = new PointF(location.X - state.Root.Location.X, location.Y - state.Root.Location.Y);
            }
            else
            {
                Joint.State target = state.Root.JointAtLocation(location);

                if (target == null)
                {
                    return(null);
                }

                if (mparams.PivotDrag && target.Parent != null)
                {
                    mparams.PivotLength = (float)MathUtil.Length(target.Location, target.Parent.Location);
                    mparams.PivotAngle  = (float)MathUtil.Angle(target.Location, target.Parent.Location);

                    // you need to go through every descendant (not child) of target here and store their angle and distance to target's parent
                    mparams.PivotInfo = new Dictionary <Joint.State, Tuple <float, float> >();
                    Stack <Joint.State> open = new Stack <Joint.State>();
                    open.Push(target);

                    while (open.Count > 0)
                    {
                        Joint.State current = open.Pop();

                        foreach (Joint.State child in current.Children)
                        {
                            open.Push(child);

                            float distance = (float)MathUtil.Length(target.Parent.Location, child.Location);
                            float angle    = (float)MathUtil.Angle(child.Location, target.Parent.Location);                          // or the other way around, depends

                            mparams.PivotInfo[child] = new Tuple <float, float>(distance, angle);
                        }
                    }
                }

                result.Target        = target;
                mparams.AbsoluteDrag = false;
            }

            return(result);
        }
Example #15
0
        public ManipulateResult TryManipulate(IEntityState _state, Point location, System.Windows.Forms.MouseButtons button, System.Windows.Forms.Keys modifiers)
        {
            State state = _state as State;

            if (state == null)
                return null;

            ManipulateResult result = new ManipulateResult();
            ManipulateParams mparams = new ManipulateParams();
            result.Params = mparams;

            if (button == System.Windows.Forms.MouseButtons.Right)
            {
                result.Target = state;
                mparams.AbsoluteDrag = true;
                mparams.AbsoluteOffset = new PointF(location.X - state.Bounds.X, location.Y - state.Bounds.Y);
            }
            else
            {
                mparams.CornerGrabbed = state.HandleAtLocation(location);

                if (mparams.CornerGrabbed == -1)
                    return null;

                result.Target = state;
                mparams.AbsoluteDrag = false;
            }

            return result;
        }
Example #16
0
                public void Move(PointF target, ManipulateParams mparams, State from)
                {
                    List <State> affected = new List <State>();

                    if (Parent != null && from != Parent)
                    {
                        affected.Add(Parent);
                    }

                    foreach (State child in Children)
                    {
                        if (child != from)
                        {
                            affected.Add(child);
                        }
                    }

                    if (mparams.AbsoluteDrag && from == null)
                    {
                        target = new PointF(
                            target.X - mparams.AbsoluteOffset.X,
                            target.Y - mparams.AbsoluteOffset.Y);
                    }

                    if (!mparams.PivotDrag)
                    {
                        float nx = target.X;
                        float ny = target.Y;

                        float ox = Location.X;
                        float oy = Location.Y;

                        Location = target;

                        foreach (State state in affected)
                        {
                            PointF loc;

                            if (mparams.AbsoluteDrag)
                            {
                                loc = new PointF(
                                    state.Location.X + (nx - ox),
                                    state.Location.Y + (ny - oy)
                                    );
                            }
                            else
                            {
                                if (mparams.DisableIK)
                                {
                                    return;
                                }

                                float jx = state.Location.X;
                                float jy = state.Location.Y;

                                float dx = ox - jx;
                                float dy = oy - jy;
                                float dm = (float)Math.Sqrt((double)(dx * dx + dy * dy));

                                float lx = jx - nx;
                                float ly = jy - ny;
                                float lm = (float)Math.Sqrt((double)(lx * lx + ly * ly));

                                loc = new PointF(nx + (lx / lm) * dm, ny + (ly / lm) * dm);
                            }

                            state.Move(loc, mparams, this);
                        }
                    }
                    else
                    {
                        if (Parent != null)
                        {
                            float dx = target.X - Parent.Location.X;
                            float dy = target.Y - Parent.Location.Y;

                            float length = (float)Math.Sqrt(dx * dx + dy * dy);

                            dx /= length;
                            dy /= length;

                            dx *= mparams.PivotLength;
                            dy *= mparams.PivotLength;

                            Location = new PointF(Parent.Location.X + dx, Parent.Location.Y + dy);

                            float angleDiff = (float)MathUtil.Angle(Location, Parent.Location) - mparams.PivotAngle;

                            Stack <State> open = new Stack <State>();
                            open.Push(this);

                            while (open.Count > 0)
                            {
                                State current = open.Pop();

                                foreach (State child in current.Children)
                                {
                                    open.Push(child);
                                    var info = mparams.PivotInfo[child];

                                    float angle = info.Item2 + angleDiff;
                                    float x     = (float)(Parent.Location.X + Math.Cos(angle) * info.Item1);
                                    float y     = (float)(Parent.Location.Y + Math.Sin(angle) * info.Item1);                                  // or maybe the other way around, depends
                                    child.Location = new PointF(x, y);
                                }
                            }
                        }
                        else
                        {
                            Stack <State> open = new Stack <State>();
                            open.Push(this);

                            while (open.Count > 0)
                            {
                                State current = open.Pop();

                                foreach (State child in current.Children)
                                {
                                    open.Push(child);

                                    child.Location = new PointF(
                                        child.Location.X + (target.X - Location.X),
                                        child.Location.Y + (target.Y - Location.Y));
                                }
                            }

                            Location = target;
                        }
                    }
                }
Example #17
0
        public ManipulateResult TryManipulate(IEntityState _state, Point location, System.Windows.Forms.MouseButtons button, System.Windows.Forms.Keys modifiers)
        {
            State state = _state as State;

            if (state == null)
                return null;

            ManipulateResult result = new ManipulateResult();
            ManipulateParams mparams = new ManipulateParams();
            result.Params = mparams;

            if (button == System.Windows.Forms.MouseButtons.Right)
            {
                result.Target = state;
                mparams.AbsoluteDrag = true;
                mparams.AbsoluteOffset = new PointF(location.X - state.Location.X, location.Y - state.Location.Y);
            }
            else
            {
                if (!MathUtil.IsPointInPoint(location, state.Location, 4))
                    return null;

                result.Target = state;
                mparams.AbsoluteDrag = false;
            }

            return result;
        }
Example #18
0
        public ManipulateResult TryManipulate(IEntityState _state, Point location, System.Windows.Forms.MouseButtons button, System.Windows.Forms.Keys modifiers)
        {
            State state = _state as State;

            if (state == null)
                return null;

            ManipulateResult result = new ManipulateResult();
            ManipulateParams mparams = new ManipulateParams();
            result.Params = mparams;

            mparams.AbsoluteOffset = new List<PointF>();

            if (button == System.Windows.Forms.MouseButtons.Right)
            {
                result.Target = state;
                mparams.AbsoluteDrag = true;

                for(int i = 0; i < state.Points.Count; i++)
                    mparams.AbsoluteOffset.Add(new PointF(location.X - state.Points[i].X, location.Y - state.Points[i].Y));
            }
            else
            {
                for (int i = 0; i < state.Points.Count; i++)
                {
                    if (MathUtil.IsPointInPoint(location, state.Points[i], 4))
                    {
                        result.Target = state.Points[i];
                        mparams.PointIndex = i;
                    }
                }

                if (result.Target == null)
                    return null;

                result.Target = state;
                mparams.AbsoluteDrag = false;
            }

            return result;
        }
                public void Move(PointF target, ManipulateParams mparams, State from)
                {
                    List<State> affected = new List<State>();

                    if (Parent != null && from != Parent)
                        affected.Add(Parent);

                    foreach (State child in Children)
                    {
                        if (child != from)
                            affected.Add(child);
                    }

                    if (mparams.AbsoluteDrag && from == null)
                    {
                        target = new PointF(
                            target.X - mparams.AbsoluteOffset.X,
                            target.Y - mparams.AbsoluteOffset.Y);
                    }

                    if (!mparams.PivotDrag)
                    {
                        float nx = target.X;
                        float ny = target.Y;

                        float ox = Location.X;
                        float oy = Location.Y;

                        Location = target;

                        foreach (State state in affected)
                        {
                            PointF loc;

                            if (mparams.AbsoluteDrag)
                            {
                                loc = new PointF(
                                    state.Location.X + (nx - ox),
                                    state.Location.Y + (ny - oy)
                                );
                            }
                            else
                            {
                                if (mparams.DisableIK)
                                    return;

                                float jx = state.Location.X;
                                float jy = state.Location.Y;

                                float dx = ox - jx;
                                float dy = oy - jy;
                                float dm = (float)Math.Sqrt((double)(dx * dx + dy * dy));

                                float lx = jx - nx;
                                float ly = jy - ny;
                                float lm = (float)Math.Sqrt((double)(lx * lx + ly * ly));

                                loc = new PointF(nx + (lx / lm) * dm, ny + (ly / lm) * dm);
                            }

                            state.Move(loc, mparams, this);
                        }
                    }
                    else
                    {
                        if (Parent != null)
                        {
                            float dx = target.X - Parent.Location.X;
                            float dy = target.Y - Parent.Location.Y;

                            float length = (float)Math.Sqrt(dx * dx + dy * dy);

                            dx /= length;
                            dy /= length;

                            dx *= mparams.PivotLength;
                            dy *= mparams.PivotLength;

                            Location = new PointF(Parent.Location.X + dx, Parent.Location.Y + dy);

                            float angleDiff = (float)MathUtil.Angle(Location, Parent.Location) - mparams.PivotAngle;

                            Stack<State> open = new Stack<State>();
                            open.Push(this);

                            while (open.Count > 0)
                            {
                                State current = open.Pop();

                                foreach (State child in current.Children)
                                {
                                    open.Push(child);
                                    var info = mparams.PivotInfo[child];

                                    float angle = info.Item2 + angleDiff;
                                    float x = (float)(Parent.Location.X + Math.Cos(angle) * info.Item1);
                                    float y  = (float)(Parent.Location.Y + Math.Sin(angle) * info.Item1); // or maybe the other way around, depends
                                    child.Location = new PointF(x, y);
                                }
                            }
                        }
                        else
                        {
                            Stack<State> open = new Stack<State>();
                            open.Push(this);

                            while (open.Count > 0)
                            {
                                State current = open.Pop();

                                foreach (State child in current.Children)
                                {
                                    open.Push(child);

                                    child.Location = new PointF(
                                        child.Location.X + (target.X - Location.X),
                                        child.Location.Y + (target.Y - Location.Y));
                                }
                            }

                            Location = target;
                        }
                    }
                }