Exemplo n.º 1
0
        public void Adding_too_many_entries_throws_exception()
        {
            var pallette = new Pallette(1);

            pallette.AddColorToPallette(255, 19, 10);
            pallette.AddColorToPallette(17, 29, 99);

            Assert.Throws <Exception>(() => pallette.AddColorToPallette(93, 49, 111));
        }
Exemplo n.º 2
0
        public void Can_get_index_for_color()
        {
            var pallette = new Pallette(1);

            pallette.AddColorToPallette(17, 93, 45);

            var indexForColor = pallette[17, 93, 45];

            Assert.Equal(0, indexForColor);
        }
Exemplo n.º 3
0
        public Pallette GetPallette(string strPalletteName)
        {
            Pallette defaultPallete = GetAvailablePallettes.Find(gap => gap.Name.Equals(strPalletteName, StringComparison.InvariantCultureIgnoreCase));

            if (defaultPallete == null)
            {
                defaultPallete = GetAvailablePallettes.First();
            }

            return(defaultPallete);
        }
Exemplo n.º 4
0
        public void Can_access_pallette_by_index()
        {
            var pallette = new Pallette(1);

            pallette.AddColorToPallette(17, 93, 45);

            var colorByIndex = pallette[0];

            Assert.Equal(17, colorByIndex[0]);
            Assert.Equal(93, colorByIndex[1]);
            Assert.Equal(45, colorByIndex[2]);
        }
Exemplo n.º 5
0
        public void SetNewPallette(Pallette thePallette)
        {
            ColorConverter cv = new ColorConverter();

            App.Current.Resources["LightFill"]   = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.LightFill));
            App.Current.Resources["DarkText"]    = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.DarkText));
            App.Current.Resources["DarkFill"]    = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.DarkFill));
            App.Current.Resources["TitleArea"]   = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.TitleArea));
            App.Current.Resources["MouseOver"]   = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.MouseOver));
            App.Current.Resources["ControlArea"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.ControlArea));
            App.Current.Resources["TitleText"]   = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.TitleText));
            App.Current.Resources["StatusArea"]  = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.StatusArea));
            GradientStopCollection dark = new GradientStopCollection();

            dark.Add(new GradientStop
            {
                Color  = (Color)cv.ConvertFrom(thePallette.DarkAreaFill[0]),
                Offset = 0
            });
            dark.Add(new GradientStop
            {
                Color  = (Color)cv.ConvertFrom(thePallette.DarkAreaFill[1]),
                Offset = 1
            });
            GradientStopCollection light = new GradientStopCollection();

            light.Add(new GradientStop
            {
                Color  = (Color)cv.ConvertFrom(thePallette.LightAreaFill[0]),
                Offset = 0
            });
            light.Add(new GradientStop
            {
                Color  = (Color)cv.ConvertFrom(thePallette.LightAreaFill[1]),
                Offset = 1
            });

            App.Current.Resources["DarkAreaFill"]  = new RadialGradientBrush(dark);
            App.Current.Resources["LightAreaFill"] = new RadialGradientBrush(light);
        }
