상속: DependencyObject, IBrush
예제 #1
0
 // Implement IDateToBrushConverter.
 // This method is used to change Forground & Background color of CalendarItem
 public Brush Convert(DateTime dateTime, bool isSelected, Brush defaultValue, BrushType brushType)
 {
     if (brushType == BrushType.Background)
     {
         if (CalDates != null && CalDates.Where(one => one.CalendarItemDate.Date == dateTime.Date).Any() && !isSelected)
         {
             return new SolidColorBrush(Colors.Blue);
         }
         else
         {
             return defaultValue;
         }
     }
     else
     {
         if (CalDates != null && CalDates.Where(one => one.CalendarItemDate.Date == dateTime.Date).Any() && !isSelected)
         {
             return new SolidColorBrush(Colors.Red);
         }
         else
         {
             return defaultValue;
         }
     }
 }
 public Series(Grid container, double margin, DataItemCollection dataItem,Brush palette)
 {
     this._container = container;
     this._ItemSource = dataItem;
     this.margin = margin;
     this._palette = palette;
 }
 public LogMessage(string title, string description = null, bool isError = false)
 {
     TimeStamp = DateTime.Now;
     Title = title;
     Description = description;
     Foreground = new SolidColorBrush(isError ? Colors.Red : Colors.White);
 }
예제 #4
0
        public static void SetHeaderForeground(DependencyObject obj, Brush value)
        {
            if (obj == null)
                throw new ArgumentNullException(nameof(obj));

            obj.SetValue(HeaderForegroundProperty, value);
        }
예제 #5
0
 public CellColor(Brush fill, Brush group, Brush star)
 {
     FillColor = fill;
     GroupColor = group;
     StarColor = star;
     BorderColor = star;
 }
        /// <summary>
        /// Create an InventariumFlyout.
        /// </summary>
        /// <param name="foreground">The color of Text and Border, NOTE: the BackButton color binds to the ApplicationTextBrush, so it's best to stick to that too.</param>
        /// <param name="background">Color of Background.</param>
        /// <param name="title">Header/Title</param>
        /// <param name="dimension">Width -> Narrow of Wide</param>
        /// <param name="url">url to open in browser.</param>
        /// <param name="image">optional: display an image next to the header</param>
        public InventariumFlyout(
            Brush foreground,
            Brush background,
            string title,
            FlyoutDimension dimension,
            string url,
            BitmapImage image = null)
        {
            this.InitializeComponent();
            this.Dimension = dimension;
            //to handle app activation -> close
            Window.Current.Activated += OnWindowActivated;
            //prepare the frame
            mainBorder.Width = (int)dimension;
            mainBorder.Height = Window.Current.Bounds.Height;
            //fill in the content
            flyoutTitle.Text = title;
            //contentPanel.Children.Add(content);
            smallImage.Source = image;
            //brush the controls according to the parameters
            mainBorder.BorderBrush = foreground;
            flyoutTitle.Foreground = foreground;
            mainFrame.Background = background;

            progressRing.IsActive = true;
            webView.LoadCompleted += OnWebViewOnLoadCompleted;

            webView.Navigate(new Uri(url));
        }
예제 #7
0
        public async static void Show(string message, string title, Brush foregroundTextBrush, Brush countdownBackgroundBrush, double timeToLive, bool autoHide = false, double width = 300, double height = 180,  string metroIcon = "", string imageIcon = "", double scaleIcon = 1)
        {

            if (NotificationService._rootControl != null && message != null)
            {
                DispatchedHandler invokedHandler = new DispatchedHandler(() =>
                {
                    if (NotificationService._rootControl == null) //|| MsgBoxService._rootControl.Visibility == Visibility.Visible)
                    {
                        return;
                    }
                    NotificationService._rootControl.Visibility = Visibility.Visible;
                    NotificationView view = new NotificationView(message, "", autoHide, timeToLive, metroIcon, imageIcon: imageIcon, scaleIcon: scaleIcon);
                    view.Width = width;
                    view.Height = height;
                    view.Margin = new Thickness(3);
                    //view.HorizontalAlignment = horizontalAlignment;
                    //view.VerticalAlignment = VerticalAlignment.Top;
                    
                    view.MessageTextForegroundColor = foregroundTextBrush;
                    view.CountdownBackgroundColor = countdownBackgroundBrush;
                    view.Show();
                    view.OnClosing += new EventHandler(NotificationService.view_OnClosing);

                    NotificationService._MsgboxContainer.Children.Insert(0, view);
                    
                });
                await NotificationService._rootControl.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, invokedHandler);
            }
        }
        public static void SetHighlightBrush(DependencyObject sender, Brush highlightBrush) {
            if (sender == null) {
                return;
            }

            sender.SetValue(HighlightBrushProperty, highlightBrush);
        }
        public static void EnqueueItem(UIElement content, Action<bool> submitAction, Brush bgBrush, bool tappable, TimeSpan timeout, bool showCloseButton)
        {
            if (_lastUsedInstance == null)
                return;

            _lastUsedInstance._notificationQueue.Enqueue(new NotificationItem(content, bgBrush, submitAction, tappable, timeout, showCloseButton));
            _lastUsedInstance.TryDequeue();
        }
예제 #10
0
 public NavigationItem(string id, Symbol symbol, string caption, IEnumerable<NavigationItem> subItems, Brush color = null, Brush background = null) : this(id, symbol, caption, color)
 {
     this.SubItems = subItems;
     if (background != null)
     {
         this.Background = background;
     }
 }
