Пример #1
0
        /// <summary>
        /// Delete current widget from grid.
        /// Then widgets are realigned, if deleted widget was alone on its row.
        /// </summary>
        public void DeleteTile(TileWrapper tile)
        {
            _tiles.Remove(tile);
            _tilesCanvas.DeleteElement(tile);

            RealignTiles();
            WriteTilesSettings();
        }
Пример #2
0
        /// <summary>
        /// add widget to internal collection 
        /// and calc widget screen coordinates
        /// </summary>
        protected TileWrapper AddTile(TileWrapper tile, bool doRealign)
        {
            // draw tile when adding
            tile.Draw(null);

            _tiles.Add(tile);
            _tilesCanvas.AddElement(tile);

            if (doRealign)
            {
                RealignTiles();
            }

            tile.TapHandler = p => TileClickAt(p, tile);
            tile.HoldHandler = p => TileHoldAt(p, tile);

            return tile;
        }
Пример #3
0
        /// <summary>
        /// move selected tile to new location
        /// </summary>
        /// <param name="movingTile"> </param>
        /// <param name="location"> </param>
        private void MoveTileTo(TileWrapper movingTile, Point location)
        {
            var targetCell = GetTileCell(location);

            // if widget doesn't fit to new position by width, do not do anything
            if (targetCell.X + movingTile.GridSize.Width > _gridWidth)
                targetCell.X = _gridWidth - movingTile.GridSize.Width;
                //return;

            var targetCellIsEmpty = false;
            while (!targetCellIsEmpty)
            {
                object[,] cells = new object[_gridHeight, _gridWidth];
                foreach (TileWrapper wsInfo in _tiles)
                {
                    if (wsInfo != movingTile)
                        for (int y = 0; y < wsInfo.GridSize.Height; y++)
                            for (int x = 0; x < wsInfo.GridSize.Width; x++)
                                cells[wsInfo.GridPosition.Y + y, wsInfo.GridPosition.X + x] = wsInfo;
                }

                targetCellIsEmpty = true;
                for (int y = targetCell.Y; y < Math.Min(targetCell.Y + movingTile.GridSize.Height, 100); y++)
                    for (int x = targetCell.X; x < Math.Min(targetCell.X + movingTile.GridSize.Width, _gridWidth); x++)
                        if ((cells[y, x] != null) && (!cells[y, x].Equals(movingTile)))
                        {
                            targetCellIsEmpty = false;
                            break;
                        }

                if (!targetCellIsEmpty)
                {
                    foreach (TileWrapper wsInfo in _tiles)
                    {
                        if ((wsInfo.GridPosition.Y + wsInfo.GridSize.Height - 1) >= targetCell.Y)
                            wsInfo.GridPosition = new Point(wsInfo.GridPosition.X, wsInfo.GridPosition.Y + 1);
                    }
                }
            }

            movingTile.GridPosition = targetCell;

            RealignTiles();
        }
Пример #4
0
 private IAnimation GetExitAnimation(TileWrapper target)
 {
     var random = new Random();
     return new FunctionBasedAnimation(FunctionBasedAnimation.Functions.Linear)
                {
                    Duration = AnimationDuration,
                    To = -target.Size.Width - random.Next(1000),
                    From = target.Location.X,
                    OnAnimation = v => target.Location = new Point(v, target.Location.Y),
                    OnAnimationStop = () => { target.ExitAnimation = null; },
     };
 }
Пример #5
0
 private IAnimation GetEntranceAnimation(TileWrapper target)
 {
     var random = new Random();
     var x = target.GetScreenRect().Left; // here use GetScreenRect instead Bounds because real coords are wrong
     return new FunctionBasedAnimation(FunctionBasedAnimation.Functions.Linear)
     {
         Duration = AnimationDuration,
         From = x - 1000 + random.Next(1000 - x - 173),
         To = x,
         OnAnimation = v => target.Location = new Point(v, target.Location.Y),
         OnAnimationStop = () => { target.EntranceAnimation = null; },
     };
 }
Пример #6
0
        /// <summary>
        /// Click at tile handler
        /// </summary>
        /// <param name="location"></param>
        /// <param name="tile"> </param>
        private bool TileClickAt(Point location, TileWrapper tile)
        {
            // if Move mode is enabled, place selected widget to the new position
            // if we click at moving widget, exit from move mode
            if (SelectionMode)
            {
                // if click at moving tile - exit from moving mode
                // if click at another tile - change moving tile to selected
                SelectedTile = (tile == SelectedTile) ? null : tile;
                return true;
            }

            // if tile launches external program, start exit animation for visible tiles
            if (tile.Tile.DoExitAnimation)
            {
                Active = false;
                _launching = true;
                _tilesCanvas.AnimateExit();
            }

            var clickResult = tile.OnClick(location);

            // if tile's onClick action failed, play back entrance animation
            if ((tile.Tile.DoExitAnimation) && (!clickResult))
            {
                // when page activate it plays entrance animation
                Active = true;
            }
            return true;
        }
Пример #7
0
        /// <summary>
        /// Long tap handler - entering to customizing mode
        /// </summary>
        private bool TileHoldAt(Point location, TileWrapper tile)
        {
            if (ParentControl == null)
                return false;

            SelectedTile = null;

            var tileMenu = new ContextMenu();

            var menuTileEdit = new MenuItem { Text = "Edit".Localize() };
            menuTileEdit.Click += (s, e) => ShowTileSettings(tile);
            tileMenu.MenuItems.Add(menuTileEdit);

            var menuTileMove = new MenuItem { Text = "Move".Localize() };
            menuTileMove.Click += (s, e) => { SelectedTile = tile; };
            tileMenu.MenuItems.Add(menuTileMove);

            var menuTileDelete = new MenuItem { Text = "Delete".Localize() };
            menuTileDelete.Click += (s, e) => DeleteTile(tile);
            tileMenu.MenuItems.Add(menuTileDelete);

            var position = ScreenRoutines.ScreenLocaton(tile);
            position.Offset(location.X, location.Y);
            tileMenu.Show(ParentControl, position.ToPixels());

            return true;
        }