Beispiel #1
0
        private void UpdateLayoutFromRealtimeStack()
        {
            // iterate through all the positions in the icon stack and animate the blocks
            // to move to their specified locations
            for (int index = 0; index < IconStack_Realtime.Count; index++)
            {
                // there could be nothing in this position, if so then skip this index/position
                IIcon icon = IconStack_Realtime[index];
                if (icon == null)
                {
                    continue;
                }

                // if there is an icon currently being moved then we don't want to update it
                if (MouseCapturedIcon != null && index == IconStack_Realtime.IndexOf(MouseCapturedIcon))
                {
                    continue;
                }

                // get a handle on the icon UIElement and where it should go for this index
                UIElement iconElement  = icon as UIElement;
                Point     iconPosition = GridCalculator.GetPosition(index);

                // build a moving storyboard and start it
                Storyboard sbMove = TransitionHelper.BuildTranslateTransformTransition(iconElement,
                                                                                       iconPosition, CommonConstants.CANVAS_ICON_MOVING_TIMING, false);

                sbMove.Begin();
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
            }
        }