/// <summary> /// User hit the "Add Images" button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mAddImagesButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.jpg, *.png, *.tga)|*.jpg;*.png;*.tga|All files (*.*)|*.*"; openFileDialog.InitialDirectory = GUIProject.CurrentProject.ProjectDirectory; openFileDialog.Multiselect = true; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } foreach (string fn in openFileDialog.FileNames) { FontBuilder.ImageGlyph glyph = new FontBuilder.ImageGlyph(); glyph.ImagePath = Utils.GetRelativePath(GUIProject.CurrentProject.ProjectDirectory, fn); int count = 0; foreach (FontBuilder.ImageGlyph existingGlyph in mGlyphs.OfType <FontBuilder.ImageGlyph>()) { string newId = String.Format("{0:0000}", count); if (existingGlyph.ID == newId) { count++; if (count > 9999) { break; } continue; } } if (count <= 9999) { glyph.ID = String.Format("{0:0000}", count); mGlyphs.Add(glyph); } } PopulateDataGrid(); }
/// <summary> /// User hit the "Add Images" button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mAddImagesButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.jpg, *.png, *.tga)|*.jpg;*.png;*.tga|All files (*.*)|*.*"; openFileDialog.InitialDirectory = GUIProject.CurrentProject.ProjectDirectory; openFileDialog.Multiselect = true; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() != DialogResult.OK) return; foreach (string fn in openFileDialog.FileNames) { FontBuilder.ImageGlyph glyph = new FontBuilder.ImageGlyph(); glyph.ImagePath = Utils.GetRelativePath(GUIProject.CurrentProject.ProjectDirectory, fn); int count = 0; foreach (FontBuilder.ImageGlyph existingGlyph in mGlyphs.OfType<FontBuilder.ImageGlyph>()) { string newId = String.Format("{0:0000}", count); if (existingGlyph.ID == newId) { count++; if (count > 9999) { break; } continue; } } if (count <= 9999) { glyph.ID = String.Format("{0:0000}", count); mGlyphs.Add(glyph); } } PopulateDataGrid(); }
/// <summary> /// Editing has ended /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mGlyphDataGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = mGlyphDataGrid.Rows[e.RowIndex]; DataGridViewCell cell = row.Cells[e.ColumnIndex]; // We want to edit the name if (row.Tag is FontBuilder.ImageGlyph && e.ColumnIndex == 1) { DataGridViewTextBoxCell textCell = cell as DataGridViewTextBoxCell; string text = textCell.Value as string; if (textCell != null && text != null) { FontBuilder.ImageGlyph glyph = row.Tag as FontBuilder.ImageGlyph; text = text.Trim(new char[] { '{', '}' }); if (text != "") { // First check to see if this ID is not taken by anyone. foreach (FontBuilder.ImageGlyph existingGlyph in mGlyphs.OfType <FontBuilder.ImageGlyph>()) { if (existingGlyph.ID == text) { text = glyph.ID; break; } } } else { text = glyph.ID; } glyph.ID = text; textCell.Value = String.Format("{{{0}}}", glyph.ID); } } }