private LinearGradientBrush CreateBrush(string baseColor, string centerColor)
 {
     var converter = new ColorConverter();
     var linearGradientBrush = new LinearGradientBrush();
     linearGradientBrush.StartPoint = new Point(0.5, 0);
     linearGradientBrush.EndPoint = new Point(0.5, 1);
     linearGradientBrush.GradientStops.Add(new GradientStop((Color)converter.ConvertFrom(baseColor), 0));
     linearGradientBrush.GradientStops.Add(new GradientStop((Color)converter.ConvertFrom(centerColor), 0.5));
     linearGradientBrush.GradientStops.Add(new GradientStop((Color)converter.ConvertFrom(baseColor), 1));
     return linearGradientBrush;
 }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RubberbandAdorner"/> class.
        /// </summary>
        /// <param name="canvas">The canvas.</param>
        /// <param name="dragStartPoint">The drag start point.</param>
        public RubberbandAdorner(Desktop canvas, Point? dragStartPoint)
            : base(canvas)
        {
            ColorConverter cconverter = new ColorConverter();

            this.desktop                    = canvas;
            this.startPoint                 = dragStartPoint;
            this.rubberbandPen              = new Pen(new SolidColorBrush((Color)cconverter.ConvertFrom("#FF7AA3D4")), 1);
            this.rubberbandPen.DashStyle    = new DashStyle();
            this.backgroundBrush            = new SolidColorBrush((Color)cconverter.ConvertFrom("#FFC5D5E9"));
            this.backgroundBrush.Opacity    = 0.40;
        }
        public ButtonOfDevice(XElement dev)
        {
            InitializeComponent();

            if (dev.Parent.Name == "Adapter")
            {
                //this.usercontrol.Width = 120;
                this.Width = 120;
                this.grid.Width = 110;
                this.Code.Width = 110;
                this.Tag1.Width = 110;
                this.Tag2.Width = 110;
                this.Tag3.Width = 110;
                this.Tag4.Width = 110;
                this.Tag5.Width = 110;
                this.Power.Width = 110;
                this.line2.X2 += 50;
                this.line3.X1 += 50;
                this.line3.X2 += 50;
                this.line1.Stroke = Brushes.Red;
                this.line2.Stroke = Brushes.Red;
                this.line3.Stroke = Brushes.Red;

                this.line1.StrokeThickness = 4;
                this.line3.StrokeThickness = 0;
            }

            if (dev.Element("Name").Value == "电源模块")
            {
                this.line1.Stroke = Brushes.Red;
                this.line2.Stroke = Brushes.Red;
                this.line3.Stroke = Brushes.Red;

                this.line1.StrokeThickness = 4;
                this.line3.StrokeThickness = 0;
            }

            ColorConverter cc = new ColorConverter();
            Color c = (Color)cc.ConvertFrom(dev.Parent.Attribute("color").Value);
            this.Code.Background = new SolidColorBrush(c);
            this.Margin = new Thickness(5, 0, 0, 0);

            this.Code.Content = dev.Element("Code").Value.ToString();
            this.Tag1.Content = dev.Element("Tags").Attribute("tag1").Value;
            this.Tag2.Content = dev.Element("Tags").Attribute("tag2").Value;
            this.Tag3.Content = dev.Element("Tags").Attribute("tag3").Value;
            this.Tag4.Content = dev.Element("Tags").Attribute("tag4").Value;
            this.Tag5.Content = dev.Element("Tags").Attribute("tag5").Value;
            this.Power.Content = Convert.ToInt32(dev.Element("OutCurrent").Value) - Convert.ToInt32(dev.Element("InCurrent").Value);

            if (Convert.ToInt32(this.Power.Content.ToString()) == 0)
            {
                this.line1.StrokeThickness = 0;
                this.line2.Stroke = Brushes.Green;
                this.line3.StrokeThickness = 0;
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var converter = new ColorConverter();

            switch ((TaskState)value)
            {
                case TaskState.Normal:
                    //#13aa13
                    return new SolidColorBrush((Color)converter.ConvertFrom("#00CC00"));
                case TaskState.Warning:
                    //#b8a400
                    return new SolidColorBrush((Color)converter.ConvertFrom("#FFFF00")); //"#d9bf1b"
                case TaskState.Error:
                    //#d21313
                    return new SolidColorBrush((Color)converter.ConvertFrom("#FF0000"));
            }
            throw new NotImplementedException("Could not convert state to color");
        }
Beispiel #5
0
        public void SetValue(string key, string value, IFormatProvider format = null)
        {
            try
            {
                if (format == null)
                {
                    format = CultureInfo.CurrentCulture;
                }

                var type = Default[key].GetType()
                           .Name;
                switch (type)
                {
                case "Boolean":
                    Default[key] = Convert.ToBoolean(value);
                    break;

                case "Color":
                    var cc    = new ColorConverter();
                    var color = cc.ConvertFrom(value);
                    Default[key] = color ?? Colors.Black;
                    break;

                case "Double":
                    Default[key] = Double.Parse(value, NumberStyles.Any, format);
                    break;

                case "Font":
                    var fc   = new FontConverter();
                    var font = fc.ConvertFromString(value);
                    Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12);
                    break;

                case "Int32":
                    Default[key] = Int32.Parse(value, NumberStyles.Any, format);
                    break;

                default:
                    Default[key] = value;
                    break;
                }
                RaisePropertyChanged(key);
            }
            catch (SettingsPropertyNotFoundException ex)
            {
                LogHelper.Log(Logger, ex, LogLevel.Error);
            }
            catch (SettingsPropertyWrongTypeException ex)
            {
                LogHelper.Log(Logger, ex, LogLevel.Error);
            }
            catch (FormatException ex)
            {
                LogHelper.Log(Logger, ex, LogLevel.Error);
            }
        }