예제 #11
0
 public NavigationItem(string id, Symbol symbol, string caption, Action<NavigationItem> onClick = null, Brush color = null, Brush background = null) : this(id, symbol, caption, color)
 {
     this.OnClick = onClick;
     if (background != null)
     {
         this.Background = background;
     }
 }
예제 #12
0
 public NavigationItem(string id, string glyph, string caption, IEnumerable<NavigationItem> subItems, Brush background = null) : this(id, glyph, caption)
 {
     this.SubItems = subItems;
     if (background != null)
     {
         this.Background = background;
     }
 }
예제 #13
0
 public NavigationItem(string id, string glyph, string caption, Action<NavigationItem> onClick, Brush background = null) : this(id, glyph, caption)
 {
     this.OnClick = onClick;
     if (background != null)
     {
         this.Background = background;
     }
 }
		public ChartControl()
		{
			this.DataPointCount = DefaultDatapoints;

			this.chartColor = new SolidColorBrush(Windows.UI.Color.FromArgb(0xFF, 0xDD, 0xFF, 0xDD));

			DrawBackground();
		}
예제 #15
0
        public TextBoxCueBanner()
        {
            this.DefaultStyleKey = typeof(TextBox);

            CueBannerState = true;
            CueBannerActiveBrush = this.BorderBrush;
            CueBannerInactiveBrush = this.Foreground;
        }
예제 #16
0
		public void DrawEllipse (Rect frame, Pen pen = null, Brush brush = null)
		{
			var ch = GetChild (ChildType.Ellipse);
			var s = (Shapes.Rectangle)ch.Shape;
			s.Width = frame.Width;
			s.Height = frame.Height;
			FormatShape (s, pen, brush);
		}
예제 #17
0
        public Overlay(Image imageControl, Rect rect)
        {
            _Parent = (Grid)imageControl.Parent;
            _Rectangle = rect;

            _Transparent = new SolidColorBrush(Colors.Transparent);
            _Red = new SolidColorBrush(Colors.Red);
        }
예제 #18
0
        protected override void OnElementChanged(ElementChangedEventArgs <Slider> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    var slider = new FormsSlider();
                    SetNativeControl(slider);

                    slider.Ready += (sender, args) =>
                    {
                        UpdateThumbColor();
                        UpdateThumbImage();
                    };

                    Control.Minimum = e.NewElement.Minimum;
                    Control.Maximum = e.NewElement.Maximum;
                    Control.Value   = e.NewElement.Value;
                    Control.IsThumbToolTipEnabled = false;

                    slider.ValueChanged += OnNativeValueChanged;

                    defaultforegroundcolor = slider.Foreground;
                    defaultbackgroundcolor = slider.Background;

                    // Even when using Center/CenterAndExpand, a Slider has an oddity where it looks
                    // off-center in its layout by a smidge. The default templates are slightly different
                    // between 8.1/UWP; the 8.1 rows are 17/Auto/32 and UWP are 18/Auto/18. The value of
                    // the hardcoded 8.1 rows adds up to 49 (when halved is 24.5) and UWP are 36 (18). Using
                    // a difference of about 6 pixels to correct this oddity seems to make them both center
                    // more correctly.
                    //
                    // The VerticalAlignment needs to be set as well since a control would not actually be
                    // centered if a larger HeightRequest is set.
                    if (Element.VerticalOptions.Alignment == LayoutAlignment.Center && Control.Orientation == Windows.UI.Xaml.Controls.Orientation.Horizontal)
                    {
                        Control.VerticalAlignment = VerticalAlignment.Center;

                        slider.Margin = new Windows.UI.Xaml.Thickness(0, 7, 0, 0);
                    }

                    _pointerPressedHandler  = new PointerEventHandler(OnPointerPressed);
                    _pointerReleasedHandler = new PointerEventHandler(OnPointerReleased);

                    Control.AddHandler(PointerPressedEvent, _pointerPressedHandler, true);
                    Control.AddHandler(PointerReleasedEvent, _pointerReleasedHandler, true);
                    Control.AddHandler(PointerCanceledEvent, _pointerReleasedHandler, true);
                }

                double stepping = Math.Min((e.NewElement.Maximum - e.NewElement.Minimum) / 1000, 1);
                Control.StepFrequency = stepping;
                Control.SmallChange   = stepping;
                UpdateFlowDirection();
                UpdateSliderColors();
            }
        }
예제 #19
0
        public BulletNPC(Position basePosition, double angle, int x, int y): base(x, y)
        {
            this.basePosition = basePosition;
            this.angle = angle;

            this.image = new BitmapImage();
            this.brush = setBrush();
            this.Size = 20;
        }
 private void lstColorPalette_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     ColorPickerBrush objColor = (ColorPickerBrush)lstColorPalette.SelectedItem;
     if (ColorSelectedEvent != null)
     {
         SelectedColor = objColor.ColorBrush;
         ColorSelectedEvent(this, EventArgs.Empty);
     }
 }
예제 #21
0
 public MainPage()
 {
     this.InitializeComponent();
     currentRatio = AspectRatioType.ratio_4_3;
     selectedBrush = new SolidColorBrush(Windows.UI.Colors.CadetBlue);
     unselectedBrush = new SolidColorBrush(Windows.UI.Colors.DarkGray);
     updateButtons();
     updateRightText();
 }
