public void AddIcon(IIcon icon, int pos) { if (pos >= CellCount) { RowCount += 1; for (int i = 0; i < ColumnCount; i++) { IconStack_Realtime.Add(null); IconStack_LastChanged.Add(null); IconStack_LastCommitted.Add(null); } this.Height += IconSize.Y; GridCalculator.PanelHeight += IconSize.Y; GridCalculator.RowCount = RowCount; GridCalculator.ColumnCount = ColumnCount; } // TODO:: sanity check that position is within bounds // TODO:: sanity check that IIcon is a UIElement UIElement iconUIElement = icon as UIElement; iconUIElement.SetValue(Canvas.ZIndexProperty, 0); this.Children.Add(iconUIElement); IconStack_Realtime[pos] = icon; IconStack_LastChanged[pos] = icon; IconStack_LastCommitted[pos] = icon; int position = GetIconStackPosition(icon); Point canvasPosition = GridCalculator.GetPosition(position); UIElement iconElement = icon as UIElement; // we do an initial render transform so that later when we animate it no exception is thrown TransformGroup tg = TransitionHelper.GetTransformGroupForXYOffset(canvasPosition.X, canvasPosition.Y, 1.00D, 1.00D); iconElement.RenderTransform = tg; iconUIElement.MouseLeftButtonDown += new MouseButtonEventHandler(iconUIElement_MouseLeftButtonDown); iconUIElement.MouseLeftButtonUp += new MouseButtonEventHandler(iconUIElement_MouseLeftButtonUp); iconUIElement.MouseMove += new MouseEventHandler(iconUIElement_MouseMove); iconUIElement.Drop += new DragEventHandler(iconUIElement_Drop); }
void iconUIElement_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (!IsEditing) { return; } // TODO:: use constants for ZIndex UIElement element = sender as UIElement; TransformGroup tg = TransitionHelper.GetTransformGroupForXYOffset( e.GetPosition(this).X - MouseCapturedClickPosition.X, e.GetPosition(this).Y - MouseCapturedClickPosition.Y, 1.0D, 1.0D); element.RenderTransform = tg; element.Opacity = 1.00D; element.SetValue(Canvas.ZIndexProperty, 0); // move the block back down to the common zindex element.ReleaseMouseCapture(); Point mousePosition = e.GetPosition(this); // get a handle on the icon the mouse is over CellPosition cellPosition = GetCellPositionFromMousePoint(mousePosition); // if the cell position is null then the user is out of bounds, assume the icon // will go to the last position if (cellPosition == null) { cellPosition = GridCalculator.GetCellFromCellIndex(CellCount - 1); } // take the Icon which was captured by the mouse // and put it into the Icon stack at the provided position UpdateIconStack(ref IconStack_LastChanged, MouseCapturedIcon, cellPosition); // the icon is no longer being dragged by the mouse, so clear out the captured icon MouseCapturedIcon = null; // transition to this stack (and update the realtime stack) TransitionToIconStack(IconStack_LastChanged); }
void iconUIElement_MouseMove(object sender, MouseEventArgs e) { if (!IsEditing) { return; } if (MouseCapturedIcon != null) { // update the icon being dragged around's position UIElement iconElement = MouseCapturedIcon as UIElement; TransformGroup tg = TransitionHelper.GetTransformGroupForXYOffset( e.GetPosition(this).X - MouseCapturedClickPosition.X, e.GetPosition(this).Y - MouseCapturedClickPosition.Y, 1.2D, 1.2D); iconElement.RenderTransform = tg; Point mousePosition = e.GetPosition(this); // get a handle on the icon the mouse is over CellPosition cellPosition = GetCellPositionFromMousePoint(mousePosition); // if the cell position is null then the user is out of bounds, assume the icon // will go to the last position if (cellPosition == null) { cellPosition = GridCalculator.GetCellFromCellIndex(CellCount - 1); } // take the Icon which was captured by the mouse // and put it into the Icon stack at the provided position UpdateIconStack(ref IconStack_Realtime, MouseCapturedIcon, cellPosition); // transition to this stack (and update the realtime stack) TransitionToIconStack(IconStack_Realtime); } }