Beispiel #6
0
        public void SetValue(string key, string value, CultureInfo cultureInfo)
        {
            try
            {
                var type = Default[key]
                           .GetType()
                           .Name;
                switch (type)
                {
                case "Boolean":
                    Default[key] = Boolean.Parse(value);
                    break;

                case "Color":
                    var cc    = new ColorConverter();
                    var color = cc.ConvertFrom(value);
                    Default[key] = color ?? Colors.Black;
                    break;

                case "Double":
                    Default[key] = Double.Parse(value, cultureInfo);
                    break;

                case "Font":
                    var fc   = new FontConverter();
                    var font = fc.ConvertFromString(value);
                    Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12);
                    break;

                case "Int32":
                    Default[key] = Int32.Parse(value, cultureInfo);
                    break;

                default:
                    Default[key] = value;
                    break;
                }
            }
            catch (Exception ex)
            {
                Logging.Log(Logger, new LogItem(ex, true));
            }
            RaisePropertyChanged(key);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Color color = (Color)System.Convert.ChangeType(value, typeof(Color));
            Color parameterColor;
            if (parameter is Color)
                parameterColor = (Color)parameter;
            else
            {
                var converter = new System.Windows.Media.ColorConverter();
                parameterColor = (Color)converter.ConvertFrom(parameter);
            }

            return Color.FromArgb(
                (byte)(color.A * parameterColor.A / 255),
                (byte)(color.R * parameterColor.R / 255),
                (byte)(color.G * parameterColor.G / 255),
                (byte)(color.B * parameterColor.B / 255)
                );
        }
