private IEnumerator TestTheme <T, C>(
            GameObject host,
            List <List <ThemePropertyValue> > stateValues,
            List <ThemeProperty> customProperties,
            params Action <InteractableThemeBase>[] stateTests)
            where T : InteractableThemeBase
            where C : UnityEngine.Component
        {
            foreach (List <ThemePropertyValue> values in stateValues)
            {
                Assert.AreEqual(values.Count, stateTests.Length);
            }

            var themeDefinition = ThemeDefinition.GetDefaultThemeDefinition <T>().Value;

            for (int i = 0; i < stateValues.Count; i++)
            {
                themeDefinition.StateProperties[i].Values = stateValues[i];
            }

            for (int i = 0; i < customProperties.Count; i++)
            {
                themeDefinition.CustomProperties[i] = customProperties[i];
            }

            yield return(TestTheme <C>(host, themeDefinition, stateTests));
        }
Exemplo n.º 2
0
        private Interactable attachInteractible(string topic, GameObject parent)
        {
            Interactable i = parent.AddComponent <Interactable>();

            ThemeDefinition theme = ThemeDefinition.GetDefaultThemeDefinition <InteractableColorTheme>().Value;

            i.Profiles = new List <InteractableProfileItem>()
            {
                new InteractableProfileItem()
                {
                    Themes = new List <Theme>()
                    {
                        Interactable.GetDefaultThemeAsset(new List <ThemeDefinition>()
                        {
                            theme
                        })
                    },
                    Target = parent,
                }
            };

            i.enabled = true;
            i.OnClick.AddListener(() => this.Toggle(topic));
            return(i);
        }
