public SettingsItemViewModel(AppIconType icon, string headline, Func <string> getDescription, Action navigate)
        {
            this.icon           = icon;
            this.headline       = headline;
            this.getDescription = getDescription;

            this.description = getDescription();
            this.navigate    = navigate;

            this.navigateCommand = new RelayCommand(this.NavigateExecute);
        }
Example #2
0
        private void OnIconChanged(DependencyPropertyChangedEventArgs e)
        {
            AppIconType type = (AppIconType)e.NewValue;

            this.templateLoaded = () => this.textBlock.Text = FontIconHelper.GetSymbolCode(type);
            if (this.textBlock != null)
            {
                this.templateLoaded();
                this.templateLoaded = null;
            }
        }
Example #3
0
        public static string GetSymbolCode(AppIconType icon)
        {
            if (!iconDescriptors.ContainsKey(icon))
            {
                Debug.WriteLine("WARNING: unknown icon: {0}", icon);
                return(String.Empty);
            }

            FontIconDescriptor fontIconDescriptor = iconDescriptors[icon];

            char code = (char)(fontIconDescriptor.Offset + (int)fontIconDescriptor.Group);

            return(code.ToString());
        }
        public HeadedSettingItemViewModel(AppIconType icon, string headline, string description, Action navigateAction)
        {
            if (string.IsNullOrEmpty(headline))
            {
                throw new ArgumentNullException(nameof(headline));
            }
            if (navigateAction == null)
            {
                throw new ArgumentNullException(nameof(navigateAction));
            }

            this.icon        = icon;
            this.headline    = headline;
            this.description = description;

            this.navigateCommand = new RelayCommand(navigateAction);
        }
Example #5
0
        public static Icon Get(AppIconType t, Size sz, Color clr)
        {
            int w = Math.Min(Math.Max(sz.Width, 0), 256);
            int h = Math.Min(Math.Max(sz.Height, 0), 256);

            if ((w == 0) || (h == 0))
            {
                Size szDefault = UIUtil.GetIconSize();
                w = szDefault.Width;
                h = szDefault.Height;
            }

            Color c = clr;

            if (!UIUtil.ColorsEqual(c, Color.Empty))
            {
                c = RoundColor(c);
            }

            NumberFormatInfo nf    = NumberFormatInfo.InvariantInfo;
            string           strID = ((long)t).ToString(nf) + ":" + w.ToString(nf) + ":" +
                                     h.ToString(nf) + ":" + c.ToArgb().ToString(nf);

            Icon ico = null;

            lock (g_oCacheSync)
            {
                if (g_dCache.TryGetValue(strID, out ico))
                {
                    return(ico);
                }
            }

            if (t == AppIconType.Main)
            {
                ico = Properties.Resources.KeePass;
            }
            else if (t == AppIconType.QuadNormal)
            {
                ico = Properties.Resources.QuadNormal;
            }
            else if (t == AppIconType.QuadLocked)
            {
                ico = Properties.Resources.QuadLocked;

                Debug.Assert(UIUtil.ColorsEqual(c, Color.Empty));
                c = Color.Empty;                 // This icon should not be recolored
            }
            else
            {
                Debug.Assert(false);
            }

            if ((ico != null) && !UIUtil.ColorsEqual(c, Color.Empty))
            {
                ico = IconColorizer.Recolor(ico, c);
            }

            // Select requested resolution
            if (ico != null)
            {
                ico = new Icon(ico, w, h);                         // Preserves icon data
            }
            Debug.Assert(ico != null);
            lock (g_oCacheSync) { g_dCache[strID] = ico; }
            return(ico);
        }
Example #6
0
        public static Icon Get(AppIconType t, Size sz, Color clr)
        {
            int w = Math.Min(Math.Max(sz.Width, 0), 256);
            int h = Math.Min(Math.Max(sz.Height, 0), 256);

            if ((w == 0) || (h == 0))
            {
                Size szDef = UIUtil.GetIconSize();
                w = szDef.Width;
                h = szDef.Height;
            }

            Color c = RoundColor(clr);

            NumberFormatInfo nf    = NumberFormatInfo.InvariantInfo;
            string           strID = ((long)t).ToString(nf) + ":" + w.ToString(nf) + ":" +
                                     h.ToString(nf) + ":" + c.ToArgb().ToString(nf);

            Icon ico = null;

            lock (g_oCacheSync)
            {
                if (g_dCache.TryGetValue(strID, out ico))
                {
                    return(ico);
                }
            }

            if (t == AppIconType.Main)
            {
                if (c == Color.Red)
                {
                    ico = Properties.Resources.KeePass_R;
                }
                else if (c == Color.Lime)
                {
                    ico = Properties.Resources.KeePass_G;
                }
                else if (c == Color.Yellow)
                {
                    ico = Properties.Resources.KeePass_Y;
                }
                else
                {
                    Debug.Assert(c == Color.Blue);
                    ico = Properties.Resources.KeePass;
                }
            }
            else if (t == AppIconType.QuadNormal)
            {
                if (c == Color.Red)
                {
                    ico = Properties.Resources.QuadNormal_R;
                }
                else if (c == Color.Lime)
                {
                    ico = Properties.Resources.QuadNormal_G;
                }
                else if (c == Color.Yellow)
                {
                    ico = Properties.Resources.QuadNormal_Y;
                }
                else
                {
                    Debug.Assert(c == Color.Blue);
                    ico = Properties.Resources.QuadNormal;
                }
            }
            else if (t == AppIconType.QuadLocked)
            {
                Debug.Assert(c == Color.Blue);
                ico = Properties.Resources.QuadLocked;
            }
            else
            {
                Debug.Assert(false);
            }

            Icon icoSc = null;

            if (ico != null)
            {
                icoSc = new Icon(ico, w, h);                         // Preserves icon data
            }
            else
            {
                Debug.Assert(false);
            }

            lock (g_oCacheSync) { g_dCache[strID] = icoSc; }
            return(icoSc);
        }