Ejemplo n.º 1
0
 /*============================= Circle << CTOR ======================*/
 public Circle(SolidColorBrush solColBrush)
 {
     //deep copy mh
     this.solColBrush = solColBrush.Clone();
     //no change mh
     this.solColBrush.Freeze();
 }
Ejemplo n.º 2
0
        private void checkIsFrozenExample()
        {
            // <SnippetCheckIsFrozenExample>

            Button          myButton = new Button();
            SolidColorBrush myBrush  = new SolidColorBrush(Colors.Yellow);

            if (myBrush.CanFreeze)
            {
                // Makes the brush unmodifiable.
                myBrush.Freeze();
            }

            myButton.Background = myBrush;

            if (myBrush.IsFrozen) // Evaluates to true.
            {
                // If the brush is frozen, create a clone and
                // modify the clone.
                SolidColorBrush myBrushClone = myBrush.Clone();
                myBrushClone.Color  = Colors.Red;
                myButton.Background = myBrushClone;
            }
            else
            {
                // If the brush is not frozen,
                // it can be modified directly.
                myBrush.Color = Colors.Red;
            }

            // </SnippetCheckIsFrozenExample>

            myMainPanel.Children.Add(myButton);
        }
Ejemplo n.º 3
0
        private void CloneExample()
        {
            // <SnippetCloneExample>
            Button          myButton = new Button();
            SolidColorBrush myBrush  = new SolidColorBrush(Colors.Yellow);

            // Freezing a Freezable before it provides
            // performance improvements if you don't
            // intend on modifying it.
            if (myBrush.CanFreeze)
            {
                // Makes the brush unmodifiable.
                myBrush.Freeze();
            }

            myButton.Background = myBrush;

            // If you need to modify a frozen brush,
            // the Clone method can be used to
            // create a modifiable copy.
            SolidColorBrush myBrushClone = myBrush.Clone();

            // Changing myBrushClone does not change
            // the color of myButton, because its
            // background is still set by myBrush.
            myBrushClone.Color = Colors.Red;

            // Replacing myBrush with myBrushClone
            // makes the button change to red.
            myButton.Background = myBrushClone;
            // </SnippetCloneExample>

            myMainPanel.Children.Add(myButton);
        }
