private void DrawRenderingAction(RenderingAction action, Control component, Dictionary <string, object> variables)
        {
            if (variables == null)
            {
                variables = new Dictionary <string, object>();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            foreach (KeyValuePair <string, object> kvp in variables)
            {
                dict.Add(kvp.Key, kvp.Value);
            }

            Rectangle bounds = component.Parent.Layout.GetControlBounds(component);

            dict.Add("Component.Width", bounds.Width);
            dict.Add("Component.Height", bounds.Height);

            /*
             * if (component is System.Windows.Forms.ToolStripDropDownMenu)
             * {
             *      System.Windows.Forms.ToolStripDropDownMenu tsddm = (component as System.Windows.Forms.ToolStripDropDownMenu);
             *      if (tsddm.OwnerItem != null)
             *      {
             *              dict.Add("Component.Parent.Width", tsddm.OwnerItem.Width);
             *              dict.Add("Component.Parent.Height", tsddm.OwnerItem.Height);
             *      }
             * }
             * if (component is System.Windows.Forms.ToolStripSplitButton)
             * {
             *      dict.Add("Component.ButtonWidth", (component as System.Windows.Forms.ToolStripSplitButton).ButtonBounds.Width);
             *      dict.Add("Component.DropDownButtonWidth", (component as System.Windows.Forms.ToolStripSplitButton).DropDownButtonBounds.Width);
             * }
             */

            if (action is RectangleRenderingAction)
            {
                RectangleRenderingAction act = (action as RectangleRenderingAction);

                double x = act.X.Evaluate(dict) + bounds.X;
                double y = act.Y.Evaluate(dict) + bounds.Y;
                double w = act.Width.Evaluate(dict);
                double h = act.Height.Evaluate(dict);

                if (act.Fill != null)
                {
                    FillRectangle(BrushFromFill(act.Fill, new Rectangle(x, y, w, h)), x, y, w, h);
                }
                if (act.Outline != null)
                {
                    if (act.Outline is SolidOutline)
                    {
                        DrawRectangle(PenFromOutline(act.Outline), x, y, w - 1, h - 1);
                    }
                    else if (act.Outline is ThreeDOutline)
                    {
                        ThreeDOutline threed = (act.Outline as ThreeDOutline);

                        Color lightColor = Color.Empty;
                        Color darkColor  = Color.Empty;

                        switch (threed.Type)
                        {
                        case ThreeDOutlineType.Inset:
                        {
                            lightColor = Color.FromString(threed.DarkColor);
                            darkColor  = Color.FromString(threed.LightColor);
                            break;
                        }

                        case ThreeDOutlineType.Outset:
                        {
                            lightColor = Color.FromString(threed.LightColor);
                            darkColor  = Color.FromString(threed.DarkColor);
                            break;
                        }
                        }

                        Pen lightPen = new Pen(lightColor, new Measurement(act.Outline.Width, MeasurementUnit.Pixel));
                        Pen darkPen  = new Pen(darkColor, new Measurement(act.Outline.Width, MeasurementUnit.Pixel));

                        DrawLine(lightPen, x, y, x + w, y);
                        DrawLine(lightPen, x, y, x, y + h);
                        DrawLine(darkPen, x + w - 1, y, x + w - 1, y + h - 1);
                        DrawLine(darkPen, x, y + h - 1, x + w - 1, y + h - 1);
                    }
                }
            }
            else if (action is LineRenderingAction)
            {
                LineRenderingAction act = (action as LineRenderingAction);

                double x1 = act.X1.Evaluate(dict) + bounds.X;
                double y1 = act.Y1.Evaluate(dict) + bounds.Y;
                double x2 = act.X2.Evaluate(dict);
                double y2 = act.Y2.Evaluate(dict);

                if (act.Outline != null)
                {
                    DrawLine(PenFromOutline(act.Outline), x1, y1, x2, y2);
                }
            }
            else if (action is TextRenderingAction)
            {
                TextRenderingAction act = (action as TextRenderingAction);

                int    x      = (int)Math.Round(act.X.Evaluate(dict) + bounds.X);
                int    y      = (int)Math.Round(act.Y.Evaluate(dict) + bounds.Y);
                int    width  = (int)Math.Round(act.Width.Evaluate(dict));
                int    height = (int)Math.Round(act.Height.Evaluate(dict));
                Color  color  = Color.FromString(act.Color);
                string value  = act.Value.ReplaceVariables(dict);

                // graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                Font font = SystemFonts.MenuFont;

                /*
                 * if (act.Font != null)
                 * {
                 *      font = Font.FromFamily(act.Font, 8);
                 * }
                 */
                DrawText(value, font, new Rectangle(x, y, width, height), color, act.HorizontalAlignment, act.VerticalAlignment);
            }
        }
Beispiel #2
0
        protected override void AfterLoadInternal(Stack <ObjectModel> objectModels)
        {
            base.AfterLoadInternal(objectModels);

            MarkupObjectModel mom    = (objectModels.Pop() as MarkupObjectModel);
            ThemeObjectModel  themes = (objectModels.Pop() as ThemeObjectModel);

            MarkupTagElement tagThemes = (mom.FindElement("AwesomeControls", "Theming", "Themes") as MarkupTagElement);

            if (tagThemes != null)
            {
                foreach (MarkupElement elTheme in tagThemes.Elements)
                {
                    MarkupTagElement tagTheme = (elTheme as MarkupTagElement);
                    if (tagTheme == null)
                    {
                        continue;
                    }

                    MarkupAttribute attThemeID = tagTheme.Attributes["ID"];
                    if (attThemeID == null)
                    {
                        continue;
                    }

                    Theme theme = new Theme();

                    UniversalEditor.Accessors.FileAccessor fa = (this.Accessor as UniversalEditor.Accessors.FileAccessor);
                    if (fa != null)
                    {
                        theme.BasePath = System.IO.Path.GetDirectoryName(fa.FileName);
                    }

                    theme.ID = new Guid(attThemeID.Value);

                    MarkupAttribute attInheritsThemeID = tagTheme.Attributes["InheritsThemeID"];
                    if (attInheritsThemeID != null)
                    {
                        theme.InheritsThemeID = new Guid(attInheritsThemeID.Value);
                    }

                    MarkupTagElement tagInformation = (tagTheme.Elements["Information"] as MarkupTagElement);
                    if (tagInformation != null)
                    {
                        MarkupTagElement tagInformationTitle = (tagInformation.Elements["Title"] as MarkupTagElement);
                        if (tagInformationTitle != null)
                        {
                            theme.Title = tagInformationTitle.Value;
                        }
                    }

                    MarkupTagElement tagMetrics = (tagTheme.Elements["Metrics"] as MarkupTagElement);
                    if (tagMetrics != null)
                    {
                        foreach (MarkupElement elMetric in tagMetrics.Elements)
                        {
                            MarkupTagElement tagMetric = (elMetric as MarkupTagElement);
                            if (tagMetric == null)
                            {
                                continue;
                            }

                            MarkupAttribute attMetricName = tagMetric.Attributes["Name"];
                            if (attMetricName == null)
                            {
                                continue;
                            }

                            switch (tagMetric.FullName.ToLower())
                            {
                            case "paddingmetric":
                            {
                                PaddingMetric metric = new PaddingMetric();
                                metric.Name = attMetricName.Value;

                                MarkupAttribute attMetricLeft = tagMetric.Attributes["Left"];
                                if (attMetricLeft != null)
                                {
                                    metric.Left = Single.Parse(attMetricLeft.Value);
                                }
                                MarkupAttribute attMetricTop = tagMetric.Attributes["Top"];
                                if (attMetricTop != null)
                                {
                                    metric.Top = Single.Parse(attMetricTop.Value);
                                }
                                MarkupAttribute attMetricBottom = tagMetric.Attributes["Bottom"];
                                if (attMetricBottom != null)
                                {
                                    metric.Bottom = Single.Parse(attMetricBottom.Value);
                                }
                                MarkupAttribute attMetricRight = tagMetric.Attributes["Right"];
                                if (attMetricRight != null)
                                {
                                    metric.Right = Single.Parse(attMetricRight.Value);
                                }

                                theme.Metrics.Add(metric);
                                break;
                            }
                            }
                        }
                    }

                    MarkupTagElement tagColors = (tagTheme.Elements["Colors"] as MarkupTagElement);
                    if (tagColors != null)
                    {
                        foreach (MarkupElement elColor in tagColors.Elements)
                        {
                            MarkupTagElement tagColor = (elColor as MarkupTagElement);
                            if (tagColor == null)
                            {
                                continue;
                            }
                            if (tagColor.FullName != "Color")
                            {
                                continue;
                            }

                            MarkupAttribute attColorID   = tagColor.Attributes["ID"];
                            MarkupAttribute attColorName = tagColor.Attributes["Name"];

                            if (attColorID == null && attColorName == null)
                            {
                                continue;
                            }

                            MarkupAttribute attColorValue = tagColor.Attributes["Value"];
                            if (attColorValue == null)
                            {
                                continue;
                            }

                            ThemeColor color = new ThemeColor();
                            if (attColorID != null)
                            {
                                color.ID = new Guid(attColorID.Value);
                            }
                            if (attColorName != null)
                            {
                                color.Name = attColorName.Value;
                            }
                            if (attColorValue != null)
                            {
                                color.Value = attColorValue.Value;
                            }

                            theme.Colors.Add(color);
                        }
                    }

                    MarkupTagElement tagFonts = (tagTheme.Elements["Fonts"] as MarkupTagElement);
                    if (tagFonts != null)
                    {
                        foreach (MarkupElement elFont in tagFonts.Elements)
                        {
                            MarkupTagElement tagFont = (elFont as MarkupTagElement);
                            if (tagFont == null)
                            {
                                continue;
                            }
                            if (tagFont.FullName != "Font")
                            {
                                continue;
                            }

                            MarkupAttribute attFontName = tagFont.Attributes["Name"];
                            if (attFontName == null)
                            {
                                continue;
                            }

                            MarkupAttribute attFontValue = tagFont.Attributes["Value"];
                            if (attFontValue == null)
                            {
                                continue;
                            }

                            ThemeFont font = new ThemeFont();
                            font.Name  = attFontName.Value;
                            font.Value = attFontValue.Value;

                            theme.Fonts.Add(font);
                        }
                    }

                    MarkupTagElement tagStockImages = (tagTheme.Elements["StockImages"] as MarkupTagElement);
                    if (tagStockImages != null)
                    {
                        foreach (MarkupElement elStockImage in tagStockImages.Elements)
                        {
                            MarkupTagElement tagStockImage = (elStockImage as MarkupTagElement);
                            if (tagStockImage == null)
                            {
                                continue;
                            }
                            if (tagStockImage.FullName != "StockImage")
                            {
                                continue;
                            }

                            MarkupAttribute attStockImageName = tagStockImage.Attributes["Name"];
                            if (attStockImageName == null)
                            {
                                continue;
                            }

                            MarkupAttribute attStockImageFileName = tagStockImage.Attributes["FileName"];
                            if (attStockImageFileName == null)
                            {
                                continue;
                            }

                            ThemeStockImage stockImage = new ThemeStockImage();
                            stockImage.Name          = attStockImageName.Value;
                            stockImage.ImageFileName = attStockImageFileName.Value;

                            theme.StockImages.Add(stockImage);
                        }
                    }

                    MarkupTagElement tagProperties = (tagTheme.Elements["Properties"] as MarkupTagElement);
                    if (tagProperties != null)
                    {
                        foreach (MarkupElement elProperty in tagProperties.Elements)
                        {
                            MarkupTagElement tagProperty = (elProperty as MarkupTagElement);
                            if (tagProperty == null)
                            {
                                continue;
                            }
                            if (tagProperty.FullName != "Property")
                            {
                                continue;
                            }

                            MarkupAttribute attName = tagProperty.Attributes["Name"];
                            if (attName == null)
                            {
                                continue;
                            }

                            ThemeProperty property = new ThemeProperty();
                            property.Name = attName.Value;

                            MarkupAttribute attValue = tagProperty.Attributes["Value"];
                            if (attValue != null)
                            {
                                property.Value = attValue.Value;
                            }

                            theme.Properties.Add(property);
                        }
                    }

                    MarkupTagElement tagComponents = (tagTheme.Elements["Components"] as MarkupTagElement);
                    if (tagComponents != null)
                    {
                        foreach (MarkupElement elComponent in tagComponents.Elements)
                        {
                            MarkupTagElement tagComponent = (elComponent as MarkupTagElement);
                            if (tagComponent == null)
                            {
                                continue;
                            }
                            if (tagComponent.FullName != "Component")
                            {
                                continue;
                            }

                            MarkupAttribute attComponentID = tagComponent.Attributes["ID"];
                            if (attComponentID == null)
                            {
                                continue;
                            }

                            ThemeComponent component = new ThemeComponent();
                            component.ID = new Guid(attComponentID.Value);

                            MarkupAttribute attInheritsComponentID = tagComponent.Attributes["InheritsComponentID"];
                            if (attInheritsComponentID != null)
                            {
                                component.InheritsComponentID = new Guid(attInheritsComponentID.Value);
                            }

                            MarkupTagElement tagComponentStates = (tagComponent.Elements["States"] as MarkupTagElement);
                            if (tagComponentStates != null)
                            {
                                // if States is specified, only apply to specific states
                                foreach (MarkupElement elState in tagComponentStates.Elements)
                                {
                                    MarkupTagElement tagState = (elState as MarkupTagElement);
                                    if (tagState == null)
                                    {
                                        continue;
                                    }
                                    if (tagState.FullName != "State")
                                    {
                                        continue;
                                    }

                                    MarkupAttribute attStateID = tagState.Attributes["ID"];
                                    if (attStateID == null)
                                    {
                                        continue;
                                    }

                                    ThemeComponentState state = new ThemeComponentState();
                                    state.ID = new Guid(attStateID.Value);

                                    MarkupAttribute attStateName = tagState.Attributes["Name"];
                                    if (attStateName != null)
                                    {
                                        state.Name = attStateName.Value;
                                    }

                                    component.States.Add(state);
                                }
                            }

                            MarkupTagElement tagRenderings = (tagComponent.Elements["Renderings"] as MarkupTagElement);
                            if (tagRenderings != null)
                            {
                                foreach (MarkupElement elRendering in tagRenderings.Elements)
                                {
                                    MarkupTagElement tagRendering = (elRendering as MarkupTagElement);
                                    if (tagRendering == null)
                                    {
                                        continue;
                                    }
                                    if (tagRendering.FullName != "Rendering")
                                    {
                                        continue;
                                    }

                                    MarkupTagElement tagRenderingActions = (tagRendering.Elements["Actions"] as MarkupTagElement);
                                    if (tagRenderingActions == null)
                                    {
                                        continue;
                                    }

                                    Rendering rendering = new Rendering();
                                    foreach (MarkupElement elRenderingAction in tagRenderingActions.Elements)
                                    {
                                        MarkupTagElement tagRenderingAction = (elRenderingAction as MarkupTagElement);
                                        if (tagRenderingAction == null)
                                        {
                                            continue;
                                        }

                                        switch (tagRenderingAction.FullName)
                                        {
                                        case "Rectangle":
                                        {
                                            MarkupAttribute attX      = tagRenderingAction.Attributes["X"];
                                            MarkupAttribute attY      = tagRenderingAction.Attributes["Y"];
                                            MarkupAttribute attWidth  = tagRenderingAction.Attributes["Width"];
                                            MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"];

                                            RectangleRenderingAction item = new RectangleRenderingAction();
                                            item.X      = RenderingExpression.Parse(attX.Value);
                                            item.Y      = RenderingExpression.Parse(attY.Value);
                                            item.Width  = RenderingExpression.Parse(attWidth.Value);
                                            item.Height = RenderingExpression.Parse(attHeight.Value);

                                            item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement);
                                            item.Fill    = FillFromTag(tagRenderingAction.Elements["Fill"] as MarkupTagElement);

                                            rendering.Actions.Add(item);
                                            break;
                                        }

                                        case "Line":
                                        {
                                            LineRenderingAction item = new LineRenderingAction();

                                            MarkupAttribute attX1 = tagRenderingAction.Attributes["X1"];
                                            if (attX1 != null)
                                            {
                                                item.X1 = RenderingExpression.Parse(attX1.Value);
                                            }
                                            MarkupAttribute attX2 = tagRenderingAction.Attributes["X2"];
                                            if (attX2 != null)
                                            {
                                                item.X2 = RenderingExpression.Parse(attX2.Value);
                                            }
                                            MarkupAttribute attY1 = tagRenderingAction.Attributes["Y1"];
                                            if (attY1 != null)
                                            {
                                                item.Y1 = RenderingExpression.Parse(attY1.Value);
                                            }
                                            MarkupAttribute attY2 = tagRenderingAction.Attributes["Y2"];
                                            if (attY2 != null)
                                            {
                                                item.Y2 = RenderingExpression.Parse(attY2.Value);
                                            }

                                            item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement);

                                            rendering.Actions.Add(item);
                                            break;
                                        }

                                        case "Text":
                                        {
                                            MarkupAttribute attX      = tagRenderingAction.Attributes["X"];
                                            MarkupAttribute attY      = tagRenderingAction.Attributes["Y"];
                                            MarkupAttribute attWidth  = tagRenderingAction.Attributes["Width"];
                                            MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"];

                                            if (attX == null || attY == null)
                                            {
                                                continue;
                                            }

                                            MarkupAttribute attHorizontalAlignment = tagRenderingAction.Attributes["HorizontalAlignment"];
                                            MarkupAttribute attVerticalAlignment   = tagRenderingAction.Attributes["VerticalAlignment"];

                                            TextRenderingAction item = new TextRenderingAction();
                                            item.X = RenderingExpression.Parse(attX.Value);
                                            item.Y = RenderingExpression.Parse(attY.Value);

                                            if (attWidth != null)
                                            {
                                                item.Width = RenderingExpression.Parse(attWidth.Value);
                                            }
                                            if (attWidth != null)
                                            {
                                                item.Height = RenderingExpression.Parse(attHeight.Value);
                                            }

                                            if (attHorizontalAlignment != null)
                                            {
                                                switch (attHorizontalAlignment.Value.ToLower())
                                                {
                                                case "center":
                                                {
                                                    item.HorizontalAlignment = HorizontalAlignment.Center;
                                                    break;
                                                }

                                                case "justify":
                                                {
                                                    item.HorizontalAlignment = HorizontalAlignment.Justify;
                                                    break;
                                                }

                                                case "left":
                                                {
                                                    item.HorizontalAlignment = HorizontalAlignment.Left;
                                                    break;
                                                }

                                                case "right":
                                                {
                                                    item.HorizontalAlignment = HorizontalAlignment.Right;
                                                    break;
                                                }
                                                }
                                            }

                                            if (attVerticalAlignment != null)
                                            {
                                                switch (attVerticalAlignment.Value.ToLower())
                                                {
                                                case "bottom":
                                                {
                                                    item.VerticalAlignment = VerticalAlignment.Bottom;
                                                    break;
                                                }

                                                case "middle":
                                                {
                                                    item.VerticalAlignment = VerticalAlignment.Middle;
                                                    break;
                                                }

                                                case "top":
                                                {
                                                    item.VerticalAlignment = VerticalAlignment.Top;
                                                    break;
                                                }
                                                }
                                            }

                                            MarkupAttribute attColor = tagRenderingAction.Attributes["Color"];
                                            if (attColor != null)
                                            {
                                                item.Color = attColor.Value;
                                            }

                                            MarkupAttribute attFont = tagRenderingAction.Attributes["Font"];
                                            if (attFont != null)
                                            {
                                                item.Font = attFont.Value;
                                            }

                                            MarkupAttribute attValue = tagRenderingAction.Attributes["Value"];
                                            if (attValue != null)
                                            {
                                                item.Value = attValue.Value;
                                            }

                                            rendering.Actions.Add(item);
                                            break;
                                        }
                                        }
                                    }

                                    MarkupTagElement tagRenderingStates = (tagRendering.Elements["States"] as MarkupTagElement);
                                    if (tagRenderingStates != null)
                                    {
                                        // if States is specified, only apply to specific states
                                        foreach (MarkupElement elState in tagRenderingStates.Elements)
                                        {
                                            MarkupTagElement tagState = (elState as MarkupTagElement);
                                            if (tagState == null)
                                            {
                                                continue;
                                            }
                                            if (tagState.FullName != "State")
                                            {
                                                continue;
                                            }

                                            MarkupAttribute attStateID = tagState.Attributes["ID"];
                                            if (attStateID == null)
                                            {
                                                continue;
                                            }

                                            ThemeComponentStateReference state = new ThemeComponentStateReference();
                                            state.StateID = new Guid(attStateID.Value);
                                            rendering.States.Add(state);
                                        }
                                    }

                                    component.Renderings.Add(rendering);
                                }
                            }

                            theme.Components.Add(component);
                        }
                    }
                    themes.Themes.Add(theme);
                }
            }
        }