private void UpdateGlyphGrid(GlyphFontViewModel glyphFontViewModel) { if (_currentGlyphFontViewModelOfGlyphGrid == glyphFontViewModel) { return; } if (glyphFontViewModel.GlyphCount > 256) { throw new Exception("Only fonts allowed of up to 256 characters."); } var glyphButtonViewModels = new GlyphButtonViewModel[glyphFontViewModel.GlyphCount]; for (var glyphIndex = 0; glyphIndex < glyphFontViewModel.GlyphCount; glyphIndex++) { if (glyphIndex >= glyphFontViewModel.GlyphCount) { break; } var glyphCropInFontImage = glyphFontViewModel.GetGlyphCropRectangle(glyphIndex); glyphButtonViewModels[glyphIndex] = new GlyphButtonViewModel(glyphFontViewModel, glyphIndex, glyphCropInFontImage); } GlyphGrid.ItemsSource = glyphButtonViewModels; _currentGlyphFontViewModelOfGlyphGrid = glyphFontViewModel; }
public GlyphChangedEvent(GlyphFontViewModel previousGlyphFontViewModel, GlyphFontViewModel newNewGlyphFontViewModel, int previousGlyphIndex, int newGlyphIndex) { PreviousGlyphFontViewModel = previousGlyphFontViewModel; NewGlyphFontViewModel = newNewGlyphFontViewModel; PreviousGlyphIndex = previousGlyphIndex; NewGlyphIndex = newGlyphIndex; }
public GlyphButtonViewModel(GlyphFontViewModel glyphFontViewModel, int glyphIndex, Int32Rect cropInFontBitmap) { GlyphFontViewModel = glyphFontViewModel; GlyphIndex = glyphIndex; CropInFontBitmap = cropInFontBitmap; var size = Math.Max(glyphFontViewModel.GlyphSize.X, glyphFontViewModel.GlyphSize.Y); Stretch = size > 12 ? Stretch.Uniform : Stretch.None; }
private void ChangeGlyph(GlyphFontViewModel glyphFontViewModel, int glyphIndex) { if (CurrentGlyphMapTexture?.GlyphFontViewModel != glyphFontViewModel) { if (!_glyphMapTextures.ContainsKey(glyphFontViewModel)) { var texture = Texture2D.FromStream(GraphicsDevice, File.OpenRead(glyphFontViewModel.Filename)); CurrentGlyphMapTexture = new GlyphMapTexture(glyphFontViewModel, texture, glyphFontViewModel.GlyphSize.X, glyphFontViewModel.GlyphSize.Y); _glyphMapTextures.Add(glyphFontViewModel, CurrentGlyphMapTexture); } else { CurrentGlyphMapTexture = _glyphMapTextures[glyphFontViewModel]; } } Brush.GlyphIndex = glyphIndex; }
public GlyphMapTexture(GlyphFontViewModel glyphFontViewModel, Texture2D texture, int glyphWidth, int glyphHeight) { GlyphFontViewModel = glyphFontViewModel; Texture = texture; if (texture.Width % glyphWidth != 0) { throw new ArgumentOutOfRangeException($"Texture width ({texture.Width}) is not a multitude of GlyphWidth ({glyphWidth})."); } if (texture.Height % glyphHeight != 0) { throw new ArgumentOutOfRangeException($"Texture height ({texture.Height}) is not a multitude of GlyphHeight ({glyphHeight})."); } ColumnCount = texture.Width / glyphWidth; RowCount = texture.Height / glyphHeight; GlyphWidth = glyphWidth; GlyphHeight = glyphHeight; GlyphWidthU = GlyphWidth / texture.Width; GlyphHeightV = GlyphHeight / texture.Height; ConvertGrayValuesToAlpha(texture); BuildGlyphUVLookup(texture, glyphHeight); }
public ChangeGlyphFontCommand(GlyphFontViewModel glyphFontViewModel) { GlyphFontViewModel = glyphFontViewModel; }