file360

Log | Files | Refs

ColorPicker.xaml.cs (7753B)


      1 using System;
      2 using System.Collections.Generic;
      3 using Windows.UI;
      4 using Windows.UI.Xaml;
      5 using Windows.UI.Xaml.Controls;
      6 using Windows.UI.Xaml.Media;
      7 
      8 // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
      9 
     10 namespace File360
     11 {
     12     /// <summary>
     13     /// An empty page that can be used on its own or navigated to within a Frame.
     14     /// </summary>
     15     public sealed partial class ColorPicker : UserControl
     16     {
     17         public ColorPicker()
     18         {
     19             this.InitializeComponent();
     20             Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
     21             #region blahblahblah
     22             //            string[] colorNames =
     23             //{
     24             //  "Yellow","BananaYellow","LaserLemon","Jasmine","Green","Emerald",
     25             //  "GreenYellow","Lime","Chartreuse","LimeGreen","SpringGreen","LightGreen",
     26             //  "MediumSeaGreen","MediumSpringGreen","Olive","SeaGreen","Red","OrangeRed",
     27             //  "DarkOrange","Orange","ImperialRed","Maroon","Brown","Chocolate",
     28             //  "Coral","Crimson","DarkSalmon","DeepPink","#Firebrick","HotPink",
     29             //  "IndianRed","LightCoral","LightPink","LightSalmon","Magenta","MediumVioletRed",
     30             //  "Orchid","PaleVioletRed","Salmon","SandyBrown","Navy","Indigo",
     31             //  "MidnightBlue","Blue","Purple","BlueViolet","CornflowerBlue","Cyan",
     32             //  "DarkCyan","DarkSlateBlue","DeepSkyBlue","DodgerBlue","LightBlue","LightSeaGreen",
     33             //  "LightSkyBlue","LightSteelBlue","Mauve","MediumSlateBlue","RoyalBlue","SlateBlue",
     34             //  "SlateGray","SteelBlue","Teal","Turquoise","DarkGrey","LightGray"
     35             //};
     36             #endregion
     37 
     38         }
     39 
     40         private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
     41         {
     42             Height = 50;
     43         }
     44 
     45         private void ColorSetInitializer(string n)
     46         {
     47             if (n == "0")
     48             {
     49                 string[] accentColors =
     50                 {
     51             "#FFFFFF00","#FFFFE135","#FFFFFF66","#FFF8DE7E","#FF008000","#FF008A00",
     52             "#FFADFF2F","#FF00FF00","#FF7FFF00","#FF32CD32","#FF00FF7F","#FF90EE90",
     53             "#FF3CB371","#FF00FA9A","#FF808000","#FF2E8B57","#FFFF0000","#FFFF4500",
     54             "#FFFF8C00","#FFFFA500","#FFED2939","#FF800000","#FFA52A2A","#FFD2691E",
     55             "#FFFF7F50","#FFDC143C","#FFE9967A","#FFFF1493","#FFB22222","#FFFF69B4",
     56             "#FFCD5C5C","#FFF08080","#FFFFB6C1","#FFFFA07A","#FFFF00FF","#FFC71585",
     57             "#FFDA70D6","#FFDB7093","#FFFA8072","#FFF4A460","#FF000080","#FF4B0082",
     58             "#FF191970","#FF0000FF","#FF800080","#FF8A2BE2","#FF6495ED","#FF00FFFF",
     59             "#FF008B8B","#FF483D8B","#FF00BFFF","#FF1E90FF","#FFADD8E6","#FF20B2AA",
     60             "#FF87CEFA","#FFB0C4DE","#FF76608A","#FF7B68EE","#FF4169E1","#FF6A5ACD",
     61             "#FF708090","#FF4682B4","#FF008080","#FF40E0D0","#FFA9A9A9","#FFD3D3D3"
     62             };
     63                 List<ColorList> accentItem = new List<ColorList>();
     64                 for (int i = 0; i < 66; i++)
     65                 {
     66                     accentItem.Add(new ColorList(accentColors[i]));
     67                 }
     68                 ColorContainer.ItemsSource = accentItem;
     69             }
     70             if (n == "1")
     71             {
     72                 string[] themeColors =
     73                 {
     74                 "#FFFFFFFF","#FF000000"
     75             };
     76                 List<ColorList> accentItem = new List<ColorList>();
     77                 for (int i = 0; i < 2; i++)
     78                 {
     79                     accentItem.Add(new ColorList(themeColors[i]));
     80                 }
     81                 ColorContainer.ItemsSource = accentItem;
     82             }
     83             if (n == "2")
     84             {
     85                 string[] folderColors =
     86                 {
     87             "#FFFFFF00","#FFFFE135","#FFFFFF66","#FFF8DE7E","#FF008000","#FF008A00",
     88             "#FFADFF2F","#FF00FF00","#FF7FFF00","#FF32CD32","#FF00FF7F","#FF90EE90",
     89             "#FF3CB371","#FF00FA9A","#FF808000","#FF2E8B57","#FFFF0000","#FFFF4500",
     90             "#FFFF8C00","#FFFFA500","#FFED2939","#FF800000","#FFA52A2A","#FFD2691E",
     91             "#FFFF7F50","#FFDC143C","#FFE9967A","#FFFF1493","#FFB22222","#FFFF69B4",
     92             "#FFCD5C5C","#FFF08080","#FFFFB6C1","#FFFFA07A","#FFFF00FF","#FFC71585",
     93             "#FFDA70D6","#FFDB7093","#FFFA8072","#FFF4A460","#FF000080","#FF4B0082",
     94             "#FF191970","#FF0000FF","#FF800080","#FF8A2BE2","#FF6495ED","#FF00FFFF",
     95             "#FF008B8B","#FF483D8B","#FF00BFFF","#FF1E90FF","#FFADD8E6","#FF20B2AA",
     96             "#FF87CEFA","#FFB0C4DE","#FF76608A","#FF7B68EE","#FF4169E1","#FF6A5ACD",
     97             "#FF708090","#FF4682B4","#FF008080","#FF40E0D0","#FFA9A9A9","#FFD3D3D3"
     98             };
     99                 List<ColorList> accentItem = new List<ColorList>();
    100                 for (int i = 0; i < 66; i++)
    101                 {
    102                     accentItem.Add(new ColorList(folderColors[i]));
    103                 }
    104                 ColorContainer.ItemsSource = accentItem;
    105             }
    106         }
    107 
    108         public string ColorSet
    109         {
    110             set { ColorSetInitializer(value); }
    111         }
    112 
    113         public string OptionName
    114         {
    115             get { return ColorProperty.Text; }
    116             set { ColorProperty.Text = value; }
    117         }
    118         //public event EventArgs ColorSelected;
    119         //private void lstColorPalette_SelectionChanged(object sender, SelectionChangedEventArgs e)
    120         //{
    121         //    if (ColorSelected != null)
    122         //    {
    123         //        //SelectedColor = objColor.ColorBrush;
    124         //        //ColorSelectedEvent(this, EventArgs.Empty);
    125         //    }
    126         //}
    127         public SolidColorBrush SelectedColor
    128         {
    129             get { return new SolidColorBrush(StringToColor(CurrentColorItem.Color)); }
    130         }
    131 
    132         public ColorList CurrentColorItem { set; get; }
    133 
    134         private void ColorPickerPage_Loaded(object sender, RoutedEventArgs e)
    135         {
    136         }
    137         private static Color StringToColor(string s)
    138         {
    139             // remove artifacts
    140             s = s.Trim().TrimStart('#');
    141 
    142             // only 8 (with alpha channel) or 6 symbols are allowed
    143             if (s.Length != 8 && s.Length != 6)
    144                 throw new ArgumentException("Unknown string format!");
    145 
    146             int startParseIndex = 0;
    147             bool alphaChannelExists = s.Length == 8; // check if alpha canal exists            
    148 
    149             // read alpha channel value
    150             byte a = 255;
    151             if (alphaChannelExists)
    152             {
    153                 a = System.Convert.ToByte(s.Substring(0, 2), 16);
    154                 startParseIndex += 2;
    155             }
    156 
    157             // read r value
    158             byte r = System.Convert.ToByte(s.Substring(startParseIndex, 2), 16);
    159             startParseIndex += 2;
    160             // read g value
    161             byte g = System.Convert.ToByte(s.Substring(startParseIndex, 2), 16);
    162             startParseIndex += 2;
    163             // read b value
    164             byte b = System.Convert.ToByte(s.Substring(startParseIndex, 2), 16);
    165 
    166             return Color.FromArgb(a, r, g, b);
    167         }
    168         private void ColorContainer_SelectionChanged(object sender, SelectionChangedEventArgs e)
    169         {
    170             if (e.AddedItems.Count > 0)
    171             {
    172                 CurrentColorItem = ((ColorList)e.AddedItems[0]);
    173                 RectangleFill.Fill = new SolidColorBrush(StringToColor(CurrentColorItem.Color));
    174             }
    175         }
    176         private void ButtonCheck(object sender, RoutedEventArgs e)
    177         {
    178             stackPanel.Height = 300;
    179         }
    180         private void ButtonUncheck(object sender, RoutedEventArgs e)
    181         {
    182             stackPanel.Height = 50;
    183         }
    184     }
    185 }