예제 #1
0
        private WidgetSiteControl CreateWidgetSite(MatrixLoc location, bool withAnimation, ref TimeSpan animationTime)
        {
            var site      = new WidgetSiteControl();
            var transform = new TransformGroup();

            transform.Children.Add(withAnimation ? new ScaleTransform(0, 0) : new ScaleTransform(1, 1));
            transform.Children.Add(new TranslateTransform());

            site.RenderTransform       = transform;
            site.RenderTransformOrigin = new Point(0.5, 0.5);

            if (withAnimation)
            {
                AnimateSiteScaleTransform(site, ref animationTime, 0, 1, null);
            }

            matrixPanel.Children.Add(site);

            site.Location = location;

            return(site);
        }
예제 #2
0
        private void AnimateSiteScaleTransform(WidgetSiteControl site, ref TimeSpan beginTime,
                                               double fromScale, double toScale, EventHandler completedCallback)
        {
            ScaleTransform transform = (ScaleTransform)((TransformGroup)site.RenderTransform).Children[0];

            if (fromScale == double.NaN)
            {
                transform.BeginAnimation(ScaleTransform.ScaleXProperty, null);
                transform.BeginAnimation(ScaleTransform.ScaleYProperty, null);
            }
            else
            {
                AnimationTimeline animation = BuildSiteScaleAnimation(beginTime, fromScale, toScale);

                if (completedCallback != null)
                {
                    animation.Completed += completedCallback;
                }

                transform.BeginAnimation(ScaleTransform.ScaleXProperty, animation);
                transform.BeginAnimation(ScaleTransform.ScaleYProperty,
                                         BuildSiteScaleAnimation(beginTime, fromScale, toScale));
            }
        }
예제 #3
0
        private void FindParent()
        {
            DependencyObject obj = VisualTreeHelper.GetParent( this );

            while( obj != null )
            {
                _parentSite = obj as WidgetSiteControl;

                if( _parentSite != null ) break;

                obj = VisualTreeHelper.GetParent( obj );
            }
        }
예제 #4
0
 /// <summary>
 /// Initializing constructor
 /// </summary>
 /// <param name="parentSite">Reference to the parent site control</param>
 public WidgetSiteDragHelper(WidgetSiteControl parentSite) : base(parentSite)
 {
     WidgetSiteControl.AddUndraggableHandler(parentSite, OnWidgetUndraggable);
     WidgetSiteControl.AddDraggableHandler(parentSite, OnWidgetDraggable);
 }
예제 #5
0
 /// <summary>
 /// Initializing constructor
 /// </summary>
 /// <param name="parentSite">Reference to the parent site control</param>
 public WidgetSiteDragHelper( WidgetSiteControl parentSite )
     : base(parentSite)
 {
     WidgetSiteControl.AddUndraggableHandler( parentSite, OnWidgetUndraggable );
     WidgetSiteControl.AddDraggableHandler( parentSite, OnWidgetDraggable );
 }
예제 #6
0
 private void AnimateTranslate(WidgetSiteControl site, DependencyProperty property, AnimationTimeline animation)
 {
     ((TransformGroup)site.RenderTransform).Children[1].BeginAnimation(property, animation);
 }
예제 #7
0
 private void AnimateSiteTranslate(WidgetSiteControl site, double toX, double toY)
 {
     AnimateTranslate(site, TranslateTransform.XProperty, BuildAnimation(toX));
     AnimateTranslate(site, TranslateTransform.YProperty, BuildAnimation(toY));
 }
