Exemplo n.º 1
0
        private void UI_TestTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (FontImageTexFile.SheetData == null)
            {
                return;
            }
            var image = FontCodeFile.RenderFont(FontImageTexFile, " " + UI_TestTextBox.Text);

            UI_FontTest.Source = ImageTools.ConvertToSource(image);
        }
Exemplo n.º 2
0
        private void UI_LoadTextureButton_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Filter = "All Supported Files|*.tex|Texture|*.tex";
            if (ofd.ShowDialog() == true)
            {
                // Load Font TEX
                FontImageTexFile.Load(ofd.FileName);
                UI_FontImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap());
            }
        }
Exemplo n.º 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Filter = "All Supported Files|*.code;*.pck|Font Code|*.code|PCK Archive|*.pck";
            if (ofd.ShowDialog() == true)
            {
                LoadFile(ofd.FileName);
                var image = FontCodeFile.RenderFont(FontImageTexFile, " " + UI_TestTextBox.Text);
                UI_FontTest.Source = ImageTools.ConvertToSource(image);
            }
        }
Exemplo n.º 4
0
        public void LoadFile(string path)
        {
            if (path == null)
            {
                return;
            }

            // Check if its a PCK
            if (path.ToLowerInvariant().Contains(".pck"))
            {
                LoadFontPCK(path);
                return;
            }

            // Check if file is valid and make sure FilePath is the .code
            if (path.ToLowerInvariant().Contains("_data.tex") || path.ToLowerInvariant().Contains(".code"))
            {
                FilePath = path.Replace("_data.tex", ".code");
            }
            else
            {
                MessageBox.Show($"Unknown file type\n{path}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // Recreate Objects
            FontImageTexFile           = new TEXFile();
            FontCodeFile               = new FontFile();
            FontCodeFile.MonospaceOnly = MonospaceOnly;

            try
            {
                // Load Font TEX
                FontImageTexFile.Load(FilePath.Replace(".code", "_data.tex"));
                UI_FontImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap());
            }
            catch
            {
                MessageBox.Show("Failed to load Texture!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            LastIndex  = -1;
            HoverIndex = -1;

            // Load FontCode
            FontCodeFile.Load(FilePath);

            // Reload
            ReloadUI();

            UI_SaveButton.IsEnabled = true;
        }
Exemplo n.º 5
0
        public void LoadFontPCK(string path)
        {
            FilePath       = path;
            PCKFontArchive = new PCKFile();
            PCKFontArchive.Load(path);

            var textureFilePath  = PCKFontArchive.SearchForFile(".tex");
            var fontCodeFilePath = PCKFontArchive.SearchForFile(".code");

            FontImageTexFile           = new TEXFile();
            FontCodeFile               = new FontFile();
            FontCodeFile.MonospaceOnly = MonospaceOnly;

            // Load Font Code
            if (fontCodeFilePath != null)
            {
                FontCodeFile.Load(PCKFontArchive.GetFileStream(fontCodeFilePath));
            }
            else
            {
                MessageBox.Show("Failed to load Code File!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (textureFilePath != null)
            {
                // Load Texture
                FontImageTexFile.Load(PCKFontArchive.GetFileStream(textureFilePath));
                // Set Texture
                UI_FontImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap());
            }
            else
            {
                MessageBox.Show("Failed to load Texture!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            LastIndex  = -1;
            HoverIndex = -1;

            // Reload
            ReloadUI();

            UI_SaveButton.IsEnabled = true;
        }
Exemplo n.º 6
0
        public void UpdatePreview()
        {
            var entry = UI_CharactersListBox.SelectedItem as FontFile.FontEntry;

            if (entry == null)
            {
                return;
            }
            double x = Math.Round(entry.XScale * UI_FontImage.Source.Width + entry.Kerning);
            double y = Math.Round(entry.YScale * (UI_FontImage.Source.Height));
            double w = entry.Width;
            double h = FontCodeFile.CharacterHeight;

            UI_CharTextBox.Text    = entry.Character.ToString();
            UI_XTextBox.Text       = x.ToString(CultureInfo.GetCultureInfo("en-US"));
            UI_YTextBox.Text       = y.ToString(CultureInfo.GetCultureInfo("en-US"));
            UI_WTextBox.Text       = entry.Width.ToString();
            UI_KTextBox.Text       = entry.Kerning.ToString();
            UI_PreviewImage.Source = ImageTools.ConvertToSource(FontImageTexFile.CreateBitmap((int)x, (int)y, (int)w, (int)h));
        }
Exemplo n.º 7
0
        private void UI_ImportTextureButton_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Filter = "All Supported Files|*.tex;*.png|Texture|*.tex|Supported Image Files|*.png";
            if (ofd.ShowDialog() == true)
            {
                if (ofd.FileName.ToLower(CultureInfo.GetCultureInfo("en-US")).EndsWith(".tex"))
                {
                    var textureFilePath = PCKFontArchive.SearchForFile(".tex");
                    var newTexture      = new TEXFile();

                    // Set Sigless
                    newTexture.Sigless = true;

                    // Load new Texture
                    newTexture.Load(ofd.FileName);

                    // Check Dimensions
                    if (FontImageTexFile.SheetData != null &&
                        (newTexture.SheetWidth != FontImageTexFile.SheetWidth ||
                         newTexture.SheetHeight != FontImageTexFile.SheetHeight))
                    {
                        if (MessageBox.Show("Texture dimensions do not match!\n" +
                                            "FontEditor currently does not support rescaling, Do you want to continue?",
                                            "WARNING",
                                            MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                        {
                            return;
                        }
                    }

                    // Import Texture into PCK
                    PCKFontArchive.ReplaceFile(textureFilePath, File.ReadAllBytes(ofd.FileName));

                    // Set Texture
                    UI_FontImage.Source = ImageTools.ConvertToSource((FontImageTexFile = newTexture).CreateBitmap());
                }
                else
                {
                    var textureFilePath = PCKFontArchive.SearchForFile(".tex");
                    var newTexture      = new TEXFile();

                    // Set Sigless
                    newTexture.Sigless = true;

                    // Load Image to Texture
                    newTexture.LoadSheetImage(ofd.FileName);

                    // Check Dimensions
                    if (FontImageTexFile.SheetData != null &&
                        (newTexture.SheetWidth != FontImageTexFile.SheetWidth ||
                         newTexture.SheetHeight != FontImageTexFile.SheetHeight))
                    {
                        if (MessageBox.Show("Texture dimensions do not match!\n" +
                                            "FontEditor currently does not support rescaling, Do you want to continue?",
                                            "WARNING",
                                            MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                        {
                            return;
                        }
                    }

                    // Save Texture to PCK
                    using (var stream = new MemoryStream())
                    {
                        newTexture.Save(stream);
                        PCKFontArchive.ReplaceFile(textureFilePath, stream.ToArray());
                    }

                    // Set Texture
                    UI_FontImage.Source = ImageTools.ConvertToSource((FontImageTexFile = newTexture).CreateBitmap());
                }
            }
        }