Example #1
0
        public static CompartmentMapping[] DecorateInheritedCompartmentNamedElements(this CompartmentShape shape, CompartmentMapping[] mappings)
        {
            Guard.NotNull(() => shape, shape);
            Guard.NotNull(() => mappings, mappings);

            // Iterate through each element in the compartment and update its image.
            foreach (var elementMap in mappings.OfType <ElementListCompartmentMapping>())
            {
                if (elementMap != null)
                {
                    // Set the image
                    elementMap.ImageGetter = mel =>
                    {
                        // Construct a composite image with both Inherited and Customization icons
                        var customizableElement = mel as CustomizableElementSchema;
                        var namedElement        = mel as NamedElementSchema;
                        if (namedElement != null)
                        {
                            // Example images for sizing calculation only
                            using (Bitmap inheritedImage = Properties.Resources.Inherited)
                            {
                                using (Bitmap tempCustomizationImage = Properties.Resources.CustomizationInheritedDisabled)
                                {
                                    // Calculate composite image
                                    Bitmap compositeGlyph = new Bitmap((inheritedImage.Width + tempCustomizationImage.Width + CompositeImageSpacing), System.Math.Max(inheritedImage.Height, tempCustomizationImage.Height));
                                    using (Graphics graphics = Graphics.FromImage(compositeGlyph))
                                    {
                                        // Add Inherited icon
                                        if (namedElement.IsInheritedFromBase)
                                        {
                                            // Add customizable icon
                                            if (customizableElement != null)
                                            {
                                                Bitmap customizationImage = GetCustomizationStateImage(customizableElement.IsCustomizationEnabledState);

                                                // Draw combined image
                                                graphics.DrawImage(inheritedImage, 0, 0);
                                                graphics.DrawImage(customizationImage, (inheritedImage.Width + CompositeImageSpacing), 0);
                                            }
                                            else
                                            {
                                                // Just draw inherited image
                                                graphics.DrawImage(inheritedImage, 0, 0);
                                            }
                                        }
                                        else
                                        {
                                            if (customizableElement != null)
                                            {
                                                Bitmap customizationImage = GetCustomizationStateImage(customizableElement.IsCustomizationEnabledState);

                                                // Just draw the customiable icon
                                                graphics.DrawImage(customizationImage, (inheritedImage.Width + CompositeImageSpacing), 0);
                                            }
                                        }

                                        return(compositeGlyph);
                                    }
                                }
                            }
                        }

                        return(null);
                    };

                    // Set the displayed text
                    elementMap.StringGetter = mel =>
                    {
                        // Custom format for Properties
                        var property = mel as PropertySchema;
                        if (property != null)
                        {
                            return(property.GetDisplayText());
                        }

                        // Custom format for AutomationSettings
                        var automation = mel as AutomationSettingsSchema;
                        if (automation != null)
                        {
                            return(automation.GetDisplayText());
                        }

                        // Returns default string for other items
                        return(SerializationUtilities.GetElementName(mel));
                    };
                }
            }

            return(mappings);
        }