Ejemplo n.º 4
0
        SolidColorBrush darkerBrush(SolidColorBrush brush0)
        {
            SolidColorBrush brush = brush0.Clone();
            float           r     = brush.Color.ScR / 2;
            float           g     = brush.Color.ScG / 2;
            float           b     = brush.Color.ScB / 2;

            brush.Color = Color.FromScRgb(0.75f, r, g, b);
            return(brush);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reset the <seealso cref="SolidColorBrush"/> to be used for highlighting the current editor line.
        /// </summary>
        /// <param name="newValue"></param>
        private void AdjustCurrentLineBackground(SolidColorBrush newValue)
        {
            if (newValue != null)
            {
                this.textEditor.TextArea.TextView.BackgroundRenderers.Clear();

                this.textEditor.TextArea.TextView.BackgroundRenderers.Add(
                    new HighlightCurrentLineBackgroundRenderer(this.textEditor, newValue.Clone()));
            }
        }
Ejemplo n.º 6
0
        private void BackgroundAnim(Label btc, SolidColorBrush color)
        {
            ColorAnimation animation = new ColorAnimation();

            animation.From     = color.Color;
            animation.To       = Colors.Transparent;
            animation.Duration = animduration;

            btc.Background = color.Clone();
            btc.Background.BeginAnimation(SolidColorBrush.ColorProperty, animation);
        }
Ejemplo n.º 7
0
 protected override void OnInitialized(EventArgs e)
 {
     base.OnInitialized(e);
     for (int index = 0; index < 10; index++)
     {
         Ellipse ellipse = new Ellipse
         {
             Fill = DefaultBrush.Clone()
         };
         MainGrid.Children.Add(ellipse);
         System.Windows.Controls.Grid.SetRow(ellipse, index);
         System.Windows.Controls.Grid.SetColumn(ellipse, 1);
         ellipse.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
         ellipse.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
         ellipse.Width  = 28;
         ellipse.Height = 28;
         Grid.SetRow(this, index);
         circles[index] = ellipse;
     }
 }
Ejemplo n.º 8
0
        private void ColorChanged()
        {
            Color c = Color.FromArgb(a, r, g, b);

            if (Check_UIA.IsChecked == true || Check_UIB.IsChecked == true)
            {
                LinearGradientBrush br    = Application.Current.TryFindResource("MainColorBrush") as LinearGradientBrush;
                LinearGradientBrush brush = br.Clone();
                bool i = true;
                foreach (GradientStop gs in brush.GradientStops)
                {
                    if (Check_UIA.IsChecked == true)
                    {
                        if (i)
                        {
                            gs.Color = c;
                        }
                    }
                    else if (Check_UIB.IsChecked == true)
                    {
                        if (!i)
                        {
                            gs.Color = c;
                        }
                    }
                    i = !i;
                }
                Application.Current.Resources.Remove("MainColorBrush");
                Application.Current.Resources.Add("MainColorBrush", brush);
            }
            else
            {
                string box;
                if (Check_STOCKLIST.IsChecked == true)
                {
                    box = "CanvasColor";
                }
                else if (Check_STOCKUI.IsChecked == true)
                {
                    box = "BoxColor";
                }
                else
                {
                    return;
                }
                SolidColorBrush br    = Application.Current.TryFindResource(box) as SolidColorBrush;
                SolidColorBrush brush = br.Clone();
                brush.Color = c;
                Application.Current.Resources.Remove(box);
                Application.Current.Resources.Add(box, brush);
            }
        }
Ejemplo n.º 9
0
 public virtual void SetDefaultFill()
 {
     Fill = new SolidColorBrush(FillColor);
     if (Fill.IsFrozen)
     {
         var myFill = Fill.Clone();
         myFill.Opacity = FillOpacity;
         Fill           = myFill;
     }
     else
     {
         Fill.Opacity = FillOpacity;
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Re-define an existing <seealso cref="SolidColorBrush"/> and backup the originial color
        /// as it was before the application of the custom coloring.
        /// </summary>
        /// <param name="resourceName"></param>
        /// <param name="newColor"></param>
        /// <param name="backupDynResources"></param>
        private void ApplyToDynamicResource(string resourceName,
                                            SolidColorBrush newColor,
                                            List <string> backupDynResources)
        {
            if (Application.Current.Resources[resourceName] != null && newColor != null)
            {
                // Re-coloring works with SolidColorBrushs linked as DynamicResource
                if (Application.Current.Resources[resourceName] is SolidColorBrush)
                {
                    backupDynResources.Add(resourceName);

                    Application.Current.Resources[resourceName] = newColor.Clone();
                }
            }
        }
Ejemplo n.º 11
0
        public static SolidColorBrush SetIdentity(
            [NotNull] this SolidColorBrush @this,
            [CanBeNull] MaterialIdentity materialIdentity)
        {
            @this.IsNotNull(nameof(@this));

            if ((@this.CanFreeze && @this.IsFrozen) || @this.IsSealed)
            {
                //@this.Changed += (s, args) =>
                //{

                //};
                var cloned = @this.Clone();

                cloned.SetValue(
                    MDH.IdentityProperty,
                    materialIdentity);

                cloned.Freeze();

                return(cloned);
            }
            else
            {
                //@this.Changed += (s, args) =>
                //{

                //};

                var existingIdentity = @this.GetIdentity();
                if (existingIdentity != null)
                {
                    if (!existingIdentity.Equals(materialIdentity))
                    {
                    }
                }
                @this.SetValue(
                    MDH.IdentityProperty,
                    materialIdentity);

                if (@this.CanFreeze)
                {
                    @this.Freeze();
                }

                return(@this);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Re-define an existing <seealso cref="SolidColorBrush"/> and backup the originial color
        /// as it was before the application of the custom coloring.
        /// </summary>
        /// <param name="ResourceName"></param>
        /// <param name="NewColor"></param>
        /// <param name="backupDynResources"></param>
        private void ApplyToDynamicResource(string ResourceName,
                                            SolidColorBrush NewColor,
                                            List <string> backupDynResources)
        {
            if (Application.Current.Resources[ResourceName] != null && NewColor != null)
            {
                // Re-coloring works with SolidColorBrushs linked as DynamicResource
                if (Application.Current.Resources[ResourceName] is SolidColorBrush)
                {
                    var oldBrush = Application.Current.Resources[ResourceName] as SolidColorBrush;
                    backupDynResources.Add(ResourceName);

                    Application.Current.Resources[ResourceName] = NewColor.Clone();
                }
            }
        }
Ejemplo n.º 13
0
        private void MaterialCard_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (WaveFeedback)
            {
                double radius = Math.Max(ActualHeight, ActualWidth) * 2;
                ellipse2SizeAnim.To = radius;
                Point p = e.GetPosition((IInputElement)sender);
                fixAnim.To = new Thickness(-radius / 2, -radius / 2, 0, 0);
                Color c = new Color();
                if (Background is SolidColorBrush)
                {
                    c = (Background as SolidColorBrush).Color;

                    SolidColorBrush background = (Background as SolidColorBrush);
                    originBrush = background.Clone();
                    Color c3 = originBrush.Color;
                    Color c2 = Color.FromArgb(255, (byte)(c.R * 0.96), (byte)(c.G * 0.96), (byte)(c.B * 0.96));
                    backgroundAnimUsingKey.KeyFrames.Clear();
                    backgroundAnimUsingKey.KeyFrames.Add(new EasingColorKeyFrame(c2)
                    {
                        EasingFunction = easeFunction
                    });
                    backgroundAnimUsingKey.KeyFrames.Add(new EasingColorKeyFrame(c)
                    {
                        EasingFunction = easeFunction
                    });
                    background = new SolidColorBrush(Color.FromArgb(c3.A, c3.R, c3.G, c3.B));//防冻结
                    background.BeginAnimation(SolidColorBrush.ColorProperty, backgroundAnimUsingKey);
                }
                else if (BorderBrush is SolidColorBrush)
                {
                    c = (BorderBrush as SolidColorBrush).Color;
                }

                ellipse2.Fill = new SolidColorBrush(new Color()
                {
                    A = (byte)(Math.Min(((byte)1.2 * c.A), 255) + 40), R = (byte)(c.R * 0.8), B = (byte)(c.B * 0.8), G = (byte)(c.G * 0.8)
                });

                ellipse2.RenderTransform = new TranslateTransform(p.X, p.Y);
                ellipse2.BeginAnimation(WidthProperty, ellipse2SizeAnim);
                ellipse2.BeginAnimation(HeightProperty, ellipse2SizeAnim);
                ellipse2.BeginAnimation(OpacityProperty, ellipse2OpacityAnim);
                ellipse2.BeginAnimation(MarginProperty, fixAnim);
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SolidColorBrush brush = GetBrush(value as string);

            if (targetType == typeof(Color))
            {
                return(brush.Color);
            }

            if (parameter is double opacity)
            {
                brush         = brush.Clone();
                brush.Opacity = opacity;
            }

            return(brush);
        }
Ejemplo n.º 15
0
        // Vẽ tự do
        private void freeDrawing(MouseEventArgs e)
        {
            Line line = new Line();

            var newBrush = myBrush.Clone();

            line.Stroke          = newBrush;
            line.X1              = currentPoint.X;
            line.Y1              = currentPoint.Y;
            line.X2              = e.GetPosition(paintCanvas).X;
            line.Y2              = e.GetPosition(paintCanvas).Y;
            line.StrokeThickness = size;
            paintCanvas.Children.Add(line);
            currentPoint = e.GetPosition(paintCanvas);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BrushPicker"/> class.
 /// The class allows for the selection of a solid color brush and setting its opacity.
 /// </summary>
 /// <param name="inputBrush">The input brush.</param>
 public BrushPicker(Brush inputBrush)
 {
     InitializeComponent();
     PropertyInfo[] properties = typeof(Brushes).GetProperties();
     foreach (PropertyInfo property in properties)
     {
         if (property.PropertyType == typeof(SolidColorBrush))
         {
             var       propVal = (SolidColorBrush)(property.GetValue(null, null));
             TextBlock item    = new TextBlock()
             {
                 FontStyle  = FontStyles.Italic,
                 Text       = property.Name,
                 Background = propVal
             };
             this._brushes.Items.Add(item);
             if (inputBrush != null)
             {
                 if (propVal.Color == ((SolidColorBrush)inputBrush).Color)
                 {
                     this._brushes.SelectedItem = item;
                 }
             }
         }
     }
     this.Loaded += new RoutedEventHandler(BrushPicker_Loaded);
     this._brushes.DropDownClosed += new EventHandler(_brushes_DropDownClosed);
     this._opacity.ValueChanged   += new RoutedPropertyChangedEventHandler <double>(_opacity_ValueChanged);
     if (inputBrush != null)
     {
         SolidColorBrush brsh = (SolidColorBrush)inputBrush;
         if (brsh != null)
         {
             this._Brush           = brsh.Clone();
             this.Rect_.Fill       = this._Brush;
             this._opacity.Value   = (1 - this._Brush.Opacity) * this._opacity.Maximum;
             this.Description.Text = string.Format("Opacity: {0}", (1 - this._opacity.Value / this._opacity.Maximum).ToString());
         }
     }
     this.KeyDown += new KeyEventHandler(BrushPicker_KeyDown);
     this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
 }
Ejemplo n.º 17
0
        public void ChangeIconColor(Color color)
        {
            Brush colorBrush = new SolidColorBrush(color);

            iconAttach.Foreground  = colorBrush;
            iconSend.Foreground    = colorBrush;
            iconImage.Foreground   = colorBrush;
            iconBuzz.Foreground    = colorBrush;
            iconSticker.Foreground = colorBrush;
            ChatTitle.Foreground   = colorBrush;
            iconColor.Foreground   = colorBrush;

            foreach (var item in spMessagesContainer.Children)
            {
                if (!(item is BubbleChat))
                {
                    continue;
                }
                (item as BubbleChat).NickName.Foreground = colorBrush;
            }

            LastActive.Foreground         = colorBrush.Clone();
            LastActive.Foreground.Opacity = 0.6;
        }
Ejemplo n.º 18
0
        private void SetHighlightCurrentLineBackground(SolidColorBrush brush)
        {
            try
            {
                var oldRenderer = null as HighlightCurrentLineBackgroundRenderer;

                foreach (var item in this.TextArea.TextView.BackgroundRenderers)
                {
                    if (item != null && item is HighlightCurrentLineBackgroundRenderer)
                    {
                        oldRenderer = item as HighlightCurrentLineBackgroundRenderer;
                    }
                }

                this.TextArea.TextView.BackgroundRenderers.Remove(oldRenderer);

                if (this._currentLineRenderer != null)
                {
                    if (this.TextArea.TextView.BackgroundRenderers.Contains(this._currentLineRenderer))
                    {
                        this.TextArea.TextView.BackgroundRenderers.Remove(this._currentLineRenderer);
                    }
                    this._currentLineRenderer = null;
                }

                this._currentLineRenderer = new HighlightCurrentLineBackgroundRenderer(this, brush.Clone());
                this.TextArea.TextView.BackgroundRenderers.Add(this._currentLineRenderer);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Ejemplo n.º 19
0
        // --------------------------------------------------------------

        public SolidColorBrush Clone()
        {
            return(brush.Clone());
        }
Ejemplo n.º 20
0
        public CircleSprite(SolidColorBrush solidColorBursh)
        {
            this.solidColorBursh = solidColorBursh.Clone();

            this.solidColorBursh.Freeze();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Constructor! Hurrah!
        /// </summary>
        /// <param name="feeditem"></param>
        public FeedWin(FeedConfigItem feeditem)
        {
            Log.Debug("Constructing feedwin. GUID:{0} URL: {1}", feeditem.Guid, feeditem.Url);
            InitializeComponent();

            fci   = feeditem;
            Width = fci.Width;
            Left  = fci.Position.X;
            Top   = fci.Position.Y;
            //Kick of thread to figure out what sort of plugin to load for this sort of feed.
            ThreadPool.QueueUserWorkItem(state => GetFeedType(fci));

            //Set up the animations for the mouseovers
            fadein = new ColorAnimation {
                AutoReverse = false, From = fci.DefaultColor, To = fci.HoverColor, Duration = new Duration(TimeSpan.FromMilliseconds(200)), RepeatBehavior = new RepeatBehavior(1)
            };
            fadeout = new ColorAnimation {
                AutoReverse = false, To = fci.DefaultColor, From = fci.HoverColor, Duration = new Duration(TimeSpan.FromMilliseconds(200)), RepeatBehavior = new RepeatBehavior(1)
            };

            textbrush = new SolidColorBrush(feeditem.DefaultColor);

            //Add the right number of textblocks to the form, depending on what the user asked for.
            for (var ii = 0; ii < fci.DisplayedItems; ii++)
            {
                maingrid.RowDefinitions.Add(new RowDefinition());
                var textblock = new TextBlock
                {
                    Style        = (Style)FindResource("linkTextStyle"),
                    Name         = string.Format("TextBlock{0}", ii + 1),
                    TextTrimming = TextTrimming.CharacterEllipsis,
                    Foreground   = textbrush.Clone(),
                    Background   = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)),
                    FontFamily   = fci.FontFamily,
                    FontSize     = fci.FontSize,
                    FontStyle    = fci.FontStyle,
                    FontWeight   = fci.FontWeight,
                    Visibility   = Visibility.Collapsed
                };


                textblock.SetValue(Grid.ColumnSpanProperty, 2);
                RegisterName(textblock.Name, textblock);
                maingrid.Children.Add(textblock);
                Grid.SetRow(textblock, ii + 1);
            }


            maingrid.RowDefinitions.Add(new RowDefinition());
            movehandle       = new Image();
            movehandle.Width = movehandle.Height = 16;
            movehandle.Name  = "movehandle";

            movehandle.HorizontalAlignment = HorizontalAlignment.Left;

            movehandle.Cursor = Cursors.SizeAll;
            movehandle.Source = new BitmapImage(new Uri("/Feedling;component/Resources/move-icon.png", UriKind.Relative));
            movehandle.SetValue(Grid.ColumnSpanProperty, 2);
            RegisterName(movehandle.Name, movehandle);
            maingrid.Children.Add(movehandle);
            movehandle.MouseDown += movehandle_MouseDown;
            movehandle.Visibility = Visibility.Collapsed;
            Grid.SetRow(movehandle, maingrid.RowDefinitions.Count);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Thread-safe window drawing method. Decides basically what colour everything should be, depending on the state of the window (selected, pinned etc.)
        /// Also sets the text of the textblocks to either the feed items, some sort of error, or random mumblings from Hamlet.
        /// </summary>
        internal void RedrawWin()
        {
            if (Dispatcher.Thread != Thread.CurrentThread)
            {
                RedrawWinCallback d = RedrawWin;
                Dispatcher.Invoke(d, null);
            }
            else
            {
                if (selected)
                {
                    Background = new SolidColorBrush(Colors.White);
                    textbrush  = new SolidColorBrush(Colors.Black);
                    fadein.To  = fadein.From = Colors.Black;
                    fadeout.To = fadeout.From = Colors.Black;
                }
                else
                {
                    Background            = new SolidColorBrush(Colors.Transparent);
                    textbrush             = new SolidColorBrush(fci.DefaultColor);
                    fadein.To             = fadeout.From = fci.HoverColor;
                    fadeout.To            = fadein.From = fci.DefaultColor;
                    movehandle.Visibility = !pinned ? Visibility.Visible : Visibility.Collapsed;
                }

                //Set textblock styling
                titleTextBlock.FontFamily = fci.TitleFontFamily;
                titleTextBlock.FontSize   = fci.TitleFontSize;
                titleTextBlock.FontStyle  = fci.TitleFontStyle;
                titleTextBlock.FontWeight = fci.TitleFontWeight;
                titleTextBlock.Foreground = textbrush.Clone();
                for (var n = 1; n <= fci.DisplayedItems; n++)
                {
                    var textblock = ((TextBlock)FindName(string.Format("TextBlock{0}", n)));
                    if (textblock == null)
                    {
                        continue;
                    }
                    textblock.Foreground = textbrush.Clone();
                    textblock.FontFamily = fci.FontFamily;
                    textblock.FontSize   = fci.FontSize;
                    textblock.FontWeight = fci.FontWeight;
                    textblock.FontStyle  = fci.FontStyle;
                }

                //Figure out what to display
                if (rssfeed != null && rssfeed.Loaded)
                {
                    if (rssfeed.HasError)
                    {
                        Log.Debug("Feed has error, so setting title error: {0}", rssfeed.ErrorMessage);
                        //Error has been discovered loading this feed.
                        titleTextBlock.Text = "Error";
                        var leadingtextblock = ((TextBlock)FindName("TextBlock1"));
                        if (leadingtextblock != null)
                        {
                            leadingtextblock.Text       = string.IsNullOrEmpty(rssfeed.ErrorMessage) ? "No error message was given" : rssfeed.ErrorMessage;
                            leadingtextblock.Visibility = Visibility.Visible;
                        }
                        for (var n = 2; n <= fci.DisplayedItems; n++)
                        {
                            var textblock = ((TextBlock)FindName(string.Format("TextBlock{0}", n)));
                            if (textblock == null)
                            {
                                continue;
                            }
                            textblock.Text       = "";
                            textblock.Tag        = null;
                            textblock.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        Log.Debug("No error, get on with the headlines for: {0}", rssfeed.Title);
                        //No error, get one with putting the headlines out.
                        titleTextBlock.Text = rssfeed.Title;
                        titleTextBlock.Tag  = rssfeed.FeedUri;
                        for (var n = 1; n <= fci.DisplayedItems; n++)
                        {
                            var textblock = ((TextBlock)FindName(string.Format("TextBlock{0}", n)));
                            if (textblock == null)
                            {
                                continue;
                            }
                            if (rssfeed.FeedItems.Count >= n)
                            {
                                textblock.Text       = rssfeed.FeedItems[n - 1].Title;
                                textblock.Tag        = rssfeed.FeedItems[n - 1].Link;
                                textblock.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                textblock.Text       = "";
                                textblock.Tag        = null;
                                textblock.Visibility = Visibility.Collapsed;
                            }
                        }
                    }
                }
                else if (rssfeed != null && !rssfeed.Loaded)
                {
                    //Still fetching the feed. Let the user know.
                    titleTextBlock.Text = "Fetching...";
                    var textblock = ((TextBlock)FindName("TextBlock1"));
                    if (textblock != null)
                    {
                        textblock.Text       = fci.Url;
                        textblock.Visibility = Visibility.Visible;
                    }
                }
                else if (rssfeed == null)
                {
                    titleTextBlock.Text = errormsg;
                    var textblock = ((TextBlock)FindName("TextBlock1"));
                    if (textblock != null)
                    {
                        textblock.Text       = fci.Url;
                        textblock.Visibility = Visibility.Visible;
                    }
                }
                InvalidateVisual();
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Reset the <seealso cref="SolidColorBrush"/> to be used for highlighting the current editor line.
        /// </summary>
        /// <param name="newValue"></param>
        private void AdjustCurrentLineBackground(SolidColorBrush newValue)
        {
            if (newValue != null)
            {
                HighlightCurrentLineBackgroundRenderer oldRenderer = null;

                // Make sure there is only one of this type of background renderer
                // Otherwise, we might keep adding and WPF keeps drawing them on top of each other
                foreach (var item in this.TextArea.TextView.BackgroundRenderers)
                {
                    if (item != null)
                    {
                        if (item is HighlightCurrentLineBackgroundRenderer)
                        {
                            oldRenderer = item as HighlightCurrentLineBackgroundRenderer;
                        }
                    }
                }

                this.TextArea.TextView.BackgroundRenderers.Remove(oldRenderer);

                this.TextArea.TextView.BackgroundRenderers.Add(new HighlightCurrentLineBackgroundRenderer(this, newValue.Clone()));

                // Remove reference to old background renderer instance (if any) and construct BracketRenderer from scratch
                if (this.mBracketRenderer != null)
                {
                    this.TextArea.TextView.BackgroundRenderers.Remove(this.mBracketRenderer);
                    this.mBracketRenderer = null;
                }

                this.mBracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView);
                this.TextArea.TextView.BackgroundRenderers.Add(this.mBracketRenderer);
            }
        }
        private static void ApplyThemeInternal(this FrameworkElement control, Theme?theme, SolidColorBrush accentBrush, SolidColorBrush contrastBrush)
        {
            ValidationHelper.NotNull(control, () => control);

            // Resource dictionaries paths
            var lightBrushesUri = new Uri("/Elysium;component/Themes/LightBrushes.xaml", UriKind.Relative);
            var darkBrushesUri  = new Uri("/Elysium;component/Themes/DarkBrushes.xaml", UriKind.Relative);

            // Resource dictionaries
            var lightBrushesDictionary = new ResourceDictionary {
                Source = lightBrushesUri
            };
            var darkBrushesDictionary = new ResourceDictionary {
                Source = darkBrushesUri
            };

            if (theme == Theme.Light)
            {
                // Add LightBrushes.xaml, if not included
                if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != lightBrushesUri))
                {
                    control.Resources.MergedDictionaries.Add(lightBrushesDictionary);
                }

                // Remove DarkBrushes.xaml, if included
                var darkColorsDictionaries = control.Resources.MergedDictionaries.Where(dictionary => dictionary.Source == darkBrushesUri).ToList();
                foreach (var dictionary in darkColorsDictionaries)
                {
                    control.Resources.MergedDictionaries.Remove(dictionary);
                }
            }
            if (theme == Theme.Dark)
            {
                // Add DarkBrushes.xaml, if not included
                if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != darkBrushesUri))
                {
                    control.Resources.MergedDictionaries.Add(darkBrushesDictionary);
                }

                // Remove LightBrushes.xaml, if included
                var lightColorsDictionaries = control.Resources.MergedDictionaries.Where(dictionary => dictionary.Source == lightBrushesUri).ToList();
                foreach (var dictionary in lightColorsDictionaries)
                {
                    control.Resources.MergedDictionaries.Remove(dictionary);
                }
            }

            // Bug in WPF 4: http://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references
            if (control.Resources.Keys.Count == 0)
            {
                control.Resources.Add(typeof(Window), new Style(typeof(Window)));
            }

            if (accentBrush != null)
            {
                var accentBrushFrozen = !accentBrush.IsFrozen && accentBrush.CanFreeze ? accentBrush.GetAsFrozen() : accentBrush;
                if (control.Resources.Contains("AccentBrush"))
                {
                    // Set AccentBrush value, if key exist
                    control.Resources["AccentBrush"] = accentBrushFrozen;
                }
                else
                {
                    // Add AccentBrush key and value, if key doesn't exist
                    control.Resources.Add("AccentBrush", accentBrushFrozen);
                }
            }

            if (contrastBrush != null)
            {
                var contrastBrushFrozen = !contrastBrush.IsFrozen && contrastBrush.CanFreeze ? contrastBrush.GetAsFrozen() : contrastBrush;
                if (control.Resources.Contains("ContrastBrush"))
                {
                    // Set ContrastBrush value, if key exist
                    control.Resources["ContrastBrush"] = contrastBrushFrozen;
                }
                else
                {
                    // Add ContrastBrush key and value, if key doesn't exist
                    control.Resources.Add("ContrastBrush", contrastBrushFrozen);
                }

                var semitransparentContrastBrush = contrastBrush.Clone();
                semitransparentContrastBrush.Opacity = 1d / 8d;
                var semitransparentContrastBrushFrozen = !semitransparentContrastBrush.IsFrozen && semitransparentContrastBrush.CanFreeze
                                                             ? semitransparentContrastBrush.GetAsFrozen()
                                                             : semitransparentContrastBrush;
                if (control.Resources.Contains("SemitransparentContrastBrush"))
                {
                    // Set SemitransparentContrastBrush value, if key exist
                    control.Resources["SemitransparentContrastBrush"] = semitransparentContrastBrushFrozen;
                }
                else
                {
                    // Add SemitransparentContrastBrush key and value, if key doesn't exist
                    control.Resources.Add("SemitransparentContrastBrush", semitransparentContrastBrushFrozen);
                }
            }

            // Add Generic.xaml, if not included
            var genericDictionaryUri = new Uri("/Elysium;component/Themes/Generic.xaml", UriKind.Relative);

            if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != genericDictionaryUri))
            {
                control.Resources.MergedDictionaries.Add(new ResourceDictionary {
                    Source = genericDictionaryUri
                });
            }

            OnThemeChanged();
        }
Ejemplo n.º 25
0
        public Action SetTagReader(string key, Delegate tagChanged)
        {
            switch (key)
            {
            case TagActions.ALARM:
                var _funcAlarm = tagChanged as Func <bool>;
                if (_funcAlarm != null)
                {
                    if (animation == null)
                    {
                        brush = Background as SolidColorBrush;
                        if (brush != null)
                        {
                            brush     = brush.Clone();
                            animation = new ColorAnimationUsingKeyFrames
                            {
                                KeyFrames = new ColorKeyFrameCollection
                                {
                                    new DiscreteColorKeyFrame(brush.Color, TimeSpan.FromSeconds(0.0)),
                                    new DiscreteColorKeyFrame(Colors.Red, TimeSpan.FromSeconds(0.5)),
                                    new DiscreteColorKeyFrame(brush.Color, TimeSpan.FromSeconds(1))
                                },
                                AutoReverse    = true,
                                RepeatBehavior = RepeatBehavior.Forever
                            };
                        }
                    }
                    return(delegate
                    {
                        if (brush != null)
                        {
                            if (_funcAlarm())
                            {
                                brush.BeginAnimation(SolidColorBrush.ColorProperty, animation);
                                Background = brush;
                            }
                            else
                            {
                                brush.BeginAnimation(SolidColorBrush.ColorProperty, null);
                                Background = brush;
                            }
                        }
                    });
                }
                else
                {
                    return(null);
                }

            case TagActions.VISIBLE:
                var _funcVisible = tagChanged as Func <bool>;
                if (_funcVisible != null)
                {
                    return(delegate
                    {
                        this.Visibility = _funcVisible() ? Visibility.Visible : Visibility.Hidden;
                    });
                }
                else
                {
                    return(null);
                }

            case TagActions.CAPTION:
                var _funcCaption = tagChanged as Func <string>;
                if (_funcCaption != null)
                {
                    return(delegate { this.Content = _funcCaption(); });
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
Ejemplo n.º 26
0
        internal static void ApplyCore(ResourceDictionary resources, Theme?theme, SolidColorBrush accentBrush, SolidColorBrush contrastBrush)
        {
            ValidationHelper.NotNull(resources, "resources");

            // Resource dictionaries
            var genericDictionary = new ResourceDictionary {
                Source = GenericDictionaryUri
            };
            var brushesDictionary = new ResourceDictionary {
                Source = BrushesDictionaryUri
            };
            var lightBrushesDictionary = new ResourceDictionary {
                Source = LightBrushesDictionaryUri
            };
            var darkBrushesDictionary = new ResourceDictionary {
                Source = DarkBrushesDictionaryUri
            };

            // Switch theme
            switch (theme)
            {
            case null:
                RemoveDictionaries(genericDictionary, LightBrushesDictionaryUri);
                RemoveDictionaries(genericDictionary, DarkBrushesDictionaryUri);
                break;

            case Theme.Light:
                ReplaceDictionary(genericDictionary, lightBrushesDictionary, LightBrushesDictionaryUri);
                RemoveDictionaries(genericDictionary, DarkBrushesDictionaryUri);
                break;

            case Theme.Dark:
                ReplaceDictionary(genericDictionary, darkBrushesDictionary, DarkBrushesDictionaryUri);
                RemoveDictionaries(genericDictionary, LightBrushesDictionaryUri);
                break;
            }

            if (accentBrush != null)
            {
                // Must be frozen
                var accentBrushFrozen = FreezableExtensions.TryFreeze(accentBrush);
                brushesDictionary.SafeSet("AccentBrush", accentBrushFrozen);
            }
            else
            {
                brushesDictionary.SafeRemove("AccentBrush");
            }

            if (contrastBrush != null)
            {
                // Must be frozen
                var contrastBrushFrozen = FreezableExtensions.TryFreeze(contrastBrush);
                brushesDictionary.SafeSet("ContrastBrush", contrastBrushFrozen);

                // Must be frozen
                var semitransparentContrastBrush = contrastBrush.Clone();

                // NOTE: Lack of contracts: Clone() must ensure non-null return value
                Contract.Assume(semitransparentContrastBrush != null);
                semitransparentContrastBrush.Opacity = 1d / 8d;
                var semitransparentContrastBrushFrozen = FreezableExtensions.TryFreeze(semitransparentContrastBrush);
                brushesDictionary.SafeSet("SemitransparentContrastBrush", semitransparentContrastBrushFrozen);
            }
            else
            {
                brushesDictionary.SafeRemove("ContrastBrush");
                brushesDictionary.SafeRemove("SemitransparentContrastBrush");
            }

            // Bug in WPF 4: http://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references
            if (resources.Keys.Count == 0)
            {
                resources.Add(typeof(Window), new Style(typeof(Window)));
            }

            // Replace Brushes.xaml
            ReplaceDictionary(genericDictionary, brushesDictionary, BrushesDictionaryUri);

            // Replace Generic.xaml
            ReplaceDictionary(resources, genericDictionary, GenericDictionaryUri);

            OnThemeChanged();
        }