Exemplo n.º 1
0
        public ThemeAccentInfo(TelegramThemeType type, Color accent, Dictionary <string, Color> values)
        {
            Type        = type;
            AccentColor = accent;
            Values      = values;

            switch (type)
            {
            case TelegramThemeType.Day:
                Parent = TelegramTheme.Light;
                Name   = Strings.Resources.ThemeDay;
                break;

            case TelegramThemeType.Night:
                Parent = TelegramTheme.Dark;
                Name   = Strings.Resources.ThemeNight;
                break;

            case TelegramThemeType.Tinted:
                Parent = TelegramTheme.Dark;
                Name   = Strings.Resources.ThemeDark;
                break;
            }

            IsOfficial = true;
        }
Exemplo n.º 2
0
        public static ThemeAccentInfo FromAccent(TelegramThemeType type, Color accent, Color outgoing = default)
        {
            var color = accent;

            if (color == default)
            {
                color = BootStrapper.Current.UISettings.GetColorValue(UIColorType.Accent);
            }

            var colorizer         = ThemeColorizer.FromTheme(type, _accent[type][AccentShade.Default], color);
            var outgoingColorizer = outgoing != default ? ThemeColorizer.FromTheme(type, _accent[type][AccentShade.Default], outgoing) : null;
            var values            = new Dictionary <string, Color>();
            var shades            = new Dictionary <AccentShade, Color>();

            foreach (var item in _map[type])
            {
                if (outgoingColorizer != null && item.Key.EndsWith("Outgoing"))
                {
                    values[item.Key] = outgoingColorizer.Colorize(item.Value);
                }
                else
                {
                    values[item.Key] = colorizer.Colorize(item.Value);
                }
            }

            foreach (var item in _accent[type])
            {
                shades[item.Key] = colorizer.Colorize(item.Value);
            }

            return(new ThemeAccentInfo(type, accent, values, shades));
        }
Exemplo n.º 3
0
        protected ThemeAccentInfo(TelegramThemeType type, Color accent, Dictionary <string, Color> values, Dictionary <AccentShade, Color> shades)
        {
            Type        = type;
            AccentColor = accent;
            Values      = values ?? new Dictionary <string, Color>();
            Shades      = shades ?? new Dictionary <AccentShade, Color>();

            switch (type)
            {
            case TelegramThemeType.Day:
                Parent = TelegramTheme.Light;
                Name   = Strings.Resources.ThemeDay;
                break;

            case TelegramThemeType.Night:
                Parent = TelegramTheme.Dark;
                Name   = Strings.Resources.ThemeNight;
                break;

            case TelegramThemeType.Tinted:
                Parent = TelegramTheme.Dark;
                Name   = Strings.Resources.ThemeDark;
                break;
            }

            IsOfficial = type != TelegramThemeType.Custom;
        }
Exemplo n.º 4
0
        public static Color Colorize(TelegramThemeType type, Color accent, string key)
        {
            var colorizer = ThemeColorizer.FromTheme(type, _accent[type][AccentShade.Default], accent);

            if (_map[type].TryGetValue(key, out Color color))
            {
                return(colorizer.Colorize(color));
            }

            var lookup = type == TelegramThemeType.Day ? ThemeIncoming.Light : ThemeIncoming.Dark;

            return(colorizer.Colorize(lookup[key].Color));
        }
Exemplo n.º 5
0
        public static ThemeAccentInfo FromAccent(TelegramThemeType type, Color accent)
        {
            var color = accent;

            if (color == default)
            {
                color = BootStrapper.Current.UISettings.GetColorValue(UIColorType.Accent);
            }

            var colorizer = ThemeColorizer.FromTheme(type, _accent[type], color);
            var values    = new Dictionary <string, Color>();

            foreach (var item in _map[type])
            {
                values[item.Key] = colorizer.Colorize(item.Value);
            }

            return(new ThemeAccentInfo(type, accent, values));
        }
