コード例 #1
0
        public void DisplayCollection(Collection collection, Matrix matrix, Grid mainGrid)
        {
            CollectionGrid.RowDefinitions.Clear();
            CollectionGrid.Children.Clear();

            // Iterate through the list
            for (int row = 0; row < collection.Graphics.Count; row++)
            {
                MatrixData graphicData = collection.Graphics[row];

                RowDefinition rowDefinition = new RowDefinition();

                RowDefinition spacer = new RowDefinition();
                spacer.Height = new GridLength(5);

                Label nameLabel = new Label();
                nameLabel.Background = new SolidColorBrush(Colors.LightGray);
                nameLabel.MinWidth   = 200;
                nameLabel.VerticalContentAlignment = VerticalAlignment.Center;
                nameLabel.Content = graphicData.Name;

                Button editButton = new Button();
                editButton.Content = "Edit";
                editButton.Width   = 50;

                editButton.Click += (s, e) =>
                {
                    matrix.SetMatrix(graphicData);
                };

                Button removeButton = new Button();
                removeButton.Content = "Remove";
                removeButton.Width   = 50;

                removeButton.Click += (s, e) =>
                {
                    collection.Graphics.Remove(graphicData);
                    collection.Save();

                    DisplayCollection(collection, matrix, mainGrid);
                };

                Grid.SetColumn(nameLabel, 0);
                Grid.SetRow(nameLabel, 2 * row);
                Grid.SetColumn(editButton, 1);
                Grid.SetRow(editButton, 2 * row);
                Grid.SetColumn(removeButton, 2);
                Grid.SetRow(removeButton, 2 * row);

                CollectionGrid.RowDefinitions.Add(rowDefinition);
                if (row != collection.Graphics.Count - 1)
                {
                    CollectionGrid.RowDefinitions.Add(spacer);
                }

                CollectionGrid.Children.Add(nameLabel);
                CollectionGrid.Children.Add(editButton);
                CollectionGrid.Children.Add(removeButton);
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds a graphic to the list or overwrites if one is present with the same name
        /// (Used instead of Graphics.Add())
        /// </summary>
        public void AddGraphic(MatrixData graphic)
        {
            int existingDataIndex = Graphics.FindIndex(x => x.Name == graphic.Name);

            if (existingDataIndex != -1)
            {
                Graphics[existingDataIndex] = graphic;
            }
            else
            {
                Graphics.Add(graphic);
            }

            Graphics.Sort((x, y) => x.Name.CompareTo(y.Name));
            Save();
        }
コード例 #3
0
        /// <summary>
        /// Sets the matrix according to MatrixData (from collection)
        /// </summary>
        public void SetMatrix(MatrixData data)
        {
            nameText.Text = data.Name;
            CreateMatrix(data.Size);

            // Enable LEDs
            for (int j = 0; j < size.Item2; j++)
            {
                for (int i = 0; i < size.Item1; i++)
                {
                    int rowCode = data.RowCodes[j];
                    int place   = 1 << Math.Abs(i - size.Item1 + 1);

                    if ((rowCode & place) == place)
                    {
                        rows[j].LEDs[i].Enabled = true;
                    }
                }
            }

            UpdateCode(currentType, true);
        }