private void UpdateMatrixUI(MatrixLoc insertLoc, WidgetSiteDragDropData data) { List <SiteShiftInfo> relocatedSites; relocatedSites = CalculateWhichSitesToShift(insertLoc, data); var sitesToMove = relocatedSites.Except(_prevRelocatedSites, SiteShiftInfoComparer.Comparer).ToList(); var sitesToReverse = _prevRelocatedSites.Except(relocatedSites, SiteShiftInfoComparer.Comparer).ToList(); foreach (var s in sitesToMove) { AnimateSiteTranslate(s.site, s.translateX, s.translateY); } foreach (var s in sitesToReverse) { AnimateSiteTranslate(s.site, 0.0, 0.0); } _prevRelocatedSites = relocatedSites; }
/// <inheritdoc/> protected override void OnQueryDragData(QueryDragDataEventArgs e) { if (_dragFrozenCount > 0) { return; } base.OnQueryDragData(e); if (e.DragData == null) { var data = new WidgetSiteDragDropData() { DraggableOffset = e.DraggableOffset, Site = Parent, Widget = (Data.WidgetData)Parent.Content }; var dataObject = new DataObject(data); e.DragData = dataObject; } }
private bool ProcessDataObject(DragEventArgs eventArgs, ProcessDataObjectDelegate callback) { WidgetSiteDragDropData data = eventArgs.Data.GetData("Droppy.WidgetSiteDragDropData") as WidgetSiteDragDropData; if (data == null) { eventArgs.Effects = DragDropEffects.None; return(false); } Point pt = eventArgs.GetPosition(this.Target) - new Vector(data.DraggableOffset.X, data.DraggableOffset.Y); Rect dragRect = new Rect(pt, new Size(data.Site.ActualWidth + data.Site.Margin.Width(), data.Site.ActualHeight + data.Site.Margin.Height())); Point dragCenter = new Point(dragRect.X + dragRect.Width / 2, dragRect.Y + dragRect.Height / 2); MatrixLoc insertIndex = new MatrixLoc( (int)((dragCenter.Y + dragRect.Height) / dragRect.Height) - 1, (int)((dragCenter.X + dragRect.Width) / dragRect.Width) - 1); MatrixLoc insertLoc = _controlData.Source.Bounds.ToLocation(insertIndex); if (_controlData.Source.Bounds.Contains(insertLoc)) { eventArgs.Effects = DragDropEffects.Move; callback(insertLoc, data); } else { eventArgs.Effects = DragDropEffects.None; } return(true); }
private void CommitMove(MatrixLoc insertLoc, WidgetSiteDragDropData data) { List <SiteShiftInfo> relocatedSites; relocatedSites = CalculateWhichSitesToShift(insertLoc, data); if (relocatedSites.Count > 0) { foreach (var s in relocatedSites) { _controlData.Source[s.newLocation] = s.widget; AnimateTranslate(s.site, TranslateTransform.XProperty, null); AnimateTranslate(s.site, TranslateTransform.YProperty, null); } _controlData.Source[insertLoc] = data.Widget; } // If there are any controls left out of original position, return them now. _prevRelocatedSites = _prevRelocatedSites.Except(relocatedSites, SiteShiftInfoComparer.Comparer).ToList(); CancelMove(); }
/// <inheritdoc/> protected override void OnQueryDragData( QueryDragDataEventArgs e ) { if( _dragFrozenCount > 0 ) return; base.OnQueryDragData( e ); if( e.DragData == null ) { var data = new WidgetSiteDragDropData() { DraggableOffset = e.DraggableOffset, Site = Parent, Widget = (Data.WidgetData)Parent.Content }; var dataObject = new DataObject( data ); e.DragData = dataObject; } }
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); }