Example #1
0
        private void onExportObjectSelected(ExportTableEntrySelectedMessage message)
        {
            if (message.ExportTableEntry.DomainObject == null)
            {
                return;
            }

            switch (message.ExportTableEntry.DomainObject.Viewable)
            {
            case ViewableTypes.Sound:
            {
                Task.Run(() => playSound(message.ExportTableEntry.DomainObject.GetObjectStream(), resetToken())).FireAndForget();

                break;
            }

            case ViewableTypes.Image:
            {
                texture = message.ExportTableEntry.DomainObject as DomainObjectTexture2D;

                if (texture != null)
                {
                    clearViewModel();

                    viewModel.MipMaps = new ObservableCollection <MipMapViewEntity>(mapper.Map <IEnumerable <MipMapViewEntity> >(texture.MipMaps));

                    for (int i = 0; i < viewModel.MipMaps.Count; ++i)
                    {
                        viewModel.MipMaps[i].Level = i + 1;

                        viewModel.MipMaps[i].PropertyChanged += onMipMapViewEntityChanged;
                    }

                    MipMapViewEntity largest = viewModel.MipMaps.Aggregate((i1, i2) => i1 != null && i1.IsEnabled & (i1.Width > i2.Width || i1.Height > i2.Height) ? i1 : (i2.IsEnabled ? i2 : null));

                    if (largest != null)
                    {
                        largest.IsChecked = true;
                    }
                }

                break;
            }

            case ViewableTypes.Font:
            {
                var fontexport = message.ExportTableEntry.DomainObject as DomainObjectFontResource;
                using (MemoryStream fontms = new MemoryStream(fontexport.Font))
                {
                    var fontfamilies = FontConversion.Load(fontms);
                    var fontfamily   = fontfamilies.Families.First();

                    using (Bitmap b = new Bitmap(600, 400))
                    {
                        using (Graphics g = Graphics.FromImage(b))
                        {
                            g.Clear(Color.White);         // White background
                            using (Font font = new Font(fontfamily, 24, FontStyle.Regular, GraphicsUnit.Pixel))
                            {
                                using (Font arial = new Font(new FontFamily("Arial"), 24, FontStyle.Regular, GraphicsUnit.Pixel))
                                {
                                    using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                    {
                                        g.DrawString(String.Format("{0}, {1}, {2}px", font.Name, font.Style, 24), arial, solidBrush, new RectangleF(10, 10, 600, 600));
                                    }
                                }
                                using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                {
                                    g.DrawString("abcdefghijklmnopqrstuvwxyz", font, solidBrush, new RectangleF(10, 36, 600, 600));
                                    g.DrawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", font, solidBrush, new RectangleF(10, 62, 600, 600));
                                    g.DrawString("1234567890", font, solidBrush, new RectangleF(10, 88, 600, 600));
                                    g.DrawString("The quick brown fox jumps over the lazy dog.", font, solidBrush, new RectangleF(10, 114, 600, 600));
                                }
                            }
                            using (Font font = new Font(fontfamily, 48, FontStyle.Regular, GraphicsUnit.Pixel))
                            {
                                using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                {
                                    g.DrawString("The quick brown fox jumps over the lazy dog.", font, solidBrush, new RectangleF(10, 166, 600, 600));
                                }
                            }
                        }
                        viewModel.Texture = BitmapConversion.ToWpfBitmap(b);
                    }
                }
                break;
            }

            default:
            {
                clearViewModel();

                break;
            }
            }
        }
Example #2
0
        private void onExportedObjectSelected(ExportedObjectSelectedMessage message)
        {
            string extension = Path.GetExtension(message.Filename)?.ToLowerInvariant();

            switch (extension)
            {
            case ".ogg":
            {
                Task.Run(() => playSound(new FileStream(message.Filename, FileMode.Open), resetToken())).FireAndForget();

                break;
            }

            case ".dds":
            {
                DdsFile image = new DdsFile(message.Filename);

                viewModel.MipMaps = null;

                viewModel.Texture = image.BitmapSource;

                break;
            }

            case ".ttf":
            case ".otf":
            {
                using (MemoryStream fontms = new MemoryStream(File.ReadAllBytes(message.Filename)))
                {
                    var fontfamilies = FontConversion.Load(fontms);
                    var fontfamily   = fontfamilies.Families.First();

                    using (Bitmap b = new Bitmap(600, 400))
                    {
                        using (Graphics g = Graphics.FromImage(b))
                        {
                            g.Clear(Color.White);         // White background
                            using (Font font = new Font(fontfamily, 24, FontStyle.Regular, GraphicsUnit.Pixel))
                            {
                                using (Font arial = new Font(new FontFamily("Arial"), 24, FontStyle.Regular, GraphicsUnit.Pixel))
                                {
                                    using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                    {
                                        g.DrawString(String.Format("{0}, {1}, {2}px", font.Name, font.Style, 24), arial, solidBrush, new RectangleF(10, 10, 600, 600));
                                    }
                                }
                                using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                {
                                    g.DrawString("abcdefghijklmnopqrstuvwxyz", font, solidBrush, new RectangleF(10, 36, 600, 600));
                                    g.DrawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", font, solidBrush, new RectangleF(10, 62, 600, 600));
                                    g.DrawString("1234567890", font, solidBrush, new RectangleF(10, 88, 600, 600));
                                    g.DrawString("The quick brown fox jumps over the lazy dog.", font, solidBrush, new RectangleF(10, 114, 600, 600));
                                }
                            }
                            using (Font font = new Font(fontfamily, 48, FontStyle.Regular, GraphicsUnit.Pixel))
                            {
                                using (SolidBrush solidBrush = new SolidBrush(Color.Black))
                                {
                                    g.DrawString("The quick brown fox jumps over the lazy dog.", font, solidBrush, new RectangleF(10, 166, 600, 600));
                                }
                            }
                        }
                        viewModel.Texture = BitmapConversion.ToWpfBitmap(b);
                    }
                }
                break;
            }
            }
        }