Пример #1
0
        public void Execute(object parameter)
        {
            mpm.FB_UI_Atlas.Sprites.Clear();
            mpm.Rectangles.Clear();
            mpm.FB_UI_Atlas.Fonts.Clear();

            FontSettings fontSettings = new FontSettings();

            MaxRectsBinPack binPack = new MaxRectsBinPack((int)mpm.TextureWidth, (int)mpm.TextureHeight, false);

            //fontsize 20
            mpm.FontSystem.GenerateFont(mpm.Rectangles,
                                        mpm.FB_UI_Atlas.Fonts,
                                        binPack,
                                        fontSettings);

            //fontsize 40
            fontSettings = new FontSettings()
            {
                FontSize = 40
            };

            mpm.FontSystem.GenerateFont(mpm.Rectangles,
                                        mpm.FB_UI_Atlas.Fonts,
                                        binPack,
                                        fontSettings);


            AtlasHelper.GenAtlas(binPack, mpm.Rectangles, mpm.FB_UI_Atlas.Sprites, mpm.ImageFolder, mpm.ImageExtensions, mpm.TextureWidth, mpm.TextureHeight);
        }
Пример #2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var mpm = ((AtlasModel)this.DataContext);

                mpm.Sprites.Clear();
                mpm.Rectangles.Clear();
                //    mpm.Fonts.Clear();

                //     FontSettings fontSettings = new FontSettings();

                MaxRectsBinPack binPack = new MaxRectsBinPack((int)mpm.TextureWidth, (int)mpm.TextureHeight, false);

                System.Drawing.Image image = System.Drawing.Image.FromFile(@"F:\Projekte\coop\XGame\_devFolder\Work\UI\Button_test-export.png");//mpm.AngelcodeFontFile);
                Rect newPos = binPack.Insert(image.Width, image.Height, MaxRectsBinPack.FreeRectChoiceHeuristic.RectBestLongSideFit);
                foreach (var fontModel in mpm.Fonts)
                {
                    foreach (FontData character  in fontModel.Items)
                    {
                        character.Glyph.X += (int)newPos.X;
                        character.Glyph.Y += (int)newPos.Y;
                    }
                }

                Rectangle testRect = new Rectangle
                {
                    Stroke          = Brushes.LightBlue,
                    StrokeThickness = 0
                };
                ImageBrush  ib  = new ImageBrush();
                BitmapImage bmi = new BitmapImage(new Uri(@"F:\Projekte\coop\XGame\_devFolder\Work\UI\Button_test-export.png", UriKind.Absolute));
                ib.ImageSource = bmi;
                testRect.Fill  = ib;


                testRect.Width  = newPos.Width;
                testRect.Height = newPos.Height;

                Canvas.SetLeft(testRect, newPos.Left);
                Canvas.SetTop(testRect, newPos.Top);

                mpm.Rectangles.Add(testRect);
                //mpm.FontSystem.GenerateFont(mpm.Rectangles,
                //                           mpm.Fonts,
                //                            binPack,
                //                          fontSettings);

                //fontSettings = new FontSettings()
                //{
                //    FontSize = 40
                //};

                //mpm.FontSystem.GenerateFont(mpm.Rectangles,
                //                          mpm.FB_UI_Atlas.Fonts,
                //                          binPack,
                //                          fontSettings);


                AtlasHelper.GenAtlas(binPack, mpm.Rectangles, mpm.Sprites, mpm.ImageFolder, mpm.ImageExtensions, mpm.TextureWidth, mpm.TextureHeight);


                RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
                    (int)canvas.Width, (int)canvas.Height,
                    96d, 96d, PixelFormats.Pbgra32);
                // needed otherwise the image output is black
                canvas.Measure(new Size((int)canvas.Width, (int)canvas.Height));
                canvas.Arrange(new Rect(new Size((int)canvas.Width, (int)canvas.Height)));

                renderBitmap.Render(canvas);

                //JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));

                using (FileStream file = File.Create(((AtlasModel)this.DataContext).FB_UI_Atlas.TextureName))
                {
                    encoder.Save(file);
                }

                var fbData = mpm.FB_UI_Atlas.CreateFBData();

                //@"F:\Projekte\coop\XGame\data\dbData\UI\TestAtlas.fbbin"
                using (FileStream fileStream = new FileStream(mpm.TargetFbbinFile, FileMode.Create))
                {
                    // Write the data to the file, byte by byte.
                    for (int i = 0; i < fbData._fbData.Length; i++)
                    {
                        fileStream.WriteByte(fbData._fbData[i]);
                    }

                    // Set the stream position to the beginning of the file.
                    fileStream.Seek(0, SeekOrigin.Begin);

                    // Read and verify the data.
                    for (int i = 0; i < fileStream.Length; i++)
                    {
                        if (fbData._fbData[i] != fileStream.ReadByte())
                        {
                            Console.WriteLine("Error writing data.");
                            return;
                        }
                    }
                    Console.WriteLine("The data was written to {0} " +
                                      "and verified.", fileStream.Name);
                }
            }
            catch (Exception ex)
            {
            }
        }