예제 #8
0
        private List <SiteShiftInfo> CalculateWhichSitesToShift(MatrixLoc insertLoc, WidgetSiteDragDropData data)
        {
            MatrixLoc            sourceLoc = data.Site.Location;
            List <SiteShiftInfo> relocatedSites;
            int    i, step;
            double translateBy;

            // preallocate enough so we don't need to worry about reallocations
            relocatedSites = new List <SiteShiftInfo>(_controlData.Source.Bounds.RowCount +
                                                      _controlData.Source.Bounds.ColumnCount + 10);

            if (insertLoc.Column != sourceLoc.Column)
            {
                translateBy = data.Site.ActualWidth + data.Site.Margin.Width();

                if (insertLoc.Column < sourceLoc.Column)
                {
                    step = 1;
                }
                else
                {
                    step        = -1;
                    translateBy = -translateBy;
                }

                for (i = insertLoc.Column; i != sourceLoc.Column; i += step)
                {
                    MatrixLoc arrayIndex = _controlData.Source.Bounds.ToIndex(new MatrixLoc(sourceLoc.Row, i));

                    WidgetSiteControl ctrl = _controlData.SiteGrid[arrayIndex];

                    relocatedSites.Add(new SiteShiftInfo()
                    {
                        site        = ctrl, widget = (Data.WidgetData)ctrl.Content,
                        translateX  = translateBy, translateY = 0.0,
                        newLocation = new MatrixLoc(sourceLoc.Row, i + step)
                    });
                }
            }

            if (insertLoc.Row != sourceLoc.Row)
            {
                translateBy = data.Site.ActualHeight + data.Site.Margin.Height();

                if (insertLoc.Row < sourceLoc.Row)
                {
                    step = 1;
                }
                else
                {
                    step        = -1;
                    translateBy = -translateBy;
                }

                for (i = insertLoc.Row; i != sourceLoc.Row; i += step)
                {
                    MatrixLoc arrayIndex = _controlData.Source.Bounds.ToIndex(new MatrixLoc(i, insertLoc.Column));

                    WidgetSiteControl ctrl = _controlData.SiteGrid[arrayIndex];

                    relocatedSites.Add(new SiteShiftInfo()
                    {
                        site        = ctrl, widget = (Data.WidgetData)ctrl.Content,
                        translateY  = translateBy, translateX = 0.0,
                        newLocation = new MatrixLoc(i + step, insertLoc.Column)
                    });
                }
            }

            return(relocatedSites);
        }
예제 #9
0
        private void UpdateGrid(bool withAnimation)
        {
            TimeSpan animationTime = new TimeSpan();
            List <WidgetSiteControl> sitesToRemove = new List <WidgetSiteControl>(256);

            int rowCount    = _controlData.Source.Bounds.RowCount;
            int columnCount = _controlData.Source.Bounds.ColumnCount;

            ResizeRowOrColumn(matrixPanel.RowDefinitions, rowCount);
            ResizeRowOrColumn(matrixPanel.ColumnDefinitions, columnCount);

            _controlData.SiteGrid = new Array2D <WidgetSiteControl>(rowCount, columnCount);

            foreach (var child in matrixPanel.Children)
            {
                WidgetSiteControl site = child as WidgetSiteControl;

                if (site == null)
                {
                    continue;
                }

                if (!_controlData.Source.Bounds.Contains(site.Location))
                {
                    if (withAnimation)
                    {
                        MatrixSize siteDistance = _controlData.Source.Bounds.Distance(site.Location);

                        TranslateTransform transform = (TranslateTransform)((TransformGroup)site.RenderTransform).Children[1];

                        transform.Y = site.HeightWithMargin * siteDistance.RowCount;
                        transform.X = site.WidthWithMargin * siteDistance.ColumnCount;

                        AnimateSiteScaleTransform(site, ref animationTime, 1, 0,
                                                  new EventHandler((o, e) => {
                            matrixPanel.Children.Remove(site);
                        }));
                    }
                    else
                    {
                        sitesToRemove.Add(site);
                    }
                }
                else
                {
                    MatrixLoc arrayIndex = _controlData.Source.Bounds.ToIndex(site.Location);

                    _controlData.SiteGrid[arrayIndex] = site;

                    site.UpdateGridPosition();
                }
            }

            foreach (var site in sitesToRemove)
            {
                matrixPanel.Children.Remove(site);
            }

            foreach (MatrixLoc loc in _controlData.Source.Bounds)
            {
                MatrixLoc arrayIndex = _controlData.Source.Bounds.ToIndex(loc);

                if (_controlData.SiteGrid[arrayIndex] == null)
                {
                    var site = CreateWidgetSite(loc, withAnimation, ref animationTime);

                    _controlData.SiteGrid[arrayIndex] = site;
                }

                _controlData.SiteGrid[arrayIndex].Content = _controlData.Source[loc];
            }
        }