コード例 #1
0
            public static void UpdateFonts(string CategoryGuid, dynamic data)
            {
                ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalSettings.Current.PortalId, CategoryGuid);

                if (ThemeEditorWrapper == null)
                {
                    ThemeEditorWrapper = new ThemeEditorWrapper();
                }

                if (ThemeEditorWrapper.Fonts == null)
                {
                    ThemeEditorWrapper.Fonts = new List <ThemeFont>();
                }

                string GUID = !string.IsNullOrEmpty(data.Guid.ToString()) ? data.Guid.ToString() : Guid.NewGuid().ToString();

                if (ThemeEditorWrapper.Fonts.Where(a => a.Guid.ToLower() == GUID.ToLower()).FirstOrDefault() != null)
                {
                    ThemeFont ThemeFont = ThemeEditorWrapper.Fonts.Where(a => a.Guid.ToLower() == GUID.ToLower()).FirstOrDefault();
                    if (ThemeFont != null)
                    {
                        ThemeFont.Name   = data.Name;
                        ThemeFont.Family = data.Family;
                        ThemeFont.Css    = data.Css;
                    }
                }
                else
                {
                    ThemeEditorWrapper.Fonts.Add(new ThemeFont {
                        Guid = GUID, Name = data.Name.ToString(), Family = data.Family.ToString(), Css = data.Css.ToString()
                    });
                }

                UpdateThemeEditorJson(CategoryGuid, ThemeEditorWrapper);
            }
コード例 #2
0
ファイル: ThemeMapper.cs プロジェクト: Zongsoft/Framework
            static ThemeFont GetFont(string text)
            {
                if (string.IsNullOrEmpty(text))
                {
                    return(null);
                }

                var parts = Zongsoft.Common.StringExtension.Slice(text, ',').ToArray();
                var font  = new ThemeFont()
                {
                    Family = parts[0]
                };

                switch (parts.Length)
                {
                case 2:
                    font.Style = parts[1];
                    break;

                case 3:
                    font.Style = parts[1];
                    font.Size  = parts[2];
                    break;

                case 4:
                    font.Style  = parts[1];
                    font.Size   = parts[2];
                    font.Weight = parts[3];
                    break;
                }

                return(font);
            }
コード例 #3
0
ファイル: ThemeResolver.cs プロジェクト: Zongsoft/Framework
            static string GetFontText(ThemeFont font)
            {
                if (font == null)
                {
                    return(null);
                }

                return($"{font.Family},{font.Style},{font.Size},{font.Weight}");
            }
コード例 #4
0
        private Font GetThemeFont(ThemeFont font)
        {
            switch (font)
            {
            case ThemeFont.Bold:
                return(FizzTheme.FizzThemeData.BoldFont);

            case ThemeFont.Normal:
                return(FizzTheme.FizzThemeData.NormalFont);

            default:
                return(FizzTheme.FizzThemeData.NormalFont);
            }
        }
コード例 #5
0
        public ActionResult Deletefont(string Guid, ThemeFont Data)
        {
            ActionResult actionResult = new ActionResult();
            dynamic      result       = new ExpandoObject();

            try
            {
                Core.Managers.ThemeManager.DeleteFonts(Guid, Data);
                result.Fonts = Core.Managers.ThemeManager.GetFonts(PortalSettings.Current.PortalId, Guid);
            }
            catch (Exception)
            {
            }
            actionResult.Data = result;
            return(actionResult);
        }
コード例 #6
0
ファイル: ThemeMapper.cs プロジェクト: Zongsoft/Framework
        private static ThemeFonts GetFonts(IDictionary <string, ReportResourceEntry> dictionary)
        {
            if (dictionary == null)
            {
                return(null);
            }

            ThemeFont major = null, minor = null;

            if (dictionary.TryGetValue(FONTS_MAJOR_KEY, out var entry) && entry.Value != null)
            {
                major = GetFont(entry.Value.ToString());
            }

            if (dictionary.TryGetValue(FONTS_MINOR_KEY, out entry) && entry.Value != null)
            {
                minor = GetFont(entry.Value.ToString());
            }

            return(new ThemeFonts()
            {
                MajorFont = major, MinorFont = minor
            });
コード例 #7
0
            public static void DeleteFonts(string CategoryGuid, ThemeFont data)
            {
                ThemeEditorWrapper ThemeEditorWrapper = GetThemeEditors(PortalSettings.Current.PortalId, CategoryGuid);

                if (ThemeEditorWrapper == null)
                {
                    ThemeEditorWrapper = new ThemeEditorWrapper();
                }

                if (ThemeEditorWrapper.Fonts == null)
                {
                    ThemeEditorWrapper.Fonts = new List <ThemeFont>();
                }

                string GUID = !string.IsNullOrEmpty(data.Guid.ToString()) ? data.Guid.ToString() : Guid.NewGuid().ToString();

                if (ThemeEditorWrapper.Fonts.Where(a => a.Guid.ToLower() == GUID.ToLower()).FirstOrDefault() != null)
                {
                    ThemeFont ThemeFont = ThemeEditorWrapper.Fonts.Where(a => a.Guid.ToLower() == GUID.ToLower()).FirstOrDefault();
                    ThemeEditorWrapper.Fonts.Remove(ThemeFont);
                    UpdateThemeEditorJson(CategoryGuid, ThemeEditorWrapper);
                }
            }
コード例 #8
0
ファイル: Font.cs プロジェクト: BlackGad/PS.Framework
        private string GeneratePath(ThemeFont font)
        {
            var result = nameof(Theme.Fonts) + "." + font;

            return(result);
        }
コード例 #9
0
ファイル: Font.cs プロジェクト: BlackGad/PS.Framework
 public Font(ThemeFont type)
 {
     Type   = type;
     Mode   = BindingMode.OneWay;
     Source = Theme.Current;
 }
コード例 #10
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);
                }
            }
        }
