Ejemplo n.º 1
0
        private void MoveSelectedGroup(IGroupOperation pageVM, double deltaHorizontal, double deltaVertical)
        {
            if (_groups.Count <= 0)
            {
                this.designerCanvas.InvalidateMeasure();
                return;
            }

            //TODO:
            if (this.designerItem.IsSelected == true)
            {
                return;
            }

            foreach (WidgetViewModBase item in _infoItems)
            {
                if (item == _infoItems.Last())
                {
                    SendFirePositionEvent(true);
                }

                if (item.IsLocked == true)
                {
                    continue;
                }

                item.Raw_Left = item.Left + deltaHorizontal;
                item.Raw_Top  = item.Top + deltaVertical;
            }

            foreach (GroupViewModel it in _groups)
            {
                pageVM.UpdateGroup(it.WidgetID);
            }
        }
Ejemplo n.º 2
0
        private void MoveEditedGroup(IGroupOperation pageVM, double deltaHorizontal, double deltaVertical)
        {
            if (this.designerItem.IsSelected == false)
            {
                return;
            }

            foreach (WidgetViewModBase item in _infoItems)
            {
                if (item == _infoItems.Last())
                {
                    SendFirePositionEvent(true);
                }

                if (item.IsLocked == true)
                {
                    continue;
                }

                item.Raw_Left = item.Left + deltaHorizontal;
                item.Raw_Top  = item.Top + deltaVertical;
            }

            pageVM.UpdateGroup(this.designerItem.ParentID);
        }
Ejemplo n.º 3
0
        private void MoveExternalElements(double deltaHorizontal, double deltaVertical)
        {
            if (this.designerItem.IsSelected == false)
            {
                return;
            }

            foreach (WidgetViewModBase item in _infoItems)
            {
                if (item == _infoItems.Last())
                {
                    SendFirePositionEvent(true);
                }

                if (item.IsLocked == true)
                {
                    continue;
                }

                item.Raw_Top  = item.Top + deltaVertical;;
                item.Raw_Left = item.Left + deltaHorizontal;
            }

            IGroupOperation pageVM    = designerCanvas.DataContext as IGroupOperation;
            List <Guid>     GroupGIDs = pageVM.GetAllSelectedGroups();

            if (GroupGIDs.Count <= 0)
            {
                return;
            }

            foreach (GroupViewModel it in _groups)
            {
                pageVM.UpdateGroup(it.WidgetID);
            }
        }
Ejemplo n.º 4
0
        private void RotateThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            //Initialize the selected widgets' context when first rotate
            if (_infoItems.Count <= 0)
            {
                WidgetViewModBase wdg = designerItem.DataContext as WidgetViewModBase;
                if (wdg.IsGroup == false)
                {
                    wdg.CreateNewPropertyMementos();
                    wdg.PropertyMementos.AddPropertyMemento(new PropertyMemento("RotateAngle", wdg.RotateAngle, wdg.RotateAngle));
                    _infoItems.Add(wdg);
                }
                else
                {
                    foreach (WidgetViewModBase item in (wdg as GroupViewModel).WidgetChildren)
                    {
                        item.CreateNewPropertyMementos();

                        item.CreateNewPropertyMementos();

                        item.PropertyMementos.AddPropertyMemento(new PropertyMemento("RotateAngle", item.RotateAngle, item.RotateAngle));
                        item.PropertyMementos.AddPropertyMemento(new PropertyMemento("Left", item.Raw_Left, item.Raw_Left));
                        item.PropertyMementos.AddPropertyMemento(new PropertyMemento("Top", item.Raw_Top, item.Raw_Top));
                        _infoItems.Add(item);
                    }
                }
            }

            //Rotate the current widget
            if (this.designerItem != null && this.canvas != null)
            {
                ContentPresenter wrapper = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(designerItem)) as ContentPresenter;

                Point  currentPoint = Mouse.GetPosition(this.canvas);
                Vector deltaVector  = Point.Subtract(currentPoint, this.centerPoint);

                double angle = Vector.AngleBetween(this.startVector, deltaVector);

                RotateTransform rotateTransform = designerItem.RenderTransform as RotateTransform;
                angle = this.initialAngle + Math.Round(angle, 0);



                if (angle < 0)
                {
                    angle += 360;
                }
                else if (angle >= 360)
                {
                    angle -= 360;
                }


                wrapper.InvalidateMeasure();

                if (this.designerItem.IsGroup == true)
                {
                    GroupViewModel group = this.designerItem.DataContext as GroupViewModel;

                    DesignerCanvas dc = canvas as DesignerCanvas;

                    foreach (WidgetViewModBase item in group.WidgetChildren)
                    {
                        RotateTransform rt = new RotateTransform(); // bw.RenderTransform as RotateTransform;
                        rt.Angle   = angle - groupIntialAngle;
                        rt.CenterX = groupCenterX;
                        rt.CenterY = groupCenterY;

                        double oldAngle = item.RotateAngle;
                        item.RotateAngle = Convert.ToInt16(angle - groupIntialAngle);
                        Rect rect1 = rt.TransformBounds(new Rect(item.Left, item.Top, item.ItemWidth, item.ItemHeight));
                        Rect rect2 = item.RevertBoundingRectangle(rect1);

                        //item.IsActual = true;
                        item.Raw_Left = rect2.Left;
                        item.Raw_Top  = rect2.Top;

                        //only widget can rotate
                        if (item is WidgetRotateViewModBase)
                        {
                            int newAngle = Convert.ToInt16(oldAngle + (angle - groupIntialAngle)) % 360;
                            if (newAngle < 0)
                            {
                                newAngle += 360;
                            }
                            else if (angle >= 360)
                            {
                                newAngle -= 360;
                            }
                            item.RotateAngle = newAngle;
                        }
                        else
                        {
                            item.RotateAngle = 0;
                        }
                    }

                    group.Refresh();
                    groupIntialAngle = angle;
                }
                else
                {
                    rotateTransform.Angle = angle;
                }


                if (this.designerItem.ParentID != Guid.Empty)
                {
                    IGroupOperation pageVM = canvas.DataContext as IGroupOperation;
                    pageVM.UpdateGroup(this.designerItem.ParentID);
                }

                if (this.designerItem.IsGroup)
                {
                    IGroupOperation pageVM = canvas.DataContext as IGroupOperation;
                    pageVM.UpdateGroup((this.designerItem.DataContext as GroupViewModel).WidgetID);
                }
            }
        }