Example #1
0
        private void btnSave2_Click(object sender, RoutedEventArgs e)
        {
            if (bitmapFont == null)
            {
                MessageBox.Show(@"You need to load an image to save the bitmap font.");
                return;
            }
            if (!this.grd_UCD.IsEnabled && charElements.Count == 0)
            {
                MessageBox.Show(@"You need to add elements in the advanced editor if you want to use the individual character dimension.");
                return;
            }

            GameEngine.Font.BitmapEncoder encoder = new GameEngine.Font.BitmapEncoder();

            if (this.grd_UCD.IsEnabled)
            {
                List<CharElement> characterlist = new List<CharElement>();

                int width = int.Parse(this.tbX_ud.Text);
                int height = int.Parse(this.tbY_ud.Text);
                int x = 0;
                int y = 0;
                for (int i = 0; i < this.tbCharacters2.Text.Length; i++)
                {
                    if (bitmapFont.Width < x + width)
                    {
                        y += height;
                        x = 0;
                    }

                    CharElement ce = new CharElement(this.tbCharacters2.Text[i], x, y, width, height);

                    characterlist.Add(ce);
                    x += width;

                    if (y > bitmapFont.Height)
                        break;
                }

                encoder.Chars = characterlist;
            }
            else
            {
                encoder.Chars = this.charElements;
            }
            encoder.Source = this.bitmapFont;
            encoder.Encode(tbFontname.Text);
        }
Example #2
0
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "xml Files (*.xml)|*.xml";
            ofd.AddExtension = true;
            bool? dialogresult = ofd.ShowDialog();

            if (dialogresult.HasValue ? (bool)dialogresult : false)
            {
                using (XmlReader reader = XmlReader.Create(File.OpenRead(ofd.FileName)))
                {
                    charElements.Clear();
                    CharElement element = new CharElement();
                    while (reader.Read())
                    {
                        if (reader.Name == "CharElement" && reader.NodeType == XmlNodeType.EndElement)
                            charElements.Add(element);

                        if (reader.NodeType == XmlNodeType.Element)
                            switch (reader.Name)
                            {
                                case "Name":
                                    reader.Read();
                                    element.Name = (char)int.Parse(reader.Value);
                                    break;
                                case "Position":
                                    element.position = ReadPoint(reader);
                                    break;
                                case "Dimension":
                                    element.dimension = ReadPoint(reader);
                                    break;
                            }
                    }
                }
                tbCharCount.Text = this.charElements.Count.ToString();
            #if DEBUG
                Console.WriteLine("Loading complete.");
            #endif
            }
        }