protected void OnEmptySpaceEventBoxButtonReleased(object sender, ButtonReleaseEventArgs args)
        {
            emptySpaceClicked = false;

            if (emptySpaceLongHeld)
            {
                var parent = Toplevel as Window;
                var addHomeWidgetDialog = new AddHomeWidgetDialog(parent);
                addHomeWidgetDialog.Run();
                var newWidgetSettings = addHomeWidgetDialog.newWidget;

                emptySpaceGraphicalBox.color.A = 0;
                emptySpaceGraphicalBox.QueueDraw();
                if (newWidgetSettings == null)
                {
                    return;
                }

                var pair = HomeWidgetPlacement.GetRowColumn(args.Event.X.ToInt(), args.Event.Y.ToInt());

                var row    = pair.Item1;
                var column = pair.Item2;

                var widget = HomeWindowWidgets.GetNewHomeWidget(
                    newWidgetSettings.type,
                    newWidgetSettings.name,
                    newWidgetSettings.group,
                    row,
                    column);

                if (widget != null)
                {
                    if (row < 0 && (row + widget.rowHeight > 5) && column < 0 && (column + widget.columnWidth > 7))
                    {
                        MessageBox.Show("Not enough room on the screen for widget");
                    }
                    else
                    {
                        tileBoard.OccupyTiles(widget);

                        if (tileBoard.containsConflictTiles)
                        {
                            tileBoard.FreeTiles(widget);
                            MessageBox.Show("Widget conflicts with other widgets");
                        }
                        else
                        {
                            Put(widget, widget.x, widget.y);
                            widget.Show();
                            widgets.Add(widget);
                            widget.WidgetSelectedEvent         += OnWidgetSelected;
                            widget.WidgetUnselectedEvent       += OnWidgetUnselected;
                            widget.RequestNewTileLocationEvent += OnRequestNewTileLocation;
                        }
                    }
                }
            }

            QueueDraw();
        }
        protected void OnRequestNewTileLocation(int x, int y)
        {
            if (x.WithinRange(755, 795) && y.WithinRange(435, 475))
            {
                hoveredOverTrash        = true;
                trashButton.buttonColor = "compl";
                trashButton.QueueDraw();
                return;
            }

            if (hoveredOverTrash)
            {
                hoveredOverTrash = false;
                trashButton.buttonColor.ModifyColor(0.75);
                trashButton.QueueDraw();
            }

            var pair = HomeWidgetPlacement.GetRowColumn(x, y);

            var newRow    = pair.Item1;
            var newColumn = pair.Item2;

            if (newRow == newWidgetLocation.placement.row && newColumn == newWidgetLocation.placement.column)
            {
                return;
            }

            if (newRow >= 0 && (newRow + newWidgetLocation.placement.rowHeight <= 5) &&
                newColumn >= 0 && (newColumn + newWidgetLocation.placement.columnWidth <= 7))
            {
                if (!newWidgetLocation.Visible)
                {
                    newWidgetLocation.Visible = true;
                }

                tileBoard.FreeTiles(newWidgetLocation);
                newWidgetLocation.placement.row    = newRow;
                newWidgetLocation.placement.column = newColumn;
                tileBoard.OccupyTiles(newWidgetLocation);

                if (tileBoard.containsConflictTiles)
                {
                    newWidgetLocation.color = new TouchColor("compl", 0.5);
                }
                else
                {
                    newWidgetLocation.color = new TouchColor("grey2", 0.5);
                }
                Remove(newWidgetLocation);
                Put(newWidgetLocation, newWidgetLocation.placement.x, newWidgetLocation.placement.y);
                newWidgetLocation.Show();
            }
        }
Example #3
0
        public HomeWidget(string type, string name, string group, int row, int column)
        {
            SetSizeRequest(100, 82);

            this.type  = type;
            this.name  = name;
            this.group = group;
            placement  = new HomeWidgetPlacement(row, column);

            switch (type)
            {
            case "Timer":
                placement.columnWidth = 3;
                placement.rowHeight   = 2;
                break;

            case "LinePlot":
                placement.columnWidth = 3;
                placement.rowHeight   = 1;
                break;

            case "BarPlot":
                placement.columnWidth = 1;
                placement.rowHeight   = 2;
                break;

            case "CurvedBarPlot":
                placement.columnWidth = 2;
                placement.rowHeight   = 2;
                break;

            case "Button":
                placement.columnWidth = 1;
                placement.rowHeight   = 1;
                break;

            default:
                throw new Exception(string.Format("Unknown home widget type {0}", type));
            }
        }
 public NewWidgetLocation(HomeWidget widget) : base(widget.width, widget.height)
 {
     placement = new HomeWidgetPlacement(widget.row, widget.column, widget.columnWidth, widget.rowHeight);
 }