예제 #22
0
        public static void SetForeground(this FrameworkElement element, WBrush foregroundBrush)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            element.SetValue(GetForegroundProperty(element), foregroundBrush);
        }
 public MarkdownTable(int columnCount, int rowCount, double borderThickness, Brush borderBrush)
 {
     this.columnCount = columnCount;
     this.rowCount = rowCount;
     this.borderThickness = borderThickness;
     for (int col = 0; col < columnCount + 1; col++)
         Children.Add(new Rectangle { Fill = borderBrush });
     for (int row = 0; row < rowCount + 1; row++)
         Children.Add(new Rectangle { Fill = borderBrush });
 }
예제 #24
0
        public static Color ToEtoColor(this swm.Brush brush)
        {
            var solidBrush = brush as swm.SolidColorBrush;

            if (solidBrush != null)
            {
                return(solidBrush.Color.ToEto());
            }
            return(Colors.Transparent);
        }
예제 #25
0
파일: Album.cs 프로젝트: JulianMH/music-3
 public async void LoadCover()
 {
     var cover = await library.GetAlbumCoverForSong(this.Name, this.Artist);
     if (cover != null)
     {
         var bitmapImage = new BitmapImage(new Uri(cover));
         loadedCover = new ImageBrush() { ImageSource = bitmapImage, Stretch = Stretch.UniformToFill };
         NotifyPropertyChanged("AlbumCover");
     }
 }
 public void Attach(DependencyObject associatedObject)
 {
   AssociatedObject = associatedObject;
   _shape = associatedObject as Shape;
   if (_shape != null)
   {
     _originalFillBrush = _shape.Fill;
     Messenger.Default.Register<DataReceivedMessage>(this, OnDateReceivedMessage);
   }
 }
예제 #27
0
 public Page_AddEditContact()
 {
     InitializeComponent();
     Suggestions = new ObservableCollection<string>();
     //this.KeyDown += Page_AddEditContact_KeyDown;
     //Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
     //this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
     defaultBackground = GridAddEditContact.Background;
     listGroup_EF = dbController.GetAllGroups_EF();
     addressBook = UC_AddressBook.Instance;
 }
예제 #28
0
        void ControlOnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            WireUpFormsVsm();

            // The defaults from the control template won't be available
            // right away; we have to wait until after the template has been applied
            _defaultBrush      = Control.Foreground;
            _defaultFontFamily = Control.FontFamily;
            UpdateFont();
            UpdateTextColor();
        }
예제 #29
0
        public static D2D.Brush ToD2DBrush(this Media.Brush brush, global::SharpDX.Direct2D1.RenderTarget target)
        {
            if (brush is Media.SolidColorBrush solid)
            {
                return(new global::SharpDX.Direct2D1.SolidColorBrush(target, solid.Color.ToColor4()));
            }
            else if (brush is Media.LinearGradientBrush linear)
            {
                return(new D2D.LinearGradientBrush(target,
                                                   new D2D.LinearGradientBrushProperties()
                {
                    StartPoint = linear.StartPoint.ToVector2(), EndPoint = linear.EndPoint.ToVector2()
                },
                                                   new D2D.GradientStopCollection
                                                   (
                                                       target,
                                                       linear.GradientStops.Select(x => new D2D.GradientStop()
                {
                    Color = x.Color.ToColor4(), Position = (float)x.Offset
                }).ToArray(),
                                                       linear.ColorInterpolationMode.ToD2DColorInterpolationMode(),
                                                       linear.SpreadMethod.ToD2DExtendMode()
                                                   )
                                                   ));
            }
#if NETFX_CORE || WINUI
#else
            else if (brush is Media.RadialGradientBrush radial)
            {
                return(new D2D.RadialGradientBrush(target,
                                                   new D2D.RadialGradientBrushProperties()
                {
                    Center = radial.Center.ToVector2(),
                    GradientOriginOffset = radial.GradientOrigin.ToVector2(),
                    RadiusX = (float)radial.RadiusX,
                    RadiusY = (float)radial.RadiusY
                },
                                                   new D2D.GradientStopCollection
                                                   (
                                                       target,
                                                       radial.GradientStops.Select(x => new D2D.GradientStop()
                {
                    Color = x.Color.ToColor4(), Position = (float)x.Offset
                }).ToArray(),
                                                       radial.ColorInterpolationMode.ToD2DColorInterpolationMode(),
                                                       radial.SpreadMethod.ToD2DExtendMode()
                                                   )));
            }
#endif
            else
            {
                throw new NotImplementedException("Brush does not support yet.");
            }
        }
        public StyleUserControl(Brush brush)
        {
            this.InitializeComponent();
            Style style = (Style)Resources["PolylineItemStyle"];
            //ControlTemplate ct = (ControlTemplate)Resources["ControlT"];

            //ct.TargetType = typeof(MapItem);
            MapPolyline mp = new MapPolyline();

            //style.
        }
예제 #31
0
 public NavigatorNode(
     int index,
     string name,
     ICommand action,
     Brush background,
     bool isLast,
     IEnumerable<string> itemList)
     : this(index, name, action, background, isLast)
 {
     ItemList = itemList;
 }
 public GameControl()
 {
     dispatcherTimer = new DispatcherTimer();
     dispatcherTimer.Tick += OnTimer;
     dispatcherTimer.Interval = TimeSpan.FromMilliseconds(100);
     this.InitializeComponent();
     originalTextColor = WhitePlayer.Foreground;
     DrawPieces(true);
     foreach (ChessPieceColor pieceColor in Enum.GetValues(typeof(ChessPieceColor)))
         foreach (ChessPieceType pieceType in Enum.GetValues(typeof(ChessPieceType)))
             SetChessPieceCount(pieceColor, pieceType, 0);
 }
