private void CancelControlMove(Control[] controls, BoundsInfo[] bounds)
 {
     Rectangle rectangle = new Rectangle();
     for (int i = 0; i < controls.Length; i++)
     {
         Control parent = controls[i].Parent;
         if (parent != null)
         {
             parent.SuspendLayout();
         }
         rectangle.X = bounds[i].X;
         rectangle.Y = bounds[i].Y;
         rectangle.Width = bounds[i].Width;
         rectangle.Height = bounds[i].Height;
         controls[i].Bounds = rectangle;
     }
     for (int j = 0; j < controls.Length; j++)
     {
         Control control2 = controls[j].Parent;
         if (control2 != null)
         {
             control2.ResumeLayout();
         }
     }
 }
Esempio n. 2
0
 protected override void OnResize(EventArgs e)
 {
     base.OnResize(e);
     if (_ResizeBounds != null)
     {
         var index = _ResizeBounds.CurrentBoundIndex;
         _ResizeBounds = new BoundsInfo(ClientRectangle);
         Region        = _ResizeBounds.GetBoundRegion();
         _ResizeBounds.CurrentBoundIndex = index;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Vrátí požadovaný bod, nacházející se na daném místě absolutní souřadnice daného prvku.
        /// Pokud je prvek neviditelný (on, nebo kterýkoli z jeho Parentů), může vrátit null pokud je požadavek "onlyVisible" = true.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="side"></param>
        /// <param name="onlyVisible">true = vracet bod pouze pro objekt, který může být viditelný (z hlediska Is.Visible jeho a všech jeho Parentů)</param>
        /// <param name="shiftInner">Posunout výsledný bod mírně směrem doprostřed objektu</param>
        /// <returns></returns>
        protected static Point?GetPoint(InteractiveObject item, RectangleSide side, bool onlyVisible, bool shiftInner)
        {
            if (item == null)
            {
                return(null);
            }
            BoundsInfo boundsInfo = item.BoundsInfo;

            if (onlyVisible && !boundsInfo.CurrentItemIsVisible)
            {
                return(null);
            }
            Rectangle absBounds = boundsInfo.CurrentItemAbsoluteBounds;

            if (shiftInner)
            {
                absBounds = GetInnerBounds(absBounds);
            }
            return(absBounds.GetPoint(side));
        }
Esempio n. 4
0
        ///<summary>
        /// Creates new instance of <see cref="BoundControl" /> binded to <see cref="c" />
        ///</summary>
        ///<param name="c">Instance of Movable control that new control should bind to</param>
        public BoundControl([NotNull] HtmlDesignMovableControl c)
        {
            Debug.Assert(c != null);
            Owner       = c;
            c.Disposed += Dispose;
            c.Deleting += Dispose;
            Control control = c.Control;

            Location = control.Location;
            Size     = control.Size;
            Parent   = control.Parent;

            _ResizeBounds = new BoundsInfo(ClientRectangle);
            Region        = _ResizeBounds.GetBoundRegion();

            c.BindEvents(this);
            control.LocationChanged += Owner_LocationChanged;
            control.SizeChanged     += Owner_SizeChanged;
            Show();
            BringToFront();
        }
        /// <include file='doc\SelectionUIHandler.uex' path='docs/doc[@for="SelectionUIHandler.MoveControls"]/*' />
        /// <devdoc>
        ///      Called when we need to move the controls on our frame while dragging.  This
        ///      can perform three operations:  It can update the current controls location,
        ///      it can commit the new controls (final move), and it can roll back a movement
        ///      to the beginning of the operation.
        /// </devdoc>
        private void MoveControls(object[] components, bool cancel, bool finalMove)
        {
            Control[] controls = dragControls;
            Rectangle offset   = dragOffset;

            BoundsInfo[] bounds      = originalCoords;
            Point        adjustedLoc = new Point();

            // Erase the clipping and other state if this is the final move.
            //
            if (finalMove)
            {
                Cursor.Clip    = Rectangle.Empty;
                dragOffset     = Rectangle.Empty;
                dragControls   = null;
                originalCoords = null;
            }

            // If we haven't started to move yet, there's nothing to do.
            //
            if (offset.IsEmpty)
            {
                return;
            }

            // Short circuit the work if we didn't move anything.
            // This will prevent a change notification for just
            // selecting components.
            //
            if (finalMove && offset.X == 0 && offset.Y == 0 && offset.Width == 0 && offset.Height == 0)
            {
                return;
            }

            // If cancel was specified, we must roll all controls back to their original positions.
            //
            if (cancel)
            {
                CancelControlMove(controls, bounds);
                return;
            }

            // We must keep track of the original coordinates of each control, just in case
            // the user cancels out of moving them.  So, we create a "BoundsInfo" object for
            // each control that saves this state.
            //
            if (originalCoords == null && !finalMove)
            {
                originalCoords = new BoundsInfo[controls.Length];
                for (int i = 0; i < controls.Length; i++)
                {
                    originalCoords[i] = new BoundsInfo(controls[i]);
                }
                bounds = originalCoords;
            }

            // Two passes here.  First pass suspends all parent layout and updates the
            // component positions.  Second pass re-enables layout.
            //
            for (int i = 0; i < controls.Length; i++)
            {
                Debug.Assert(controls[i] == GetControl((IComponent)components[i]), "Control->Component mapping is out of sync");

                Control parent = controls[i].Parent;

                // Suspend parent layout so that we don't continously re-arrange components
                // while we move.
                //
                if (parent != null)
                {
                    parent.SuspendLayout();
                }

                BoundsInfo ctlBounds = bounds[i];

                adjustedLoc.X = ctlBounds.lastRequestedX;
                adjustedLoc.Y = ctlBounds.lastRequestedY;

                if (!finalMove)
                {
                    ctlBounds.lastRequestedX      += offset.X;
                    ctlBounds.lastRequestedY      += offset.Y;
                    ctlBounds.lastRequestedWidth  += offset.Width;
                    ctlBounds.lastRequestedHeight += offset.Height;
                }

                // Our "target" values are the ones we would like to set
                // the control to.  We may modify them if they would mke the control
                // size negative or zero, however.
                //
                int targetX      = ctlBounds.lastRequestedX;
                int targetY      = ctlBounds.lastRequestedY;
                int targetWidth  = ctlBounds.lastRequestedWidth;
                int targetHeight = ctlBounds.lastRequestedHeight;

                Rectangle oldBounds = controls[i].Bounds;

                if ((rules & SelectionRules.Moveable) == 0)
                {
                    // We use the minimum size of either a grid snap or 1
                    //
                    Size minSize;

                    if (GetShouldSnapToGrid())
                    {
                        minSize = GetCurrentSnapSize();
                    }
                    else
                    {
                        minSize = new Size(1, 1);
                    }

                    if (targetWidth < minSize.Width)
                    {
                        targetWidth = minSize.Width;
                        targetX     = oldBounds.X;
                    }

                    if (targetHeight < minSize.Height)
                    {
                        targetHeight = minSize.Height;
                        targetY      = oldBounds.Y;
                    }
                }

                //Bug #72905  <subhag> Form X,Y defaulted to (0,0)
                //

                IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
                Debug.Assert(host != null, "No designer host");
                if (controls[i] == host.RootComponent)
                {
                    targetX = 0;
                    targetY = 0;
                }

                // Adjust our target dimensions by the grid snaps
                //
                Rectangle tempNewBounds = GetUpdatedRect(oldBounds, new Rectangle(targetX, targetY, targetWidth, targetHeight), true);
                Rectangle newBounds     = oldBounds;

                // Now apply the correct values to newBounds -- we only want to apply the new value if our
                // selection rules dictate so.
                //
                if ((rules & SelectionRules.Moveable) != 0)
                {
                    newBounds.X = tempNewBounds.X;
                    newBounds.Y = tempNewBounds.Y;
                }
                else
                {
                    if ((rules & SelectionRules.TopSizeable) != 0)
                    {
                        newBounds.Y      = tempNewBounds.Y;
                        newBounds.Height = tempNewBounds.Height;
                    }
                    if ((rules & SelectionRules.BottomSizeable) != 0)
                    {
                        newBounds.Height = tempNewBounds.Height;
                    }
                    if ((rules & SelectionRules.LeftSizeable) != 0)
                    {
                        newBounds.X     = tempNewBounds.X;
                        newBounds.Width = tempNewBounds.Width;
                    }
                    if ((rules & SelectionRules.RightSizeable) != 0)
                    {
                        newBounds.Width = tempNewBounds.Width;
                    }
                }

                bool locChanged  = (offset.X != 0 || offset.Y != 0);
                bool sizeChanged = (offset.Width != 0 || offset.Height != 0);

                // If both the location and size changed, attempt to update the control in
                // one step.  This will prevent flicker.
                //
                if (locChanged && sizeChanged)
                {
                    // We shouldn't care if we're directly manipulating the control or not during
                    // the move.  For perf, just call directly on the control.  For the final
                    // move, however, we must go through the property descriptor.
                    //
                    PropertyDescriptor boundsProp = TypeDescriptor.GetProperties(components[i])["Bounds"];

                    if (boundsProp != null && !boundsProp.IsReadOnly)
                    {
                        if (finalMove)
                        {
                            object component = components[i];
                            boundsProp.SetValue(component, newBounds);
                        }
                        else
                        {
                            controls[i].Bounds = newBounds;
                        }

                        // Now reset the loc and size changed flags so
                        // we don't try to change again.
                        //
                        locChanged = sizeChanged = false;
                    }
                }

                // Adjust the location property with the new value.  ONLY do this if the offset
                // is nonzero, however.  Otherwise we may get round-off errors that can cause flicker.
                // Plus, why set the property if it shouldn't be?
                //
                if (locChanged)
                {
                    adjustedLoc.X = newBounds.X;
                    adjustedLoc.Y = newBounds.Y;

                    // We shouldn't care if we're directly manipulating the control or not during
                    // the move.  For perf, just call directly on the control.  For the final
                    // move, however, we must go through the property descriptor.
                    //
                    PropertyDescriptor locationProp = TypeDescriptor.GetProperties(components[i])["Location"];

                    if (locationProp != null && !locationProp.IsReadOnly)
                    {
                        if (finalMove)
                        {
                            object component = components[i];
                            locationProp.SetValue(component, adjustedLoc);
                        }
                        else
                        {
                            controls[i].Location = adjustedLoc;
                        }
                    }
                }

                // Adjust the size property with the new value.  ONLY do this if the offset
                // is nonzero, however.  Otherwise we may get round-off errors that can cause flicker.
                // Plus, why set the property if it shouldn't be?
                //
                if (sizeChanged)
                {
                    // If you are tempted to hoist this "new" out of the loop, don't.  The undo
                    // unit below just holds a reference to it.
                    //
                    Size size = new Size(Math.Max(MinControlWidth, newBounds.Width), Math.Max(MinControlHeight, newBounds.Height));

                    PropertyDescriptor sizeProp = TypeDescriptor.GetProperties(components[i])["Size"];

                    if (sizeProp != null && !sizeProp.IsReadOnly)
                    {
                        if (finalMove)
                        {
                            object component = components[i];
                            sizeProp.SetValue(component, size);
                        }
                        else
                        {
                            controls[i].Size = size;
                        }
                    }
                }
            }

            // Now resume the parent layouts
            //
            for (int i = 0; i < controls.Length; i++)
            {
                Control parent = controls[i].Parent;

                if (parent != null)
                {
                    parent.ResumeLayout();
                    parent.Update();
                }

                controls[i].Update();
            }
        }
Esempio n. 6
0
        public ModelDraw(Model m, string name)
        {
            name_ = name;
              model_ = m;
              world_ = Matrix.Identity;

              //  I'll need the world-space pose of each bone
              matrices_ = new Matrix[m.Bones.Count];

              //  inverse bind pose for skinning pose only
              object ibp;
              Dictionary<string, object> tagDict = m.Tag as Dictionary<string, object>;
              if (tagDict == null)
            throw new System.ArgumentException(String.Format(
            "Model {0} wasn't processed with the AnimationProcessor.", name));
              if (tagDict.TryGetValue("InverseBindPose", out ibp))
              {
            inverseBindPose_ = ibp as SkinnedBone[];
            CalculateIndices();
              }

              //  information about bounds, in case the bind pose contains scaling
              object bi;
              if (((Dictionary<string, object>)m.Tag).TryGetValue("BoundsInfo", out bi))
            boundsInfo_ = bi as BoundsInfo;
              if (boundsInfo_ == null)
            boundsInfo_ = new BoundsInfo(1, 0);

              //  pick apart the model, so I know how to draw the different pieces
              List<Chunk> chl = new List<Chunk>();
              foreach (ModelMesh mm in m.Meshes)
              {
            int mmpIx = 0;
            foreach (ModelMeshPart mmp in mm.MeshParts)
            {
              ++mmpIx;
              //  chunk is used to draw an individual subset
              Chunk ch = new Chunk();

              //  set up all the well-known parameters through the EffectConfig helper.
              ch.Fx = new EffectConfig(mmp.Effect, mm.Name + "_" + mmpIx.ToString());

              //  if this effect is skinned, set up additional data
              if (ch.Fx.HasPose)
              {
            //  If I haven't built the pose, then build it now
            if (pose_ == null)
            {
              if (inverseBindPose_ == null)
                throw new System.ArgumentNullException(String.Format(
                    "The model {0} should have an inverse bone transform because it has a pose, but it doesn't.",
                    name));
              //  Send bones as sets of three 4-vectors (column major) to the shader
              pose_ = new Vector4[inverseBindPose_.Length * 3];
              for (int i = 0; i != inverseBindPose_.Length; ++i)
              {
                //  start out with the identity pose (which is terrible)
                pose_[i * 3 + 0] = new Vector4(1, 0, 0, 0);
                pose_[i * 3 + 1] = new Vector4(0, 1, 0, 0);
                pose_[i * 3 + 2] = new Vector4(0, 0, 1, 0);
              }
            }
            ch.Fx.PoseData = pose_;
              }

              ch.Mesh = mm;
              ch.Part = mmp;

              //  check out whether the technique contains transparency
              EffectAnnotation ea = mmp.Effect.CurrentTechnique.Annotations["transparent"];
              if (ea != null && ea.GetValueBoolean() == true)
            ch.Deferred = true;

              chl.Add(ch);
            }
              }
              //  use a native array instead of a List<> for permanent storage
              chunks_ = chl.ToArray();
              //  calculate bounds information (won't take animation into account)
              CalcBoundingSphere();

              //  animate this instance based on the bind pose
              Animation an = GetAnimation("$bind$", false);
              if (an != null)
              {
            instance_ = new AnimationInstance(an);
            instance_.Advance(0);
              }
        }
        private void MoveControls(object[] components, bool cancel, bool finalMove)
        {
            Control[] dragControls = this.dragControls;
            Rectangle dragOffset   = this.dragOffset;

            BoundsInfo[] originalCoords = this.originalCoords;
            Point        point          = new Point();

            if (finalMove)
            {
                Cursor.Clip         = Rectangle.Empty;
                this.dragOffset     = Rectangle.Empty;
                this.dragControls   = null;
                this.originalCoords = null;
            }
            if (!dragOffset.IsEmpty && (((!finalMove || (dragOffset.X != 0)) || ((dragOffset.Y != 0) || (dragOffset.Width != 0))) || (dragOffset.Height != 0)))
            {
                if (cancel)
                {
                    this.CancelControlMove(dragControls, originalCoords);
                }
                else
                {
                    if ((this.originalCoords == null) && !finalMove)
                    {
                        this.originalCoords = new BoundsInfo[dragControls.Length];
                        for (int k = 0; k < dragControls.Length; k++)
                        {
                            this.originalCoords[k] = new BoundsInfo(dragControls[k]);
                        }
                        originalCoords = this.originalCoords;
                    }
                    for (int i = 0; i < dragControls.Length; i++)
                    {
                        Control parent = dragControls[i].Parent;
                        if (parent != null)
                        {
                            parent.SuspendLayout();
                        }
                        BoundsInfo info = originalCoords[i];
                        point.X = info.lastRequestedX;
                        point.Y = info.lastRequestedY;
                        if (!finalMove)
                        {
                            info.lastRequestedX      += dragOffset.X;
                            info.lastRequestedY      += dragOffset.Y;
                            info.lastRequestedWidth  += dragOffset.Width;
                            info.lastRequestedHeight += dragOffset.Height;
                        }
                        int       lastRequestedX      = info.lastRequestedX;
                        int       lastRequestedY      = info.lastRequestedY;
                        int       lastRequestedWidth  = info.lastRequestedWidth;
                        int       lastRequestedHeight = info.lastRequestedHeight;
                        Rectangle bounds = dragControls[i].Bounds;
                        if ((this.rules & SelectionRules.Moveable) == SelectionRules.None)
                        {
                            Size currentSnapSize;
                            if (this.GetShouldSnapToGrid())
                            {
                                currentSnapSize = this.GetCurrentSnapSize();
                            }
                            else
                            {
                                currentSnapSize = new Size(1, 1);
                            }
                            if (lastRequestedWidth < currentSnapSize.Width)
                            {
                                lastRequestedWidth = currentSnapSize.Width;
                                lastRequestedX     = bounds.X;
                            }
                            if (lastRequestedHeight < currentSnapSize.Height)
                            {
                                lastRequestedHeight = currentSnapSize.Height;
                                lastRequestedY      = bounds.Y;
                            }
                        }
                        IDesignerHost service = (IDesignerHost)this.GetService(typeof(IDesignerHost));
                        if (dragControls[i] == service.RootComponent)
                        {
                            lastRequestedX = 0;
                            lastRequestedY = 0;
                        }
                        Rectangle rectangle3 = this.GetUpdatedRect(bounds, new Rectangle(lastRequestedX, lastRequestedY, lastRequestedWidth, lastRequestedHeight), true);
                        Rectangle rectangle4 = bounds;
                        if ((this.rules & SelectionRules.Moveable) != SelectionRules.None)
                        {
                            rectangle4.X = rectangle3.X;
                            rectangle4.Y = rectangle3.Y;
                        }
                        else
                        {
                            if ((this.rules & SelectionRules.TopSizeable) != SelectionRules.None)
                            {
                                rectangle4.Y      = rectangle3.Y;
                                rectangle4.Height = rectangle3.Height;
                            }
                            if ((this.rules & SelectionRules.BottomSizeable) != SelectionRules.None)
                            {
                                rectangle4.Height = rectangle3.Height;
                            }
                            if ((this.rules & SelectionRules.LeftSizeable) != SelectionRules.None)
                            {
                                rectangle4.X     = rectangle3.X;
                                rectangle4.Width = rectangle3.Width;
                            }
                            if ((this.rules & SelectionRules.RightSizeable) != SelectionRules.None)
                            {
                                rectangle4.Width = rectangle3.Width;
                            }
                        }
                        bool flag  = (dragOffset.X != 0) || (dragOffset.Y != 0);
                        bool flag2 = (dragOffset.Width != 0) || (dragOffset.Height != 0);
                        if (flag && flag2)
                        {
                            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(components[i])["Bounds"];
                            if ((descriptor != null) && !descriptor.IsReadOnly)
                            {
                                if (finalMove)
                                {
                                    object component = components[i];
                                    descriptor.SetValue(component, rectangle4);
                                }
                                else
                                {
                                    dragControls[i].Bounds = rectangle4;
                                }
                                flag = flag2 = false;
                            }
                        }
                        if (flag)
                        {
                            point.X = rectangle4.X;
                            point.Y = rectangle4.Y;
                            PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(components[i])["TrayLocation"];
                            if ((descriptor2 != null) && !descriptor2.IsReadOnly)
                            {
                                descriptor2.SetValue(components[i], point);
                            }
                            else
                            {
                                PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(components[i])["Left"];
                                PropertyDescriptor descriptor4 = TypeDescriptor.GetProperties(components[i])["Top"];
                                if ((descriptor4 != null) && !descriptor4.IsReadOnly)
                                {
                                    if (finalMove)
                                    {
                                        object obj3 = components[i];
                                        descriptor4.SetValue(obj3, point.Y);
                                    }
                                    else
                                    {
                                        dragControls[i].Top = point.Y;
                                    }
                                }
                                if ((descriptor3 != null) && !descriptor3.IsReadOnly)
                                {
                                    if (finalMove)
                                    {
                                        object obj4 = components[i];
                                        descriptor3.SetValue(obj4, point.X);
                                    }
                                    else
                                    {
                                        dragControls[i].Left = point.X;
                                    }
                                }
                                if ((descriptor3 == null) || (descriptor4 == null))
                                {
                                    PropertyDescriptor descriptor5 = TypeDescriptor.GetProperties(components[i])["Location"];
                                    if ((descriptor5 != null) && !descriptor5.IsReadOnly)
                                    {
                                        descriptor5.SetValue(components[i], point);
                                    }
                                }
                            }
                        }
                        if (flag2)
                        {
                            Size size2 = new Size(Math.Max(3, rectangle4.Width), Math.Max(3, rectangle4.Height));
                            PropertyDescriptor descriptor6 = TypeDescriptor.GetProperties(components[i])["Width"];
                            PropertyDescriptor descriptor7 = TypeDescriptor.GetProperties(components[i])["Height"];
                            if (((descriptor6 != null) && !descriptor6.IsReadOnly) && (size2.Width != ((int)descriptor6.GetValue(components[i]))))
                            {
                                if (finalMove)
                                {
                                    object obj5 = components[i];
                                    descriptor6.SetValue(obj5, size2);
                                }
                                else
                                {
                                    dragControls[i].Width = size2.Width;
                                }
                            }
                            if (((descriptor7 != null) && !descriptor7.IsReadOnly) && (size2.Height != ((int)descriptor7.GetValue(components[i]))))
                            {
                                if (finalMove)
                                {
                                    object obj6 = components[i];
                                    descriptor7.SetValue(obj6, size2);
                                }
                                else
                                {
                                    dragControls[i].Height = size2.Height;
                                }
                            }
                        }
                    }
                    for (int j = 0; j < dragControls.Length; j++)
                    {
                        Control control2 = dragControls[j].Parent;
                        if (control2 != null)
                        {
                            control2.ResumeLayout();
                            control2.Update();
                        }
                        dragControls[j].Update();
                    }
                }
            }
        }