public static void SaveProfilesTexture(BackgroundWorker worker) { float buttonSize = 0.1f; int gridWidth = 4; int gridHeight = 2; while ((gridWidth * (gridHeight - 1)) < profiles.Count) { if (gridWidth == gridHeight - 1) { gridWidth++; } else { gridHeight++; } } Profile p = new Profile(DirectoryInfo.FolderPath); ButtonGrid g = p.NewGrid(); g.filename = DirectoryInfo.ProfilesTextureName; g.GridWidth = gridWidth; g.GridHeight = gridHeight; g.Width = gridWidth * buttonSize; g.Height = gridHeight * buttonSize; g.Outline = true; GridButton resetButton = g.NewButton(0, 0); resetButton.Width = gridWidth / 2; resetButton.Text = "Reset Seated Position"; resetButton.FontSize = 0.0125; GridButton laserButton = g.NewButton(2, 0); laserButton.Width = gridWidth - (gridWidth / 2); laserButton.Text = "Toggle Laser Mode"; laserButton.FontSize = 0.0125; int gridX = 0; int gridY = 1; foreach (Profile profile in profiles) { GridButton b = g.NewButton(gridX, gridY); b.Text = profile.Name; gridX++; if (gridX >= gridWidth) { gridX = 0; gridY++; } } g.CreateAndSaveImage(worker); }
private void GridSelected(object sender, SelectionChangedEventArgs e) { this.ButtonGrid = (ButtonGrid)GridNameBox.SelectedItem; this.CurrentButton = null; this.SelectedX = -1; this.SelectedY = -1; UpdateDisplayAndImage(); }
private void NewProfile(object sender, RoutedEventArgs e) { this.ButtonGrid = null; this.CurrentButton = null; this.SelectedX = -1; this.SelectedY = -1; this.Profile = Profiles.NewProfile(); UpdateDisplayAndImage(); UpdateProfileImage(); }
private void NewButton(object sender, RoutedEventArgs e) { if (this.CurrentButton != null || this.SelectedX < 0 || this.SelectedY < 0) { return; } this.CurrentButton = this.ButtonGrid.NewButton(this.SelectedX, this.SelectedY); UpdateDisplayAndImage(); }
public GridButton NewButton(int x, int y) { Debug.Assert(this.SpatialIndex[x, y] == null); GridButton button = new GridButton(x, y); button.parent = this; this.buttons.Add(button); this.SpatialIndex[x, y] = button; parent.Save(); return(button); }
public void AddButtonToIndex(GridButton button) { for (int x = button.X; x < button.X + button.Width; x++) { for (int y = button.Y; y < button.Y + button.Height; y++) { Debug.Assert(this.SpatialIndex[x, y] == null); this.SpatialIndex[x, y] = button; } } }
public void RemoveButtonFromIndex(GridButton button) { for (int x = button.X; x < button.X + button.Width; x++) { for (int y = button.Y; y < button.Y + button.Height; y++) { Debug.Assert(this.SpatialIndex[x, y] == button); this.SpatialIndex[x, y] = null; } } }
private void NewGrid(object sender, RoutedEventArgs e) { if (this.Profile == null) { return; } this.CurrentButton = null; this.SelectedX = -1; this.SelectedY = -1; this.ButtonGrid = this.Profile.NewGrid(); UpdateDisplayAndImage(); }
private void UpdateDisplay() { if (this.ButtonGrid == null || this.SelectedX >= this.ButtonGrid.GridWidth || this.SelectedY >= this.ButtonGrid.GridHeight) { this.CurrentButton = null; this.SelectedX = -1; this.SelectedY = -1; } this.UpdateGridDisplay(); this.UpdateButtonDisplay(); this.UpdateSelectionDisplay(); }
private void ProfileSelected(object sender, SelectionChangedEventArgs e) { if (ProfileNameBox.SelectedItem != this.Profile && ProfileNameBox.SelectedItem != null) { this.Profile = (Profile)ProfileNameBox.SelectedItem; this.ButtonGrid = null; this.CurrentButton = null; this.SelectedX = -1; this.SelectedY = -1; if (this.Profile.grids.Count > 0) { this.ButtonGrid = this.Profile.grids[0]; } UpdateDisplayAndImage(); } }
private void ImageClicked(object sender, MouseButtonEventArgs e) { if (this.ButtonGrid == null) { return; } Point position = e.GetPosition(TextureImage); int x = ((int)position.X) * this.ButtonGrid.GridWidth / (int)TextureImage.Width; int y = ((int)position.Y) * this.ButtonGrid.GridHeight / (int)TextureImage.Height; this.SelectedX = x; this.SelectedY = y; this.CurrentButton = this.ButtonGrid.ButtonAtPosition(x, y); this.UpdateDisplay(); }
private void DeleteButton(object sender, RoutedEventArgs e) { if (this.CurrentButton == null) { return; } MessageBoxResult result = MessageBox.Show("Delete this button?", "Confirm", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { var temp = this.CurrentButton; this.CurrentButton = null; this.SelectedX = -1; this.SelectedY = -1; this.ButtonGrid.DeleteButton(temp); UpdateDisplayAndImage(); } }
public bool CanMoveTo(int x, int y) { if (x < 0 || y < 0 || x + this.width > this.parent.GridWidth || y + this.height > this.parent.GridHeight) { return(false); } for (; x < this.x + this.width; x++) { for (; y < this.y + this.height; y++) { GridButton button = this.parent.ButtonAtPosition(x, y); if (button != null && button != this) { return(false); } } } return(true); }
public void DeleteButton(GridButton button) { this.RemoveButtonFromIndex(button); this.buttons.Remove(button); parent.Save(); }