예제 #33
0
 void SetDefaultSwitchColor()
 {
     if (_defaultOnColor == null && Cell is SwitchCell)
     {
         var nativeSwitch = FrameworkElementExtensions.GetFirstDescendant <ToggleSwitch>(this);
         var rects        = nativeSwitch.GetDescendantsByName <Windows.UI.Xaml.Shapes.Rectangle>("SwitchKnobBounds");
         foreach (var rect in rects)
         {
             _defaultOnColor = rect.Fill;
         }
         UpdateOnColor();
     }
 }
        private Rectangle Hand(double width, double height,
                Brush background, double radiusX, double radiusY, double thickness)
        {
            Rectangle hand = new Rectangle();
            hand.Width = width;
            hand.Height = height;
            hand.Fill = background;
            hand.StrokeThickness = thickness;
            hand.RadiusX = radiusX;
            hand.RadiusY = radiusY;

            return hand;
        }
예제 #35
0
 private void LoadTheme()
 {
     Accent1 = new Color() { R = 204, G = 204, B = 204, A = 255 };
     Accent1Brush = new SolidColorBrush(Accent1);
     Accent1Contrast = Colors.Black;
     Accent1ContrastBrush = new SolidColorBrush(Colors.Black);
     Accent2 = new Color() { R = 133, G = 133, B = 133, A = 255 };
     Accent2Brush = new SolidColorBrush(Accent2);
     Accent3 = Accent1;
     Accent3Brush = new SolidColorBrush(Accent1);
     Accent4 = new Color() { R = 230, G = 230, B = 230, A = 255 };
     Accent4Brush = new SolidColorBrush(Accent4);
 }
예제 #36
0
 public NavigatorNode(
     int index,
     string name,
     ICommand action,
     Brush background,
     bool isLast)
 {
     NodeIndex = index;
     NodeName = name;
     NodeAction = action;
     Background = background;
     IsLast = isLast;
 }
예제 #37
0
        public static swm.Brush ToWpfBrush(this Color value, swm.Brush brush = null)
        {
            var solidBrush = brush as swm.SolidColorBrush;

            if (solidBrush == null
#if TODO_XAML
                || solidBrush.IsSealed
#endif
                )
            {
                solidBrush = new swm.SolidColorBrush();
            }
            solidBrush.Color = value.ToWpf();
            return(solidBrush);
        }
예제 #38
0
        void UpdateButtonBackgroundColor(Color value)
        {
            WBrush brush = value.ToBrush();

            _minus = GetTemplateChild("Minus") as Windows.UI.Xaml.Controls.Button;
            _plus  = GetTemplateChild("Plus") as Windows.UI.Xaml.Controls.Button;
            if (_minus != null)
            {
                _minus.Background = brush;
            }
            if (_plus != null)
            {
                _plus.Background = brush;
            }
        }
예제 #39
0
 private void buttonGreen_Click(object sender, RoutedEventArgs e)
 {
     bitmask  = 0x02;
     ledGreen = !ledGreen;
     if (ledGreen)
     {
         ledGreenDefault        = buttonGreen.Background;
         buttonGreen.Background = new SolidColorBrush(Colors.YellowGreen);
         ioStatus |= bitmask;
     }
     else
     {
         buttonGreen.Background = ledGreenDefault;
         ioStatus &= (byte)~bitmask;
     }
     sensor.WriteValue(new byte[] { ioStatus &= 0x07 });
 }
예제 #40
0
        byte bitmask = 0; // Work bit

        private void buttonRed_Click(object sender, RoutedEventArgs e)
        {
            bitmask = 0x01;
            ledRed  = !ledRed;
            if (ledRed)
            {
                ledRedDefault        = buttonRed.Background;
                buttonRed.Background = new SolidColorBrush(Colors.Pink);
                ioStatus            |= bitmask;
            }
            else
            {
                buttonRed.Background = ledRedDefault;
                ioStatus            &= (byte)~bitmask;
            }
            sensor.WriteValue(new byte[] { ioStatus &= 0x07 });
        }
예제 #41
0
 public static Windows.UI.Xaml.Media.Brush GetViewIllustratorForce()
 {
     Windows.UI.Xaml.Media.Brush brush = null;
     brush = new Windows.UI.Xaml.Media.SolidColorBrush()
     {
         Color   = Color.FromArgb(0xFF, 0x00, 0x00, 0x00),
         Opacity = OperatingData.AcrylicOpacity
     };
     //switch (OperatingData._Theme)
     //{
     //    case KXTDataStruct._Interface_Theme._Green_:
     //        brush = new Windows.UI.Xaml.Media.SolidColorBrush()
     //        {
     //            Color = Color.FromArgb(0x7F, 0xAF, 0xF0, 0x00),
     //            Opacity = OperatingData.AcrylicOpacity
     //        };
     //        break;
     //    case KXTDataStruct._Interface_Theme._Red_:
     //        brush = new Windows.UI.Xaml.Media.SolidColorBrush()
     //        {
     //            Color = Color.FromArgb(0xFF, 0xF0, 0xA9, 0xFF),
     //            Opacity = OperatingData.AcrylicOpacity
     //        };
     //        break;
     //    case KXTDataStruct._Interface_Theme._White_:
     //        brush = new Windows.UI.Xaml.Media.SolidColorBrush()
     //        {
     //            Color = Color.FromArgb(0xFF, 0xCC, 0xCC, 0xCC),
     //            Opacity = OperatingData.AcrylicOpacity
     //        };
     //        break;
     //    case KXTDataStruct._Interface_Theme._Default_:
     //        brush = new Windows.UI.Xaml.Media.SolidColorBrush()
     //        {
     //            Color = Color.FromArgb(0xFF, 0x66, 0xCC, 0xFF),
     //            Opacity = OperatingData.AcrylicOpacity
     //        };
     //        break;
     //}
     return(brush);
 }