コード例 #11
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);
                }
            }
        }
コード例 #12
0
        protected override Theme Read(ContentReader input, Theme existingInstance)
        {
            if (existingInstance == null)
            {
                existingInstance = new Theme();
            }
            else
            {
                foreach (var cursor in existingInstance.Cursors)
                {
                    PlatformHelper.DestroyCursor(cursor.Cursor);
                }

                existingInstance.Cursors.Clear();
                existingInstance.Fonts.Clear();
                existingInstance.Styles.Clear();
                existingInstance.Textures.Clear();
            }

            existingInstance.Content = input.ContentManager;

            // Read cursors.
            int numberOfCursors = input.ReadInt32();

            for (int i = 0; i < numberOfCursors; i++)
            {
                var cursor = new ThemeCursor();
                cursor.Name      = input.ReadString();
                cursor.IsDefault = input.ReadBoolean();
                cursor.Cursor    = LoadCursor(input);
                existingInstance.Cursors.Add(cursor);
            }

            // Read fonts.
            int numberOfFonts = input.ReadInt32();

            for (int i = 0; i < numberOfFonts; i++)
            {
                var font = new ThemeFont();
                font.Name      = input.ReadString();
                font.IsDefault = input.ReadBoolean();
                font.Font      = input.ReadExternalReference <SpriteFont>();
                existingInstance.Fonts.Add(font);
            }

            // Read textures.
            int numberOfTextures = input.ReadInt32();

            for (int i = 0; i < numberOfTextures; i++)
            {
                var texture = new ThemeTexture();
                texture.Name      = input.ReadString();
                texture.IsDefault = input.ReadBoolean();
                texture.Texture   = input.ReadExternalReference <Texture2D>();
                existingInstance.Textures.Add(texture);
            }

            // Read styles.
            int numberOfStyles   = input.ReadInt32();
            var inheritanceTable = new Dictionary <ThemeStyle, string>();

            for (int i = 0; i < numberOfStyles; i++)
            {
                var style = new ThemeStyle();
                style.Name = input.ReadString();
                inheritanceTable.Add(style, input.ReadString());

                // Read attributes
                int numberOfAttributes = input.ReadInt32();
                for (int j = 0; j < numberOfAttributes; j++)
                {
                    var attribute = new ThemeAttribute();
                    attribute.Name  = input.ReadString();
                    attribute.Value = input.ReadString();
                    style.Attributes.Add(attribute);
                }

                // Read states.
                int numberOfStates = input.ReadInt32();
                for (int j = 0; j < numberOfStates; j++)
                {
                    var state = new ThemeState();
                    state.Name        = input.ReadString();
                    state.IsInherited = input.ReadBoolean();

                    // Read images.
                    int numberOfImages = input.ReadInt32();
                    for (int k = 0; k < numberOfImages; k++)
                    {
                        var image = new ThemeImage();
                        image.Name = input.ReadString();

                        string textureName = input.ReadString();
                        if (!string.IsNullOrEmpty(textureName))
                        {
                            ThemeTexture texture;
                            if (existingInstance.Textures.TryGet(textureName, out texture))
                            {
                                image.Texture = texture;
                            }
                        }

                        image.SourceRectangle     = input.ReadRawObject <Rectangle>();
                        image.Margin              = input.ReadRawObject <Vector4F>();
                        image.HorizontalAlignment = (HorizontalAlignment)input.ReadInt32();
                        image.VerticalAlignment   = (VerticalAlignment)input.ReadInt32();
                        image.TileMode            = (TileMode)input.ReadInt32();
                        image.Border              = input.ReadRawObject <Vector4F>();
                        image.IsOverlay           = input.ReadBoolean();
                        image.Color = input.ReadColor();
                        state.Images.Add(image);
                    }

                    bool hasBackground = input.ReadBoolean();
                    if (hasBackground)
                    {
                        state.Background = input.ReadColor();
                    }

                    bool hasForeground = input.ReadBoolean();
                    if (hasForeground)
                    {
                        state.Foreground = input.ReadColor();
                    }

                    bool hasOpacity = input.ReadBoolean();
                    if (hasOpacity)
                    {
                        state.Opacity = input.ReadSingle();
                    }

                    style.States.Add(state);
                }

                existingInstance.Styles.Add(style);
            }

            // Resolve style inheritance.
            foreach (var entry in inheritanceTable)
            {
                var    style      = entry.Key;
                string parentName = entry.Value;
                if (string.IsNullOrEmpty(parentName))
                {
                    continue;
                }

                ThemeStyle parent;
                if (existingInstance.Styles.TryGet(parentName, out parent))
                {
                    style.Inherits = parent;
                }
            }

            return(existingInstance);
        }