Beispiel #8
0
        //public Light Lighting { get; private set; }
        public FullScene()
        {
            // Define the camera
            var camera = new PerspectiveCamera();
            camera.Position = new Point3D(0, .25, 10);
            camera.LookDirection = new Vector3D(0, 0, -1);

            //camera.LookDirection = new Vector3D(0, -.05, -1);
            camera.UpDirection = new Vector3D(0, 1, 0);
            camera.FieldOfView = 60;

            //var camera = new OrthographicCamera();
            //camera.Position = new Point3D(0, 0, 85);
            //camera.LookDirection = new Vector3D(0, -.05, -4);

            //camera.NearPlaneDistance = 0;
            //camera.FarPlaneDistance = 100;
            ColorConverter conv = new ColorConverter();
            var color = (Color)conv.ConvertFrom("#ffffff");
            //var ambient = new AmbientLight(color);
            var pos = new Point3D(0, 10, 10);
            var spotlight = new SpotLight();
            spotlight.Color = color;
            spotlight.Position = pos;
            spotlight.InnerConeAngle = 180;
            spotlight.OuterConeAngle = 90;
            spotlight.Direction = new Vector3D(pos.X * -1, pos.Y * -1, pos.Z * -1);

            // Define a lighting model
            // Collect the components
            this.modelGroup = new Model3DGroup();
            this.modelGroup.Children.Add(ambientLight);
            this.modelGroup.Children.Add(spotlight);

            ModelVisual3D visual = new ModelVisual3D();
            visual.Content = this.modelGroup;
            Viewport3D viewport = new Viewport3D();

            viewport.Children.Add(visual);
            viewport.Camera = camera;

            this.Viewport = viewport;
        }
Beispiel #9
0
        public static void SetValue(string key, string value)
        {
            try
            {
                var type = Default[key].GetType()
                           .Name;
                switch (type)
                {
                case "Boolean":
                    Default[key] = Convert.ToBoolean(value);
                    break;

                case "Color":
                    var cc    = new ColorConverter();
                    var color = cc.ConvertFrom(value);
                    Default[key] = color ?? Colors.Black;
                    break;

                case "Double":
                    Default[key] = Convert.ToDouble(value);
                    break;

                case "Font":
                    var fc   = new FontConverter();
                    var font = fc.ConvertFromString(value);
                    Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12);
                    break;

                default:
                    Default[key] = value;
                    break;
                }
            }
            catch (SettingsPropertyNotFoundException ex)
            {
                Logging.Log(LogManager.GetCurrentClassLogger(), "", ex);
            }
            catch (SettingsPropertyWrongTypeException ex)
            {
                Logging.Log(LogManager.GetCurrentClassLogger(), "", ex);
            }
        }
        /// <summary>
        /// 色をブラシに変換します。
        /// </summary>
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            try
            {
                if (targetType != typeof(Brush) &&
                    targetType != typeof(SolidColorBrush))
                {
                    throw new InvalidOperationException(
                        "変換先のオブジェクトがブラシではありません。");
                }

                if (value.GetType() == typeof(Color))
                {
                    var brush = new SolidColorBrush((Color)value);
                    brush.Freeze();
                    return brush;
                }
                else if (value.GetType() == typeof(string))
                {
                    var converter = new ColorConverter();
                    var color = (Color)converter.ConvertFrom(value);

                    var brush = new SolidColorBrush((Color)value);
                    brush.Freeze();
                    return brush;
                }

                return null;
            }
            catch (InvalidCastException ex)
            {
                Log.ErrorException(ex,
                    "ColorToSolidColorBrushConverter: " +
                    "ブラシに変換できませんでした。");

                return Brushes.Red;
            }
        }
Beispiel #11
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Color color = (Color)System.Convert.ChangeType(value, typeof(Color));
            Color parameterColor;

            if (parameter is Color)
            {
                parameterColor = (Color)parameter;
            }
            else
            {
                var converter = new System.Windows.Media.ColorConverter();
                parameterColor = (Color)converter.ConvertFrom(parameter);
            }

            return(Color.FromArgb(
                       (byte)(color.A * parameterColor.A / 255),
                       (byte)(color.R * parameterColor.R / 255),
                       (byte)(color.G * parameterColor.G / 255),
                       (byte)(color.B * parameterColor.B / 255)
                       ));
        }
 public static void SetValue(string key, string value)
 {
     try
     {
         var type = Default[key].GetType()
                                .Name;
         switch (type)
         {
             case "Boolean":
                 Default[key] = Convert.ToBoolean(value);
                 break;
             case "Color":
                 var cc = new ColorConverter();
                 var color = cc.ConvertFrom(value);
                 Default[key] = color ?? Colors.Black;
                 break;
             case "Double":
                 Default[key] = Convert.ToDouble(value);
                 break;
             case "Font":
                 var fc = new FontConverter();
                 var font = fc.ConvertFromString(value);
                 Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12);
                 break;
             default:
                 Default[key] = value;
                 break;
         }
     }
     catch (SettingsPropertyNotFoundException ex)
     {
         Logging.Log(LogManager.GetCurrentClassLogger(), "", ex);
     }
     catch (SettingsPropertyWrongTypeException ex)
     {
         Logging.Log(LogManager.GetCurrentClassLogger(), "", ex);
     }
 }