예제 #42
0
        public static D2D.Brush ToSharpDX(
            this Jupiter.Media.Brush brush,
            D2D.RenderTarget renderTarget,
            RectangleF rect)
        {
            if (brush == null)
            {
                return(null);
            }

            var solidColorBrush = brush as Jupiter.Media.SolidColorBrush;

            if (solidColorBrush != null)
            {
                var color = solidColorBrush.Color.ToSharpDX();

                return(new D2D.SolidColorBrush(
                           renderTarget,
                           color));
            }

            var linearGradientBrush = brush as Jupiter.Media.LinearGradientBrush;

            if (linearGradientBrush != null)
            {
                var properties = new D2D.LinearGradientBrushProperties();
                //properties.StartPoint =
                //    new DrawingPointF(
                //        (float)(linearGradientBrush.StartPoint.X * renderTarget.Size.Width),
                //        (float)(linearGradientBrush.StartPoint.Y * renderTarget.Size.Height));
                //properties.EndPoint =
                //    new DrawingPointF(
                //        (float)(linearGradientBrush.EndPoint.X * renderTarget.Size.Width),
                //        (float)(linearGradientBrush.EndPoint.Y * renderTarget.Size.Height));
                properties.StartPoint =
                    new DrawingPointF(
                        rect.Left + (float)(linearGradientBrush.StartPoint.X * rect.Width),
                        rect.Top + (float)(linearGradientBrush.StartPoint.Y * rect.Height));
                properties.EndPoint =
                    new DrawingPointF(
                        rect.Left + (float)(linearGradientBrush.EndPoint.X * rect.Width),
                        rect.Top + (float)(linearGradientBrush.EndPoint.Y * rect.Height));

                var brushProperties = new D2D.BrushProperties();

                brushProperties.Opacity = (float)linearGradientBrush.Opacity;

                if (linearGradientBrush.Transform != null)
                {
                    brushProperties.Transform = linearGradientBrush.Transform.ToSharpDX();
                }

                var gradientStopCollection = linearGradientBrush.GradientStops.ToSharpDX(renderTarget);

                return(new D2D.LinearGradientBrush(
                           renderTarget,
                           properties,
                           //brushProperties,
                           gradientStopCollection));
            }

            //var imageBrush = brush as Jupiter.Media.ImageBrush;

            //if (imageBrush != null)
            //{
            //    var writeableBitmap = imageBrush.ImageSource as WriteableBitmap;
            //    var bitmapImage = imageBrush.ImageSource as BitmapImage;

            //    if (bitmapImage != null)
            //    {
            //        writeableBitmap =
            //            await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(bitmapImage);
            //    }
            //    CompositionEngine c;

            //    return new D2D.BitmapBrush(
            //        renderTarget,
            //        writeableBitmap.ToSharpDX(),
            //}

#if DEBUG
            throw new NotSupportedException("Only SolidColorBrush supported for now");
#else
            return(new D2D.SolidColorBrush(renderTarget, Color.Transparent));
#endif
        }
예제 #43
0
        public static Windows.UI.Xaml.Media.Brush GetViewBackground()
        {
            Windows.UI.Xaml.Media.Brush brush = null;
            if (OperatingData.AcrylicModel)
            {
                switch (OperatingData._Theme)
                {
                case _Interface_Theme._Green_:
                    brush = new Windows.UI.Xaml.Media.AcrylicBrush()
                    {
                        BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop,
                        TintOpacity      = OperatingData.AcrylicOpacity,
                        TintColor        = Color.FromArgb(0x7F, 0xAF, 0xF0, 0x00),
                        FallbackColor    = Color.FromArgb(0x7F, 0xAF, 0xF0, 0x00)
                    };
                    break;

                case _Interface_Theme._Red_:
                    brush = new Windows.UI.Xaml.Media.AcrylicBrush()
                    {
                        BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop,
                        TintOpacity      = OperatingData.AcrylicOpacity,
                        TintColor        = Color.FromArgb(0xFF, 0xF0, 0xA9, 0xFF),
                        FallbackColor    = Color.FromArgb(0xFF, 0xF0, 0xA9, 0xFF)
                    };
                    break;

                case _Interface_Theme._White_:
                    brush = new Windows.UI.Xaml.Media.AcrylicBrush()
                    {
                        BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop,
                        TintOpacity      = OperatingData.AcrylicOpacity,
                        TintColor        = Color.FromArgb(0xFF, 0xCC, 0xCC, 0xCC),
                        FallbackColor    = Color.FromArgb(0xFF, 0xCC, 0xCC, 0xCC)
                    };
                    break;

                case _Interface_Theme._Default_:
                    brush = new Windows.UI.Xaml.Media.AcrylicBrush()
                    {
                        BackgroundSource = Windows.UI.Xaml.Media.AcrylicBackgroundSource.HostBackdrop,
                        TintOpacity      = OperatingData.AcrylicOpacity,
                        TintColor        = Color.FromArgb(0xFF, 0x66, 0xCC, 0xFF),
                        FallbackColor    = Color.FromArgb(0xFF, 0x66, 0xCC, 0xFF)
                    };
                    break;
                }
            }
            else
            {
                switch (OperatingData._Theme)
                {
                case _Interface_Theme._Green_:
                    brush = new Windows.UI.Xaml.Media.SolidColorBrush()
                    {
                        Color   = Color.FromArgb(0x7F, 0xAF, 0xF0, 0x00),
                        Opacity = OperatingData.AcrylicOpacity
                    };
                    break;

                case _Interface_Theme._Red_:
                    brush = new Windows.UI.Xaml.Media.SolidColorBrush()
                    {
                        Color   = Color.FromArgb(0xFF, 0xF0, 0xA9, 0xFF),
                        Opacity = OperatingData.AcrylicOpacity
                    };
                    break;

                case _Interface_Theme._White_:
                    brush = new Windows.UI.Xaml.Media.SolidColorBrush()
                    {
                        Color   = Color.FromArgb(0xFF, 0xCC, 0xCC, 0xCC),
                        Opacity = OperatingData.AcrylicOpacity
                    };
                    break;

                case _Interface_Theme._Default_:
                    brush = new Windows.UI.Xaml.Media.SolidColorBrush()
                    {
                        Color   = Color.FromArgb(0xFF, 0x66, 0xCC, 0xFF),
                        Opacity = OperatingData.AcrylicOpacity
                    };
                    break;
                }
            }
            return(brush);
        }