Exemplo n.º 6
0
 public Color this[TelegramThemeType type]
 {
     get => ColorEx.FromHex(GetValueOrDefault(ConvertToKey(type, "Accent"), ColorEx.ToHex(ThemeAccentInfo.Accents[type])));
Exemplo n.º 7
0
        //void Colorize(string name, ref byte r, ref byte g, ref byte b)
        //{
        //    if (ignoreKeys.Contains(name))
        //    {
        //        return;
        //    }

        //    const auto i = keepContrast.find(name);
        //    if (i == end(colorizer.keepContrast))
        //    {
        //        Colorize(r, g, b);
        //        return;
        //    }
        //    var check = i->second.first;
        //    var rgb = QColor(int(r), int(g), int(b));
        //    var changed = Colorize(rgb, colorizer);
        //    var checkez = Colorize(check, colorizer).value_or(check);
        //    double lightness(HSV hsv)
        //    {
        //        return hsv.V - (hsv.V * hsv.S) / 511;
        //    };
        //    var changedLightness = lightness(changed.value_or(rgb).toHsv());
        //    var checkedLightness = lightness(
        //        new HSV(checkez.hue, checkez.saturation, checkez.value));
        //    var delta = Math.Abs(changedLightness - checkedLightness);
        //    if (delta >= kEnoughLightnessForContrast)
        //    {
        //        if (changed)
        //        {
        //            FillColorizeResult(r, g, b, *changed);
        //        }
        //        return;
        //    }
        //    const auto replace = i->second.second;
        //    const auto result = Colorize(replace, colorizer).value_or(replace);
        //    FillColorizeResult(
        //        r,
        //        g,
        //        b,
        //        QColor::fromHsv(result.hue, result.saturation, result.value));
        //}

        public static ThemeColorizer FromTheme(TelegramThemeType type, Color accent, Color color)
        {
            var temp = (RGB)color;

            var result = new ThemeColorizer();

            //result.ignoreKeys = kColorizeIgnoredKeys;
            result._hueThreshold = 15;
            result._was          = accent.ToHSV();
            result._now          = color.ToHSV();
            switch (type)
            {
            case TelegramThemeType.Day:
                result._lightnessMax = 160d / 255d;
                break;

            case TelegramThemeType.Night:
                //                  result.keepContrast = base::flat_map<QLatin1String, Pair>{
                //                      {
                //                          //{ qstr("windowFgActive"), Pair{ cColor("5288c1"), cColor("17212b") } }, // windowBgActive
                //                          {
                //                              qstr("activeButtonFg"), Pair{ cColor("2f6ea5"), cColor("17212b") }
                //                          }, // activeButtonBg
                //	{ qstr("profileVerifiedCheckFg"), Pair{ cColor("5288c1"), cColor("17212b") } }, // profileVerifiedCheckBg
                //	{ qstr("overviewCheckFgActive"), Pair{ cColor("5288c1"), cColor("17212b") } }, // overviewCheckBgActive
                //	{ qstr("historyFileInIconFg"), Pair{ cColor("3f96d0"), cColor("182533") } }, // msgFileInBg, msgInBg
                //	{ qstr("historyFileInIconFgSelected"), Pair{ cColor("6ab4f4"), cColor("2e70a5") } }, // msgFileInBgSelected, msgInBgSelected
                //	{ qstr("historyFileInRadialFg"), Pair{ cColor("3f96d0"), cColor("182533") } }, // msgFileInBg, msgInBg
                //	{ qstr("historyFileInRadialFgSelected"), Pair{ cColor("6ab4f4"), cColor("2e70a5") } }, // msgFileInBgSelected, msgInBgSelected
                //	{ qstr("historyFileOutIconFg"), Pair{ cColor("4c9ce2"), cColor("2b5278") } }, // msgFileOutBg, msgOutBg
                //	{ qstr("historyFileOutIconFgSelected"), Pair{ cColor("58abf3"), cColor("2e70a5") } }, // msgFileOutBgSelected, msgOutBgSelected
                //	{ qstr("historyFileOutRadialFg"), Pair{ cColor("4c9ce2"), cColor("2b5278") } }, // msgFileOutBg, msgOutBg
                //	{ qstr("historyFileOutRadialFgSelected"), Pair{ cColor("58abf3"), cColor("2e70a5") } }, // msgFileOutBgSelected, msgOutBgSelected
                //}
                //                  };
                result._lightnessMin = 64d / 255d;
                break;

            case TelegramThemeType.Tinted:
                //                  result.keepContrast = base::flat_map<QLatin1String, Pair>{
                //                      {
                //                          //{ qstr("windowFgActive"), Pair{ cColor("3fc1b0"), cColor("282e33") } }, // windowBgActive, windowBg
                //                          { qstr("activeButtonFg"), Pair{ cColor("2da192"), cColor("282e33") } }, // activeButtonBg, windowBg
                //	{ qstr("profileVerifiedCheckFg"), Pair{ cColor("3fc1b0"), cColor("282e33") } }, // profileVerifiedCheckBg, windowBg
                //	{ qstr("overviewCheckFgActive"), Pair{ cColor("3fc1b0"), cColor("282e33") } }, // overviewCheckBgActive
                //	{ qstr("callIconFg"), Pair{ cColor("5ad1c1"), cColor("26282c") } }, // callAnswerBg, callBg
                //}
                //                  };
                result._lightnessMin = 64d / 255d;
                break;
            }
            var nowLightness     = temp.ToHSL().L;
            var limitedLightness = Math.Clamp(
                nowLightness,
                result._lightnessMin,
                result._lightnessMax);

            if (limitedLightness != nowLightness)
            {
                var temp1 = temp.ToHSL();
                var temp2 = new HSL(temp1.H, temp1.S, limitedLightness);
                var temp3 = temp2.ToRGB();

                result._now = temp3.ToHSV();
            }

            return(result);
        }
Exemplo n.º 8
0
 public static bool IsAccent(TelegramThemeType type)
 {
     return(type == TelegramThemeType.Tinted ||
            type == TelegramThemeType.Night ||
            type == TelegramThemeType.Day);
 }
Exemplo n.º 9
0
 public static bool IsAccent(TelegramThemeType type)
 {
     return(type is TelegramThemeType.Tinted or
            TelegramThemeType.Night or
            TelegramThemeType.Day);
 }
Exemplo n.º 10
0
 public Color this[TelegramThemeType type]
 {
     get => ColorEx.FromHex(GetValueOrDefault(ConvertToKey(type, "Accent"), ColorEx.ToHex(ThemeInfoBase.Accents[type][AccentShade.Default])), true);