Beispiel #13
0
        public static Color GetColor(this Configuration cfg, string key, Color defaultColor)
        {
            string colorString = cfg.GetValue<string>(key);

            if (colorString != null)
            {
                ColorConverter converter = new ColorConverter();

                if (converter.CanConvertFrom(typeof(string)))
                {
                    try
                    {
                        Color color = (Color)converter.ConvertFrom(null, null, colorString);
                        return color;
                    }
                    catch (Exception)
                    {
                        stdio.ErrorFormat("color setting {0} = {1} not supported", key, colorString);
                    }
                }
            }

            return defaultColor;
        }
Beispiel #14
0
 /// <summary>
 /// Converts a hexidecimal string to a WPF Color object.
 /// </summary>
 /// <param name="hex"></param>
 /// <returns></returns>
 public static Color ToColor(this string hex)
 {
     ColorConverter converter = new ColorConverter();
     return (Color)converter.ConvertFrom(hex);
 }
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     var colorConverter = new ColorConverter();
     return colorConverter.IsValid(value) ? colorConverter.ConvertFrom(value) : DependencyProperty.UnsetValue;
 }
        public void SetValue(string key, string value, IFormatProvider format = null)
        {
            try
            {
                if (format == null)
                {
                    format = CultureInfo.CurrentCulture;
                }

                var type = Default[key].GetType()
                                       .Name;
                switch (type)
                {
                    case "Boolean":
                        Default[key] = Convert.ToBoolean(value);
                        break;
                    case "Color":
                        var cc = new ColorConverter();
                        var color = cc.ConvertFrom(value);
                        Default[key] = color ?? Colors.Black;
                        break;
                    case "Double":
                        Default[key] = Double.Parse(value, NumberStyles.Any, format);
                        break;
                    case "Font":
                        var fc = new FontConverter();
                        var font = fc.ConvertFromString(value);
                        Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12);
                        break;
                    case "Int32":
                        Default[key] = Int32.Parse(value, NumberStyles.Any, format);
                        break;
                    default:
                        Default[key] = value;
                        break;
                }
                RaisePropertyChanged(key);
            }
            catch (SettingsPropertyNotFoundException ex)
            {
                LogHelper.Log(Logger, ex, LogLevel.Error);
            }
            catch (SettingsPropertyWrongTypeException ex)
            {
                LogHelper.Log(Logger, ex, LogLevel.Error);
            }
            catch (FormatException ex)
            {
                LogHelper.Log(Logger, ex, LogLevel.Error);
            }
        }
        public MagnifyingGlass(MarkableCanvas markableCanvas)
        {
            this.FieldOfView = Constant.MarkableCanvas.MagnifyingGlassDefaultFieldOfView;
            this.IsEnabled = false;
            this.IsHitTestVisible = false;
            this.HorizontalAlignment = HorizontalAlignment.Left;
            this.Parent = markableCanvas;
            this.VerticalAlignment = VerticalAlignment.Top;
            this.Visibility = Visibility.Collapsed;

            this.lensAngle = 0.0;
            this.magnifyingGlassAngle = 0.0;

            // Create the handle of the magnifying glass
            Line handle = new Line();
            handle.StrokeThickness = 5;
            handle.X1 = Constant.MarkableCanvas.MagnifyingGlassHandleStart;
            handle.Y1 = Constant.MarkableCanvas.MagnifyingGlassHandleStart;
            handle.X2 = Constant.MarkableCanvas.MagnifyingGlassHandleEnd;
            handle.Y2 = Constant.MarkableCanvas.MagnifyingGlassHandleEnd;
            LinearGradientBrush handleBrush = new LinearGradientBrush();
            handleBrush.StartPoint = new Point(0.78786, 1);
            handleBrush.EndPoint = new Point(1, 0.78786);
            handleBrush.GradientStops.Add(new GradientStop(Colors.DarkGreen, 0));
            handleBrush.GradientStops.Add(new GradientStop(Colors.LightGreen, 0.9));
            handleBrush.GradientStops.Add(new GradientStop(Colors.Green, 1));
            handle.Stroke = handleBrush;
            this.Children.Add(handle);

            // Create the lens of the magnifying glass
            this.lensCanvas = new Canvas();
            this.Children.Add(this.lensCanvas);

            // lens has a white backgound
            Ellipse lensBackground = new Ellipse();
            lensBackground.Width = Constant.MarkableCanvas.MagnifyingGlassDiameter;
            lensBackground.Height = Constant.MarkableCanvas.MagnifyingGlassDiameter;
            lensBackground.Fill = Brushes.White;
            this.lensCanvas.Children.Add(lensBackground);

            this.magnifierLens = new Ellipse();
            this.magnifierLens.Width = Constant.MarkableCanvas.MagnifyingGlassDiameter;
            this.magnifierLens.Height = Constant.MarkableCanvas.MagnifyingGlassDiameter;
            this.magnifierLens.StrokeThickness = 3;

            // fill the lens
            VisualBrush lensFill = new VisualBrush();
            lensFill.ViewboxUnits = BrushMappingMode.Absolute;
            lensFill.Viewbox = new Rect(0, 0, 50, 50);
            lensFill.ViewportUnits = BrushMappingMode.RelativeToBoundingBox;
            lensFill.Viewport = new Rect(0, 0, 1, 1);
            this.magnifierLens.Fill = lensFill;

            // outline the lens
            LinearGradientBrush outlineBrush = new LinearGradientBrush();
            outlineBrush.StartPoint = new Point(0, 0);
            outlineBrush.EndPoint = new Point(0, 1);
            ColorConverter cc = new ColorConverter();
            outlineBrush.GradientStops.Add(new GradientStop((Color)cc.ConvertFrom("#AAA"), 0));
            outlineBrush.GradientStops.Add(new GradientStop((Color)cc.ConvertFrom("#111"), 1));
            this.magnifierLens.Stroke = outlineBrush;
            this.lensCanvas.Children.Add(this.magnifierLens);

            Ellipse lensImage = new Ellipse();
            Canvas.SetLeft(lensImage, 2);
            Canvas.SetTop(lensImage, 2);
            lensImage.StrokeThickness = 4;
            lensImage.Width = Constant.MarkableCanvas.MagnifyingGlassDiameter - 4;
            lensImage.Height = Constant.MarkableCanvas.MagnifyingGlassDiameter - 4;
            this.lensCanvas.Children.Add(lensImage);

            // crosshairs
            Line verticalCrosshair = new Line();
            verticalCrosshair.StrokeThickness = 0.25;
            verticalCrosshair.X1 = 5;
            verticalCrosshair.Y1 = Constant.MarkableCanvas.MagnifyingGlassDiameter / 2;
            verticalCrosshair.X2 = Constant.MarkableCanvas.MagnifyingGlassDiameter - 5;
            verticalCrosshair.Y2 = Constant.MarkableCanvas.MagnifyingGlassDiameter / 2;
            verticalCrosshair.Stroke = Brushes.Black;
            verticalCrosshair.Opacity = 0.5;
            this.lensCanvas.Children.Add(verticalCrosshair);

            Line horizontalCrosshair = new Line();
            horizontalCrosshair.StrokeThickness = 0.25;
            horizontalCrosshair.X1 = Constant.MarkableCanvas.MagnifyingGlassDiameter / 2;
            horizontalCrosshair.Y1 = 5;
            horizontalCrosshair.X2 = Constant.MarkableCanvas.MagnifyingGlassDiameter / 2;
            horizontalCrosshair.Y2 = Constant.MarkableCanvas.MagnifyingGlassDiameter - 5;
            horizontalCrosshair.Stroke = Brushes.Black;
            horizontalCrosshair.Opacity = 0.5;
            this.lensCanvas.Children.Add(horizontalCrosshair);

            // set render transform
            // Rotate the glass before translating it as that ordering means translation calculations don't have to account for rotation.  If this is changed
            // RedrawIfVisible() must be updated.
            this.rotation = new RotateTransform(this.magnifyingGlassAngle, Constant.MarkableCanvas.MagnifyingGlassDiameter, Constant.MarkableCanvas.MagnifyingGlassDiameter);
            this.translation = new TranslateTransform();

            TransformGroup transformGroup = new TransformGroup();
            transformGroup.Children.Add(this.rotation);
            transformGroup.Children.Add(this.translation);
            this.RenderTransform = transformGroup;
        }
        private void SetTitle(string fileName)
        {
            TextBlockTitle.Text = _title = ExtractFileTitle(fileName);

            BrushConverter bc = new BrushConverter();
            ColorConverter cc = new ColorConverter();
            Brush solidNotPosted = (Brush)bc.ConvertFrom("#FFDE0000"), solidPosted = (Brush)bc.ConvertFrom("#FF0BC113");
            LinearGradientBrush gradientPosted = new LinearGradientBrush((Color)cc.ConvertFrom("#FF6EF300"), (Color)cc.ConvertFrom("#FF54B800"), 90);
            LinearGradientBrush gradientNotPosted = new LinearGradientBrush((Color)cc.ConvertFrom("#FFA80000"), Colors.Red, 90);

            EllipseTitle.Fill = fileName.Contains(']') ? gradientPosted : gradientNotPosted;
            //EllipseTitle.Stroke = fileName.Contains(']') ? gradientPosted : gradientNotPosted;
        }
 public void SetValue(string key, string value, CultureInfo cultureInfo)
 {
     try
     {
         var type = Default[key].GetType()
                                .Name;
         switch (type)
         {
             case "Boolean":
                 Default[key] = Boolean.Parse(value);
                 break;
             case "Color":
                 var cc = new ColorConverter();
                 var color = cc.ConvertFrom(value);
                 Default[key] = color ?? Colors.Black;
                 break;
             case "Double":
                 Default[key] = Double.Parse(value, cultureInfo);
                 break;
             case "Font":
                 var fc = new FontConverter();
                 var font = fc.ConvertFromString(value);
                 Default[key] = font ?? new Font(new FontFamily("Microsoft Sans Serif"), 12);
                 break;
             case "Int32":
                 Default[key] = Int32.Parse(value, cultureInfo);
                 break;
             default:
                 Default[key] = value;
                 break;
         }
     }
     catch (Exception ex)
     {
         Logging.Log(LogManager.GetCurrentClassLogger(), "", ex);
     }
     RaisePropertyChanged(key);
 }
        private Color MakeColorFromHex(object sender)
        {
            try
            {
                ColorConverter cc = new ColorConverter();
                return (Color)cc.ConvertFrom(((TextBox)sender).Text);

            }
            catch
            {
                string alphaHex = CustomColor.A.ToString("X").PadLeft(2, '0');
                string redHex = CustomColor.R.ToString("X").PadLeft(2, '0');
                string greenHex = CustomColor.G.ToString("X").PadLeft(2, '0');
                string blueHex = CustomColor.B.ToString("X").PadLeft(2, '0');
                txtAll.Text = String.Format("#{0}{1}{2}{3}",
                alphaHex, redHex,
                greenHex, blueHex);
            }
            return _customColor;
        }
        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);
        }
        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;
        }
Beispiel #23
0
 private Color _parseColor(string input) {
    try {
       var converter = new ColorConverter();
       return (Color)converter.ConvertFrom(input);
    } catch {
       throw new InvalidCastException("Invalid or unknown color '{0}'".Substitute(input));
    }
 }