Exemplo n.º 6
0
        public List <string> SetupMainForm(System.Windows.Shapes.Path theBackgroundPath, Grid grdTitle, Grid grdWindowButtons, Grid grdStatusArea, Border brdServerControls, string strCurrentPallette, ScaleTransform formScale, Border brdMessageBox)
        {
            List <string> lstPaths = new List <string>();

            if (theXmlSkin != null)
            {
                //try and read the MainForm node
                XElement mainForm = theXmlSkin.Element("MainForm");

                if (mainForm == null)
                {
                    MessageBox.Show("Settings file is missing it's MainForm element\r\nUnable to continue");
                    Application.Current.Shutdown();
                }
                else
                {
                    //scale it
                    if (mainForm.Element("FormZoom") != null)
                    {
                        formScale.ScaleX = Convert.ToDouble(mainForm.Element("FormZoom").Element("x").Value, ni);
                        formScale.ScaleY = Convert.ToDouble(mainForm.Element("FormZoom").Element("y").Value, ni);
                    }

                    //set up the corner radiuseseses
                    if (mainForm.Element("RoundedCornerRadius") != null)
                    {
                        double dblCornerBase = Convert.ToDouble(mainForm.Element("RoundedCornerRadius").Value, ni);
                        App.Current.Resources["BigCornerRadius"]   = new CornerRadius(dblCornerBase);
                        App.Current.Resources["SmallCornerRadius"] = new CornerRadius(dblCornerBase / 2.0);
                        App.Current.Resources["TinyCornerRadius"]  = new CornerRadius(dblCornerBase / 5.0);
                        App.Current.Resources["PrefsBorder"]       = new CornerRadius(0, dblCornerBase, dblCornerBase, dblCornerBase);
                        App.Current.Resources["PrefsTabBorder"]    = new CornerRadius(dblCornerBase / 5.0, dblCornerBase / 5.0, 0, 0);
                        App.Current.Resources["RectangleRadius"]   = dblCornerBase;
                    }
                    else
                    {
                        //reset
                        CornerRadius cnrBase = new CornerRadius(0);
                        App.Current.Resources["BigCornerRadius"]   = cnrBase;
                        App.Current.Resources["SmallCornerRadius"] = cnrBase;
                        App.Current.Resources["TinyCornerRadius"]  = cnrBase;
                        App.Current.Resources["PrefsBorder"]       = cnrBase;
                        App.Current.Resources["PrefsTabBorder"]    = cnrBase;
                        App.Current.Resources["RectangleRadius"]   = 0;
                    }

                    //make a ColorConverter to manage the string-to-color handling
                    ColorConverter cv = new ColorConverter();

                    //What's the default palette?
                    string strDefaultPalette = "Standard";


                    XElement defaultPalette = mainForm.Element("DefaultPalette");
                    if (defaultPalette != null)
                    {
                        strDefaultPalette = defaultPalette.Value;
                    }

                    //do we have one from the cache maybe?
                    if (!String.IsNullOrEmpty(strCurrentPallette))
                    {
                        strDefaultPalette = strCurrentPallette;
                    }

                    //what type of server selector?
                    if (App.Current.Resources["ServerType"] == null)
                    {
                        App.Current.Resources.Add("ServerType", "Textual");
                    }
                    else
                    {
                        App.Current.Resources["ServerType"] = "Textual";
                    }
                    if (mainForm.Element("ServerType") != null)
                    {
                        App.Current.Resources["ServerType"] = mainForm.Element("ServerType").Value;
                    }

                    //Load it from the list
                    List <Pallette> lstPalletes  = App.Current.Resources["UIPalettes"] as List <Pallette>;
                    var             somePalettes = lstPalletes.Where(pal => pal.Name.Equals(strDefaultPalette, StringComparison.InvariantCultureIgnoreCase));
                    if (somePalettes.Count() > 0)
                    {
                        Pallette theDefaultPalette = somePalettes.First();
                        SetNewPallette(theDefaultPalette);
                    }

                    //and work out what type of MainForm is required
                    XElement formType = mainForm.Element("BackgroundType");

                    if (formType == null)
                    {
                        MessageBox.Show("Can't determine the BackgroundType\r\nUnable to continue");
                    }
                    else
                    {
                        switch (formType.Value.ToLowerInvariant())
                        {
                        case "image":

                            //here's a default one in case it all goes wrong
                            BitmapImage bmImage = new BitmapImage();
                            bmImage.BeginInit();
                            bmImage.UriSource = new Uri("pack://application:,,,/Images/background.jpg", UriKind.RelativeOrAbsolute);
                            bmImage.EndInit();
                            //do we have more than one image?
                            if (mainForm.Elements("BackgroundImage").Count() > 1)
                            {
                                var imagePaths = from bi in mainForm.Elements("BackgroundImage")
                                                 select bi.Value;

                                List <string> lstTempPaths = new List <string>();

                                lstTempPaths = imagePaths.ToList();

                                //do they all exists?
                                foreach (string strImage in lstTempPaths)
                                {
                                    if (File.Exists(strRootPath + strImage))
                                    {
                                        lstPaths.Add(strImage);
                                    }
                                }

                                //Load the first image
                                ImageBrush bgImage = new ImageBrush();
                                if (lstPaths.Count > 0)
                                {
                                    bgImage.ImageSource = new BitmapImage(new Uri(strRootPath + lstPaths[0], UriKind.Relative));
                                }
                                else
                                {
                                    bgImage.ImageSource = bmImage;
                                }

                                theBackgroundPath.Fill = bgImage;
                            }
                            else
                            {
                                //Load the specified image
                                ImageBrush bgImage = new ImageBrush();
                                if (File.Exists(strRootPath + mainForm.Element("BackgroundImage").Value))
                                {
                                    bgImage.ImageSource = new BitmapImage(new Uri(strRootPath + mainForm.Element("BackgroundImage").Value, UriKind.Relative));
                                }
                                else
                                {
                                    bgImage.ImageSource = bmImage;
                                }

                                theBackgroundPath.Fill = bgImage;
                            }
                            break;

                        case "path":
                            //load the path geometry
                            theBackgroundPath.Data = Geometry.Parse(mainForm.Element("PathData").Value);
                            brdMessageBox.Clip     = Geometry.Parse(mainForm.Element("MsgBoxPathData").Value);
                            if (mainForm.Element("BorderThickness") != null)
                            {
                                theBackgroundPath.StrokeThickness = Convert.ToDouble(mainForm.Element("BorderThickness").Value, ni);
                            }
                            if (mainForm.Element("BackgroundColor") != null)
                            {
                                theBackgroundPath.Fill = new SolidColorBrush((Color)cv.ConvertFrom(mainForm.Element("BackgroundColor").Value));
                            }

                            if (mainForm.Element("TitlePath") != null)
                            {
                                grdTitle.Clip = Geometry.Parse(mainForm.Element("TitlePath").Value);
                            }

                            if (mainForm.Element("WindowControlsPath") != null)
                            {
                                grdWindowButtons.Clip   = Geometry.Parse(mainForm.Element("WindowControlsPath").Value);
                                grdWindowButtons.Margin = new Thickness(grdWindowButtons.Margin.Left, grdTitle.ActualHeight + theBackgroundPath.StrokeThickness, grdWindowButtons.Margin.Right, grdWindowButtons.Margin.Bottom);
                            }

                            if (mainForm.Element("StatusPath") != null)
                            {
                                grdStatusArea.Clip = Geometry.Parse(mainForm.Element("StatusPath").Value);
                            }

                            if (mainForm.Element("StatusBorderThickness") != null)
                            {
                                //make a new thickness
                                Thickness thck = new Thickness();

                                if (mainForm.Element("StatusBorderThickness").Element("Top") != null)
                                {
                                    thck.Top = Convert.ToInt32(mainForm.Element("StatusBorderThickness").Element("Top").Value, ni);
                                }

                                if (mainForm.Element("StatusBorderThickness").Element("Bottom") != null)
                                {
                                    thck.Bottom = Convert.ToInt32(mainForm.Element("StatusBorderThickness").Element("Bottom").Value, ni);
                                }

                                if (mainForm.Element("StatusBorderThickness").Element("Right") != null)
                                {
                                    thck.Right = Convert.ToInt32(mainForm.Element("StatusBorderThickness").Element("Right").Value, ni);
                                }

                                if (mainForm.Element("StatusBorderThickness").Element("Left") != null)
                                {
                                    thck.Left = Convert.ToInt32(mainForm.Element("StatusBorderThickness").Element("Left").Value, ni);
                                }

                                brdServerControls.BorderThickness = thck;
                            }
                            break;
                        }
                    }
                }
            }

            return(lstPaths);
        }
        public void SetNewPallette(Pallette thePallette)
        {
            ColorConverter cv = new ColorConverter();
            App.Current.Resources["LightFill"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.LightFill));
            App.Current.Resources["DarkText"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.DarkText));
            App.Current.Resources["DarkFill"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.DarkFill));
            App.Current.Resources["TitleArea"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.TitleArea));
            App.Current.Resources["MouseOver"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.MouseOver));
            App.Current.Resources["ControlArea"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.ControlArea));
            App.Current.Resources["TitleText"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.TitleText));
            App.Current.Resources["StatusArea"] = new SolidColorBrush((Color)cv.ConvertFrom(thePallette.StatusArea));
            GradientStopCollection dark = new GradientStopCollection();
            dark.Add(new GradientStop
            {
                Color = (Color)cv.ConvertFrom(thePallette.DarkAreaFill[0]),
                Offset = 0
            });
            dark.Add(new GradientStop
            {
                Color = (Color)cv.ConvertFrom(thePallette.DarkAreaFill[1]),
                Offset = 1
            });
            GradientStopCollection light = new GradientStopCollection();
            light.Add(new GradientStop
            {
                Color = (Color)cv.ConvertFrom(thePallette.LightAreaFill[0]),
                Offset = 0
            });
            light.Add(new GradientStop
            {
                Color = (Color)cv.ConvertFrom(thePallette.LightAreaFill[1]),
                Offset = 1
            });

            App.Current.Resources["DarkAreaFill"] = new RadialGradientBrush(dark);
            App.Current.Resources["LightAreaFill"] = new RadialGradientBrush(light);
        }