예제 #44
0
        public object ConvertToNative(Brush brush, object context)
        {
            winMedia.Brush winBrush = null;

            // SolidColorBrush
            if (brush is SolidColorBrush)
            {
                SolidColorBrush xamBrush = brush as SolidColorBrush;

                winBrush = new winMedia.SolidColorBrush
                {
                    Color = ConvertColor(xamBrush.Color)
                };
            }

            // LinearGradientBrush
            else if (brush is LinearGradientBrush)
            {
                LinearGradientBrush xamBrush = brush as LinearGradientBrush;

                winBrush = new winMedia.LinearGradientBrush
                {
                    StartPoint   = ConvertPoint(xamBrush.StartPoint),
                    EndPoint     = ConvertPoint(xamBrush.EndPoint),
                    SpreadMethod = ConvertGradientSpread(xamBrush.SpreadMethod)
                };

                foreach (GradientStop xamGradientStop in xamBrush.GradientStops)
                {
                    winMedia.GradientStop winGradientStop = new winMedia.GradientStop
                    {
                        Color  = ConvertColor(xamGradientStop.Color),
                        Offset = xamGradientStop.Offset
                    };

                    (winBrush as winMedia.LinearGradientBrush).GradientStops.Add(winGradientStop);
                }
            }

            else if (brush is ImageBrush)
            {
                ImageBrush xamBrush = brush as ImageBrush;

                winBrush = new winMedia.ImageBrush
                {
                    Stretch    = (winMedia.Stretch)(int) xamBrush.Stretch,
                    AlignmentX = (winMedia.AlignmentX)(int) xamBrush.AlignmentX,
                    AlignmentY = (winMedia.AlignmentY)(int) xamBrush.AlignmentY,
                };

                ImageSource xamImageSource = (brush as ImageBrush).ImageSource;

                if (xamImageSource != null)
                {
                    IImageSourceHandler handler = null;

                    if (xamImageSource.GetType() == typeof(FileImageSource))
                    {
                        handler = new FileImageSourceHandler();
                    }
                    else if (xamImageSource.GetType() == typeof(StreamImageSource))
                    {
                        handler = new StreamImageSourceHandler();
                    }
                    else if (xamImageSource.GetType() == typeof(UriImageSource))
                    {
                        handler = new UriImageSourceHandler();
                    }

                    if (handler != null)
                    {
                        Task <winMedia.ImageSource> winImageSourceTask = handler.LoadImageAsync(xamImageSource);

                        winImageSourceTask.ContinueWith((task) =>
                        {
                            winFound.IAsyncAction asyncAction = winBrush.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                            {
                                (winBrush as winMedia.ImageBrush).ImageSource = task.Result;
                            });
                        });
                    }
                }
            }

            if (winBrush != null)
            {
                winBrush.Transform = brush.Transform?.GetNativeObject() as winMedia.MatrixTransform;

                // TODO: RelativeTransform and Opacity
            }

            return(winBrush);
        }
        public static D2D.Brush ToD2DBrush(this Media.Brush brush, global::SharpDX.Vector2 renderSize, D2D.RenderTarget renderTarget)
        {
            if (brush == null)
            {
                return(null);
            }

            if (brush is Media.SolidColorBrush solid)
            {
                return(new D2D.SolidColorBrush(renderTarget, solid.Color.ToColor4()));
            }
            else if (brush is Media.LinearGradientBrush linear)
            {
                var brushProperties = new D2D.LinearGradientBrushProperties()
                {
                    StartPoint = linear.StartPoint.ToVector2(),
                    EndPoint   = linear.EndPoint.ToVector2()
                };

                if (linear.MappingMode == Media.BrushMappingMode.RelativeToBoundingBox)
                {
                    Point strtPoint = new Point(linear.StartPoint.X * renderSize.X, linear.StartPoint.Y * renderSize.Y);
                    Point endPoint  = new Point(linear.EndPoint.X * renderSize.X, linear.EndPoint.Y * renderSize.Y);
                    brushProperties.StartPoint = strtPoint.ToVector2();
                    brushProperties.EndPoint   = endPoint.ToVector2();
                }

                return(new D2D.LinearGradientBrush(renderTarget,
                                                   brushProperties,
                                                   new D2D.GradientStopCollection
                                                   (
                                                       renderTarget,
                                                       linear.GradientStops.Select(x => new D2D.GradientStop()
                {
                    Color = x.Color.ToColor4(), Position = (float)x.Offset
                }).ToArray(),
                                                       linear.ColorInterpolationMode.ToD2DColorInterpolationMode(),
                                                       linear.SpreadMethod.ToD2DExtendMode()
                                                   )
                                                   ));
            }
#if NETFX_CORE
#else
            else if (brush is Media.RadialGradientBrush radial)
            {
                var brushProperties = new D2D.RadialGradientBrushProperties()
                {
                    Center = radial.Center.ToVector2(),
                    GradientOriginOffset = radial.GradientOrigin.ToVector2(),
                    RadiusX = (float)radial.RadiusX,
                    RadiusY = (float)radial.RadiusY
                };

                if (radial.MappingMode == Media.BrushMappingMode.RelativeToBoundingBox)
                {
                    Point center = new Point(radial.Center.X * renderSize.X, radial.Center.Y * renderSize.Y);
                    Point gradientOriginOffset = new Point((radial.GradientOrigin.X - 0.5) * renderSize.X, (radial.GradientOrigin.Y - 0.5) * renderSize.Y);
                    brushProperties.Center = center.ToVector2();
                    brushProperties.GradientOriginOffset = gradientOriginOffset.ToVector2();
                    brushProperties.RadiusX = (float)(renderSize.X * radial.RadiusX);
                    brushProperties.RadiusY = (float)(renderSize.Y * radial.RadiusY);
                }

                return(new D2D.RadialGradientBrush(renderTarget,
                                                   brushProperties,
                                                   new D2D.GradientStopCollection
                                                   (
                                                       renderTarget,
                                                       radial.GradientStops.Select(x => new D2D.GradientStop()
                {
                    Color = x.Color.ToColor4(), Position = (float)x.Offset
                }).ToArray(),
                                                       radial.ColorInterpolationMode.ToD2DColorInterpolationMode(),
                                                       radial.SpreadMethod.ToD2DExtendMode()
                                                   )));
            }
#endif
            else
            {
                throw new NotImplementedException("Brush does not support yet.");
            }
        }
