Example #1
0
        private void onMipMapViewEntityChanged(object sender, PropertyChangedEventArgs args)
        {
            if (isSelf)
            {
                return;
            }

            MipMapViewEntity entity = sender as MipMapViewEntity;

            if (entity == null)
            {
                return;
            }

            switch (args.PropertyName)
            {
            case "IsChecked": {
                if (entity.IsChecked)
                {
                    isSelf = true;

                    viewModel.MipMaps.Where(mip => mip != entity).ToList().ForEach(mip => mip.IsChecked = false);

                    isSelf = false;

                    Stream stream = texture.GetObjectStream(entity.Level - 1);

                    if (stream != null)
                    {
                        DdsFile ddsFile = new DdsFile();

                        ddsFile.Load(stream);

                        viewModel.Texture = ddsFile.BitmapSource;

                        stream.Close();
                    }
                }
                else
                {
                    isSelf = true;

                    entity.IsChecked = true;

                    isSelf = false;
                }

                break;
            }

            default: {
                break;
            }
            }
        }
Example #2
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;
            }

            default: {
                clearViewModel();

                break;
            }
            }
        }
Example #3
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;
            }
            }
        }