Exemplo n.º 3
0
        public void Generate(ThemeDefinition themeDefinition)
        {
            var caller = new ColorGeneratorCaller();

            foreach (Variant variant in themeDefinition.Variants)
            {
                Console.WriteLine($"{variant.Name} =>");
                foreach (Block block in themeDefinition.Blocks)
                {
                    if (!variant.BlockSources.ContainsKey(block.Name))
                    {
                        continue;
                    }

                    VariantBlockColorSource source = variant.BlockSources[block.Name];
                    if (source == VariantBlockColorSource.Undefined)
                    {
                        continue;
                    }

                    Dictionary <string, string> blockColors = new Dictionary <string, string>();

                    variant.Colors ??= new Dictionary <string, Dictionary <string, string> >();

                    if (source == VariantBlockColorSource.Range)
                    {
                        if (variant.BlockColorsRange?.ContainsKey(block.Name) != true)
                        {
                            continue;
                        }

                        ColorRange   range = variant.BlockColorsRange ![block.Name];
Exemplo n.º 4
0
        private void CreateDefaultsSettings(ISettingsManager settings
                                            , IAppearanceManager appearance)
        {
            var themeInfos = settings.Themes;

            for (int i = 0; i < _WpfThemes.GetLength(0); i++)
            {
                var        item         = _WpfThemes[i];
                List <Uri> WpfResources = null;
                switch (item[1])
                {
                case "Light":
                    WpfResources = new List <Uri>(LightResources);
                    break;

                case "Dark":
                    WpfResources = new List <Uri>(DarkResources);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("WPF theme base:" + item[1] + " not supported.");
                }

                try
                {
                    // Combine resources into one consistent model
                    var theme = new ThemeDefinition(item[0], WpfResources, item[2]);
                    themeInfos.AddThemeInfo(theme);
                }
                catch (Exception exc)
                {
                    Debug.WriteLine(exc.StackTrace);
                }
            }

            appearance.SetDefaultTheme(themeInfos, "Light");             // configure a default WPF theme

            try
            {
                // Create a general settings model to make sure the app is at least governed by defaults
                // if there are no customized settings on first ever start-up of application
                var options = settings.Options;

                SettingDefaults.CreateGeneralSettings(options);
                SettingDefaults.CreateAppearanceSettings(options, settings);

                settings.Options.SetUndirty();
            }
            catch
            {
            }
        }
Exemplo n.º 5
0
        protected virtual void AddThemeDefinition()
        {
            Type defaultType = typeof(InteractableActivateTheme);

            ThemeDefinition newDefinition = ThemeDefinition.GetDefaultThemeDefinition(defaultType).Value;

            if (theme.Definitions == null)
            {
                theme.Definitions = new List <ThemeDefinition>();
            }
            theme.Definitions.Add(newDefinition);
            theme.History.Add(new Dictionary <Type, ThemeDefinition>());
            theme.ValidateDefinitions();

            serializedObject.Update();
            EditorUtility.SetDirty(theme);
        }
        private IEnumerator TestTheme <C>(
            GameObject host,
            ThemeDefinition themeDefinition,
            params Action <InteractableThemeBase>[] stateTests)
            where C : UnityEngine.Component
        {
            host.AddComponent <C>();

            var theme = InteractableThemeBase.CreateAndInitTheme(themeDefinition, host);

            for (int i = 0; i < stateTests.Length; i++)
            {
                theme.OnUpdate(i);
                yield return(null);

                stateTests[i](theme);
            }
            GameObjectExtensions.DestroyGameObject(host);
        }
Exemplo n.º 7
0
        private void ChangeThemeDefinitionType(int index, Type oldType, Type newType)
        {
            // Save theme definition to cache
            SaveThemeDefinitionHistory(index, oldType);

            // Try to load theme from history cache
            ThemeDefinition?definition = LoadThemeDefinitionHistory(index, newType);

            if (definition == null)
            {
                // if not available, then create a new one
                definition = ThemeDefinition.GetDefaultThemeDefinition(newType);
            }

            theme.Definitions[index] = definition.Value;
            theme.ValidateDefinitions();

            themeDefinitions.serializedObject.Update();
            EditorUtility.SetDirty(theme);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Standard Constructor
        /// </summary>
        public ThemeViewModel()
        {
            var settings = GetService <ISettingsManager>(); // add the default themes

            _ListOfThemes = new Dictionary <string, ThemeDefinition>();

            foreach (var item in settings.Themes.GetThemeInfos())
            {
                var list = new List <string>();
                foreach (var subitem in item.ThemeSources)
                {
                    list.Add(subitem.ToString());
                }

                _ListOfThemes.Add(item.DisplayName, new ThemeDefinition(item.DisplayName, list));
            }

            // Lets make sure there is a default
            _ListOfThemes.TryGetValue(GetService <IAppearanceManager>().GetDefaultTheme().DisplayName, out _DefaultTheme);

            // and something sensible is selected
            _SelectedTheme = _DefaultTheme;
        }
        /// <summary>
        /// Generates an interactable from primitives and assigns a select action.
        /// </summary>
        private void AssembleInteractableButton(out Interactable interactable, out Transform translateTargetObject, string selectActionDescription = "Select")
        {
            // Assemble an interactable out of a set of primitives
            // This will be the button housing
            var interactableObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

            interactableObject.name = "RuntimeInteractable";
            interactableObject.transform.position    = new Vector3(0.05f, 0.05f, 0.625f);
            interactableObject.transform.localScale  = new Vector3(0.15f, 0.025f, 0.15f);
            interactableObject.transform.eulerAngles = new Vector3(90f, 0f, 180f);

            // This will be the part that gets scaled
            GameObject childObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            var        renderer    = childObject.GetComponent <Renderer>();

            renderer.material.color  = DefaultColor;
            renderer.material.shader = StandardShaderUtility.MrtkStandardShader;

            childObject.transform.parent        = interactableObject.transform;
            childObject.transform.localScale    = new Vector3(0.9f, 1f, 0.9f);
            childObject.transform.localPosition = new Vector3(0f, 1.5f, 0f);
            childObject.transform.localRotation = Quaternion.identity;
            // Only use a collider on the main object
            GameObject.Destroy(childObject.GetComponent <Collider>());

            translateTargetObject = childObject.transform;

            // Add an interactable
            interactable = interactableObject.AddComponent <Interactable>();

            var themeDefinition = ThemeDefinition.GetDefaultThemeDefinition <ScaleOffsetColorTheme>().Value;

            // themeDefinition.Easing.Enabled = false;
            // Set the offset state property (index = 1) to move on the Pressed state (index = 2)
            themeDefinition.StateProperties[1].Values = new List <ThemePropertyValue>()
            {
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
                new ThemePropertyValue()
                {
                    Vector3 = new Vector3(0.0f, -0.32f, 0.0f)
                },
                new ThemePropertyValue()
                {
                    Vector3 = Vector3.zero
                },
            };
            // Set the color state property (index = 2) values
            themeDefinition.StateProperties[2].Values = new List <ThemePropertyValue>()
            {
                new ThemePropertyValue()
                {
                    Color = DefaultColor
                },
                new ThemePropertyValue()
                {
                    Color = FocusColor
                },
                new ThemePropertyValue()
                {
                    Color = Color.green
                },
                new ThemePropertyValue()
                {
                    Color = DisabledColor
                },
            };

            Theme testTheme = ScriptableObject.CreateInstance <Theme>();

            testTheme.States      = interactable.States;
            testTheme.Definitions = new List <ThemeDefinition>()
            {
                themeDefinition
            };

            interactable.Profiles = new List <InteractableProfileItem>()
            {
                new InteractableProfileItem()
                {
                    Themes = new List <Theme>()
                    {
                        testTheme
                    },
                    Target = translateTargetObject.gameObject,
                },
            };

            // Set the interactable to respond to the requested input action
            MixedRealityInputAction selectAction = CoreServices.InputSystem.InputSystemProfile.InputActionsProfile.InputActions.Where(m => m.Description == selectActionDescription).FirstOrDefault();

            Assert.NotNull(selectAction.Description, "Couldn't find " + selectActionDescription + " input action in input system profile.");
            interactable.InputAction = selectAction;
        }
Exemplo n.º 10
0
        public static void Write(ThemeDefinition theme, string assembly)
        {
            var constLines = new List <string>();

            foreach (Block block in theme.Blocks)
            {
                foreach (string id in block.IDs)
                {
                    constLines.Add(
                        C + $"{block.Name}_{id} = \"var(--Colorant_{theme.Name}_{block.Name}_{id})\";");

                    if (!block.CreateDisplayTextVariables)
                    {
                        continue;
                    }

                    constLines.Add(
                        C + $"{block.Name}_{id}_Text = \"var(--Colorant_{theme.Name}_{block.Name}_{id}_Text)\";");
                }
            }

            File.WriteAllLines($"Themes/{theme.Name}/Constants.cs", new List <string>
            {
                $"namespace {assembly}.Themes.{theme.Name}",
                "{",
                I + "public static class Constants",
                I + "{",
                string.Join('\n', constLines),
                I + "}",
                "}",
            });

            //

            var variantLines = new List <string>();

            foreach (Variant variant in theme.Variants)
            {
                variantLines.Add(I + I + $"{variant.Name},");
            }

            File.WriteAllLines($"Themes/{theme.Name}/Variants.cs", new List <string>
            {
                $"namespace {assembly}.Themes.{theme.Name}",
                "{",
                I + "public enum Variants",
                I + "{",
                I + I + "Undefined,",
                string.Join('\n', variantLines),
                I + "}",
                "}",
            });

            //

            string variants = "\"" + string.Join("\", \"", theme.Variants.Select(v => v.Name)) + "\"";

            File.WriteAllLines($"Themes/{theme.Name}/Theme.cs", new List <string>
            {
                "using System.Collections.Generic;",
                "using Integrant.Colorant.Schema;",
                $"namespace {assembly}.Themes.{theme.Name}",
                "{",
                I + "public class Theme : ITheme",
                I + "{",
                I + I + $"public string Assembly {{ get; }} = \"{assembly}\";",
                I + I + $"public string Name {{ get; }} = \"{theme.Name}\";",
                I + I + $"public IEnumerable<string> Variants {{ get; }} = new [] {{ {variants} }};",
                I + "}",
                "}",
            });

            //

            foreach (Variant variant in theme.Variants)
            {
                if (variant.Colors == null)
                {
                    continue;
                }

                var cssLines = new List <string>();
                cssLines.Add(":root {");

                foreach (Block block in theme.Blocks)
                {
                    if (!variant.Colors.ContainsKey(block.Name))
                    {
                        continue;
                    }

                    foreach (var(id, color) in variant.Colors[block.Name])
                    {
                        cssLines.Add(
                            $"\t--Colorant_{theme.Name}_{block.Name}_{id}: {color};");
                    }
                }

                cssLines.Add("}");

                Directory.CreateDirectory($"wwwroot/css/{theme.Name}");

                File.WriteAllLines($"wwwroot/css/{theme.Name}/{variant.Name}.css", cssLines);
            }
        }
Exemplo n.º 11
0
 protected ThemeDefinitionViewModel()
 {
     _model      = null;
     _IsSelected = false;
 }
Exemplo n.º 12
0
 public ThemeDefinitionViewModel(ThemeDefinition model)
     : this()
 {
     _model = model;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Converts CSSX to CSS, using the current theme
        /// </summary>
        /// <param name="Cssx">CSSX</param>
        /// <param name="Session">Current session</param>
        /// <returns>CSS</returns>
        public static string Convert(string Cssx, Variables Session)
        {
            bool Pushed = false;

            Session.Lock();
            try
            {
                Session.Push();
                Pushed = true;

                ThemeDefinition Def = Theme.CurrerntTheme;
                if (Def != null)
                {
                    Session["TextColor"]          = Def.TextColor;
                    Session["BackgroundColor"]    = Def.BackgroundColor;
                    Session["HeaderColor"]        = Def.HeaderColor;
                    Session["HeaderTextColor"]    = Def.HeaderTextColor;
                    Session["ButtonColor"]        = Def.ButtonColor;
                    Session["ButtonTextColor"]    = Def.ButtonTextColor;
                    Session["MenuTextColor"]      = Def.MenuTextColor;
                    Session["EditColor"]          = Def.EditColor;
                    Session["LinkColorUnvisited"] = Def.LinkColorUnvisited;
                    Session["LinkColorVisited"]   = Def.LinkColorVisited;
                    Session["LinkColorHot"]       = Def.LinkColorHot;
                    Session["BackgroundImages"]   = Def.BackgroundImages;
                    Session["BannerImages"]       = Def.BannerImages;

                    foreach (KeyValuePair <string, string> P in Def.GetCustomProperties())
                    {
                        Session[P.Key] = P.Value;
                    }
                }

                StringBuilder Result = new StringBuilder();
                Expression    Exp;
                int           i = 0;
                int           c = Cssx.Length;
                int           j, k;
                string        Script;
                object        Value;

                while (i < c)
                {
                    j = Cssx.IndexOf('¤', i);
                    if (j < 0)
                    {
                        break;
                    }

                    if (j > i)
                    {
                        Result.Append(Cssx.Substring(i, j - i));
                    }

                    k = Cssx.IndexOf('¤', j + 1);
                    if (k < 0)
                    {
                        break;
                    }

                    Script = Cssx.Substring(j + 1, k - j - 1);
                    Exp    = new Expression(Script);
                    Value  = Exp.Evaluate(Session);

                    if (Value is SKColor Color)
                    {
                        if (Color.Alpha == 255)
                        {
                            Result.Append('#');
                            Result.Append(Color.Red.ToString("X2"));
                            Result.Append(Color.Green.ToString("X2"));
                            Result.Append(Color.Blue.ToString("X2"));
                        }
                        else
                        {
                            Result.Append("rgba(");
                            Result.Append(Color.Red.ToString());
                            Result.Append(',');
                            Result.Append(Color.Green.ToString());
                            Result.Append(',');
                            Result.Append(Color.Blue.ToString());
                            Result.Append(',');
                            Result.Append(Expression.ToString(Color.Alpha / 255.0));
                            Result.Append(')');
                        }
                    }
                    else if (Value is string s)
                    {
                        Result.Append(s);
                    }
                    else
                    {
                        Result.Append(Expression.ToString(Value));
                    }

                    i = k + 1;
                }

                if (i < c)
                {
                    Result.Append(Cssx.Substring(i));
                }

                return(Result.ToString());
            }
            finally
            {
                if (Pushed)
                {
                    Session.Pop();
                }

                Session.Release();
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Performs the actual conversion.
        /// </summary>
        /// <param name="FromContentType">Content type of the content to convert from.</param>
        /// <param name="From">Stream pointing to binary representation of content.</param>
        /// <param name="FromFileName">If the content is coming from a file, this parameter contains the name of that file.
        /// Otherwise, the parameter is the empty string.</param>
        /// <param name="LocalResourceName">Local resource name of file, if accessed from a web server.</param>
        /// <param name="URL">URL of resource, if accessed from a web server.</param>
        /// <param name="ToContentType">Content type of the content to convert to.</param>
        /// <param name="To">Stream pointing to where binary representation of content is to be sent.</param>
        /// <param name="Session">Session states.</param>
        /// <returns>If the result is dynamic (true), or only depends on the source (false).</returns>
        public bool Convert(string FromContentType, Stream From, string FromFileName, string LocalResourceName, string URL, string ToContentType,
                            Stream To, Variables Session)
        {
            string Cssx;

            using (StreamReader rd = new StreamReader(From))
            {
                Cssx = rd.ReadToEnd();
            }

            Session.Push();
            try
            {
                ThemeDefinition Def = Theme.CurrerntTheme;
                if (Def != null)
                {
                    Session["TextColor"]          = Def.TextColor;
                    Session["BackgroundColor"]    = Def.BackgroundColor;
                    Session["HeaderColor"]        = Def.HeaderColor;
                    Session["HeaderTextColor"]    = Def.HeaderTextColor;
                    Session["ButtonColor"]        = Def.ButtonColor;
                    Session["ButtonTextColor"]    = Def.ButtonTextColor;
                    Session["MenuTextColor"]      = Def.MenuTextColor;
                    Session["EditColor"]          = Def.EditColor;
                    Session["LinkColorUnvisited"] = Def.LinkColorUnvisited;
                    Session["LinkColorVisited"]   = Def.LinkColorVisited;
                    Session["LinkColorHot"]       = Def.LinkColorHot;
                    Session["BackgroundImages"]   = Def.BackgroundImages;
                    Session["BannerImages"]       = Def.BannerImages;

                    foreach (KeyValuePair <string, string> P in Def.GetCustomProperties())
                    {
                        Session[P.Key] = P.Value;
                    }
                }

                StringBuilder Result = new StringBuilder();
                Expression    Exp;
                int           i = 0;
                int           c = Cssx.Length;
                int           j, k;
                string        Script;
                object        Value;

                while (i < c)
                {
                    j = Cssx.IndexOf('¤', i);
                    if (j < 0)
                    {
                        break;
                    }

                    if (j > i)
                    {
                        Result.Append(Cssx.Substring(i, j - i));
                    }

                    k = Cssx.IndexOf('¤', j + 1);
                    if (k < 0)
                    {
                        break;
                    }

                    Script = Cssx.Substring(j + 1, k - j - 1);
                    Exp    = new Expression(Script);
                    Value  = Exp.Evaluate(Session);

                    if (Value is SKColor Color)
                    {
                        if (Color.Alpha == 255)
                        {
                            Result.Append('#');
                            Result.Append(Color.Red.ToString("X2"));
                            Result.Append(Color.Green.ToString("X2"));
                            Result.Append(Color.Blue.ToString("X2"));
                        }
                        else
                        {
                            Result.Append("rgba(");
                            Result.Append(Color.Red.ToString());
                            Result.Append(',');
                            Result.Append(Color.Green.ToString());
                            Result.Append(',');
                            Result.Append(Color.Blue.ToString());
                            Result.Append(',');
                            Result.Append(Expression.ToString(Color.Alpha / 255.0));
                            Result.Append(')');
                        }
                    }
                    else if (Value is string s)
                    {
                        Result.Append(s);
                    }
                    else
                    {
                        Result.Append(Expression.ToString(Value));
                    }

                    i = k + 1;
                }

                if (i < c)
                {
                    Result.Append(Cssx.Substring(i));
                }

                byte[] Data = Utf8WithBOM.GetBytes(Result.ToString());
                To.Write(Data, 0, Data.Length);
            }
            finally
            {
                Session.Pop();
            }

            return(false);
        }
Exemplo n.º 15
0
        public ThemeDefinition LoadTheme(string file)
        {
            if (!File.Exists(file))
            {
                return(null);
            }
            using (var reader = new StreamReader(file))
            {
                ThemeDefinition result = new ThemeDefinition()
                {
                    Title = Path.GetFileName(file)
                };
                WordCollection collection = null;
                string         line;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();

                    // On passe les lignes vides
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    // Si la ligne commence par un ';' c'est un commentaire, on passe
                    if (line.StartsWith(";"))
                    {
                        continue;
                    }

                    // Si la ligne commence par un '@' alors c'est le titre du thème
                    if (line.StartsWith("@"))
                    {
                        result.Title = line.Substring(1).Trim();
                    }
                    // Si la ligne commence par un '#' alors c'est une nouvelle collection de mot
                    else if (line.StartsWith("#"))
                    {
                        collection = new WordCollection
                        {
                            Title = line.Substring(1).Trim()
                        };
                        result.Collections.Add(collection);
                        if (string.IsNullOrWhiteSpace(collection.Title))
                        {
                            collection.Title = $"Collection #{result.Collections.Count}";
                        }
                    }
                    // Sinon c'est une définition de mot
                    else
                    {
                        // On a une collection ?
                        if (collection == null)
                        {
                            collection = new WordCollection
                            {
                                Title = $"Collection #{result.Collections.Count + 1}"
                            };
                            result.Collections.Add(collection);
                        }
                        // Détermine le format de la ligne
                        int            idx = line.IndexOf("=");
                        WordDefinition word;
                        if (idx < 0)
                        {
                            word = new WordDefinition {
                                Phrase = line
                            };
                        }
                        else
                        {
                            word = new WordDefinition
                            {
                                Word   = line.Substring(0, idx).Trim(),
                                Phrase = line.Substring(idx + 1).Trim()
                            };
                        }
                        collection.Add(word);
                    }
                }

                return(result);
            }
        }
Exemplo n.º 16
0
 public ThemeViewModel(ThemeDefinition theme)
 {
     Theme       = theme ?? throw new ArgumentNullException(nameof(theme));
     Collections = new ObservableCollection <WordCollectionViewModel>();
     BuildModel();
 }