예제 #46
0
        public static async Task <D2D.Brush> ToSharpDX(
            this Jupiter.Media.Brush brush,
            D2D.RenderTarget renderTarget,
            RectangleF rect)
        {
            if (brush == null)
            {
                return(null);
            }

            var solidColorBrush = brush as Jupiter.Media.SolidColorBrush;

            if (solidColorBrush != null)
            {
                var color = solidColorBrush.Color.ToSharpDX();

                return(new D2D.SolidColorBrush(
                           renderTarget,
                           color,
                           new D2D.BrushProperties
                {
                    Opacity = (float)solidColorBrush.Opacity
                }));
            }

            var linearGradientBrush = brush as Jupiter.Media.LinearGradientBrush;

            if (linearGradientBrush != null)
            {
                var properties = new D2D.LinearGradientBrushProperties();
                //properties.StartPoint =
                //    new Vector2(
                //        (float)(linearGradientBrush.StartPoint.X * renderTarget.Size.Width),
                //        (float)(linearGradientBrush.StartPoint.Y * renderTarget.Size.Height));
                //properties.EndPoint =
                //    new Vector2(
                //        (float)(linearGradientBrush.EndPoint.X * renderTarget.Size.Width),
                //        (float)(linearGradientBrush.EndPoint.Y * renderTarget.Size.Height));
                properties.StartPoint =
                    new Vector2(
                        rect.Left + (float)(linearGradientBrush.StartPoint.X * rect.Width),
                        rect.Top + (float)(linearGradientBrush.StartPoint.Y * rect.Height));
                properties.EndPoint =
                    new Vector2(
                        rect.Left + (float)(linearGradientBrush.EndPoint.X * rect.Width),
                        rect.Top + (float)(linearGradientBrush.EndPoint.Y * rect.Height));

                var brushProperties = new D2D.BrushProperties();

                brushProperties.Opacity = (float)linearGradientBrush.Opacity;

                if (linearGradientBrush.Transform != null)
                {
                    brushProperties.Transform = linearGradientBrush.Transform.ToSharpDX();
                }

                var gradientStopCollection = linearGradientBrush.GradientStops.ToSharpDX(renderTarget);

                return(new D2D.LinearGradientBrush(
                           renderTarget,
                           properties,
                           brushProperties,
                           gradientStopCollection));
            }

            var imageBrush = brush as Jupiter.Media.ImageBrush;

            if (imageBrush != null)
            {
                var bitmap = await imageBrush.ImageSource.ToSharpDX(renderTarget);

                var       w         = bitmap.PixelSize.Width;
                var       h         = bitmap.PixelSize.Height;
                Matrix3x2 transform = Matrix3x2.Identity;

                switch (imageBrush.Stretch)
                {
                case Stretch.None:
                    transform.M31 += rect.Left + rect.Width * 0.5f - w / 2;
                    transform.M32 += rect.Top + rect.Height * 0.5f - h / 2;
                    break;

                case Stretch.Fill:
                    transform = Matrix3x2.Scaling(
                        rect.Width / w,
                        rect.Height / h);
                    transform.M31 += rect.Left;
                    transform.M32 += rect.Top;
                    break;

                case Stretch.Uniform:
                    var bitmapAspectRatio  = (float)w / h;
                    var elementAspectRatio = rect.Width / rect.Height;

                    if (bitmapAspectRatio > elementAspectRatio)
                    {
                        var scale = rect.Width / w;
                        transform      = Matrix3x2.Scaling(scale);
                        transform.M31 += rect.Left;
                        transform.M32 += rect.Top + rect.Height * 0.5f - scale * h / 2;
                    }
                    else     // (elementAspectRatio >= bitmapAspectRatio)
                    {
                        var scale = rect.Height / h;
                        transform      = Matrix3x2.Scaling(scale);
                        transform.M31 += rect.Left + rect.Width * 0.5f - scale * w / 2;
                        transform.M32 += rect.Top;
                    }

                    break;

                case Stretch.UniformToFill:
                    var bitmapAspectRatio2  = (float)w / h;
                    var elementAspectRatio2 = rect.Width / rect.Height;

                    if (bitmapAspectRatio2 > elementAspectRatio2)
                    {
                        var scale = rect.Height / h;
                        transform      = Matrix3x2.Scaling(scale);
                        transform.M31 += rect.Left + rect.Width * 0.5f - scale * w / 2;
                        transform.M32 += rect.Top;
                    }
                    else     // (elementAspectRatio >= bitmapAspectRatio)
                    {
                        var scale = rect.Width / w;
                        transform      = Matrix3x2.Scaling(scale);
                        transform.M31 += rect.Left;
                        transform.M32 += rect.Top + rect.Height * 0.5f - scale * h / 2;
                    }

                    break;
                }


                return(new D2D.BitmapBrush1(
                           (D2D.DeviceContext)renderTarget,
                           bitmap,
                           new D2D.BitmapBrushProperties1
                {
                    ExtendModeX = D2D.ExtendMode.Clamp,
                    ExtendModeY = D2D.ExtendMode.Clamp,
                    InterpolationMode = D2D.InterpolationMode.HighQualityCubic
                })
                {
                    Opacity = (float)imageBrush.Opacity,
                    Transform = transform
                });
                //    var writeableBitmap = imageBrush.ImageSource as WriteableBitmap;
                //    var bitmapImage = imageBrush.ImageSource as BitmapImage;

                //    if (bitmapImage != null)
                //    {
                //        writeableBitmap =
                //            await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(bitmapImage);
                //    }
                //    CompositionEngine c;

                //    return new D2D.BitmapBrush(
                //        renderTarget,
                //        writeableBitmap.ToSharpDX(),
                //}
            }

#if DEBUG
            throw new NotSupportedException("Only SolidColorBrush supported for now");
#else
            return(new D2D.SolidColorBrush(renderTarget, Color.Transparent));
#endif
        }
