src/FingersDance.ActionFactory/ColorFactory.cs
author cavaliet
Tue, 24 Nov 2009 22:08:57 +0100
changeset 229 05aba5def1fc
parent 160 e940ca798fe3
permissions -rw-r--r--
add an attribute Color to a Cutting, save it in ldt xml file and redisplay it in the pivot's button. Make ColorFactory truly static.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;

namespace FingersDance.Factory
{
    public class ColorFactory
    {

        static Dictionary<uint, string> _ColorsStringId;
        static Dictionary<uint, Color> _Colors;
        static Dictionary<uint, Color> _ColorsOrig;

        public Dictionary<uint, string> ColorsStringId
        {
            get { return _ColorsStringId; }
        }
        public Dictionary<uint, Color> Colors
        {
            get { return _Colors; }
        }
        public Dictionary<uint, Color> ColorsOrig
        {
            get { return _ColorsOrig; }
        }

        public ColorFactory()
        {
            init();
        }

        private static void init()
        {
            if (_ColorsStringId == null)
            {
                _ColorsStringId = new Dictionary<uint, string>();
                //_ColorsStringId.Add(0, "DefaultColor_xaml");
                _ColorsStringId.Add(1, "Color_1_#FFFF00_xaml");
                _ColorsStringId.Add(2, "Color_12_#00C800_xaml");
                _ColorsStringId.Add(3, "Color_3_#FF7D00__xaml");
                _ColorsStringId.Add(4, "Color_4_#FF0000_xaml");
                _ColorsStringId.Add(5, "Color_5_#FF0064_xaml");
                _ColorsStringId.Add(6, "Color_6_#C80FA0_xaml");
                _ColorsStringId.Add(7, "Color_7_#5A0FC8_xaml");
                _ColorsStringId.Add(8, "Color_8_#230FD2_xaml");
                _ColorsStringId.Add(9, "Color_9_#0096FF__xaml");
                _ColorsStringId.Add(10, "Color_10_#009664_xaml");
                _ColorsStringId.Add(11, "Color_11_#006432_xaml");
                _ColorsStringId.Add(12, "Color_2_#FFC800_xaml");
            }

            if (_Colors == null)
            {
                _Colors = new Dictionary<uint, Color>();
                _Colors.Add(0, Color.FromRgb(0x88, 0x88, 0x88));
                _Colors.Add(1, Color.FromRgb(0xFF, 0xFF, 0x00));
                _Colors.Add(2, Color.FromRgb(0x00, 0xC8, 0x00));
                _Colors.Add(3, Color.FromRgb(0xFF, 0x7D, 0x00));
                _Colors.Add(4, Color.FromRgb(0xFF, 0x00, 0x00));
                _Colors.Add(5, Color.FromRgb(0xFF, 0x00, 0x64));
                _Colors.Add(6, Color.FromRgb(0xC8, 0x0F, 0xA0));
                _Colors.Add(7, Color.FromRgb(0x5A, 0x0F, 0xC8));
                _Colors.Add(8, Color.FromRgb(0x23, 0x0F, 0xD2));
                _Colors.Add(9, Color.FromRgb(0x00, 0x96, 0xFF));
                _Colors.Add(10, Color.FromRgb(0x00, 0x96, 0x64));
                _Colors.Add(11, Color.FromRgb(0x00, 0x64, 0x32));
                _Colors.Add(12, Color.FromRgb(0xFF, 0xC8, 0x00));

                _ColorsOrig = new Dictionary<uint, Color>();
                _ColorsOrig.Add(0, Color.FromRgb(0x88, 0x88, 0x88));
                _ColorsOrig.Add(1, Color.FromRgb(0xFF, 0xFF, 0x00));
                _ColorsOrig.Add(2, Color.FromRgb(0x00, 0xC8, 0x00));
                _ColorsOrig.Add(3, Color.FromRgb(0xFF, 0x7D, 0x00));
                _ColorsOrig.Add(4, Color.FromRgb(0xFF, 0x00, 0x00));
                _ColorsOrig.Add(5, Color.FromRgb(0xFF, 0x00, 0x64));
                _ColorsOrig.Add(6, Color.FromRgb(0xC8, 0x0F, 0xA0));
                _ColorsOrig.Add(7, Color.FromRgb(0x5A, 0x0F, 0xC8));
                _ColorsOrig.Add(8, Color.FromRgb(0x23, 0x0F, 0xD2));
                _ColorsOrig.Add(9, Color.FromRgb(0x00, 0x96, 0xFF));
                _ColorsOrig.Add(10, Color.FromRgb(0x00, 0x96, 0x64));
                _ColorsOrig.Add(11, Color.FromRgb(0x00, 0x64, 0x32));
                _ColorsOrig.Add(12, Color.FromRgb(0xFF, 0xC8, 0x00));
            }
        }

        public static void TakeOffColor(Color col)
        {
            init();
            foreach(KeyValuePair<uint,Color> kvp in _Colors)
            {
                if (_Colors[kvp.Key] == col)
                {
                    _Colors.Remove(kvp.Key);
                    return;
                }
            }
        }

        public static KeyValuePair<uint,Color> getAvailablePairUintColor()
        {
            init();
            foreach(KeyValuePair<uint,Color> kvp in _Colors)
            {
                if (kvp.Value != Color.FromRgb(0x88, 0x88, 0x88))
                    return kvp;
            }
            return new KeyValuePair<uint,Color>();
        }

        public static uint getId(Color col)
        {
            init();
            foreach (KeyValuePair<uint, Color> kvp in _ColorsOrig)
            {
                if (_ColorsOrig[kvp.Key] == col)
                {
                    return kvp.Key;
                }
            }
            return 0;
        }
    }
}