예제 #47
0
        public static string GetColorAutomationName(Windows.UI.Xaml.Media.Brush brush)
        {
            var resourceLoader = AppResourceProvider.GetInstance();
            var color          = ((SolidColorBrush)brush);

            var lightDictionary = (ResourceDictionary)(Application.Current.Resources.ThemeDictionaries["Light"]);
            var darkDictionary  = (ResourceDictionary)(Application.Current.Resources.ThemeDictionaries["Default"]);
            var highContrast    = (ResourceDictionary)(Application.Current.Resources.ThemeDictionaries["HighContrast"]);

            if (color == (SolidColorBrush)(lightDictionary["EquationBrush1"]) ||
                color == (SolidColorBrush)(darkDictionary["EquationBrush1"]))
            {
                return(resourceLoader.GetResourceString("equationColor1AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush2"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush2"]))
            {
                return(resourceLoader.GetResourceString("equationColor2AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush3"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush3"]))
            {
                return(resourceLoader.GetResourceString("equationColor3AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush4"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush4"]))
            {
                return(resourceLoader.GetResourceString("equationColor4AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush5"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush5"]))
            {
                return(resourceLoader.GetResourceString("equationColor5AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush6"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush6"]))
            {
                return(resourceLoader.GetResourceString("equationColor6AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush7"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush7"]))
            {
                return(resourceLoader.GetResourceString("equationColor7AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush8"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush8"]))
            {
                return(resourceLoader.GetResourceString("equationColor8AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush9"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush9"]))
            {
                return(resourceLoader.GetResourceString("equationColor9AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush10"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush10"]))
            {
                return(resourceLoader.GetResourceString("equationColor10AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush11"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush11"]))
            {
                return(resourceLoader.GetResourceString("equationColor11AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush12"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush12"]))
            {
                return(resourceLoader.GetResourceString("equationColor12AutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush13"]) ||
                     color == (SolidColorBrush)(darkDictionary["EquationBrush13"]))
            {
                return(resourceLoader.GetResourceString("equationColor13AutomationName"));
            }
            else if (color == (SolidColorBrush)(darkDictionary["EquationBrush14"]))
            {
                return(resourceLoader.GetResourceString("equationColor14WhiteAutomationName"));
            }
            else if (color == (SolidColorBrush)(lightDictionary["EquationBrush14"]))
            {
                return(resourceLoader.GetResourceString("equationColor14BlackAutomationName"));
            }
            else if (color == (SolidColorBrush)(highContrast["EquationBrush1"]))
            {
                return(resourceLoader.GetResourceString("equationHighContrastColor1AutomationName"));
            }
            else if (color == (SolidColorBrush)(highContrast["EquationBrush2"]))
            {
                return(resourceLoader.GetResourceString("equationHighContrastColor2AutomationName"));
            }
            else if (color == (SolidColorBrush)(highContrast["EquationBrush3"]))
            {
                return(resourceLoader.GetResourceString("equationHighContrastColor3AutomationName"));
            }
            else
            {
                return(resourceLoader.GetResourceString("equationHighContrastColor4AutomationName"));
            }
        }